Jump to content

Taji34

Forge Modder
  • Posts

    147
  • Joined

  • Last visited

Everything posted by Taji34

  1. Yeah, it's probably an "Anti-hack" thing, since once the event is sent, they don't want anyone to change the value of the damage.
  2. Okay, so I'm having problems reassigning the damage value, I can't write: event.ammount = damageAmmount; Because event.ammount is final, so I can't change it's value...any ideas?
  3. yes .. and this is actually somewhat basic java so maybe you should just look into it a little UNLESS you have already worked with other language before (such as C++) and you are thinking that float are used like pointers, well then you should know that in java theres no pointer, every primitive type is direct and every object is a reference happy modding Yeah, I've been on about a 5 or 6 month hiatus from coding in java, so I'm a little rusty! Plus even during then, I didn't use float variables at all.
  4. I thought that, but when I tried deleting it, it crashes on start-up. How would I go about doing that? Putting event.ammount = damageAmmount instead of damage = damageAmmount?
  5. Okay, so I registered a LivingAttackEvent, but I must have done something wrong because now my weapon doesn't do damage at all, I left click with it, and nothing happens. Here's what I got for code, tell me if I'm missing something: Troncraft.java: package taji34.troncraft; import net.minecraft.block.Block; import net.minecraft.client.renderer.entity.RenderSnowball; import net.minecraft.client.renderer.entity.RenderManager; import net.minecraft.client.settings.KeyBinding; import net.minecraft.entity.projectile.EntitySnowball; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.src.ModLoader; import net.minecraftforge.common.MinecraftForge; import cpw.mods.fml.client.registry.KeyBindingRegistry; import cpw.mods.fml.client.registry.KeyBindingRegistry.KeyHandler; import cpw.mods.fml.client.registry.RenderingRegistry; import cpw.mods.fml.common.Mod; import cpw.mods.fml.common.Mod.EventHandler; import cpw.mods.fml.common.Mod.Init; import cpw.mods.fml.common.Mod.Instance; import cpw.mods.fml.common.Mod.PostInit; import cpw.mods.fml.common.Mod.PreInit; import cpw.mods.fml.common.SidedProxy; import cpw.mods.fml.common.event.FMLInitializationEvent; import cpw.mods.fml.common.event.FMLPostInitializationEvent; import cpw.mods.fml.common.event.FMLPreInitializationEvent; import cpw.mods.fml.common.network.NetworkMod; import cpw.mods.fml.common.registry.EntityRegistry; import cpw.mods.fml.common.registry.GameRegistry; import cpw.mods.fml.common.registry.LanguageRegistry; @Mod(modid="Troncraft", name="Troncraft", version="0.0.1") @NetworkMod(clientSideRequired=true, serverSideRequired=false, channels={"troncraft"}, packetHandler = TajiPacketHandler.class) public class Troncraft { // The instance of your mod that Forge uses. @Instance("Troncraft") public static Troncraft instance; public final static Item identityDisk = new IdentityDisk(5001); int diskItemID = identityDisk.itemID; private final static Item baton = new Baton(5002); int batonItemID = baton.itemID; // Says where the client and server 'proxy' code is loaded. @SidedProxy(clientSide="taji34.troncraft.client.ClientProxy", serverSide="taji34.troncraft.CommonProxy") public static CommonProxy proxy; @EventHandler public void preInit(FMLPreInitializationEvent event) { // Stub Method } @EventHandler public void load(FMLInitializationEvent event) { LanguageRegistry.addName(identityDisk, "Identity Disk"); LanguageRegistry.addName(baton, "Baton"); EntityRegistry.registerModEntity(EntityIdentityDisk.class, "IdentityDisk", 5001, this, 40, 3, true); RenderingRegistry.registerEntityRenderingHandler(EntityIdentityDisk.class, new RenderSnowball(identityDisk)); KeyBindingRegistry.registerKeyBinding(new TajiKeyHandler()); MinecraftForge.EVENT_BUS.register(new TajiEvents()); } @EventHandler public void postInit(FMLPostInitializationEvent event) { // Stub Method } } Baton.java (the weapon): import java.io.ByteArrayOutputStream; import java.io.DataOutputStream; import com.google.common.collect.Multimap; import cpw.mods.fml.client.registry.KeyBindingRegistry.KeyHandler; import cpw.mods.fml.common.network.PacketDispatcher; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import net.minecraft.client.entity.EntityClientPlayerMP; import net.minecraft.client.renderer.texture.IconRegister; import net.minecraft.client.settings.KeyBinding; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.SharedMonsterAttributes; import net.minecraft.entity.ai.attributes.AttributeModifier; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTBase; import net.minecraft.nbt.NBTTagByte; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagString; import net.minecraft.network.packet.Packet250CustomPayload; import net.minecraft.world.World; public class Baton extends Item { private float weaponDamage; private boolean active = false; public Baton(int par1) { super(par1); setMaxStackSize(1); setCreativeTab(CreativeTabs.tabMisc); setUnlocalizedName("Baton"); this.weaponDamage = 0.0F; } @Override @SideOnly(Side.CLIENT) public void registerIcons(IconRegister iconRegister) { this.itemIcon = iconRegister.registerIcon("Troncraft:Baton"); } public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer) { if(!par2World.isRemote) { NBTTagCompound tag = par1ItemStack.getTagCompound(); if (tag == null) { tag = new NBTTagCompound(); par1ItemStack.setTagCompound(tag); } if (tag.getName().equals("tag")) { tag.setName("Normal"); } System.out.println(tag.getInteger("Damage")); if (!this.active) { this.active = true; PacketDispatcher.sendPacketToServer(new BatonModePacket("activate").makePacket()); // if(tag.getName().equals("Sword")) // { // this.weaponDamage = 10000.0F; // this.func_111205_h(); // } // else if(tag.getName().equals("Staff")) // { // this.weaponDamage = 2.0F; // } // else if(tag.getName().equals("Normal")) // { // this.weaponDamage = 0.0F; // } } else { this.active = false; PacketDispatcher.sendPacketToServer(new BatonModePacket("deactivate").makePacket()); } } return par1ItemStack; } public Multimap func_111205_h() { Multimap multimap = super.func_111205_h(); multimap.put(SharedMonsterAttributes.field_111264_e.func_111108_a(), new AttributeModifier(field_111210_e, "Weapon modifier", (double)this.weaponDamage, 0)); return multimap; } public void setWeaponDamage(float damage) { this.weaponDamage = damage; } } TajiEvents.java: package taji34.troncraft; import net.minecraft.entity.EntityLiving; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.DamageSource; import net.minecraftforge.event.ForgeSubscribe; import net.minecraftforge.event.entity.living.LivingAttackEvent; public class TajiEvents { @ForgeSubscribe public void entityAttacked(LivingAttackEvent event) { EntityLiving attackedEnt = (EntityLiving) event.entityLiving; DamageSource attackSource = event.source; float damage = event.ammount; EntityPlayer player = (EntityPlayer) attackSource.getSourceOfDamage(); ItemStack itemstack = player.getHeldItem(); if (itemstack.getDisplayName().equals("Baton")) { NBTTagCompound tag = itemstack.getTagCompound(); int damageAmmount = tag.getInteger("Damage"); damage = damageAmmount; } if (event.isCancelable()) { event.setCanceled(true); } } } I've got the NBT data working, where it switches and integer tag between values on right click.
  6. Hmm, okay, I'm still a little bit confused about the LivingAttackHandler. Is it a packet handler or something different? Is there a tutorial somewhere you could point me to? I tried googling it but nothing came up.
  7. Have you tried taking a look at the spawn egg code and replicating it with the changes you want for your item? It should be as simple as implementing the needed code in your item, and changing some values.
  8. Here's my current code for the item: package taji34.troncraft; import java.io.ByteArrayOutputStream; import java.io.DataOutputStream; import com.google.common.collect.Multimap; import cpw.mods.fml.client.registry.KeyBindingRegistry.KeyHandler; import cpw.mods.fml.common.network.PacketDispatcher; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import net.minecraft.client.entity.EntityClientPlayerMP; import net.minecraft.client.renderer.texture.IconRegister; import net.minecraft.client.settings.KeyBinding; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.SharedMonsterAttributes; import net.minecraft.entity.ai.attributes.AttributeModifier; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTBase; import net.minecraft.nbt.NBTTagByte; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagString; import net.minecraft.network.packet.Packet250CustomPayload; import net.minecraft.world.World; public class Baton extends Item { private float weaponDamage; private boolean active = false; public Baton(int par1) { super(par1); setMaxStackSize(1); setCreativeTab(CreativeTabs.tabMisc); setUnlocalizedName("Baton"); this.weaponDamage = 0.0F; } @Override @SideOnly(Side.CLIENT) public void registerIcons(IconRegister iconRegister) { this.itemIcon = iconRegister.registerIcon("Troncraft:Baton"); } public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer) { if(!par2World.isRemote) { NBTTagCompound tag = par1ItemStack.getTagCompound(); if (tag == null) { tag = new NBTTagCompound(); par1ItemStack.setTagCompound(tag); } if (tag.getName().equals("tag")) { tag.setName("Normal"); } if (!this.active) { this.active = true; PacketDispatcher.sendPacketToServer(new BatonModePacket("activate").makePacket()); // if(tag.getName().equals("Sword")) // { // this.weaponDamage = 10000.0F; // this.func_111205_h(); // } // else if(tag.getName().equals("Staff")) // { // this.weaponDamage = 2.0F; // } // else if(tag.getName().equals("Normal")) // { // this.weaponDamage = 0.0F; // } } else { this.active = false; // this.weaponDamage = 0.0F; } System.out.println(tag.getName() + " " + active + " " + this.weaponDamage); } return par1ItemStack; } public Multimap func_111205_h() { Multimap multimap = super.func_111205_h(); multimap.put(SharedMonsterAttributes.field_111264_e.func_111108_a(), new AttributeModifier(field_111210_e, "Weapon modifier", (double)this.weaponDamage, 0)); return multimap; } public void setWeaponDamage(float damage) { this.weaponDamage = damage; } } I got it to deal damage, which is just by adding the following code to the item: public Multimap func_111205_h() { Multimap multimap = super.func_111205_h(); multimap.put(SharedMonsterAttributes.field_111264_e.func_111108_a(), new AttributeModifier(field_111210_e, "Weapon modifier", (double)this.weaponDamage, 0)); return multimap; } But I can't seem to get it to deal different amounts of damage after a right click, currently I'm trying to send a packet to the server.
  9. Okay, so I got it to deal damage, but now I'm trying to get the amount of damage dealt to change on right click, but even though I change the value of weaponDamage, the damage output doesn't change. Is there something else I have to call for it the register the change?
  10. I did look at it, and I'll take another look, but I didn't see anything that explicitly said it dealt damage.
  11. Could you give me an example? I must be missing something somewhere, since it isn't dealing the damage I want it to.
  12. So I'm trying to create an item that deals damage on left click, like a sword, however I can't seem to get the item to do a custom damage amount. For debuging purposes I set the damage value to 100000, however, it still acts as if the item doesn't have a damage value set. Here is my code: (Code removed) There don't seem to be any tutorials out there that detail how to make a custom weapon in forge, so I might be missing a method, but I did my best to look through the Sword.java and pick out the relevant methods. Okay, my problem now is that I want to change the damage dealt to NPCs on a right click, however, when I change the weaponDamage variable, minecraft does not register the change.
  13. yes, to the console *FACEPALM* I figured out my problem. I changed the channel name in my packet handler, but not in my main class, so it works now Thank you!
  14. Would something print to the console if the packet was received server side? I put some println in both the constructor for BatonModePacket, and the makePacket() method that is inherited and called, and both ran and printed what I told them to the console. Debugging is obviously not my forte...
  15. Okay, so the keypress is working now, but the packet isn't. Here's my packet handler: TajiPacketHandler.java: package taji34.troncraft; import java.util.logging.Logger; import taji34.troncraft.TajiPacket.ProtocolException; import com.google.common.io.ByteArrayDataInput; import com.google.common.io.ByteStreams; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.network.INetworkManager; import net.minecraft.network.packet.Packet250CustomPayload; import cpw.mods.fml.common.network.IPacketHandler; import cpw.mods.fml.common.network.Player; import cpw.mods.fml.relauncher.Side; public class TajiPacketHandler implements IPacketHandler { @Override public void onPacketData(INetworkManager manager, Packet250CustomPayload packet, Player player) { try { EntityPlayer entityPlayer = (EntityPlayer)player; ByteArrayDataInput in = ByteStreams.newDataInput(packet.data); int packetId = in.readUnsignedByte(); // Assuming your packetId is between 0 (inclusive) and 256 (exclusive). If you need more you need to change this TajiPacket demoPacket = TajiPacket.constructPacket(packetId); demoPacket.read(in); demoPacket.execute(entityPlayer, entityPlayer.worldObj.isRemote ? Side.CLIENT : Side.SERVER); } catch (ProtocolException e) { if (player instanceof EntityPlayerMP) { ((EntityPlayerMP) player).playerNetServerHandler.kickPlayerFromServer("Protocol Exception!"); Logger.getLogger("DemoMod").warning("Player " + ((EntityPlayer)player).username + " caused a Protocol Exception!"); } } catch (ReflectiveOperationException e) { throw new RuntimeException("Unexpected Reflection exception during Packet construction!", e); } } } BatonModePacket.java: package taji34.troncraft; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import com.google.common.io.ByteArrayDataInput; import com.google.common.io.ByteArrayDataOutput; import cpw.mods.fml.relauncher.Side; public class BatonModePacket extends TajiPacket { private String text; public BatonModePacket(String text) { this.text = text; } public BatonModePacket() { } // Be sure to always have the default constructor in your class, or the reflection code will fail! @Override protected void write(ByteArrayDataOutput out) { out.writeUTF(text); } @Override protected void read(ByteArrayDataInput in) throws ProtocolException { text = in.readUTF(); } @Override protected void execute(EntityPlayer player, Side side) throws ProtocolException { // if (side.isClient()) { // player.addChatMessage(text); // } else { // throw new ProtocolException("Cannot send this packet to the server!"); // } ItemStack itemstack = player.getHeldItem(); if (side.isClient()) { player.addChatMessage(itemstack.getDisplayName() + text); } else { // throw new ProtocolException("Cannot send this packet to the server!"); System.out.println(itemstack.getDisplayName() + text); } } } I'm sending the packet using the following line of code: PacketDispatcher.sendPacketToServer(new BatonModePacket("Hello World!").makePacket()); Do I have something wrong somewhere?
  16. I fixed it! I shifted somethings around, and I found something on the wiki that helped. Hopefully it'll send the packet correctly now!
  17. I seem to be forgetting my troubleshooting basics! I did what you said, and nothing prints at all when I press J (the key I bound). So something must be going wrong elsewhere right?
  18. Okay, so apparently I don't have it all figured out. Cause it still isn't working Here are the changes to my code I've made: In TajiKeyHandler.java: @Override public void keyDown(EnumSet<TickType> types, KeyBinding kb, boolean tickEnd, boolean isRepeat) { if(kb == Baton.mode) { System.out.println("Hi"); //PacketDispatcher.sendPacketToServer(new BatonModePacket("Hello World!").makePacket()); } } @Override public void keyUp(EnumSet<TickType> types, KeyBinding kb, boolean tickEnd) { if(kb == Baton.mode) { System.out.println("Hi"); //PacketDispatcher.sendPacketToServer(new BatonModePacket("Hello World!").makePacket()); } } @Override public EnumSet<TickType> ticks() { // TODO Auto-generated method stub return null; } } I think I must be doing something wrong still here, do I need to put something in ENumSet<TickType> ticks()? In Baton.java: public static KeyBinding mode = new KeyBinding("Baton Staff Mode", 36); This is the only thing concerning key binding in this class now. My main method hasn't changed but I'll post it anyway: Troncraft.java: package taji34.troncraft; import net.minecraft.block.Block; import net.minecraft.client.renderer.entity.RenderSnowball; import net.minecraft.client.renderer.entity.RenderManager; import net.minecraft.client.settings.KeyBinding; import net.minecraft.entity.projectile.EntitySnowball; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.src.ModLoader; import cpw.mods.fml.client.registry.KeyBindingRegistry; import cpw.mods.fml.client.registry.KeyBindingRegistry.KeyHandler; import cpw.mods.fml.client.registry.RenderingRegistry; import cpw.mods.fml.common.Mod; import cpw.mods.fml.common.Mod.EventHandler; import cpw.mods.fml.common.Mod.Init; import cpw.mods.fml.common.Mod.Instance; import cpw.mods.fml.common.Mod.PostInit; import cpw.mods.fml.common.Mod.PreInit; import cpw.mods.fml.common.SidedProxy; import cpw.mods.fml.common.event.FMLInitializationEvent; import cpw.mods.fml.common.event.FMLPostInitializationEvent; import cpw.mods.fml.common.event.FMLPreInitializationEvent; import cpw.mods.fml.common.network.NetworkMod; import cpw.mods.fml.common.registry.EntityRegistry; import cpw.mods.fml.common.registry.GameRegistry; import cpw.mods.fml.common.registry.LanguageRegistry; @Mod(modid="Troncraft", name="Troncraft", version="0.0.1") @NetworkMod(clientSideRequired=true, serverSideRequired=false, channels={"Baton"}, packetHandler = TajiPacketHandler.class) public class Troncraft { // The instance of your mod that Forge uses. @Instance("Troncraft") public static Troncraft instance; public final static Item identityDisk = new IdentityDisk(5001); int diskItemID = identityDisk.itemID; private final static Item baton = new Baton(5002); int batonItemID = baton.itemID; KeyBinding[] bindings = { Baton.mode }; TajiKeyHandler keyHandler; // Says where the client and server 'proxy' code is loaded. @SidedProxy(clientSide="taji34.troncraft.client.ClientProxy", serverSide="taji34.troncraft.CommonProxy") public static CommonProxy proxy; @EventHandler public void preInit(FMLPreInitializationEvent event) { // Stub Method } @EventHandler public void load(FMLInitializationEvent event) { LanguageRegistry.addName(identityDisk, "Identity Disk"); LanguageRegistry.addName(baton, "Baton"); EntityRegistry.registerModEntity(EntityIdentityDisk.class, "IdentityDisk", 5001, this, 40, 3, true); RenderingRegistry.registerEntityRenderingHandler(EntityIdentityDisk.class, new RenderSnowball(identityDisk)); keyHandler = new TajiKeyHandler(bindings); KeyBindingRegistry.registerKeyBinding(keyHandler); } @EventHandler public void postInit(FMLPostInitializationEvent event) { // Stub Method } } Maybe I'm missing something here? I don't think so, because the key binding shows up in game, but since I'm new to this I'm not going to assume anything.
  19. Okay, everything makes sense now that it's been explained to me. I kinda feel like an idiot cause it seems so simple.
  20. Okay, but how does it know what to do for different key presses? Do I specify that myself?
  21. I though it might be the empty methods, but nothing I found really specified what to put in those methods farther than "Put what you want it to do when a button is pressed here" which didn't really help me.
  22. Okay, so I have hit a snag. My key binding is registered in the game options, but when I press it, it does nothing. I currently have it print "Hi" to the console for troubleshooting purposes, but it is not working. Here is my code: Troncraft.java: package taji34.troncraft; import net.minecraft.block.Block; import net.minecraft.client.renderer.entity.RenderSnowball; import net.minecraft.client.renderer.entity.RenderManager; import net.minecraft.client.settings.KeyBinding; import net.minecraft.entity.projectile.EntitySnowball; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.src.ModLoader; import cpw.mods.fml.client.registry.KeyBindingRegistry; import cpw.mods.fml.client.registry.KeyBindingRegistry.KeyHandler; import cpw.mods.fml.client.registry.RenderingRegistry; import cpw.mods.fml.common.Mod; import cpw.mods.fml.common.Mod.EventHandler; import cpw.mods.fml.common.Mod.Init; import cpw.mods.fml.common.Mod.Instance; import cpw.mods.fml.common.Mod.PostInit; import cpw.mods.fml.common.Mod.PreInit; import cpw.mods.fml.common.SidedProxy; import cpw.mods.fml.common.event.FMLInitializationEvent; import cpw.mods.fml.common.event.FMLPostInitializationEvent; import cpw.mods.fml.common.event.FMLPreInitializationEvent; import cpw.mods.fml.common.network.NetworkMod; import cpw.mods.fml.common.registry.EntityRegistry; import cpw.mods.fml.common.registry.GameRegistry; import cpw.mods.fml.common.registry.LanguageRegistry; @Mod(modid="Troncraft", name="Troncraft", version="0.0.1") @NetworkMod(clientSideRequired=true, serverSideRequired=false, channels={"Baton"}, packetHandler = TajiPacketHandler.class) public class Troncraft { // The instance of your mod that Forge uses. @Instance("Troncraft") public static Troncraft instance; public final static Item identityDisk = new IdentityDisk(5001); int diskItemID = identityDisk.itemID; private final static Item baton = new Baton(5002); int batonItemID = baton.itemID; KeyBinding[] bindings = { Baton.mode }; TajiKeyHandler keyHandler; // Says where the client and server 'proxy' code is loaded. @SidedProxy(clientSide="taji34.troncraft.client.ClientProxy", serverSide="taji34.troncraft.CommonProxy") public static CommonProxy proxy; @EventHandler public void preInit(FMLPreInitializationEvent event) { // Stub Method } @EventHandler public void load(FMLInitializationEvent event) { LanguageRegistry.addName(identityDisk, "Identity Disk"); LanguageRegistry.addName(baton, "Baton"); EntityRegistry.registerModEntity(EntityIdentityDisk.class, "IdentityDisk", 5001, this, 40, 3, true); RenderingRegistry.registerEntityRenderingHandler(EntityIdentityDisk.class, new RenderSnowball(identityDisk)); keyHandler = new TajiKeyHandler(bindings); KeyBindingRegistry.registerKeyBinding(keyHandler); } @EventHandler public void postInit(FMLPostInitializationEvent event) { // Stub Method } } Baton.java: package taji34.troncraft; import java.io.ByteArrayOutputStream; import java.io.DataOutputStream; import cpw.mods.fml.client.registry.KeyBindingRegistry.KeyHandler; import cpw.mods.fml.common.network.PacketDispatcher; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import net.minecraft.client.entity.EntityClientPlayerMP; import net.minecraft.client.renderer.texture.IconRegister; import net.minecraft.client.settings.KeyBinding; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTBase; import net.minecraft.nbt.NBTTagByte; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagString; import net.minecraft.network.packet.Packet250CustomPayload; import net.minecraft.world.World; public class Baton extends Item { public Baton(int par1) { super(par1); setMaxStackSize(1); setCreativeTab(CreativeTabs.tabMisc); setUnlocalizedName("Baton"); } @Override @SideOnly(Side.CLIENT) public void registerIcons(IconRegister iconRegister) { this.itemIcon = iconRegister.registerIcon("Troncraft:Baton"); } public static KeyBinding mode = new KeyBinding("Baton Staff Mode", 36); public void keyboardEvent(KeyBinding keybinding) { if(keybinding == mode) { System.out.println("Hi"); //PacketDispatcher.sendPacketToServer(new BatonModePacket("Hello World!").makePacket()); } } public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer) { NBTTagCompound tag = par1ItemStack.getTagCompound(); if (tag == null) { tag = new NBTTagCompound(); par1ItemStack.setTagCompound(tag); } if (tag.getName().equals("tag")) { tag.setName("Test1"); } System.out.println(tag.getName()); return par1ItemStack; } } TajiKeyHandler.java: package taji34.troncraft; import java.util.EnumSet; import net.minecraft.client.settings.KeyBinding; import cpw.mods.fml.client.registry.KeyBindingRegistry.KeyHandler; import cpw.mods.fml.common.TickType; public class TajiKeyHandler extends KeyHandler { public TajiKeyHandler(KeyBinding[] keyBindings, boolean[] isRepeat) { super(keyBindings, isRepeat); } public TajiKeyHandler(KeyBinding[] keyBindings) { super(keyBindings); } @Override public String getLabel() { return "Taji's Keys"; } @Override public void keyDown(EnumSet<TickType> types, KeyBinding kb, boolean tickEnd, boolean isRepeat) { // TODO Auto-generated method stub } @Override public void keyUp(EnumSet<TickType> types, KeyBinding kb, boolean tickEnd) { // TODO Auto-generated method stub } @Override public EnumSet<TickType> ticks() { // TODO Auto-generated method stub return null; } } I've tried to follow stuff on how to make a keybinding, but none of the stuff I found was very detailed, so I think I might have missed something.
  23. Thank You! I was just about to post because I couldn't figure out how to send a packet from a keypress, but what you suggested makes more sense!
  24. I meant what to send in the packet, I understand I need to send a packet to the server. I guess i'll just have to put a bit more thought into it.
  25. I'm new to coding, so that was the first thing I thought of. I'm trying to change the name of a tag in an itemstack, but I can't seem to think of a way to tell the server to do that.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.