DimDoor and Rift- (re)placement

Main:
Removed "custom" code for DimDoors' Placement and rewrote it
When right-clicking rifts with any Dimensional Door, the game will try to place the Dimensional Door onto the rift.
Rifts will now enherit their properties from broken DimDoors and Dimdoors will enherit their properties from rifts they are placed over.

Other:
Made the DimDoors logger a bit more powerful.
Made RiftRegistry reset on server-load
Created a setup for the RiftConnectionTool Item.

Layout:
Fixed TileEntityRift.java's indentation
Changed some variable names

Authored by Robijnvogel and squashed by Waterpicker.
This commit is contained in:
Waterpicker 2017-01-16 19:57:53 -06:00
parent 1745d7b450
commit 68881e17ce
10 changed files with 297 additions and 270 deletions

View file

@ -22,7 +22,6 @@ public abstract class DDProxyCommon implements IDDProxy {
@Override @Override
public void onPreInitialization(FMLPreInitializationEvent event) { public void onPreInitialization(FMLPreInitializationEvent event) {
MinecraftForge.EVENT_BUS.register(new EventHookContainer());
ModBlocks.registerBlocks(); ModBlocks.registerBlocks();
ModItems.registerItems(); ModItems.registerItems();

View file

@ -2,6 +2,7 @@ package com.zixiken.dimdoors;
import com.zixiken.dimdoors.items.ModItems; import com.zixiken.dimdoors.items.ModItems;
import com.zixiken.dimdoors.shared.PocketSavedData; import com.zixiken.dimdoors.shared.PocketSavedData;
import com.zixiken.dimdoors.shared.RiftRegistry;
import com.zixiken.dimdoors.shared.RiftSavedData; import com.zixiken.dimdoors.shared.RiftSavedData;
import net.minecraft.creativetab.CreativeTabs; import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item; import net.minecraft.item.Item;
@ -47,6 +48,7 @@ public class DimDoors {
@Mod.EventHandler @Mod.EventHandler
public void serverLoad(FMLServerStartingEvent event) { public void serverLoad(FMLServerStartingEvent event) {
//@todo event.registerServerCommand( new DDCommand() ); //to register commands that this mod offers? //@todo event.registerServerCommand( new DDCommand() ); //to register commands that this mod offers?
RiftRegistry.Instance.reset();
PocketSavedData.get(getDefWorld()); PocketSavedData.get(getDefWorld());
RiftSavedData.get(getDefWorld()); RiftSavedData.get(getDefWorld());
} }
@ -63,7 +65,7 @@ public class DimDoors {
return proxy.getDefWorld(); //gets the server or client world dim 0 handler return proxy.getDefWorld(); //gets the server or client world dim 0 handler
} }
public static void log(String text) { public static void log(Class classFiredFrom, String text) {
FMLLog.info("[DimDoors] " + text, 0); FMLLog.info("[DimDoors] " + text + " (" + classFiredFrom.toString() + " )", 0);
} }
} }

View file

@ -1,24 +0,0 @@
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;
public class EventHookContainer {
@SubscribeEvent
public void onPlayerEvent(PlayerInteractEvent event) {
// Handle all door placement here
World world = event.getEntity().world;
ItemStack stack = event.getEntityPlayer().inventory.getCurrentItem();
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);
}
}
}

View file

