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.
This commit is contained in:
parent
b61aff025c
commit
2a4c9ba120
11 changed files with 30 additions and 41 deletions
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -31,7 +31,7 @@ public class BlockDimDoorGold extends BlockDimDoorBase {
|
|||
|
||||
@Override
|
||||
public TileEntity createNewTileEntity(World world, int metadata) {
|
||||
return new TileEntityDimDoorGold(world);
|
||||
return new TileEntityDimDoorGold();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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--;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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};
|
||||
|
|
Loading…
Reference in a new issue