diff --git a/.gitignore b/.gitignore index f36ac1ed..22064b00 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ build/ .gradle/ .idea/ run/ +libs/ out/ *.iml *.ipr diff --git a/src/main/java/com/zixiken/dimdoors/shared/DDProxyCommon.java b/src/main/java/com/zixiken/dimdoors/shared/DDProxyCommon.java index eb164b02..7d222ce8 100644 --- a/src/main/java/com/zixiken/dimdoors/shared/DDProxyCommon.java +++ b/src/main/java/com/zixiken/dimdoors/shared/DDProxyCommon.java @@ -4,8 +4,10 @@ import com.zixiken.dimdoors.shared.blocks.BlockDimDoorBase; import com.zixiken.dimdoors.shared.blocks.ModBlocks; import com.zixiken.dimdoors.shared.items.ModItems; import com.zixiken.dimdoors.shared.tileentities.TileEntityDimDoor; +import com.zixiken.dimdoors.shared.tileentities.TileEntityDimDoorChaos; import com.zixiken.dimdoors.shared.tileentities.TileEntityDimDoorGold; import com.zixiken.dimdoors.shared.tileentities.TileEntityDimDoorPersonal; +import com.zixiken.dimdoors.shared.tileentities.TileEntityDimDoorWarp; import com.zixiken.dimdoors.shared.tileentities.TileEntityRift; import com.zixiken.dimdoors.shared.tileentities.TileEntityTransTrapdoor; import com.zixiken.dimdoors.shared.world.DimDoorDimensions; @@ -30,10 +32,11 @@ public abstract class DDProxyCommon implements IDDProxy { GameRegistry.registerTileEntity(TileEntityDimDoor.class, "TileEntityDimDoor"); GameRegistry.registerTileEntity(TileEntityRift.class, "TileEntityRift"); - GameRegistry.registerTileEntity(TileEntityTransTrapdoor.class, "TileEntityDimHatch"); + GameRegistry.registerTileEntity(TileEntityTransTrapdoor.class, "TileEntityTransTrapdoor"); GameRegistry.registerTileEntity(TileEntityDimDoorGold.class, "TileEntityDimDoorGold"); GameRegistry.registerTileEntity(TileEntityDimDoorPersonal.class, "TileEntityDimDoorPersonal"); - //@todo register other TileEntities + GameRegistry.registerTileEntity(TileEntityDimDoorChaos.class, "TileEntityDimDoorChaos"); + GameRegistry.registerTileEntity(TileEntityDimDoorWarp.class, "TileEntityDimDoorWarp"); } @Override diff --git a/src/main/java/com/zixiken/dimdoors/shared/RiftRegistry.java b/src/main/java/com/zixiken/dimdoors/shared/RiftRegistry.java index a18ba64d..6491adab 100644 --- a/src/main/java/com/zixiken/dimdoors/shared/RiftRegistry.java +++ b/src/main/java/com/zixiken/dimdoors/shared/RiftRegistry.java @@ -374,7 +374,7 @@ public class RiftRegistry { Location destinationRiftLocation = getRiftLocation(riftId); DDTileEntityBase destinationRift = (DDTileEntityBase) destinationRiftLocation.getTileEntity(); if (destinationRift == null) { - DimDoors.warn(this.getClass(), "The rift that an entity is trying to teleport to seems to be null."); + DimDoors.warn(this.getClass(), "The rift that an entity is trying to teleport to seems to be null. RiftID: " + riftId + ". Expecting to crash in 3... 2... 1.."); } return destinationRift.getTeleportTargetLocation(); } @@ -402,7 +402,7 @@ public class RiftRegistry { lastBrokenRift = null; } } - + public int getPocketID(int riftID) { DDTileEntityBase rift = (DDTileEntityBase) rifts.get(riftID).getTileEntity(); return rift.getPocketID(); diff --git a/src/main/java/com/zixiken/dimdoors/shared/blocks/BlockRift.java b/src/main/java/com/zixiken/dimdoors/shared/blocks/BlockRift.java index 8012076e..6a0a2ab6 100644 --- a/src/main/java/com/zixiken/dimdoors/shared/blocks/BlockRift.java +++ b/src/main/java/com/zixiken/dimdoors/shared/blocks/BlockRift.java @@ -1,5 +1,6 @@ package com.zixiken.dimdoors.shared.blocks; +import com.zixiken.dimdoors.DimDoors; import com.zixiken.dimdoors.client.ClosingRiftFX; import com.zixiken.dimdoors.shared.RiftRegistry; import com.zixiken.dimdoors.shared.items.ModItems; @@ -198,7 +199,14 @@ public class BlockRift extends Block implements ITileEntityProvider { @Override public void breakBlock(World world, BlockPos pos, IBlockState state) { - RiftRegistry.INSTANCE.unregisterLastChangedRift(); + TileEntityRift riftTile = (TileEntityRift) world.getTileEntity(pos); + if (riftTile == null || !riftTile.placingDoorOnRift) { + DimDoors.log(this.getClass(), "Unregistering rift at position " + pos.toString() + ", because it is destroyed (creative) or has closed."); + RiftRegistry.INSTANCE.unregisterLastChangedRift(); + } else { + DimDoors.log(this.getClass(), "Not unregistering rift at position " + pos.toString() + ", because it is being replaced by a door."); + riftTile.placingDoorOnRift = false; //probably not needed, but it shouldn't hurt to do this + } world.removeTileEntity(pos); } diff --git a/src/main/java/com/zixiken/dimdoors/shared/items/ItemDoorBase.java b/src/main/java/com/zixiken/dimdoors/shared/items/ItemDoorBase.java index 635bd4a3..1411b4d5 100644 --- a/src/main/java/com/zixiken/dimdoors/shared/items/ItemDoorBase.java +++ b/src/main/java/com/zixiken/dimdoors/shared/items/ItemDoorBase.java @@ -7,6 +7,7 @@ import com.zixiken.dimdoors.DimDoors; import com.zixiken.dimdoors.shared.blocks.BlockDimDoorBase; import com.zixiken.dimdoors.shared.RayTraceHelper; import com.zixiken.dimdoors.shared.tileentities.TileEntityDimDoor; +import com.zixiken.dimdoors.shared.tileentities.TileEntityRift; import net.minecraft.block.Block; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Blocks; @@ -67,6 +68,8 @@ public abstract class ItemDoorBase extends ItemDoor { return new ActionResult(canDoorBePlacedOnGroundBelowRift, stack); } return new ActionResult(EnumActionResult.FAIL, stack); //@todo, should return onItemUse(params) here? will door placement on block not work otherwise? + + //@todo personal and chaos doors can be placed on top of a rift? Should not be possible } @Override @@ -109,6 +112,10 @@ public abstract class ItemDoorBase extends ItemDoor { boolean flag = i < 0 && hitZ < 0.5F || i > 0 && hitZ > 0.5F || j < 0 && hitX > 0.5F || j > 0 && hitX < 0.5F; //Vanilla Minecraft code not consistently using EnumFacing //fetch "the" tile entity at the top block of where the door is going to be placed TileEntity possibleOldRift = world.getTileEntity(pos.up()); + if (possibleOldRift != null && possibleOldRift instanceof TileEntityRift) { + TileEntityRift oldRift = (TileEntityRift) possibleOldRift; + oldRift.placingDoorOnRift = true; + } //place the door placeDoor(world, pos, enumfacing, doorBlock, flag); SoundType soundtype = world.getBlockState(pos).getBlock().getSoundType(world.getBlockState(pos), world, pos, playerIn); diff --git a/src/main/java/com/zixiken/dimdoors/shared/tileentities/TileEntityRift.java b/src/main/java/com/zixiken/dimdoors/shared/tileentities/TileEntityRift.java index e09e2fef..bf7371a8 100644 --- a/src/main/java/com/zixiken/dimdoors/shared/tileentities/TileEntityRift.java +++ b/src/main/java/com/zixiken/dimdoors/shared/tileentities/TileEntityRift.java @@ -23,6 +23,8 @@ public class TileEntityRift extends DDTileEntityBase implements ITickable { private static final int MAX_HOSTILE_ENDERMAN_CHANCE = 3; private static final int UPDATE_PERIOD = 200; //10 seconds + public boolean placingDoorOnRift = false; //to track whether a Rift is getting broken because it is replaced by a door (do not unregister in this case) or because it is being broken another way (do unregister in this case) + private static final Random random = new Random(); //Need to be saved: @@ -35,7 +37,7 @@ public class TileEntityRift extends DDTileEntityBase implements ITickable { public TileEntityRift() { super(); - this.loadDataFrom(RiftRegistry.INSTANCE.getLastChangedRift()); + this.loadDataFrom(RiftRegistry.INSTANCE.getLastChangedRift()); //@todo this should absolutely not be done in this constructor... // Vary the update times of rifts to prevent all the rifts in a cluster // from updating at the same time.