@ -3,9 +3,10 @@ package com.zixiken.dimdoors.blocks;
import java.util.Random; import java.util.Random;
import com.zixiken.dimdoors.DimDoors; import com.zixiken.dimdoors.DimDoors;
import com.zixiken.dimdoors.shared.RiftRegistry;
import com.zixiken.dimdoors.tileentities.DDTileEntityBase; import com.zixiken.dimdoors.tileentities.DDTileEntityBase;
import com.zixiken.dimdoors.tileentities.TileEntityDimDoor; import com.zixiken.dimdoors.tileentities.TileEntityDimDoor;
import javax.annotation.Nullable;
import net.minecraft.block.BlockDoor; import net.minecraft.block.BlockDoor;
import net.minecraft.block.ITileEntityProvider; import net.minecraft.block.ITileEntityProvider;
import net.minecraft.block.material.Material; import net.minecraft.block.material.Material;
@ -13,6 +14,7 @@ import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
@ -24,9 +26,6 @@ import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly; import net.minecraftforge.fml.relauncher.SideOnly;
import javax.annotation.Nullable;
import net.minecraft.nbt.NBTTagCompound;
public abstract class BlockDimDoorBase extends BlockDoor implements IDimDoor, ITileEntityProvider { public abstract class BlockDimDoorBase extends BlockDoor implements IDimDoor, ITileEntityProvider {
public BlockDimDoorBase(Material material) { public BlockDimDoorBase(Material material) {
@ -153,22 +152,19 @@ public abstract class BlockDimDoorBase extends BlockDoor implements IDimDoor, IT
@Override @Override
public void breakBlock(World world, BlockPos pos, IBlockState state) { public void breakBlock(World world, BlockPos pos, IBlockState state) {
DDTileEntityBase origRift; DDTileEntityBase origRift = null;
BlockPos pos2 = pos; boolean isTopHalf = state.getValue(BlockDoor.HALF) == EnumDoorHalf.UPPER;
// This function runs on the server side after a block is replaced if (isTopHalf) {
// We MUST call super.breakBlock() since it involves removing tile entities
if (state.getValue(BlockDoor.HALF) == EnumDoorHalf.LOWER) {
pos2 = pos.up();
origRift = (DDTileEntityBase) world.getTileEntity(pos2);
world.setBlockToAir(pos2);
} else {
origRift = (DDTileEntityBase) world.getTileEntity(pos); origRift = (DDTileEntityBase) world.getTileEntity(pos);
RiftRegistry.Instance.setLastChangedRift(origRift);
} }
super.breakBlock(world, pos, state); super.breakBlock(world, pos, state);
world.setBlockState(pos2, ModBlocks.blockRift.getDefaultState()); if (isTopHalf) {
DDTileEntityBase newRift = (DDTileEntityBase) world.getTileEntity(pos2); world.setBlockState(pos, ModBlocks.blockRift.getDefaultState());
DDTileEntityBase newRift = (DDTileEntityBase) world.getTileEntity(pos);
newRift.loadDataFrom(origRift); newRift.loadDataFrom(origRift);
//DimDoors.log("" +newRift.riftID); DimDoors.log(this.getClass(), "New Rift rift-ID after breaking door " + newRift.riftID);
}
} }
public DDTileEntityBase getRiftTile(World world, BlockPos pos, IBlockState state) { public DDTileEntityBase getRiftTile(World world, BlockPos pos, IBlockState state) {
@ -180,4 +176,21 @@ public abstract class BlockDimDoorBase extends BlockDoor implements IDimDoor, IT
} }
return (DDTileEntityBase) tileEntity; return (DDTileEntityBase) tileEntity;
} }
@Override
public boolean canPlaceBlockAt(World worldIn, BlockPos pos) {
IBlockState stateBot = worldIn.getBlockState(pos);
IBlockState stateTop = worldIn.getBlockState(pos.up());
return pos.getY() >= worldIn.getHeight() - 1 ? false
: worldIn.getBlockState(pos.down()).isSideSolid(worldIn, pos.down(), EnumFacing.UP)
&& canPlaceBottomAt(worldIn, pos, stateBot) && canPlaceTopAt(worldIn, pos, stateTop);
}
private boolean canPlaceBottomAt(World worldIn, BlockPos pos, IBlockState state) {
return (state.equals(Blocks.AIR) || state.getBlock().isReplaceable(worldIn, pos));
}
private boolean canPlaceTopAt(World worldIn, BlockPos pos, IBlockState state) {
return (state.getBlock() == ModBlocks.blockRift || state.equals(Blocks.AIR) || state.getMaterial().isReplaceable());
}
} }

View file

