OK, so I know that I can use metadata for the timer, because I've seen it done before, and I think it would be the easiest and least resource intensive. Secondly, I really would like to use different block for each state, since I'd have to use NBT data in recipes and stuff. I'll look into the max damage, because that sounds like what I'm looking for. It that what tools use for durability, and can it be used on blocks?
I didn't say you couldn't use metadata, i imagine you would set the block to require random update ticks, then add to the metadata in the onUpdate method if the conditions are correct.
Yes it is more or less what tools use to have a damage bar Items must have isDamagable true and maxStacksize = 1 the damage bar shows up once isDamaged returns true.
OK, if you want a block(sits in the world) that lights up and has a timer and takes fuel of and ignition event, you might want to be looking into TileEntities as you may want the MetaData for positioning or at the very least on state and off state (have the tile entity store everything else and just switch the blocks metadata to change state from on off).
If you want an Item you can carry round and that has a damage bar you might want to use NBTTagCompounds to store data (if it still requires fuel ect) otherwise just set a max damage and damage it onUpdateTick if its in the player current Itemslot
Thanks, that works perfectly! I know I said only one more question, but, I realize that I forgot to ask in the OP how to remove the item from your hand when you right click the torch IF it is not another torch. I can't find the method (or whatever it's called) to handle the players inventory.
Is there some place to find all of these events? Like a list or something?
Anyways if anyone knows how to do that, I think my problem will be completely solved.
It's all the the source which you can find in your IDE under Forge..... .jar
2. If I wanted to check if the player is holding a certain block, how would I do that? getBlock()? This code gives me the error, "The method getBlock() is undefined for the type ItemStack"
If you want to get a block from Item you should use if(Block.getBlockFromItem(player.inventory.getCurrentItem().getItem()) == Blocks.whatever_block)
OR
if(player.inventory.getCurrentItem().getItem() == Item.getItemFromBlock(Blocks.whatever_block)) to get Item from Block
sorry not sure what the 3 floats are but the integer will be Block Metadata
I have an Item which opens a GUI. the player can then press buttons in the GUI to adjust values which are then sent in packets to the server to update the items NBTTag with the new variables.
This works perfectly in single player mode but whenever in multiplayer only the hosting user can use the buttons on the GUI for anyone else they are kicked from the host and the host logs this
[01:18:00] [Server thread/INFO]: gurgis lost connection: TranslatableComponent{key='disconnect.genericReason', args=[Internal Exception: io.netty.handler.codec.DecoderException: java.io.IOException: The received string length is longer than maximum allowed (25 > 20)], siblings=[], style=Style{hasParent=false, color=null, bold=null, italic=null, underlined=null, obfuscated=null, clickEvent=null, hoverEvent=null}}
It may be because your using the vanilla crafting GUI... its canInteract method looks for a crafting block at the provided coords and checks the players distance relative to that point, so your split second of display time might just be the lag between you trying to open the GUI and this condition invariably testing false
0
I didn't say you couldn't use metadata, i imagine you would set the block to require random update ticks, then add to the metadata in the onUpdate method if the conditions are correct.
Yes it is more or less what tools use to have a damage bar Items must have isDamagable true and maxStacksize = 1 the damage bar shows up once isDamaged returns true.
0
OK, if you want a block(sits in the world) that lights up and has a timer and takes fuel of and ignition event, you might want to be looking into TileEntities as you may want the MetaData for positioning or at the very least on state and off state (have the tile entity store everything else and just switch the blocks metadata to change state from on off).
If you want an Item you can carry round and that has a damage bar you might want to use NBTTagCompounds to store data (if it still requires fuel ect) otherwise just set a max damage and damage it onUpdateTick if its in the player current Itemslot
1
if(player.capabilities.isCreativeMode)
0
It's all the the source which you can find in your IDE under Forge..... .jar
Decrease Stack size - player.inventory.decrStackSize(inventory slot, amount);
Get Current Items Inventory Slot - player.inventory.currentItem;
Decrease your ItemStack size by 1
player.inventory.decrStackSize(player.inventory.currentItem, 1);
1
Points to a variable you have to set up in your Main Class like this
@Mod(modid = Reference.MODID, name = Reference.NAME, version = Reference.VERSION)
public class YourMainClassName{
@Instance(Reference.MODID)
public static YourMainClassName instance;
@Mod.EventHandler
public void preInit(FMLPreInitializationEvent event){//init events below
1
If you want to get a block from Item you should use if(Block.getBlockFromItem(player.inventory.getCurrentItem().getItem()) == Blocks.whatever_block)
OR
if(player.inventory.getCurrentItem().getItem() == Item.getItemFromBlock(Blocks.whatever_block)) to get Item from Block
sorry not sure what the 3 floats are but the integer will be Block Metadata
0
Sure Tried to limit it to only relevant code
-open GUI
//In item class
@Override
public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player){
if(player.isSneaking()){
player.openGui(StructureMappingTool.instance, 219, player.worldObj, (int)player.posX, (int)player.posY, (int)player.posZ);
}}
//in Gui Handler getClientGuiElement
if(ID == 219){
NBTTagCompound tag = player.inventory.getCurrentItem().getTagCompound();
if(tag != null){
return new GuiBuildTool(tag);
}}
GUI Button Pressed
//In Gui
protected void actionPerformed(GuiButton button){
boolean send = false;
if (button.enabled){
//example of more or less what all my buttons do
if(button.id == 1){
iheight += value;
if(imode == 2 || imode == 3){
iheight += value;
iwidth += value;
}
send = true;
}}
if(send)PacketHandler.sendToServer(new BuildPacket(imode, iheight, iwidth, idir));
}
Packet Helper
public class PacketHandler {
private static byte packetId = 0;
private static final SimpleNetworkWrapper dispatcher = NetworkRegistry.INSTANCE.newSimpleChannel(Reference.MODID);
public static final void registerPackets(){
PacketHandler.registerMessage(BPacketHandler.class, BuildPacket.class, Side.SERVER);
}
private static final void registerMessage(Class handlerClass, Class messageClass, Side side) {
PacketHandler.dispatcher.registerMessage(handlerClass, messageClass, packetId++, side);
}
public static final void sendToServer(IMessage message) {
PacketHandler.dispatcher.sendToServer(message);
}
}
Packet/Handler
//Inherited by ServerPacket
@Override
public IMessage onMessage(T message, MessageContext ctx) {
if (ctx.side.isClient()) {
return handleClientMessage(StructureMappingTool.modProxy.getPlayerEntity(ctx), message, ctx);
} else {
return handleServerMessage(StructureMappingTool.modProxy.getPlayerEntity(ctx), message, ctx);
}}
public class BuildPacket implements IMessage{
int mode;
int height;
int width;
boolean direction;
public BuildPacket() {}
public BuildPacket(int m, int h, int w, boolean dir) {
this.mode = m;
this.height = h;
this.width = w;
this.direction = dir;
}
@Override
public void fromBytes(ByteBuf buf) {
mode = buf.readInt();
height = buf.readInt();
width = buf.readInt();
direction = buf.readBoolean();
}
@Override
public void toBytes(ByteBuf buf) {
buf.writeInt(mode);
buf.writeInt(height);
buf.writeInt(width);
buf.writeBoolean(direction);
}
public static class BPacketHandler extends ServerPacket<BuildPacket> {
@Override
public IMessage handleServerMessage(EntityPlayer player,
BuildPacket message, MessageContext ctx) {
player.getCurrentEquippedItem().stackTagCompound.setInteger("Mode", message.mode);
player.getCurrentEquippedItem().stackTagCompound.setInteger("Width", message.width);
player.getCurrentEquippedItem().stackTagCompound.setInteger("Height", message.height);
player.getCurrentEquippedItem().stackTagCompound.setBoolean("Direction", message.direction);
return null;
} }}
Edit - Forgot to include Proxy Code
public class CommonProxy {
public EntityPlayer getPlayerEntity(MessageContext ctx) {
return ctx.getServerHandler().playerEntity;
}}
public class ClientProxy extends CommonProxy{
@Override
public EntityPlayer getPlayerEntity(MessageContext ctx) {
return (ctx.side.isClient() ? Minecraft.getMinecraft().thePlayer : super.getPlayerEntity(ctx));
}}
//In Main class
@SidedProxy(clientSide= "com.Mergis.StructureMappingTool.proxies.ClientProxy", serverSide = "com.Mergis.StructureMappingTool.proxies.CommonProxy")
public static CommonProxy modProxy;
1
player.inventory.getCurrentItem() returns an itemstack your checking for an item so you want to add .getItem() to get an Item from an ItemStack
if(player.inventory.getCurrentItem().getItem() == items.flint)
0
I have an Item which opens a GUI. the player can then press buttons in the GUI to adjust values which are then sent in packets to the server to update the items NBTTag with the new variables.
This works perfectly in single player mode but whenever in multiplayer only the hosting user can use the buttons on the GUI for anyone else they are kicked from the host and the host logs this
[01:18:00] [Server thread/INFO]: gurgis lost connection: TranslatableComponent{key='disconnect.genericReason', args=[Internal Exception: io.netty.handler.codec.DecoderException: java.io.IOException: The received string length is longer than maximum allowed (25 > 20)], siblings=[], style=Style{hasParent=false, color=null, bold=null, italic=null, underlined=null, obfuscated=null, clickEvent=null, hoverEvent=null}}
Thanks for any help you guys can offer
0
np
0
All of your initialization events are FMLInitializationEvent
0
Awesome thanks for the help guys
0
Thanks will try this out
0
It may be because your using the vanilla crafting GUI... its canInteract method looks for a crafting block at the provided coords and checks the players distance relative to that point, so your split second of display time might just be the lag between you trying to open the GUI and this condition invariably testing false
0
Your missing assets dir after resources and before cocorj07