These are some really awesome tutorials. But I still have recommendations for new tutorials: Multiblocks, possibly ISimpleBlockRenderingHelper or how to render an OBJ model when wearing armor. I would really love seeing this page compete with other tutorial pages like bedrockminer's, greyminecraftghost's or wuppy's because its really well, simple and to-the-point written. I like the formatting, too.
Greetings
Michal
PS.: Are all blocks in the placable items mod TileEntites just to use TESRs?
But I still wonder what the String argument in .getDynamicTextureLocation(String, DynamicTexture) is.
And I don't know what to do with the ResourceLocation if I don't use a TileEntity (There is tons of info on TileEntities). I am @Overriding the .registerBlockIcons method to register textures with my other blocks and doing
I'm trying to make several blocks with the same texture, but differently colored (or otherwise edited). I have one texture file containing only black pixels, but at different alpha levels. Then I use my utility class to load and apply the XOR filter (colorize it)
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.IOException;
public class ImageUtils
{
public static BufferedImage fromResourceLocation(ResourceLocation location)
{
BufferedImage img;
try
{
img = ImageIO.read(Minecraft.getMinecraft().getResourceManager().getResource(location).getInputStream());
} catch (IOException e)
{
e.printStackTrace();
img = null;
}
return img;
}
public static BufferedImage colorize(BufferedImage loadImg, int red, int green, int blue)
{
BufferedImage img = new BufferedImage(loadImg.getWidth(), loadImg.getHeight(), BufferedImage.TRANSLUCENT);
Graphics2D graphics = img.createGraphics();
Color newColor = new Color(red, green, blue, 0);
graphics.setXORMode(newColor);
graphics.drawImage(loadImg, null, 0, 0);
graphics.dispose();
return img;
}
public static BufferedImage colorize(BufferedImage loadImg, Color c)
{
return colorize(loadImg, c.getRed(), c.getGreen(), c.getBlue());
}
}
Now I call the .colorize and .fromResourceLocation method in every of my block classes, but with a different Color c.
So in each block class I have a BufferedImage containing the Texture I want to use for the block, but I don't know how.
I have done some research on this, read through some articles, but they seem either malfunctional or outdated. These two are the only ones that at least partially seem valid (although they aren't)
http://www.minecraftforge.net/forum/index.php?topic=9587.0: Probably outdated as well, because there is no method .allocateAndSetupTexture(), neither in Minecraft.getMinecraft().renderEngine, nor in FMLClientHandler.instance().getClient().renderEngine
That error actually isn't in my code (NetBeans would have corrected me if it was), I was rewriting that code instead of Copy&Pasting my original code.
I know of String.equals(String s) since Netbeans is bugging me with that all the time, I didn't know it was more efficient or whatever (just better). I will start replacing my '=='.
Thank you for the int-idea, since I am using a reference class to ensure the m.text string would be same on both sides it won't be too hard to use ints instead.
And just for your information, this is my actual "gateway class"
public class NetworkMessage
{
public static void onMessage(Message m, MessageContext ctx)
{
HeavenBossHandler.handleMessage(m, ctx);
//AnotherClass.handleMessage(m, ctx);
//...
}
}
And the separate classes would handle their stuff.
But following your recommendation, it will probably end up like this:
public class NetworkMessage
{
public static void onMessage(Message m, MessageContext ctx)
{
switch (m.id)
{
//The HeavenBossHandler class needs to handle both messages
case Reference.Network.Packet.ID_HEAVENBOSSHANDLER_RESETFALLDISTANCE:
HeavenBossHandler.handleMessage(m, ctx);
//FallDistanceResetter2.handleMessage(m, ctx);
case Reference.Network.Packet.ID_DIMENSIONHEAVEN_SETMOVEMENTINPUT:
HeavenBossHandler.handleMessage(m, ctx);
//MovementInputSetupNeeded.handleMessage(m,ctx);
default: {}
}
}
}
I still wonder if I should keep it like this and have the HeavenBossHandler run another switch statement, or have a method for each packet the class handles. But this is more efficient than my previous piece of code, since the classes don't get to handle what they don't need to handle.
And the last thing you recommended me I am thinking about, but what I have setup is something like this:
The classes in the event packages just have the @SubscribeEvent and are registered, and the hand out the event object to the classes in the handler package.
So the HeavenBossHandler looks like this:
public class HeavenBossHandler
{
private static int jumpKeyCooldown = 1;
public static void handleEvent(LivingEvent.LivingUpdateEvent event)
{
...
}
public static void handleEvent(InputEvent.KeyInputEvent event)
{
...
}
public static void handleMessage(Message m, MessageContext ctx)
{
switch (m.id)
{
case Reference.Network.Packet.ID_HEAVENBOSSHANDLER_RESETFALLDISTANCE:
//Reset Server Side Fall distance on ctx.getServerHandler().playerEntity
case Reference.Network.Packet.ID_HEAVENBOSSHANDLER_SETMOVEMENTINPUT:
//Set ClientSide Movement Input on Minecraft.getMinecraft().thePlayer()
}
}
}
As you can see I think of the NetworkMessage.java as of an event, which it in fact is, so I put it into the event package.
The same way the other events get called from forge/fml's respective busses, The NetworkMessage get's called from my Message.java class.
If you need to reference any other code I did not post here, please head to my github repo at https://github.com/HashtagShell/HashtagStuff . It is my first mod and I am learning on it, so it really has some random stuff (aka please don't be mad at me for making a semi-useless mod)
So I have a working packet handler and am sending packets just fine. That's not the thing.
But I have only two Packets registered, one for the client and for the server. What I am doing to actually send data with those two packets is something like this:
package com.github.hashtagshell.hashtagstuff.network.message;
import com.github.hashtagshell.hashtagstuff.handler.event.NetworkMessage;
import cpw.mods.fml.common.network.ByteBufUtils;
import cpw.mods.fml.common.network.simpleimpl.IMessage;
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
import io.netty.buffer.ByteBuf;
public class Message implements IMessage, IMessageHandler<Message, IMessage>
{
public String text;
public Message()
{
}
public Message(String text)
{
this.text = text;
}
@Override
public void fromBytes(ByteBuf buf)
{
text = ByteBufUtils.readUTF8String(buf);
}
@Override
public void toBytes(ByteBuf buf)
{
ByteBufUtils.writeUTF8String(buf, text);
}
@Override
public IMessage onMessage(Message m, MessageContext ctx)
{
NetworkMessage.onMessage(m, ctx);
return null;
}
}
EDIT: the NetworkMessage.java class is just a gateway that distributes the args to other classes(e.g. BossHandler.handleMessage(m, ctx))
and on the server side I do
public static void handleMessage(Message m, MessageContext ctx)
{
if (m.text="playerdidsomething")
{
//Do some stuff
}
}
Is it OK (and efficient) to use packets like this or should I create an extending class for each packet?
And then I need to know another thing. I am sending the packet every livingtick while the player is sneaking to the server, which then sets the players falldistance to 0F. Simple code, I know. But isn't this too much network traffic? If yes, how could I reduce it? Or is there another way to make the player take no falldmg while sneaking?
0
These are some really awesome tutorials. But I still have recommendations for new tutorials: Multiblocks, possibly ISimpleBlockRenderingHelper or how to render an OBJ model when wearing armor. I would really love seeing this page compete with other tutorial pages like bedrockminer's, greyminecraftghost's or wuppy's because its really well, simple and to-the-point written. I like the formatting, too.
Greetings
Michal
PS.: Are all blocks in the placable items mod TileEntites just to use TESRs?
0
Thanks very much. That did the trick.
Oh. I just realized the equality of your name and the class author's name. Well done!
Do I copy the class over to my project as a helper class or do I list the mod as dependency and use it as a library?
0
Hmmm... that makes sense. Thank you.
But I still wonder what the String argument in .getDynamicTextureLocation(String, DynamicTexture) is.
And I don't know what to do with the ResourceLocation if I don't use a TileEntity (There is tons of info on TileEntities). I am @Overriding the .registerBlockIcons method to register textures with my other blocks and doing
and minecraft loads the texture from /assests/MODID/textures/blocks/NAME and loads it by itself.
I don't see a way to use this in conjunction with ResourceLocation (, but I may be wrong)
-Michal
1
I'm trying to make several blocks with the same texture, but differently colored (or otherwise edited). I have one texture file containing only black pixels, but at different alpha levels. Then I use my utility class to load and apply the XOR filter (colorize it)
Now I call the .colorize and .fromResourceLocation method in every of my block classes, but with a different Color c.
So in each block class I have a BufferedImage containing the Texture I want to use for the block, but I don't know how.
I have done some research on this, read through some articles, but they seem either malfunctional or outdated. These two are the only ones that at least partially seem valid (although they aren't)
https://gist.github.com/thvortex/2138298: Created around 2011, last edited March 2012. Outdated.
http://www.minecraftforge.net/forum/index.php?topic=9587.0: Probably outdated as well, because there is no method .allocateAndSetupTexture(), neither in Minecraft.getMinecraft().renderEngine, nor in FMLClientHandler.instance().getClient().renderEngine
Thanks for any helpful information
-Michal
0
That error actually isn't in my code (NetBeans would have corrected me if it was), I was rewriting that code instead of Copy&Pasting my original code.
I know of String.equals(String s) since Netbeans is bugging me with that all the time, I didn't know it was more efficient or whatever (just better). I will start replacing my '=='.
Thank you for the int-idea, since I am using a reference class to ensure the m.text string would be same on both sides it won't be too hard to use ints instead.
And just for your information, this is my actual "gateway class"
And the separate classes would handle their stuff.
But following your recommendation, it will probably end up like this:
I still wonder if I should keep it like this and have the HeavenBossHandler run another switch statement, or have a method for each packet the class handles. But this is more efficient than my previous piece of code, since the classes don't get to handle what they don't need to handle.
And the last thing you recommended me I am thinking about, but what I have setup is something like this:
The classes in the event packages just have the @SubscribeEvent and are registered, and the hand out the event object to the classes in the handler package.
So the HeavenBossHandler looks like this:
As you can see I think of the NetworkMessage.java as of an event, which it in fact is, so I put it into the event package.
The same way the other events get called from forge/fml's respective busses, The NetworkMessage get's called from my Message.java class.
If you need to reference any other code I did not post here, please head to my github repo at https://github.com/HashtagShell/HashtagStuff . It is my first mod and I am learning on it, so it really has some random stuff (aka please don't be mad at me for making a semi-useless mod)
Thanks in advance
0
So I have a working packet handler and am sending packets just fine. That's not the thing.
But I have only two Packets registered, one for the client and for the server. What I am doing to actually send data with those two packets is something like this:
Where my Message.java is
EDIT: the NetworkMessage.java class is just a gateway that distributes the args to other classes(e.g. BossHandler.handleMessage(m, ctx))
and on the server side I do
Is it OK (and efficient) to use packets like this or should I create an extending class for each packet?
And then I need to know another thing. I am sending the packet every livingtick while the player is sneaking to the server, which then sets the players falldistance to 0F. Simple code, I know. But isn't this too much network traffic? If yes, how could I reduce it? Or is there another way to make the player take no falldmg while sneaking?
Thank you