@ -28,7 +28,6 @@ import net.minecraft.world.World;
import net.minecraftforge.fluids.IFluidBlock; import net.minecraftforge.fluids.IFluidBlock;
import com.zixiken.dimdoors.client.GoggleRiftFX; import com.zixiken.dimdoors.client.GoggleRiftFX;
import com.zixiken.dimdoors.tileentities.DDTileEntityBase; import com.zixiken.dimdoors.tileentities.DDTileEntityBase;
import net.minecraft.block.BlockDoor;
import net.minecraftforge.fml.client.FMLClientHandler; import net.minecraftforge.fml.client.FMLClientHandler;
import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly; import net.minecraftforge.fml.relauncher.SideOnly;
@ -70,6 +69,11 @@ public class BlockRift extends Block implements ITileEntityProvider {
blocksImmuneToRift.add(Blocks.EMERALD_BLOCK); blocksImmuneToRift.add(Blocks.EMERALD_BLOCK);
} }
@Override
public boolean isReplaceable(IBlockAccess worldIn, BlockPos pos) {
return false;
}
@Override @Override
public boolean isCollidable() { public boolean isCollidable() {
return false; return false;
@ -156,8 +160,8 @@ public class BlockRift extends Block implements ITileEntityProvider {
} }
public boolean tryPlacingRift(World world, BlockPos pos) { public boolean tryPlacingRift(World world, BlockPos pos) {
return world != null && !isBlockImmune(world, pos) && return world != null && !isBlockImmune(world, pos)
world.setBlockState(pos, getDefaultState()); //@todo This returns false, because this block does not have blockstates configured correctly. !isBlockImmune doesn't seem to be ture either though... && world.setBlockState(pos, getDefaultState()); //@todo This returns false, because this block does not have blockstates configured correctly. !isBlockImmune doesn't seem to be true either though...
} }
public boolean isBlockImmune(World world, BlockPos pos) { public boolean isBlockImmune(World world, BlockPos pos) {

View file

@ -20,7 +20,8 @@ import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.RayTraceResult; import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.math.Vec3d; import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World; import net.minecraft.world.World;
import com.zixiken.dimdoors.tileentities.TileEntityDimDoor; import net.minecraft.block.SoundType;
import static net.minecraft.item.ItemDoor.placeDoor;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
public abstract class ItemDoorBase extends ItemDoor { public abstract class ItemDoorBase extends ItemDoor {
@ -50,34 +51,45 @@ public abstract class ItemDoorBase extends ItemDoor {
public abstract void addInformation(ItemStack stack, EntityPlayer playerIn, List<String> tooltip, boolean advanced); public abstract void addInformation(ItemStack stack, EntityPlayer playerIn, List<String> tooltip, boolean advanced);
/** /**
* Overriden in subclasses to specify which door block that door item will * Overridden in subclasses to specify which door block that door item will
* place * place
* *
* @return * @return
*/ */
protected abstract BlockDimDoorBase getDoorBlock(); protected abstract BlockDimDoorBase getDoorBlock();
/**
* Overriden here to remove vanilla block placement functionality from
* dimensional doors, we handle this in the EventHookContainer
*/
@Override @Override
public EnumActionResult onItemUse(ItemStack stack, EntityPlayer playerIn, World worldIn, BlockPos pos, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) { public ActionResult<ItemStack> onItemRightClick(ItemStack stack, World worldIn, EntityPlayer playerIn, EnumHand hand) {
return EnumActionResult.FAIL; RayTraceResult hit = ItemDoorBase.doRayTrace(worldIn, playerIn, true);
if (hit != null) {
DimDoors.log(this.getClass(), "Hit is not null");
BlockPos pos = hit.getBlockPos();
if (worldIn.getBlockState(pos).getBlock() == ModBlocks.blockRift) {
DimDoors.log(this.getClass(), "Block is a blockRift");
EnumActionResult canDoorBePlacedOnGroundBelowRift
= onItemUse(stack, playerIn, worldIn, pos.down(2), hand, EnumFacing.UP,
(float) hit.hitVec.xCoord, (float) hit.hitVec.yCoord, (float) hit.hitVec.zCoord);
return new ActionResult(canDoorBePlacedOnGroundBelowRift, stack);
}
}
DimDoors.log(this.getClass(), "Hit is null");
return new ActionResult(EnumActionResult.PASS, stack);
} }
/** @Override
* Tries to place a door as a dimensional door public EnumActionResult onItemUse(ItemStack stack, EntityPlayer playerIn, World worldIn, BlockPos pos, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
* //@todo also check for rift raytracing replacement;
* @param stack if (worldIn.isRemote) {
* @param player return EnumActionResult.FAIL;
* @param world }
* @param side IBlockState iblockstate = worldIn.getBlockState(pos);
* @return Block block = iblockstate.getBlock();
*/ if (side != EnumFacing.UP || block == Blocks.AIR) {
public static boolean tryToPlaceDoor(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumFacing side) { return EnumActionResult.FAIL;
if (world.isRemote) { } else {
return false;
if (!block.isReplaceable(worldIn, pos)) {
pos = pos.offset(side); //we know that (side == EnumFacing.UP)
} }
// Retrieve the actual door type that we want to use here. // Retrieve the actual door type that we want to use here.
@ -85,96 +97,45 @@ public abstract class ItemDoorBase extends ItemDoor {
// return null, just as if the item was an unrecognized door type. // return null, just as if the item was an unrecognized door type.
ItemDoorBase mappedItem = doorItemMapping.get(stack.getItem()); ItemDoorBase mappedItem = doorItemMapping.get(stack.getItem());
if (mappedItem == null) { if (mappedItem == null) {
return false; return EnumActionResult.FAIL;
} }
BlockDimDoorBase doorBlock = mappedItem.getDoorBlock(); BlockDimDoorBase doorBlock = mappedItem.getDoorBlock();
return ItemDoorBase.placeDoorOnBlock(doorBlock, stack, player, world, pos, side)
|| ItemDoorBase.placeDoorOnRift(doorBlock, world, player, stack);
}
/** if (playerIn.canPlayerEdit(pos, side, stack) && playerIn.canPlayerEdit(pos.up(), side, stack)
* try to place a door block on a block && doorBlock.canPlaceBlockAt(worldIn, pos)) {
*
* @param doorBlock
* @param stack
* @param player
* @param world
* @param pos
* @param side
* @return
*/
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 TileEntity possibleOldRift = worldIn.getTileEntity(pos.up());
// side //start logging code
if (side == EnumFacing.UP) { if (possibleOldRift instanceof DDTileEntityBase) { //
Block block = world.getBlockState(pos).getBlock(); DDTileEntityBase oldRift = (DDTileEntityBase) possibleOldRift;
if (!world.getBlockState(pos).equals(Blocks.AIR) && !block.isReplaceable(world, pos)) { DimDoors.log(this.getClass(), "Old Rift rift-ID before placement: " + oldRift.riftID);
pos = pos.up();
} }
//end of logging code
EnumFacing enumfacing = EnumFacing.fromAngle((double) playerIn.rotationYaw);
int i = enumfacing.getFrontOffsetX();
int j = enumfacing.getFrontOffsetZ();
boolean flag = i < 0 && hitZ < 0.5F || i > 0 && hitZ > 0.5F || j < 0 && hitX > 0.5F || j > 0 && hitX < 0.5F;
placeDoor(worldIn, pos, enumfacing, doorBlock, flag);
SoundType soundtype = worldIn.getBlockState(pos).getBlock().getSoundType(worldIn.getBlockState(pos), worldIn, pos, playerIn);
worldIn.playSound(playerIn, pos, soundtype.getPlaceSound(), SoundCategory.BLOCKS, (soundtype.getVolume() + 1.0F) / 2.0F, soundtype.getPitch() * 0.8F);
--stack.stackSize;
BlockPos upPos = pos.up(); DDTileEntityBase newTileEntityDimDoor = (DDTileEntityBase) worldIn.getTileEntity(pos.up());
if (canPlace(world, pos) && canPlace(world, upPos) && player.canPlayerEdit(pos, side, stack) if (possibleOldRift instanceof DDTileEntityBase) { //
&& player.canPlayerEdit(upPos, side, stack) && stack.stackSize > 0 DDTileEntityBase oldRift = (DDTileEntityBase) possibleOldRift;
&& stack.getItem() instanceof ItemDoorBase && world.getBlockState(pos.down()).isSideSolid(world, pos, side)) { DimDoors.log(this.getClass(), "Old Rift rift-ID after placement: " + oldRift.riftID);
placeDoor(world, pos, EnumFacing.fromAngle(player.rotationYaw), doorBlock, true); newTileEntityDimDoor.loadDataFrom(oldRift);
TileEntity tileEntity = world.getTileEntity(pos.up()); } else {
if (tileEntity instanceof DDTileEntityBase) { newTileEntityDimDoor.register();
DDTileEntityBase rift = (DDTileEntityBase) tileEntity;
rift.register();
}
if (!player.capabilities.isCreativeMode) {
stack.stackSize--;
}
return true;
}
}
return false;
} }
DimDoors.log(this.getClass(), "New Door rift-ID after placement: " + newTileEntityDimDoor.riftID);
/** return EnumActionResult.SUCCESS;
* uses a raytrace to try and place a door on a rift } else {
* return EnumActionResult.FAIL;
* @param doorBlock
* @param world
* @param player
* @param stack
* @return
*/
public static boolean placeDoorOnRift(Block doorBlock, World world, EntityPlayer player, ItemStack stack) {
if (world.isRemote) {
return false;
}
RayTraceResult hit = ItemDoorBase.doRayTrace(world, player, true);
if (hit != null) {
BlockPos pos = hit.getBlockPos();
if (world.getBlockState(pos).getBlock() == ModBlocks.blockRift) {
BlockPos downPos = pos.down();
if (player.canPlayerEdit(pos, hit.sideHit, stack)
&& player.canPlayerEdit(downPos, hit.sideHit, stack)
&& canPlace(world, pos) && canPlace(world, downPos)) {
DDTileEntityBase riftOrig = (DDTileEntityBase) world.getTileEntity(pos);
placeDoor(world, downPos, EnumFacing.fromAngle(player.rotationYaw), doorBlock, true);
TileEntityDimDoor newRift = (TileEntityDimDoor) world.getTileEntity(pos);
if (!(stack.getItem() instanceof ItemDoorBase)) { //@todo why does THIS if statement mean that THAT field should be true?
newRift.hasGennedPair = true;
}
newRift.loadDataFrom(riftOrig); //take over the data from the original Rift
//DimDoors.log("" +newRift.riftID);
if (!player.capabilities.isCreativeMode) {
stack.stackSize--;
}
return true;
} }
} }
} }
return false;
}
public static boolean canPlace(World world, BlockPos pos) { public static boolean canPlace(World world, BlockPos pos) {
IBlockState state = world.getBlockState(pos); IBlockState state = world.getBlockState(pos);
@ -219,4 +180,17 @@ public abstract class ItemDoorBase extends ItemDoor {
} else */ break; } else */ break;
} }
} }
private boolean canDoorBePlacedOnRift(World worldIn, EntityPlayer playerIn) {
RayTraceResult hit = ItemDoorBase.doRayTrace(worldIn, playerIn, true);
if (hit != null) {
DimDoors.log(this.getClass(), "Hit is not null");
BlockPos pos = hit.getBlockPos();
if (worldIn.getBlockState(pos).getBlock() == ModBlocks.blockRift) {
return true;
}
}
DimDoors.log(this.getClass(), "Hit is null, or block at pos is not blockRift");
return false;
}
} }

View file

@ -0,0 +1,45 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.zixiken.dimdoors.items;
import com.zixiken.dimdoors.tileentities.DDTileEntityBase;
import java.util.Set;
import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemTool;
import net.minecraft.util.ActionResult;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.world.World;
/**
*
* @author Robijnvogel
*/
public class ItemRiftConnectionTool extends ItemTool {
ItemRiftConnectionTool(float attackDamageIn, float attackSpeedIn, Item.ToolMaterial materialIn, Set<Block> effectiveBlocksIn){
super(attackDamageIn, attackSpeedIn, materialIn, effectiveBlocksIn);
//@todo add extra stuff
}
//@todo actually implement this item as a tool and stuff
@Override
public ActionResult<ItemStack> onItemRightClick(ItemStack stack, World worldIn, EntityPlayer playerIn, EnumHand hand) {
RayTraceResult hit = ItemDoorBase.doRayTrace(worldIn, playerIn, true);
if (hit != null) {
BlockPos pos = hit.getBlockPos();
if (worldIn.getTileEntity(pos) instanceof DDTileEntityBase) {
//@todo implementation here?
return new ActionResult(EnumActionResult.PASS, stack);
}
}
return new ActionResult(EnumActionResult.FAIL, stack);
}
}

View file

@ -19,6 +19,7 @@ import net.minecraft.world.World;
*/ */
public class RiftRegistry { public class RiftRegistry {
private DDTileEntityBase lastBrokenRift = null; //@todo, redo this functionality in a more refined way
public static final RiftRegistry Instance = new RiftRegistry(); public static final RiftRegistry Instance = new RiftRegistry();
// Privates // Privates
@ -26,7 +27,7 @@ public class RiftRegistry {
private final Map<Integer, Location> riftList; private final Map<Integer, Location> riftList;
// Methods // Methods
public RiftRegistry() { private RiftRegistry() {
nextRiftID = 0; nextRiftID = 0;
riftList = new HashMap(); riftList = new HashMap();
} }
@ -34,6 +35,7 @@ public class RiftRegistry {
public void reset() { public void reset() {
nextRiftID = 0; nextRiftID = 0;
riftList.clear(); riftList.clear();
lastBrokenRift = null;
} }
public void readFromNBT(NBTTagCompound nbt) { public void readFromNBT(NBTTagCompound nbt) {
@ -98,4 +100,12 @@ public class RiftRegistry {
rift.unpair(); rift.unpair();
} }
} }
public void setLastChangedRift(DDTileEntityBase origRift) {
lastBrokenRift = origRift;
}
public DDTileEntityBase getLastChangedRift() {
return lastBrokenRift;
}
} }

View file

@ -77,7 +77,7 @@ public abstract class DDTileEntityBase extends TileEntity {
} }
public void loadDataFrom(DDTileEntityBase rift2) { public void loadDataFrom(DDTileEntityBase rift2) {
if (rift2.riftID != -1) { if (rift2 != null && rift2.riftID != -1) {
isPaired = rift2.isPaired; isPaired = rift2.isPaired;
riftID = rift2.riftID; //should not start at 0 riftID = rift2.riftID; //should not start at 0
pairedRiftID = rift2.pairedRiftID; pairedRiftID = rift2.pairedRiftID;

View file

@ -1,9 +1,9 @@
package com.zixiken.dimdoors.tileentities; package com.zixiken.dimdoors.tileentities;
import com.zixiken.dimdoors.blocks.ModBlocks;
import com.zixiken.dimdoors.shared.RiftRegistry;
import java.util.List; import java.util.List;
import java.util.Random; import java.util.Random;
import com.zixiken.dimdoors.blocks.ModBlocks;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.entity.monster.EntityEnderman; import net.minecraft.entity.monster.EntityEnderman;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
@ -13,6 +13,7 @@ import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
public class TileEntityRift extends DDTileEntityBase implements ITickable { public class TileEntityRift extends DDTileEntityBase implements ITickable {
private static final int ENDERMAN_SPAWNING_CHANCE = 1; private static final int ENDERMAN_SPAWNING_CHANCE = 1;
private static final int MAX_ENDERMAN_SPAWNING_CHANCE = 32; private static final int MAX_ENDERMAN_SPAWNING_CHANCE = 32;
private static final int HOSTILE_ENDERMAN_CHANCE = 1; private static final int HOSTILE_ENDERMAN_CHANCE = 1;
@ -29,8 +30,12 @@ public class TileEntityRift extends DDTileEntityBase implements ITickable {
public int riftRotation = random.nextInt(360); public int riftRotation = random.nextInt(360);
public float growth = 0; public float growth = 0;
private static int temp = 0;
public TileEntityRift() { public TileEntityRift() {
super(); super();
this.loadDataFrom(RiftRegistry.Instance.getLastChangedRift());
// Vary the update times of rifts to prevent all the rifts in a cluster // Vary the update times of rifts to prevent all the rifts in a cluster
// from updating at the same time. // from updating at the same time.
updateTimer = random.nextInt(UPDATE_PERIOD); updateTimer = random.nextInt(UPDATE_PERIOD);
@ -53,16 +58,17 @@ public class TileEntityRift extends DDTileEntityBase implements ITickable {
if (updateTimer >= UPDATE_PERIOD) { if (updateTimer >= UPDATE_PERIOD) {
spawnEndermen(); spawnEndermen();
updateTimer = 0; updateTimer = 0;
} } else if (updateTimer == UPDATE_PERIOD / 2) {
else if (updateTimer == UPDATE_PERIOD / 2) {
updateNearestRift(); updateNearestRift();
} }
growth += 1F/(growth+1); growth += 1F / (growth + 1);
updateTimer++; updateTimer++;
} }
private void spawnEndermen() { private void spawnEndermen() {
if (world.isRemote) return; if (world.isRemote) {
return;
}
// Ensure that this rift is only spawning one Enderman at a time, to prevent hordes of Endermen // Ensure that this rift is only spawning one Enderman at a time, to prevent hordes of Endermen
Entity entity = world.getEntityByID(this.spawnedEndermenID); Entity entity = world.getEntityByID(this.spawnedEndermenID);
@ -118,8 +124,7 @@ public class TileEntityRift extends DDTileEntityBase implements ITickable {
} }
@Override @Override
public NBTTagCompound writeToNBT(NBTTagCompound nbt) public NBTTagCompound writeToNBT(NBTTagCompound nbt) {
{
super.writeToNBT(nbt); super.writeToNBT(nbt);
nbt.setInteger("updateTimer", this.updateTimer); nbt.setInteger("updateTimer", this.updateTimer);
nbt.setInteger("xOffset", this.offset.getX()); nbt.setInteger("xOffset", this.offset.getX());
@ -134,8 +139,7 @@ public class TileEntityRift extends DDTileEntityBase implements ITickable {
} }
@Override @Override
public float[] getRenderColor(Random rand) public float[] getRenderColor(Random rand) {
{
return null; return null;
} }
} }