Jump to content

Moose in a Suit

Members
  • Posts

    1
  • Joined

  • Last visited

Moose in a Suit's Achievements

Tree Puncher

Tree Puncher (2/8)

0

Reputation

  1. Hey! First of all I just want to say thanks for taking the time to read this cry for help! I am a new modder but I have used Java a bit. I've been trying to fix this issue for a while: I have made an item (stable pearl) that stores the location of the player, removes the item from the players inventory and gives them a new item (charged pearl) with set coordinates. When the player right clicks on this item it will teleport them to that location. However, there are 2 issues that I cannot fix: When I use multiple stable pearls to make charged pearls, they do not store their own individual values. This results in all of the charged pearls made teleporting me to the most recent set point. If I have a made a charged pearl set to a location, shut down the game and open it again, the location will be reset to null. I have been trying to find a solution to this but cannot find any. Any suggestions would be appreciated :D I should also probably say that this is for 1.7.10 minecraft. Code of "stable pearl" (item that puts a "charged pearl" into the players inventory while removing itself) package pack.items; import pack.mainFile; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.world.World; public class ItemStablePearl extends Item { public ItemStablePearl() { this.setMaxStackSize(1); } public ItemStack onItemRightClick(ItemStack item, World world, EntityPlayer player) { //decrements the size of the stack by 1 --item.stackSize; //creates new item Item chargedPearl = mainFile.itemChargedPearl; //calls item method for setting positions ((ItemChargedPearl) chargedPearl).initPositions(player.posX, player.posY, player.posZ, player.rotationPitch, player.getRotationYawHead()); //adds item to player inventory, if it is full, the item will be dropped if (!player.inventory.addItemStackToInventory(new ItemStack(chargedPearl))) player.dropItem(chargedPearl, 1); return item; } } Code of "charged pearl" (made from the "stable Pearl" that allows the player to teleport to the set location) package pack.items; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.world.World; public class ItemChargedPearl extends Item { private Double posX; private Double posY; private Double posZ; private float pitch = 0; private float yaw = 0; public ItemChargedJubbPearl() { this.setMaxStackSize(1); } //called in "ItemStablePearl()" to initialise variables public void initPositions(Double posX, Double posY, Double posZ, float pitch, float yaw) { this.posX = posX; this.posY = posY; this.posZ = posZ; this.pitch = pitch; this.yaw = yaw; } public ItemStack onItemRightClick(ItemStack item, World world, EntityPlayer player) { //if there is no set location, a message will print to console (for some reason, it prints twice?) if (this.posX == null) { System.out.println("Unregistered Pearl"); } //otherwise, will change the players position and rotation according to the values set by the "Stable pearl" else { player.setPositionAndRotation(this.posX, this.posY, this.posZ, this.yaw, this.pitch); //if the player is not in creative mode, remove the item if (!player.capabilities.isCreativeMode) --item.stackSize; } return item; } } Oh and one final note, would I have to change anything in order to make this mod multiplayer friendly? I'd appreciate any feedback
×
×
  • Create New...

Important Information

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