AlexSocol

Connector

Mar 4th, 2016
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.97 KB | None | 0 0
  1. package alexsocol.osm.items;
  2.  
  3. import java.util.List;
  4.  
  5. import alexsocol.osm.ModInfo;
  6. import alexsocol.osm.OSMMain;
  7. import alexsocol.osm.blocks.tileentity.PortalInTileEntity;
  8. import net.minecraft.entity.player.EntityPlayer;
  9. import net.minecraft.item.Item;
  10. import net.minecraft.item.ItemStack;
  11. import net.minecraft.nbt.NBTTagCompound;
  12. import net.minecraft.tileentity.TileEntity;
  13. import net.minecraft.util.MovingObjectPosition;
  14. import net.minecraft.util.Vec3;
  15. import net.minecraft.world.World;
  16.  
  17. public class PortalConnectingModule extends Item {
  18.  
  19.     public PortalConnectingModule() {
  20.         this.setCreativeTab(OSMMain.osmTab);
  21.         this.setTextureName(ModInfo.MODID + ":PortalConnectingModule");
  22.         this.setUnlocalizedName("PortalConnectingModule");
  23.     }
  24.  
  25.     @Override
  26.     public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ) {
  27.         if (!world.isRemote){
  28.             if (player.isSneaking()){
  29.                 stack.stackTagCompound = new NBTTagCompound();
  30.                
  31.                 stack.stackTagCompound.setDouble("telepX", x + 0.5);
  32.                 stack.stackTagCompound.setDouble("telepY", y + 1);
  33.                 stack.stackTagCompound.setDouble("telepZ", z + 0.5);   
  34.             }
  35.             if (!player.isSneaking()){
  36.                 TileEntity tile = world.getTileEntity(x, y, z);
  37.                 if (tile instanceof PortalInTileEntity){
  38.                     PortalInTileEntity portal = (PortalInTileEntity)tile;
  39.                     portal.CordX = stack.stackTagCompound.getDouble("telepX");
  40.                     portal.CordY = stack.stackTagCompound.getDouble("telepY");
  41.                     portal.CordZ = stack.stackTagCompound.getDouble("telepZ");
  42.                 }
  43.             }
  44.         }
  45.         return true;
  46.     }
  47.  
  48.     public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean par4) {
  49.         if (stack.stackTagCompound != null) {
  50.             list.add("X: " + stack.stackTagCompound.getDouble("telepX"));
  51.             list.add("Y: " + stack.stackTagCompound.getDouble("telepY"));
  52.             list.add("Z: " + stack.stackTagCompound.getDouble("telepZ"));
  53.         }
  54.     }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment