diff --git a/src/main/java/com/zixiken/dimdoors/items/BaseItemDoor.java b/src/main/java/com/zixiken/dimdoors/items/BaseItemDoor.java index 744beeb9..b49ff85e 100644 --- a/src/main/java/com/zixiken/dimdoors/items/BaseItemDoor.java +++ b/src/main/java/com/zixiken/dimdoors/items/BaseItemDoor.java @@ -9,14 +9,11 @@ import com.zixiken.dimdoors.config.DDProperties; import com.zixiken.dimdoors.core.DimLink; import com.zixiken.dimdoors.core.PocketManager; import net.minecraft.block.Block; -import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.item.ItemDoor; import net.minecraft.item.ItemStack; -import net.minecraft.util.MathHelper; -import net.minecraft.util.MovingObjectPosition; -import net.minecraft.util.Vec3; +import net.minecraft.util.*; import net.minecraft.world.World; import com.zixiken.dimdoors.tileentities.TileEntityDimDoor; @@ -24,7 +21,7 @@ public abstract class BaseItemDoor extends ItemDoor { // Maps non-dimensional door items to their corresponding dimensional door item // Also maps dimensional door items to themselves for simplicity private static HashMap doorItemMapping = new HashMap(); - private static DDProperties properties = null; + private static DDProperties properties; /** * door represents the non-dimensional door this item is associated with. Leave null for none. @@ -40,20 +37,11 @@ public abstract class BaseItemDoor extends ItemDoor { doorItemMapping.put(this, this); if (vanillaDoor != null) - { doorItemMapping.put(vanillaDoor, this); - } } @Override - public void registerIcons(IIconRegister par1IconRegister) - { - this.itemIcon = par1IconRegister.registerIcon(DimDoors.modid + ":" + this.getUnlocalizedName().replace("item.", "")); - } - - @SuppressWarnings({ "rawtypes" }) - @Override - public abstract void addInformation(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, List par3List, boolean par4); + public abstract void addInformation(ItemStack stack, EntityPlayer playerIn, List tooltip, boolean advanced); /** * Overriden in subclasses to specify which door block that door item will @@ -63,15 +51,13 @@ public abstract class BaseItemDoor extends ItemDoor { */ protected abstract BaseDimDoor getDoorBlock(); - /** + /** * Overriden here to remove vanilla block placement functionality from * dimensional doors, we handle this in the EventHookContainer */ @Override - public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ) - { - return false; - } + public boolean onItemUse(ItemStack stack, EntityPlayer playerIn, World worldIn, BlockPos pos, + EnumFacing side, float hitX, float hitY, float hitZ) {return false;} /** * Tries to place a door as a dimensional door @@ -85,25 +71,18 @@ public abstract class BaseItemDoor extends ItemDoor { * @param side * @return */ - public static boolean tryToPlaceDoor(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side) - { - if (world.isRemote) - { - return false; - } + public static boolean tryToPlaceDoor(ItemStack stack, EntityPlayer player, World world, + BlockPos pos, EnumFacing side) { + if (world.isRemote) return false; + // Retrieve the actual door type that we want to use here. // It's okay if stack isn't an ItemDoor. In that case, the lookup will // return null, just as if the item was an unrecognized door type. BaseItemDoor mappedItem = doorItemMapping.get(stack.getItem()); - if (mappedItem == null) - { - return false; - } + if (mappedItem == null) return false; + BaseDimDoor doorBlock = mappedItem.getDoorBlock(); - if (BaseItemDoor.placeDoorOnBlock(doorBlock, stack, player, world, x, y, z, side)) - { - return true; - } + if (BaseItemDoor.placeDoorOnBlock(doorBlock, stack, player, world, pos, side)) return true; return BaseItemDoor.placeDoorOnRift(doorBlock, world, player, stack); } @@ -119,36 +98,22 @@ public abstract class BaseItemDoor extends ItemDoor { * @param side * @return */ - public static boolean placeDoorOnBlock(Block doorBlock, ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side) - { - if (world.isRemote) - { - return false; - } + public static boolean placeDoorOnBlock(Block doorBlock, ItemStack stack, EntityPlayer player, + World world, BlockPos pos, EnumFacing side) { + if (world.isRemote) return false; + // Only place doors on top of blocks - check if we're targeting the top // side - if (side == 1 && !world.isRemote) - { - Block block = world.getBlock(x, y, z); - if (!block.isAir(world, x, y, z)) - { - if (!block.isReplaceable(world, x, y, z)) - { - y++; - } - } + if (side == EnumFacing.UP) { + Block block = world.getBlockState(pos).getBlock(); + if (!block.isAir(world, pos) && !block.isReplaceable(world, pos)) pos = pos.up(); - if (canPlace(world, x, y, z) && canPlace(world, x, y + 1, z) && player.canPlayerEdit(x, y, z, side, stack) - && (player.canPlayerEdit(x, y + 1, z, side, stack) && stack.stackSize > 0) - &&((stack.getItem() instanceof BaseItemDoor) || PocketManager.getLink(x, y + 1, z, world) != null)) - { - int orientation = MathHelper.floor_double((player.rotationYaw + 180.0F) * 4.0F / 360.0F - 0.5D) & 3; - placeDoorBlock(world, x, y, z, orientation, doorBlock); - - if (!player.capabilities.isCreativeMode) - { - stack.stackSize--; - } + BlockPos upPos = pos.up(); + if (canPlace(world, pos) && canPlace(world, upPos) && player.canPlayerEdit(pos, side, stack) + && (player.canPlayerEdit(upPos, side, stack) && stack.stackSize > 0) + && ((stack.getItem() instanceof BaseItemDoor) || PocketManager.getLink(upPos, world) != null)) { + placeDoorBlock(world, pos, EnumFacing.fromAngle(player.rotationYaw), doorBlock); + if (!player.capabilities.isCreativeMode) stack.stackSize--; return true; } } @@ -164,41 +129,24 @@ public abstract class BaseItemDoor extends ItemDoor { * @param stack * @return */ - public static boolean placeDoorOnRift(Block doorBlock, World world, EntityPlayer player, ItemStack stack) - { - if (world.isRemote) - { - return false; - } + public static boolean placeDoorOnRift(Block doorBlock, World world, EntityPlayer player, ItemStack stack) { + if (world.isRemote) return false; - MovingObjectPosition hit = BaseItemDoor.doRayTrace(player.worldObj, player, true); - if (hit != null) - { - if (world.getBlock(hit.blockX, hit.blockY, hit.blockZ) == DimDoors.blockRift) - { - DimLink link = PocketManager.getLink(hit.blockX, hit.blockY, hit.blockZ, world.provider.dimensionId); - if (link != null) - { - int x = hit.blockX; - int y = hit.blockY; - int z = hit.blockZ; - - if (player.canPlayerEdit(x, y, z, hit.sideHit, stack) && player.canPlayerEdit(x, y - 1, z, hit.sideHit, stack)) - { - if (canPlace(world, x, y, z) && canPlace(world, x, y - 1, z)) - { - int orientation = MathHelper.floor_double(((player.rotationYaw + 180.0F) * 4.0F / 360.0F) - 0.5D) & 3; - placeDoorBlock(world, x, y - 1, z, orientation, doorBlock); - if (!(stack.getItem() instanceof BaseItemDoor)) - { - ((TileEntityDimDoor) world.getTileEntity(x, y, z)).hasGennedPair = true; - } - if (!player.capabilities.isCreativeMode) - { - stack.stackSize--; - } - return true; - } + MovingObjectPosition hit = BaseItemDoor.doRayTrace(world, player, true); + if (hit != null) { + BlockPos pos = hit.getBlockPos(); + if (world.getBlockState(pos).getBlock() == DimDoors.blockRift) { + DimLink link = PocketManager.getLink(pos, world.provider.getDimensionId()); + if (link != null) { + BlockPos downPos = pos.down(); + if (player.canPlayerEdit(pos, hit.sideHit, stack) && + player.canPlayerEdit(downPos, hit.sideHit, stack) && + canPlace(world, pos) && canPlace(world, downPos)) { + placeDoorBlock(world, downPos, EnumFacing.fromAngle(player.rotationYaw), doorBlock); + if (!(stack.getItem() instanceof BaseItemDoor)) + ((TileEntityDimDoor) world.getTileEntity(pos)).hasGennedPair = true; + if (!player.capabilities.isCreativeMode) stack.stackSize--; + return true; } } } @@ -206,11 +154,10 @@ public abstract class BaseItemDoor extends ItemDoor { return false; } - public static boolean canPlace(World world, int x, int y, int z) - { - Block block = world.getBlock(x, y, z); + public static boolean canPlace(World world, BlockPos pos) { + Block block = world.getBlockState(pos).getBlock(); - return (block == DimDoors.blockRift || block.isAir(world, x, y, z) || block.getMaterial().isReplaceable()); + return (block == DimDoors.blockRift || block.isAir(world, pos) || block.getMaterial().isReplaceable()); } /** @@ -222,28 +169,23 @@ public abstract class BaseItemDoor extends ItemDoor { * @param par3 * @return */ - protected static MovingObjectPosition doRayTrace(World par1World, EntityPlayer par2EntityPlayer, boolean par3) - { - float f = 1.0F; - float f1 = par2EntityPlayer.prevRotationPitch + (par2EntityPlayer.rotationPitch - par2EntityPlayer.prevRotationPitch) * f; - float f2 = par2EntityPlayer.prevRotationYaw + (par2EntityPlayer.rotationYaw - par2EntityPlayer.prevRotationYaw) * f; - double d0 = par2EntityPlayer.prevPosX + (par2EntityPlayer.posX - par2EntityPlayer.prevPosX) * (double) f; - double d1 = par2EntityPlayer.prevPosY + (par2EntityPlayer.posY - par2EntityPlayer.prevPosY) * (double) f - + (double) (par1World.isRemote ? par2EntityPlayer.getEyeHeight() - par2EntityPlayer.getDefaultEyeHeight() : par2EntityPlayer.getEyeHeight()); - double d2 = par2EntityPlayer.prevPosZ + (par2EntityPlayer.posZ - par2EntityPlayer.prevPosZ) * (double) f; - Vec3 vec3 = Vec3.createVectorHelper (d0, d1, d2); - float f3 = MathHelper.cos(-f2 * 0.017453292F - (float) Math.PI); - float f4 = MathHelper.sin(-f2 * 0.017453292F - (float) Math.PI); - float f5 = -MathHelper.cos(-f1 * 0.017453292F); - float f6 = MathHelper.sin(-f1 * 0.017453292F); - float f7 = f4 * f5; - float f8 = f3 * f5; - double d3 = 5.0D; - if (par2EntityPlayer instanceof EntityPlayerMP) - { - d3 = ((EntityPlayerMP) par2EntityPlayer).theItemInWorldManager.getBlockReachDistance(); - } - Vec3 vec31 = vec3.addVector((double) f7 * d3, (double) f6 * d3, (double) f8 * d3); - return par1World.rayTraceBlocks(vec3, vec31, par3); - } + protected static MovingObjectPosition doRayTrace(World worldIn, EntityPlayer playerIn, boolean useLiquids) { + float f = playerIn.rotationPitch; + float f1 = playerIn.rotationYaw; + double d0 = playerIn.posX; + double d1 = playerIn.posY + (double)playerIn.getEyeHeight(); + double d2 = playerIn.posZ; + Vec3 vec3 = new Vec3(d0, d1, d2); + float f2 = MathHelper.cos(-f1 * 0.017453292F - (float)Math.PI); + float f3 = MathHelper.sin(-f1 * 0.017453292F - (float)Math.PI); + float f4 = -MathHelper.cos(-f * 0.017453292F); + float f5 = MathHelper.sin(-f * 0.017453292F); + float f6 = f3 * f4; + float f7 = f2 * f4; + double d3 = 5.0D; + if (playerIn instanceof EntityPlayerMP) + d3 = ((EntityPlayerMP)playerIn).theItemInWorldManager.getBlockReachDistance(); + Vec3 vec31 = vec3.addVector((double)f6 * d3, (double)f5 * d3, (double)f7 * d3); + return worldIn.rayTraceBlocks(vec3, vec31, useLiquids, !useLiquids, false); + } } \ No newline at end of file