Advertisement
Guest User

Untitled

a guest
Apr 1st, 2018
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.74 KB | None | 0 0
  1. public class VanqarTeleporter extends Teleporter
  2. {
  3.     public VanqarTeleporter(WorldServer worldIn)
  4.     {
  5.         super(worldIn);
  6.     }
  7.  
  8.     @Override
  9.     public void placeInPortal(Entity entityIn, float rotationYaw)
  10.     {
  11.         if(world.provider.getDimensionType() == Dimensions.vanqarDimension)
  12.         {
  13.             this.placeInExistingPortal(entityIn, rotationYaw);
  14.             this.makePortal(entityIn);
  15.         }
  16.     }
  17.  
  18.     @Override
  19.     public boolean makePortal(Entity entityIn)
  20.     {
  21.  
  22.         int posX = MathHelper.floor(entityIn.posX);
  23.         int posY = MathHelper.floor(entityIn.posY);
  24.         int posZ = MathHelper.floor(entityIn.posZ);
  25.         BlockPos entityPos = new BlockPos(posX, posY, posZ);
  26.  
  27.         for (int y = 64; y < posY + 16; ++y)
  28.         {
  29.             for(int x = posX - 16; x <= posX + 16; ++x)
  30.             {
  31.                 for(int z = posZ; z <= posZ + 16; ++z)
  32.                 {
  33.                         BlockPos placePos = new BlockPos(x, y, z);
  34.                         if (entityPos.equals(placePos))
  35.                         {
  36.                             world.setBlockState(placePos, Blocks.OAK_DOOR.getDefaultState().withProperty(BlockDoor.HALF, BlockDoor.EnumDoorHalf.LOWER));
  37.                         } else if (placePos.equals(entityPos.up()))
  38.                         {
  39.                             world.setBlockState(placePos, Blocks.OAK_DOOR.getDefaultState().withProperty(BlockDoor.HALF, BlockDoor.EnumDoorHalf.UPPER));
  40.                         } else if (z == posZ)
  41.                         {
  42.                             world.setBlockState(placePos, Blocks.CONCRETE.getDefaultState().withProperty(BlockColored.COLOR, EnumDyeColor.GRAY));
  43.                             System.out.println(world.provider);
  44.                         }
  45.                         else
  46.                         {
  47.                             world.setBlockToAir(placePos);
  48.                         }
  49.                     }
  50.             }
  51.         }
  52.  
  53.         return true;
  54.     }
  55.  
  56.     @Override
  57.     public boolean placeInExistingPortal(Entity entityIn, float rotationYaw)
  58.     {
  59.         int posX = MathHelper.floor(entityIn.posX);
  60.         int posZ = MathHelper.floor(entityIn.posZ);
  61.         long chunkPos = ChunkPos.asLong(posX, posZ);
  62.         BlockPos teleportPos;
  63.  
  64.         if(this.destinationCoordinateCache.containsValue(chunkPos))
  65.         {
  66.             PortalPosition portalPosition = destinationCoordinateCache.get(chunkPos);
  67.             portalPosition.lastUpdateTime = world.getTotalWorldTime();
  68.             teleportPos = new BlockPos(posX, 64, posZ);
  69.         }
  70.         else
  71.         {
  72.             teleportPos = findPortal(posX, posZ);
  73.             if(teleportPos == null)
  74.             {
  75.                 teleportPos = new BlockPos(posX, 64, posZ);
  76.             }
  77.             destinationCoordinateCache.put(chunkPos, new PortalPosition(teleportPos, world.getTotalWorldTime()));
  78.         }
  79.  
  80.         if(entityIn instanceof EntityPlayerMP)
  81.             ((EntityPlayerMP) entityIn).connection.setPlayerLocation(teleportPos.getX(), teleportPos.getY(), teleportPos.getZ(), rotationYaw, entityIn.rotationPitch);
  82.         else
  83.             entityIn.setPositionAndRotation(teleportPos.getX(), teleportPos.getY(), teleportPos.getZ(), rotationYaw, entityIn.rotationPitch);
  84.  
  85.         return true;
  86.     }
  87.  
  88.     @Nullable
  89.     private BlockPos findPortal(int posX, int posZ)
  90.     {
  91.         for(int x = posX - 128; x < posX + 128; ++x)
  92.         {
  93.             for(int z = posZ - 128; z < posZ + 128; ++z)
  94.             {
  95.                 BlockPos blockPos = new BlockPos(x, 64, z);
  96.                 if(world.getBlockState(blockPos).getBlock() == SCPBlocks.door860)
  97.                     return blockPos;
  98.             }
  99.         }
  100.         return null;
  101.     }
  102. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement