From 2a4c9ba120d4af4dd9e96952e252d701ea55dc9e Mon Sep 17 00:00:00 2001 From: Mathijs Riezebos Date: Fri, 13 Jan 2017 07:45:45 +0100 Subject: [PATCH] Door-placement- and rift-registering-fixes -Due to testing, found out that "RiftRegistry.nextRiftID"gets saved and loaded correctly. -DimDoors are no longer placeable on leaves or glass (ItemDoorBase.java) -DimDoors will no longer be placed through left-clicking (EventHookContainer.java) -Relocated call to DDTileEntityBase.register() from its constructor to ItemDoorBase right after the door gets placed. Which means that that whole constructor and its overrides in other classes are not needed anymore. -Added failsafe, so that a DDTileEntityBase that is already registered, doesn't register again. --- .../zixiken/dimdoors/EventHookContainer.java | 4 ++- .../dimdoors/blocks/BlockDimDoorBase.java | 2 +- .../dimdoors/blocks/BlockDimDoorGold.java | 2 +- .../zixiken/dimdoors/blocks/BlockRift.java | 2 +- .../dimdoors/blocks/BlockTransTrapdoor.java | 2 +- .../zixiken/dimdoors/items/ItemDoorBase.java | 9 +++++- .../tileentities/DDTileEntityBase.java | 30 ++++++++----------- .../tileentities/TileEntityDimDoor.java | 5 ---- .../tileentities/TileEntityDimDoorGold.java | 5 ---- .../dimdoors/tileentities/TileEntityRift.java | 5 ++-- .../tileentities/TileEntityTransTrapdoor.java | 5 ---- 11 files changed, 30 insertions(+), 41 deletions(-) diff --git a/src/main/java/com/zixiken/dimdoors/EventHookContainer.java b/src/main/java/com/zixiken/dimdoors/EventHookContainer.java index 7f34f63a..80da22dc 100644 --- a/src/main/java/com/zixiken/dimdoors/EventHookContainer.java +++ b/src/main/java/com/zixiken/dimdoors/EventHookContainer.java @@ -2,6 +2,7 @@ package com.zixiken.dimdoors; import com.zixiken.dimdoors.items.ItemDoorBase; import net.minecraft.item.ItemStack; +import net.minecraft.util.EnumHand; import net.minecraft.world.World; import net.minecraftforge.event.entity.player.PlayerInteractEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; @@ -14,7 +15,8 @@ public class EventHookContainer { World world = event.getEntity().world; ItemStack stack = event.getEntityPlayer().inventory.getCurrentItem(); - if (stack != null && ItemDoorBase.tryToPlaceDoor(stack, event.getEntityPlayer(), world, event.getPos(), event.getFace())) // Cancel the event so that we don't get two doors from vanilla doors + if (event.getHand() == EnumHand.OFF_HAND //right-click + && stack != null && ItemDoorBase.tryToPlaceDoor(stack, event.getEntityPlayer(), world, event.getPos(), event.getFace())) // Cancel the event so that we don't get two doors from vanilla doors { event.setCanceled(true); } diff --git a/src/main/java/com/zixiken/dimdoors/blocks/BlockDimDoorBase.java b/src/main/java/com/zixiken/dimdoors/blocks/BlockDimDoorBase.java index dd6e7134..92a2d964 100644 --- a/src/main/java/com/zixiken/dimdoors/blocks/BlockDimDoorBase.java +++ b/src/main/java/com/zixiken/dimdoors/blocks/BlockDimDoorBase.java @@ -113,7 +113,7 @@ public abstract class BlockDimDoorBase extends BlockDoor implements IDimDoor, IT @Override public TileEntity createNewTileEntity(World world, int metadata) { - return new TileEntityDimDoor(world); + return new TileEntityDimDoor(); } @Override diff --git a/src/main/java/com/zixiken/dimdoors/blocks/BlockDimDoorGold.java b/src/main/java/com/zixiken/dimdoors/blocks/BlockDimDoorGold.java index aaef615b..e9fbc467 100644 --- a/src/main/java/com/zixiken/dimdoors/blocks/BlockDimDoorGold.java +++ b/src/main/java/com/zixiken/dimdoors/blocks/BlockDimDoorGold.java @@ -31,7 +31,7 @@ public class BlockDimDoorGold extends BlockDimDoorBase { @Override public TileEntity createNewTileEntity(World world, int metadata) { - return new TileEntityDimDoorGold(world); + return new TileEntityDimDoorGold(); } } diff --git a/src/main/java/com/zixiken/dimdoors/blocks/BlockRift.java b/src/main/java/com/zixiken/dimdoors/blocks/BlockRift.java index f71788ce..d77eed67 100644 --- a/src/main/java/com/zixiken/dimdoors/blocks/BlockRift.java +++ b/src/main/java/com/zixiken/dimdoors/blocks/BlockRift.java @@ -188,7 +188,7 @@ public class BlockRift extends Block implements ITileEntityProvider { @Override public TileEntity createNewTileEntity(World world, int metadata) { - return new TileEntityRift(world); + return new TileEntityRift(); } @Override diff --git a/src/main/java/com/zixiken/dimdoors/blocks/BlockTransTrapdoor.java b/src/main/java/com/zixiken/dimdoors/blocks/BlockTransTrapdoor.java index 8178c9c4..c88cab07 100644 --- a/src/main/java/com/zixiken/dimdoors/blocks/BlockTransTrapdoor.java +++ b/src/main/java/com/zixiken/dimdoors/blocks/BlockTransTrapdoor.java @@ -83,7 +83,7 @@ public class BlockTransTrapdoor extends BlockTrapDoor implements IDimDoor, ITile @Override public TileEntity createNewTileEntity(World world, int metadata) { - return new TileEntityTransTrapdoor(world); + return new TileEntityTransTrapdoor(); } @Override diff --git a/src/main/java/com/zixiken/dimdoors/items/ItemDoorBase.java b/src/main/java/com/zixiken/dimdoors/items/ItemDoorBase.java index 0382972b..fb5a0d84 100644 --- a/src/main/java/com/zixiken/dimdoors/items/ItemDoorBase.java +++ b/src/main/java/com/zixiken/dimdoors/items/ItemDoorBase.java @@ -6,6 +6,7 @@ import java.util.List; import com.zixiken.dimdoors.DimDoors; import com.zixiken.dimdoors.blocks.BlockDimDoorBase; import com.zixiken.dimdoors.blocks.ModBlocks; +import com.zixiken.dimdoors.tileentities.DDTileEntityBase; import net.minecraft.block.Block; import net.minecraft.block.state.IBlockState; import net.minecraft.entity.player.EntityPlayer; @@ -20,6 +21,7 @@ import net.minecraft.util.math.RayTraceResult; import net.minecraft.util.math.Vec3d; import net.minecraft.world.World; import com.zixiken.dimdoors.tileentities.TileEntityDimDoor; +import net.minecraft.tileentity.TileEntity; public abstract class ItemDoorBase extends ItemDoor { // Maps non-dimensional door items to their corresponding dimensional door item @@ -118,8 +120,13 @@ public abstract class ItemDoorBase extends ItemDoor { 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 ItemDoorBase) { + && stack.getItem() instanceof ItemDoorBase && world.getBlockState(pos.down()).isSideSolid(world, pos, side)) { placeDoor(world, pos, EnumFacing.fromAngle(player.rotationYaw), doorBlock, true); + TileEntity tileEntity = world.getTileEntity(pos.up()); + if (tileEntity instanceof DDTileEntityBase) { + DDTileEntityBase rift = (DDTileEntityBase) tileEntity; + rift.register(); + } if (!player.capabilities.isCreativeMode) { stack.stackSize--; } diff --git a/src/main/java/com/zixiken/dimdoors/tileentities/DDTileEntityBase.java b/src/main/java/com/zixiken/dimdoors/tileentities/DDTileEntityBase.java index dddd0b3d..6e3290eb 100644 --- a/src/main/java/com/zixiken/dimdoors/tileentities/DDTileEntityBase.java +++ b/src/main/java/com/zixiken/dimdoors/tileentities/DDTileEntityBase.java @@ -11,7 +11,7 @@ import net.minecraft.world.World; public abstract class DDTileEntityBase extends TileEntity { public boolean isPaired = false; - public int riftID; + public int riftID = -1; //should not start at 0 public int pairedRiftID; /** @@ -19,18 +19,12 @@ public abstract class DDTileEntityBase extends TileEntity { * @return an array of floats representing RGBA color where 1.0 = 255. */ public abstract float[] getRenderColor(Random rand); - - DDTileEntityBase(World world) { //@todo what is the difference between a TileEntity instance being created on Block placement and on world-load? - super(); - this.setWorld(world); - register(); - } - + @Override public boolean shouldRefresh(World world, BlockPos pos, IBlockState oldState, IBlockState newSate) { return oldState.getBlock() != newSate.getBlock(); } - + public void pair(int otherRiftID) { if (isPaired) { if (otherRiftID == pairedRiftID) { @@ -40,11 +34,11 @@ public abstract class DDTileEntityBase extends TileEntity { } } pairedRiftID = otherRiftID; - RiftRegistry.Instance.pair(pairedRiftID, riftID); + RiftRegistry.Instance.pair(pairedRiftID, riftID); isPaired = true; this.markDirty(); } - + public void unpair() { if (!isPaired) { return; @@ -54,12 +48,14 @@ public abstract class DDTileEntityBase extends TileEntity { } this.markDirty(); } - - private void register() { - riftID = RiftRegistry.Instance.registerNewRift(this); - this.markDirty(); + + public void register() { + if (riftID == -1) { + riftID = RiftRegistry.Instance.registerNewRift(this); + this.markDirty(); + } } - + @Override public void readFromNBT(NBTTagCompound nbt) { super.readFromNBT(nbt); @@ -70,7 +66,7 @@ public abstract class DDTileEntityBase extends TileEntity { } catch (Exception e) { } } - + @Override public NBTTagCompound writeToNBT(NBTTagCompound nbt) { super.writeToNBT(nbt); diff --git a/src/main/java/com/zixiken/dimdoors/tileentities/TileEntityDimDoor.java b/src/main/java/com/zixiken/dimdoors/tileentities/TileEntityDimDoor.java index 7f48dfed..638b62fa 100644 --- a/src/main/java/com/zixiken/dimdoors/tileentities/TileEntityDimDoor.java +++ b/src/main/java/com/zixiken/dimdoors/tileentities/TileEntityDimDoor.java @@ -4,7 +4,6 @@ import java.util.Random; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.EnumFacing; -import net.minecraft.world.World; public class TileEntityDimDoor extends DDTileEntityBase { @@ -15,10 +14,6 @@ public class TileEntityDimDoor extends DDTileEntityBase { public boolean isDungeonChainLink; public boolean hasGennedPair = false; - public TileEntityDimDoor(World world) { - super(world); - } - @Override public void readFromNBT(NBTTagCompound nbt) { super.readFromNBT(nbt); diff --git a/src/main/java/com/zixiken/dimdoors/tileentities/TileEntityDimDoorGold.java b/src/main/java/com/zixiken/dimdoors/tileentities/TileEntityDimDoorGold.java index ebbd45a7..eef886c2 100644 --- a/src/main/java/com/zixiken/dimdoors/tileentities/TileEntityDimDoorGold.java +++ b/src/main/java/com/zixiken/dimdoors/tileentities/TileEntityDimDoorGold.java @@ -1,7 +1,6 @@ package com.zixiken.dimdoors.tileentities; import com.zixiken.dimdoors.IChunkLoader; -import net.minecraft.world.World; import net.minecraftforge.common.ForgeChunkManager; import net.minecraftforge.common.ForgeChunkManager.Ticket; @@ -10,10 +9,6 @@ public class TileEntityDimDoorGold extends TileEntityDimDoor implements IChunkLo private Ticket chunkTicket; private boolean initialized = false; - public TileEntityDimDoorGold(World world) { - super(world); - } - @Override public boolean isInitialized() { return initialized; diff --git a/src/main/java/com/zixiken/dimdoors/tileentities/TileEntityRift.java b/src/main/java/com/zixiken/dimdoors/tileentities/TileEntityRift.java index d0a97feb..b3b1c6f8 100644 --- a/src/main/java/com/zixiken/dimdoors/tileentities/TileEntityRift.java +++ b/src/main/java/com/zixiken/dimdoors/tileentities/TileEntityRift.java @@ -11,7 +11,6 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.ITickable; import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; public class TileEntityRift extends DDTileEntityBase implements ITickable { private static final int ENDERMAN_SPAWNING_CHANCE = 1; @@ -30,8 +29,8 @@ public class TileEntityRift extends DDTileEntityBase implements ITickable { public int riftRotation = random.nextInt(360); public float growth = 0; - public TileEntityRift(World world) { - super(world); + public TileEntityRift() { + super(); // Vary the update times of rifts to prevent all the rifts in a cluster // from updating at the same time. updateTimer = random.nextInt(UPDATE_PERIOD); diff --git a/src/main/java/com/zixiken/dimdoors/tileentities/TileEntityTransTrapdoor.java b/src/main/java/com/zixiken/dimdoors/tileentities/TileEntityTransTrapdoor.java index f0d99d8b..0e639d25 100644 --- a/src/main/java/com/zixiken/dimdoors/tileentities/TileEntityTransTrapdoor.java +++ b/src/main/java/com/zixiken/dimdoors/tileentities/TileEntityTransTrapdoor.java @@ -1,14 +1,9 @@ package com.zixiken.dimdoors.tileentities; import java.util.Random; -import net.minecraft.world.World; public class TileEntityTransTrapdoor extends DDTileEntityBase { - public TileEntityTransTrapdoor(World world) { - super(world); - } - @Override public float[] getRenderColor(Random rand) { float[] rgbaColor = {1, 1, 1, 1};