Guest User

Untitled

a guest
Jun 29th, 2014
297
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.43 KB | None | 0 0
  1. package com.shane.va.items;
  2.  
  3. import net.minecraft.block.Block;
  4. import net.minecraft.block.material.Material;
  5. import net.minecraft.block.material.MaterialLiquid;
  6. import net.minecraft.entity.Entity;
  7. import net.minecraft.entity.player.EntityPlayer;
  8. import net.minecraft.entity.player.EntityPlayerMP;
  9. import net.minecraft.item.Item;
  10. import net.minecraft.item.ItemStack;
  11. import net.minecraft.network.play.server.S08PacketPlayerPosLook;
  12. import net.minecraft.util.MathHelper;
  13. import net.minecraft.world.World;
  14.  
  15. import com.shane.va.VehicleAssembly;
  16.  
  17. public class ItemTest extends Item{
  18.  
  19.     public ItemTest(){
  20.         this.setCreativeTab(VehicleAssembly.getCreativeTab());
  21.     }
  22.    
  23.     public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player) {
  24.         if(!world.isRemote)
  25.             teleportTo(player, world, (int)player.posX, (int)player.posY + 20, (int)player.posZ);
  26.         else
  27.             System.out.println("world is remote");
  28.         return super.onItemRightClick(stack, world, player);
  29.     }
  30.  
  31.     /*public void teleport( World world, EntityPlayer player){
  32.        if (!world.isRemote) teleportTo(player, maxStackSize, maxStackSize, maxStackSize);
  33.     }*/
  34.  
  35.     protected boolean teleportTo(Entity entity, World world, int randX, int randY, int randZ) {
  36.         double coordX = entity.posX;
  37.         double coordY = entity.posY;
  38.         double coordZ = entity.posZ;
  39.         boolean flag = false;
  40.         int x = MathHelper.floor_double(randX);
  41.         int y = MathHelper.floor_double(randY);
  42.         int z = MathHelper.floor_double(randZ);
  43.         float yaw = entity.rotationYaw;
  44.         float pitch = entity.rotationPitch;
  45.         if (world.blockExists(x, y, z)) {
  46.             boolean flag1 = false;
  47.             Block block = world.getBlock(x, y-2, z);
  48.             Material material = block.getMaterial();
  49.             if(!(material instanceof MaterialLiquid))
  50.                 flag1 = true;
  51.            
  52.             if (flag1) {
  53.                 flag = true;
  54.                 if(entity instanceof EntityPlayerMP)
  55.                     this.setPlayerLocation((EntityPlayerMP)entity, x, y, z, yaw, pitch);
  56.                 else
  57.                     entity.setLocationAndAngles(x, y, z, yaw, pitch);
  58.             }
  59.             else {
  60.                 flag = true;
  61.               //couldn't teleport the player.
  62.             }
  63.       }
  64.       return flag;
  65.     }
  66.    
  67.     protected void setPlayerLocation(EntityPlayerMP playerEntity, double coordX, double coordY, double coordZ, float yaw, float pitch) {
  68.         playerEntity.setPositionAndRotation(coordX, coordY, coordZ, yaw, pitch);
  69.         playerEntity.playerNetServerHandler.sendPacket(new S08PacketPlayerPosLook(coordX, coordY + 1.6200000047683716D, coordZ, yaw, pitch, false));
  70.     }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment