Set up actually registering Rifts
Repaired a derp I did in which the Tile Entities did not have a "World" to get the ID from for the Location to turn into a Location. I needed to change a lot of constructors to include said "World" as a parameter. Set up DDTileEntityBase to save after it's paired, registered or unpaired and actually wrote the readFromNBT and writeToNBT for that.
This commit is contained in:
parent
b6d6d1270d
commit
c741d5cd35
8 changed files with 50 additions and 4 deletions
|
@ -27,6 +27,6 @@ public class BlockDimDoorGold extends BlockDimDoorBase {
|
|||
public Item getItemDoor() {return ModItems.itemDimDoorGold;}
|
||||
|
||||
@Override
|
||||
public TileEntity createNewTileEntity(World world, int metadata) {return new TileEntityDimDoorGold();}
|
||||
public TileEntity createNewTileEntity(World world, int metadata) {return new TileEntityDimDoorGold(world);}
|
||||
|
||||
}
|
||||
|
|
|
@ -180,7 +180,7 @@ public class BlockRift extends Block implements ITileEntityProvider {
|
|||
@Override
|
||||
public TileEntity createNewTileEntity(World world, int metadata)
|
||||
{
|
||||
return new TileEntityRift();
|
||||
return new TileEntityRift(world);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -75,7 +75,7 @@ public class BlockTransTrapdoor extends BlockTrapDoor implements IDimDoor, ITile
|
|||
}
|
||||
|
||||
@Override
|
||||
public TileEntity createNewTileEntity(World world, int metadata) {return new TileEntityTransTrapdoor();}
|
||||
public TileEntity createNewTileEntity(World world, int metadata) {return new TileEntityTransTrapdoor(world);}
|
||||
|
||||
@Override
|
||||
public void placeLink(World world, BlockPos pos) {
|
||||
|
|
|
@ -3,6 +3,7 @@ package com.zixiken.dimdoors.tileentities;
|
|||
import com.zixiken.dimdoors.shared.RiftRegistry;
|
||||
import java.util.Random;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
@ -18,6 +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) {
|
||||
|
@ -36,6 +43,7 @@ public abstract class DDTileEntityBase extends TileEntity
|
|||
pairedRiftID = otherRiftID;
|
||||
RiftRegistry.Instance.pair(pairedRiftID, riftID);
|
||||
isPaired = true;
|
||||
this.markDirty();
|
||||
}
|
||||
|
||||
public void unpair() {
|
||||
|
@ -46,9 +54,30 @@ public abstract class DDTileEntityBase extends TileEntity
|
|||
isPaired = false;
|
||||
RiftRegistry.Instance.unpair(pairedRiftID);
|
||||
}
|
||||
this.markDirty();
|
||||
}
|
||||
|
||||
private void register() {
|
||||
riftID = RiftRegistry.Instance.registerNewRift(this);
|
||||
this.markDirty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound nbt) {
|
||||
super.readFromNBT(nbt);
|
||||
try {
|
||||
this.isPaired = nbt.getBoolean("isPaired");
|
||||
this.riftID = nbt.getInteger("riftID");
|
||||
this.pairedRiftID = nbt.getInteger("pairedRiftID");
|
||||
} catch (Exception e) {}
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTTagCompound writeToNBT(NBTTagCompound nbt) {
|
||||
super.writeToNBT(nbt);
|
||||
nbt.setBoolean("isPaired", this.isPaired);
|
||||
nbt.setInteger("riftID", this.riftID);
|
||||
nbt.setInteger("pairedRiftID", this.pairedRiftID);
|
||||
return nbt;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ 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,6 +16,10 @@ 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,12 +1,17 @@
|
|||
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;
|
||||
|
||||
public class TileEntityDimDoorGold extends TileEntityDimDoor implements IChunkLoader {
|
||||
private Ticket chunkTicket;
|
||||
private boolean initialized = false;
|
||||
|
||||
public TileEntityDimDoorGold(World world) {
|
||||
super(world);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInitialized() {
|
||||
|
|
|
@ -11,6 +11,7 @@ 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;
|
||||
|
@ -29,7 +30,8 @@ public class TileEntityRift extends DDTileEntityBase implements ITickable {
|
|||
public int riftRotation = random.nextInt(360);
|
||||
public float growth = 0;
|
||||
|
||||
public TileEntityRift() {
|
||||
public TileEntityRift(World world) {
|
||||
super(world);
|
||||
// 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,9 +1,14 @@
|
|||
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