Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.shane.va.items;
- import net.minecraft.block.Block;
- import net.minecraft.block.material.Material;
- import net.minecraft.block.material.MaterialLiquid;
- import net.minecraft.entity.Entity;
- 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.network.play.server.S08PacketPlayerPosLook;
- import net.minecraft.util.MathHelper;
- import net.minecraft.world.World;
- import com.shane.va.VehicleAssembly;
- public class ItemTest extends Item{
- public ItemTest(){
- this.setCreativeTab(VehicleAssembly.getCreativeTab());
- }
- public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player) {
- if(!world.isRemote)
- teleportTo(player, world, (int)player.posX, (int)player.posY + 20, (int)player.posZ);
- else
- System.out.println("world is remote");
- return super.onItemRightClick(stack, world, player);
- }
- /*public void teleport( World world, EntityPlayer player){
- if (!world.isRemote) teleportTo(player, maxStackSize, maxStackSize, maxStackSize);
- }*/
- protected boolean teleportTo(Entity entity, World world, int randX, int randY, int randZ) {
- double coordX = entity.posX;
- double coordY = entity.posY;
- double coordZ = entity.posZ;
- boolean flag = false;
- int x = MathHelper.floor_double(randX);
- int y = MathHelper.floor_double(randY);
- int z = MathHelper.floor_double(randZ);
- float yaw = entity.rotationYaw;
- float pitch = entity.rotationPitch;
- if (world.blockExists(x, y, z)) {
- boolean flag1 = false;
- Block block = world.getBlock(x, y-2, z);
- Material material = block.getMaterial();
- if(!(material instanceof MaterialLiquid))
- flag1 = true;
- if (flag1) {
- flag = true;
- if(entity instanceof EntityPlayerMP)
- this.setPlayerLocation((EntityPlayerMP)entity, x, y, z, yaw, pitch);
- else
- entity.setLocationAndAngles(x, y, z, yaw, pitch);
- }
- else {
- flag = true;
- //couldn't teleport the player.
- }
- }
- return flag;
- }
- protected void setPlayerLocation(EntityPlayerMP playerEntity, double coordX, double coordY, double coordZ, float yaw, float pitch) {
- playerEntity.setPositionAndRotation(coordX, coordY, coordZ, yaw, pitch);
- playerEntity.playerNetServerHandler.sendPacket(new S08PacketPlayerPosLook(coordX, coordY + 1.6200000047683716D, coordZ, yaw, pitch, false));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment