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;}
|
public Item getItemDoor() {return ModItems.itemDimDoorGold;}
|
||||||
|
|
||||||
@Override
|
@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
|
@Override
|
||||||
public TileEntity createNewTileEntity(World world, int metadata)
|
public TileEntity createNewTileEntity(World world, int metadata)
|
||||||
{
|
{
|
||||||
return new TileEntityRift();
|
return new TileEntityRift(world);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -75,7 +75,7 @@ public class BlockTransTrapdoor extends BlockTrapDoor implements IDimDoor, ITile
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TileEntity createNewTileEntity(World world, int metadata) {return new TileEntityTransTrapdoor();}
|
public TileEntity createNewTileEntity(World world, int metadata) {return new TileEntityTransTrapdoor(world);}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void placeLink(World world, BlockPos pos) {
|
public void placeLink(World world, BlockPos pos) {
|
||||||
|
|
|
@ -3,6 +3,7 @@ package com.zixiken.dimdoors.tileentities;
|
||||||
import com.zixiken.dimdoors.shared.RiftRegistry;
|
import com.zixiken.dimdoors.shared.RiftRegistry;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import net.minecraft.block.state.IBlockState;
|
import net.minecraft.block.state.IBlockState;
|
||||||
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
@ -19,6 +20,12 @@ public abstract class DDTileEntityBase extends TileEntity
|
||||||
*/
|
*/
|
||||||
public abstract float[] getRenderColor(Random rand);
|
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
|
@Override
|
||||||
public boolean shouldRefresh(World world, BlockPos pos, IBlockState oldState, IBlockState newSate) {
|
public boolean shouldRefresh(World world, BlockPos pos, IBlockState oldState, IBlockState newSate) {
|
||||||
return oldState.getBlock() != newSate.getBlock();
|
return oldState.getBlock() != newSate.getBlock();
|
||||||
|
@ -36,6 +43,7 @@ public abstract class DDTileEntityBase extends TileEntity
|
||||||
pairedRiftID = otherRiftID;
|
pairedRiftID = otherRiftID;
|
||||||
RiftRegistry.Instance.pair(pairedRiftID, riftID);
|
RiftRegistry.Instance.pair(pairedRiftID, riftID);
|
||||||
isPaired = true;
|
isPaired = true;
|
||||||
|
this.markDirty();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void unpair() {
|
public void unpair() {
|
||||||
|
@ -46,9 +54,30 @@ public abstract class DDTileEntityBase extends TileEntity
|
||||||
isPaired = false;
|
isPaired = false;
|
||||||
RiftRegistry.Instance.unpair(pairedRiftID);
|
RiftRegistry.Instance.unpair(pairedRiftID);
|
||||||
}
|
}
|
||||||
|
this.markDirty();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void register() {
|
private void register() {
|
||||||
riftID = RiftRegistry.Instance.registerNewRift(this);
|
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.nbt.NBTTagCompound;
|
||||||
import net.minecraft.util.EnumFacing;
|
import net.minecraft.util.EnumFacing;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
|
|
||||||
public class TileEntityDimDoor extends DDTileEntityBase
|
public class TileEntityDimDoor extends DDTileEntityBase
|
||||||
|
@ -15,6 +16,10 @@ public class TileEntityDimDoor extends DDTileEntityBase
|
||||||
public boolean isDungeonChainLink;
|
public boolean isDungeonChainLink;
|
||||||
public boolean hasGennedPair=false;
|
public boolean hasGennedPair=false;
|
||||||
|
|
||||||
|
public TileEntityDimDoor(World world) {
|
||||||
|
super(world);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void readFromNBT(NBTTagCompound nbt) {
|
public void readFromNBT(NBTTagCompound nbt) {
|
||||||
super.readFromNBT(nbt);
|
super.readFromNBT(nbt);
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package com.zixiken.dimdoors.tileentities;
|
package com.zixiken.dimdoors.tileentities;
|
||||||
|
|
||||||
import com.zixiken.dimdoors.IChunkLoader;
|
import com.zixiken.dimdoors.IChunkLoader;
|
||||||
|
import net.minecraft.world.World;
|
||||||
import net.minecraftforge.common.ForgeChunkManager;
|
import net.minecraftforge.common.ForgeChunkManager;
|
||||||
import net.minecraftforge.common.ForgeChunkManager.Ticket;
|
import net.minecraftforge.common.ForgeChunkManager.Ticket;
|
||||||
|
|
||||||
|
@ -8,6 +9,10 @@ public class TileEntityDimDoorGold extends TileEntityDimDoor implements IChunkLo
|
||||||
private Ticket chunkTicket;
|
private Ticket chunkTicket;
|
||||||
private boolean initialized = false;
|
private boolean initialized = false;
|
||||||
|
|
||||||
|
public TileEntityDimDoorGold(World world) {
|
||||||
|
super(world);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isInitialized() {
|
public boolean isInitialized() {
|
||||||
return initialized;
|
return initialized;
|
||||||
|
|
|
@ -11,6 +11,7 @@ import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.util.ITickable;
|
import net.minecraft.util.ITickable;
|
||||||
import net.minecraft.util.math.AxisAlignedBB;
|
import net.minecraft.util.math.AxisAlignedBB;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
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;
|
||||||
|
@ -29,7 +30,8 @@ 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;
|
||||||
|
|
||||||
public TileEntityRift() {
|
public TileEntityRift(World world) {
|
||||||
|
super(world);
|
||||||
// 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);
|
||||||
|
|
|
@ -1,9 +1,14 @@
|
||||||
package com.zixiken.dimdoors.tileentities;
|
package com.zixiken.dimdoors.tileentities;
|
||||||
|
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
public class TileEntityTransTrapdoor extends DDTileEntityBase {
|
public class TileEntityTransTrapdoor extends DDTileEntityBase {
|
||||||
|
|
||||||
|
public TileEntityTransTrapdoor(World world) {
|
||||||
|
super(world);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public float[] getRenderColor(Random rand) {
|
public float[] getRenderColor(Random rand) {
|
||||||
float[] rgbaColor = {1,1,1,1};
|
float[] rgbaColor = {1,1,1,1};
|
||||||
|
|
Loading…
Reference in a new issue