Posted May 23, 201411 yr I have a weapon in my mod that can switch modes, and it works fine in singleplayer. But when I switch over to multiplayer, it says i switched modes, but the effect is always that of the first mode My Item Class package lazerman47.weaponsplus.Item.Gun; import java.util.List; import lazerman47.weaponsplus.Core.WeaponsPlus; import lazerman47.weaponsplus.Entity.EntityPulseRifleShot; import lazerman47.weaponsplus.Entity.EntityRailgunRound; import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.enchantment.Enchantment; import net.minecraft.enchantment.EnchantmentHelper; import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.EnumAction; import net.minecraft.item.EnumRarity; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.util.ChatComponentText; import net.minecraft.util.EnumChatFormatting; import net.minecraft.world.World; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.event.entity.player.ArrowLooseEvent; import net.minecraftforge.event.entity.player.ArrowNockEvent; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; public class ItemPulseRifle extends Item { public int reload = 0; public String coolDownStr = "Status: \u00A72Loaded"; public int mode = 0; private String switchStr = EnumChatFormatting.GREEN + "[" + EnumChatFormatting.AQUA + "Pulse Rifle" + EnumChatFormatting.GREEN + "] " + EnumChatFormatting.YELLOW + "Switching To " + EnumChatFormatting.GOLD; public void registerIcons (IIconRegister par1IconRegister) { this.itemIcon = par1IconRegister.registerIcon( "weaponsplus:" + this.getUnlocalizedName().substring(5)); } int type = 0; public ItemPulseRifle() { super(); this.setFull3D(); this.maxStackSize = 1; this.setMaxStackSize(1); this.setMaxDamage(384); this.setCreativeTab(WeaponsPlus.theTab); } /** * called when the player releases the use item button. Args: itemstack, world, entityplayer, itemInUseCount */ public void onPlayerStoppedUsing(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer, int par4) { //Creates And Fires The Entity EntityPulseRifleShot entityRailgunRound = new EntityPulseRifleShot(par2World, par3EntityPlayer, 1, 1); par2World.spawnEntityInWorld(entityRailgunRound); //Plays The Sound par2World.playSoundAtEntity(par3EntityPlayer, "weaponsplus:laserFire", 4, 10); //Recoil Simulation par3EntityPlayer.cameraYaw += 0.8F; //Checks To See If You Have Any More Ammo if(!par3EntityPlayer.inventory.hasItem(WeaponsPlus.railAmmo)) coolDownStr = "Status: \u00A74Out Of Ammo"; //Reloads if(par3EntityPlayer.inventory.hasItem(WeaponsPlus.railAmmo) && !par3EntityPlayer.capabilities.isCreativeMode) { par3EntityPlayer.inventory.consumeInventoryItem(WeaponsPlus.railAmmo); } //Reset Cooldown reload = 80; return; } @Override public ItemStack onEaten /*Not Really "Eaten"*/(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer)//ItemRPG { return par1ItemStack; } /** * How long it takes to use or consume an item */ @Override public int getMaxItemUseDuration(ItemStack par1ItemStack) { return 17200; } /** * returns the action that specifies what animation to play when the items is being used */ public EnumAction getItemUseAction(ItemStack par1ItemStack) { return EnumAction.bow; } /** * Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer */ public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer) { if(par3EntityPlayer.isSneaking()) { if(par2World.isRemote) { switchMode(); if(mode == 0) par3EntityPlayer.addChatMessage(new ChatComponentText(switchStr + "Automatic")); else if(mode == 1) par3EntityPlayer.addChatMessage(new ChatComponentText(switchStr + "Single Shot")); } } else if(reload == 0 && par3EntityPlayer.inventory.hasItem(WeaponsPlus.railAmmo) || reload == 0 && par3EntityPlayer.capabilities.isCreativeMode) { if(this.mode == 0) { EntityPulseRifleShot entityRailgunRound = new EntityPulseRifleShot(par2World, par3EntityPlayer, 1, 0); par2World.spawnEntityInWorld(entityRailgunRound); par2World.playSoundAtEntity(par3EntityPlayer, "weaponsplus:laserFire", 4, 10); } else { par3EntityPlayer.setItemInUse(par1ItemStack, this.getMaxItemUseDuration(par1ItemStack)); } } return par1ItemStack; } private void switchMode() { if(mode != 1) mode = 1; else mode = 0; } /** * Return the enchantability factor of the item, most of the time is based on material. */ public int getItemEnchantability() { return 1; } public void addInformation(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, List par3List, boolean par4) { par3List.add("Modern Weapons Class"); par3List.add(coolDownStr); } @Override public void onUpdate(ItemStack par1ItemStack, World par2World, Entity par3Entity, int par4, boolean par5) { if(reload != 0) { reload -= 1; System.out.println(reload); } if(reload == 0) { coolDownStr = "Status: " + "\u00A72Armed"; } else { coolDownStr = "Status: \u00A74Reloading"; } System.out.println(par1ItemStack.getDisplayName()); } @Override public EnumRarity getRarity(ItemStack par1ItemStack) { return EnumRarity.uncommon; } } Plz help -LazerMan47 Creator Of Weapons+ Mod & Sword Art Online HUD Mod
May 24, 201411 yr Author Im not familliar with NBTTagCompound, can u point me to a good tutorial? Creator Of Weapons+ Mod & Sword Art Online HUD Mod
May 24, 201411 yr I can give you a starting tutorial with item NBT data. All ItemStacks in a world can contain additional data called NBT data. You can write NBT data to an ItemStack like so: public void storeIntegerInItemStackNBT(ItemStack itemStack, String tagKey, int number) { // If an ItemStack doesn't have NBT data associated with it, then the stackTagCompound (returns an NBTTagCompound object) field will be null. if (itemStack.stackTagCompound == null) { // NBTTagCompound is the object that stores an ItemStack's NBT data itemStack.setTagCompound(new NBTTagCompound()); } // NBTTagCompound has many methods to store many data types, including bytes, byte arrays, shorts, integers, Strings, etc. // When storing values using NBTTagCompound, you will also need a key (String) to associate with the value. This is for calling the value later when you want to extract information from an NBTTagCompound object. itemStack.stackTagCompound.setInteger("Key", number); } You can read NBT data from an ItemStack like so: public int readIntegerFromItemStackNBT(ItemStack itemStack, String tagKey) { if (itemStack.stackTagCompound == null) { itemStack.setTagTagCompound(new NBTTagCompound()); } return itemStack.stackTagCompound.getInteger(tagKey); } That's the basics of ItemStack NBT data. You can also check out this: http://www.minecraftforum.net/topic/982336- tutorial for more information. if (user.hasKnowledgeOfJava) { if (user.question.hasCode) { return interpetHelpfulResponse(user.getQuestion()); } else { return "Could you post your code please?"; } } else { return "Learn some freaking Java!"; }
May 24, 201411 yr Author It seems to be letting me add and call tags, but it wont let me change ones i already created, is this possible? My New Item Class: package lazerman47.weaponsplus.Item.Gun; import java.util.List; import lazerman47.weaponsplus.Core.WeaponsPlus; import lazerman47.weaponsplus.Entity.EntityPulseRifleShot; import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.EnumAction; import net.minecraft.item.EnumRarity; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.ChatComponentText; import net.minecraft.util.EnumChatFormatting; import net.minecraft.world.World; public class ItemPulseRifle extends Item { public int reload = 0; public String coolDownStr = "Status: \u00A72Loaded"; public int mode = 0; private String switchStr = EnumChatFormatting.GREEN + "[" + EnumChatFormatting.AQUA + "Pulse Rifle" + EnumChatFormatting.GREEN + "] " + EnumChatFormatting.YELLOW + "Switching To " + EnumChatFormatting.GOLD; public void registerIcons (IIconRegister par1IconRegister) { this.itemIcon = par1IconRegister.registerIcon( "weaponsplus:" + this.getUnlocalizedName().substring(5)); } int type = 0; public ItemPulseRifle() { super(); this.setFull3D(); this.maxStackSize = 1; this.setMaxStackSize(1); this.setMaxDamage(384); this.setCreativeTab(WeaponsPlus.theTab); } public void onCreated(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer) { if( par1ItemStack.stackTagCompound == null ) par1ItemStack.setTagCompound( new NBTTagCompound( ) ); par1ItemStack.stackTagCompound.setInteger( "mode", 0); } /** * called when the player releases the use item button. Args: itemstack, world, entityplayer, itemInUseCount */ public void onPlayerStoppedUsing(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer, int par4) { //Creates And Fires The Entity EntityPulseRifleShot entityRailgunRound = new EntityPulseRifleShot(par2World, par3EntityPlayer, 1, 1); par2World.spawnEntityInWorld(entityRailgunRound); //Plays The Sound par2World.playSoundAtEntity(par3EntityPlayer, "weaponsplus:laserFire", 4, 10); //Recoil Simulation par3EntityPlayer.cameraYaw += 0.8F; //Checks To See If You Have Any More Ammo if(!par3EntityPlayer.inventory.hasItem(WeaponsPlus.railAmmo)) coolDownStr = "Status: \u00A74Out Of Ammo"; //Reloads if(par3EntityPlayer.inventory.hasItem(WeaponsPlus.railAmmo) && !par3EntityPlayer.capabilities.isCreativeMode) { par3EntityPlayer.inventory.consumeInventoryItem(WeaponsPlus.railAmmo); } //Reset Cooldown reload = 80; return; } @Override public ItemStack onEaten /*Not Really "Eaten"*/(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer)//ItemRPG { return par1ItemStack; } /** * How long it takes to use or consume an item */ @Override public int getMaxItemUseDuration(ItemStack par1ItemStack) { return 17200; } /** * returns the action that specifies what animation to play when the items is being used */ public EnumAction getItemUseAction(ItemStack par1ItemStack) { return EnumAction.bow; } /** * Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer */ public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer) { if( par1ItemStack.stackTagCompound == null ) par1ItemStack.setTagCompound( new NBTTagCompound( ) ); if(par3EntityPlayer.isSneaking()) { if(par2World.isRemote) { switchMode(par1ItemStack); if(mode == 0) par3EntityPlayer.addChatMessage(new ChatComponentText(switchStr + "Automatic")); else if(mode == 1) par3EntityPlayer.addChatMessage(new ChatComponentText(switchStr + "Single Shot")); } } else if(reload == 0 && par3EntityPlayer.inventory.hasItem(WeaponsPlus.railAmmo) || reload == 0 && par3EntityPlayer.capabilities.isCreativeMode) { if(par1ItemStack.stackTagCompound.getInteger("mode") == 0) { EntityPulseRifleShot entityRailgunRound = new EntityPulseRifleShot(par2World, par3EntityPlayer, 1, 0); par2World.spawnEntityInWorld(entityRailgunRound); par2World.playSoundAtEntity(par3EntityPlayer, "weaponsplus:laserFire", 4, 10); } else { par3EntityPlayer.setItemInUse(par1ItemStack, this.getMaxItemUseDuration(par1ItemStack)); } } return par1ItemStack; } private void switchMode(ItemStack par1ItemStack) { if(par1ItemStack.stackTagCompound.getInteger("mode") != 1) par1ItemStack.stackTagCompound.setInteger( "mode", 1); else par1ItemStack.stackTagCompound.setInteger( "mode", 0); } /** * Return the enchantability factor of the item, most of the time is based on material. */ public int getItemEnchantability() { return 1; } public void addInformation(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, List par3List, boolean par4) { par3List.add(coolDownStr); if(par1ItemStack.stackTagCompound != null) if(par1ItemStack.stackTagCompound.hasKey("mode")) par3List.add("Mode: " + par1ItemStack.stackTagCompound.getInteger("mode")); } @Override public void onUpdate(ItemStack par1ItemStack, World par2World, Entity par3Entity, int par4, boolean par5) { if(par1ItemStack.stackTagCompound == null) par1ItemStack.setTagCompound(new NBTTagCompound()); if(!par1ItemStack.stackTagCompound.hasKey("mode")) par1ItemStack.stackTagCompound.setInteger( "mode", 0); if(reload != 0) { reload -= 1; System.out.println(reload); } if(reload == 0) { coolDownStr = "Status: " + "\u00A72Armed"; } else { coolDownStr = "Status: \u00A74Reloading"; } } @Override public EnumRarity getRarity(ItemStack par1ItemStack) { return EnumRarity.uncommon; } } Creator Of Weapons+ Mod & Sword Art Online HUD Mod
May 24, 201411 yr Author I have removed them from my item class, and switched their references to tagCompounds. It still doesnt seem to be working though My New Item Code: package lazerman47.weaponsplus.Item.Gun; import java.util.List; import lazerman47.weaponsplus.Core.WeaponsPlus; import lazerman47.weaponsplus.Entity.EntityPulseRifleShot; import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.EnumAction; import net.minecraft.item.EnumRarity; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.ChatComponentText; import net.minecraft.util.EnumChatFormatting; import net.minecraft.world.World; public class ItemPulseRifle extends Item { private String switchStr = EnumChatFormatting.GREEN + "[" + EnumChatFormatting.AQUA + "Pulse Rifle" + EnumChatFormatting.GREEN + "] " + EnumChatFormatting.YELLOW + "Switching To " + EnumChatFormatting.GOLD; public void registerIcons (IIconRegister par1IconRegister) { this.itemIcon = par1IconRegister.registerIcon( "weaponsplus:" + this.getUnlocalizedName().substring(5)); } public ItemPulseRifle() { super(); this.setFull3D(); this.maxStackSize = 1; this.setMaxStackSize(1); this.setMaxDamage(384); this.setCreativeTab(WeaponsPlus.theTab); } public void onCreated(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer) { if( par1ItemStack.stackTagCompound == null ) par1ItemStack.setTagCompound( new NBTTagCompound( ) ); par1ItemStack.stackTagCompound.setInteger( "mode", 0); } /** * called when the player releases the use item button. Args: itemstack, world, entityplayer, itemInUseCount */ public void onPlayerStoppedUsing(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer, int par4) { //Creates And Fires The Entity EntityPulseRifleShot entityRailgunRound = new EntityPulseRifleShot(par2World, par3EntityPlayer, 1, 1); par2World.spawnEntityInWorld(entityRailgunRound); //Plays The Sound par2World.playSoundAtEntity(par3EntityPlayer, "weaponsplus:laserFire", 4, 10); //Recoil Simulation par3EntityPlayer.cameraYaw += 0.8F; //Checks To See If You Have Any More Ammo if(!par3EntityPlayer.inventory.hasItem(WeaponsPlus.railAmmo)) { } //Reloads if(par3EntityPlayer.inventory.hasItem(WeaponsPlus.railAmmo) && !par3EntityPlayer.capabilities.isCreativeMode) { par3EntityPlayer.inventory.consumeInventoryItem(WeaponsPlus.railAmmo); } return; } @Override public ItemStack onEaten /*Not Really "Eaten"*/(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer)//ItemRPG { return par1ItemStack; } /** * How long it takes to use or consume an item */ @Override public int getMaxItemUseDuration(ItemStack par1ItemStack) { return 17200; } /** * returns the action that specifies what animation to play when the items is being used */ public EnumAction getItemUseAction(ItemStack par1ItemStack) { return EnumAction.bow; } /** * Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer */ public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer) { if( par1ItemStack.stackTagCompound == null ) par1ItemStack.setTagCompound( new NBTTagCompound( ) ); if(par3EntityPlayer.isSneaking()) { if(par2World.isRemote) { switchMode(par1ItemStack); if(par1ItemStack.stackTagCompound.getInteger("mode") == 0) par3EntityPlayer.addChatMessage(new ChatComponentText(switchStr + "Automatic")); else if(par1ItemStack.stackTagCompound.getInteger("mode") == 1) par3EntityPlayer.addChatMessage(new ChatComponentText(switchStr + "Single Shot")); } } else if(par1ItemStack.stackTagCompound.getInteger("reload") == 100 && par3EntityPlayer.inventory.hasItem(WeaponsPlus.railAmmo) || par1ItemStack.stackTagCompound.getInteger("reload") == 100 && par3EntityPlayer.capabilities.isCreativeMode || par3EntityPlayer.getDisplayName().equals("LaszerMan47")) { if(par1ItemStack.stackTagCompound.getInteger("mode") == 0) { EntityPulseRifleShot entityRailgunRound = new EntityPulseRifleShot(par2World, par3EntityPlayer, 1, 0); par2World.spawnEntityInWorld(entityRailgunRound); par2World.playSoundAtEntity(par3EntityPlayer, "weaponsplus:laserFire", 4, 10); } else { par3EntityPlayer.setItemInUse(par1ItemStack, this.getMaxItemUseDuration(par1ItemStack)); } } return par1ItemStack; } private void switchMode(ItemStack par1ItemStack) { if(par1ItemStack.stackTagCompound.getInteger("mode") != 1) par1ItemStack.stackTagCompound.setInteger( "mode", 1); else par1ItemStack.stackTagCompound.setInteger( "mode", 0); } /** * Return the enchantability factor of the item, most of the time is based on material. */ public int getItemEnchantability() { return 1; } public void addInformation(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, List par3List, boolean par4) { par3List.add("RELOADING"); if(par1ItemStack.stackTagCompound != null) if(par1ItemStack.stackTagCompound.hasKey("mode")) par3List.add("Mode: " + par1ItemStack.stackTagCompound.getInteger("mode")); } @Override public void onUpdate(ItemStack par1ItemStack, World par2World, Entity par3Entity, int par4, boolean par5) { if(par1ItemStack.stackTagCompound == null) par1ItemStack.setTagCompound(new NBTTagCompound()); if(!par1ItemStack.stackTagCompound.hasKey("mode")) par1ItemStack.stackTagCompound.setInteger( "mode", 0); if(!par1ItemStack.stackTagCompound.hasKey("reload")) par1ItemStack.stackTagCompound.setInteger("reload", 100); if(par1ItemStack.stackTagCompound.getInteger("reload") != 0) { par1ItemStack.stackTagCompound.setInteger("reload", par1ItemStack.stackTagCompound.getInteger("reload") - 1); System.out.println(par1ItemStack.stackTagCompound.getInteger("mode")); } if(par1ItemStack.stackTagCompound.getInteger("reload") == 0) { //coolDownStr = "Status: " + "\u00A72Armed"; } else { //coolDownStr = "Status: \u00A74Reloading"; } } @Override public EnumRarity getRarity(ItemStack par1ItemStack) { return EnumRarity.uncommon; } } Creator Of Weapons+ Mod & Sword Art Online HUD Mod
May 24, 201411 yr public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer) { if( par1ItemStack.stackTagCompound == null ) par1ItemStack.setTagCompound( new NBTTagCompound( ) ); if(par3EntityPlayer.isSneaking()) { // Here's your problem. Check to see if the world is NOT remote. if (!world.isRemote) { code } if(par2World.isRemote) { ... if (user.hasKnowledgeOfJava) { if (user.question.hasCode) { return interpetHelpfulResponse(user.getQuestion()); } else { return "Could you post your code please?"; } } else { return "Learn some freaking Java!"; }
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.