Registry rewrite part 3

This commit is contained in:
Runemoro 2017-12-15 21:04:54 -05:00
parent f248ac7fcb
commit 15eccab45a
44 changed files with 497 additions and 278 deletions

View file

@ -5,6 +5,7 @@ import com.zixiken.dimdoors.shared.commands.TeleportCommand;
import com.zixiken.dimdoors.shared.DDConfig; import com.zixiken.dimdoors.shared.DDConfig;
import com.zixiken.dimdoors.shared.DDProxyCommon; import com.zixiken.dimdoors.shared.DDProxyCommon;
import com.zixiken.dimdoors.shared.items.ModItems; import com.zixiken.dimdoors.shared.items.ModItems;
import com.zixiken.dimdoors.shared.util.DefaultSchematicGenerator;
import com.zixiken.dimdoors.shared.world.gateways.GatewayGenerator; import com.zixiken.dimdoors.shared.world.gateways.GatewayGenerator;
import lombok.Getter; import lombok.Getter;
import net.minecraft.creativetab.CreativeTabs; import net.minecraft.creativetab.CreativeTabs;
@ -61,8 +62,6 @@ public class DimDoors {
@Mod.EventHandler @Mod.EventHandler
public void serverLoad(FMLServerStartingEvent event) { public void serverLoad(FMLServerStartingEvent event) {
registerCommands(event); registerCommands(event);
// RiftRegistry.INSTANCE.reset();
//DefaultSchematicGenerator.tempGenerateDefaultSchematics();
} }
private void registerCommands(FMLServerStartingEvent event) { private void registerCommands(FMLServerStartingEvent event) {

View file

@ -37,9 +37,9 @@ public class DDProxyClient extends DDProxyCommon {
} }
public void registerRenderers() { public void registerRenderers() {
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityVerticalEntranceRift.class, new RenderVerticalEntranceRift()); ClientRegistry.bindTileEntitySpecialRenderer(TileEntityVerticalEntranceRift.class, new TileEntityVerticalEntranceRiftRenderer());
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityHorizontalEntranceRift.class, new RenderHorizontalEntranceRift()); ClientRegistry.bindTileEntitySpecialRenderer(TileEntityHorizontalEntranceRift.class, new TileEntityHorizontalEntranceRiftRenderer());
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityFloatingRift.class, new RenderRift()); ClientRegistry.bindTileEntitySpecialRenderer(TileEntityFloatingRift.class, new TileEntityFloatingRiftRenderer());
RenderingRegistry.registerEntityRenderingHandler(MobMonolith.class, manager -> new RenderMobObelisk(manager, 0.5f)); RenderingRegistry.registerEntityRenderingHandler(MobMonolith.class, manager -> new RenderMobObelisk(manager, 0.5f));
} }

View file

@ -14,7 +14,7 @@ import net.minecraft.util.ResourceLocation;
import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL11;
public class RenderRift extends TileEntitySpecialRenderer<TileEntityFloatingRift> { public class TileEntityFloatingRiftRenderer extends TileEntitySpecialRenderer<TileEntityFloatingRift> {
private static ResourceLocation tesseract_path = new ResourceLocation(DimDoors.MODID + ":textures/other/tesseract.png"); private static ResourceLocation tesseract_path = new ResourceLocation(DimDoors.MODID + ":textures/other/tesseract.png");
private static Vector4f[] tesseract = { private static Vector4f[] tesseract = {

View file

@ -22,7 +22,7 @@ import net.minecraftforge.fml.relauncher.SideOnly;
import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL11;
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
public class RenderHorizontalEntranceRift extends TileEntitySpecialRenderer<TileEntityHorizontalEntranceRift> { public class TileEntityHorizontalEntranceRiftRenderer extends TileEntitySpecialRenderer<TileEntityHorizontalEntranceRift> {
private FloatBuffer buffer = GLAllocation.createDirectFloatBuffer(16); private FloatBuffer buffer = GLAllocation.createDirectFloatBuffer(16);
private ResourceLocation riftPath = new ResourceLocation(DimDoors.MODID + ":textures/other/rift.png"); private ResourceLocation riftPath = new ResourceLocation(DimDoors.MODID + ":textures/other/rift.png");

View file

@ -22,7 +22,7 @@ import net.minecraft.util.ResourceLocation;
import static org.lwjgl.opengl.GL11.*; import static org.lwjgl.opengl.GL11.*;
public class RenderVerticalEntranceRift extends TileEntitySpecialRenderer<TileEntityVerticalEntranceRift> { public class TileEntityVerticalEntranceRiftRenderer extends TileEntitySpecialRenderer<TileEntityVerticalEntranceRift> {
private FloatBuffer buffer = GLAllocation.createDirectFloatBuffer(16); private FloatBuffer buffer = GLAllocation.createDirectFloatBuffer(16);
private ResourceLocation warpPath = new ResourceLocation(DimDoors.MODID + ":textures/other/warp.png"); private ResourceLocation warpPath = new ResourceLocation(DimDoors.MODID + ":textures/other/warp.png");

View file

@ -6,6 +6,7 @@ import com.zixiken.dimdoors.shared.blocks.ModBlocks;
import com.zixiken.dimdoors.shared.entities.MobMonolith; import com.zixiken.dimdoors.shared.entities.MobMonolith;
import com.zixiken.dimdoors.shared.items.ModItems; import com.zixiken.dimdoors.shared.items.ModItems;
import com.zixiken.dimdoors.shared.tileentities.*; import com.zixiken.dimdoors.shared.tileentities.*;
import com.zixiken.dimdoors.shared.util.DefaultSchematicGenerator;
import com.zixiken.dimdoors.shared.world.DimDoorDimensions; import com.zixiken.dimdoors.shared.world.DimDoorDimensions;
import net.minecraft.block.BlockDoor; import net.minecraft.block.BlockDoor;
import net.minecraft.block.state.IBlockState; import net.minecraft.block.state.IBlockState;
@ -41,5 +42,6 @@ public abstract class DDProxyCommon implements IDDProxy {
@Override @Override
public void onInitialization(FMLInitializationEvent event) { public void onInitialization(FMLInitializationEvent event) {
SchematicHandler.INSTANCE.loadSchematics(); SchematicHandler.INSTANCE.loadSchematics();
DefaultSchematicGenerator.generateDefaultSchematics();
} }
} }

View file

@ -286,7 +286,7 @@ public class SchematicHandler { // TODO: make this more general (not dimdoors-re
} }
public PocketTemplate getPublicPocketTemplate() { public PocketTemplate getPublicPocketTemplate() {
return getRandomTemplate("private", -1, DDConfig.getMaxPocketSize(), true); // TODO: config option for getLargest return getRandomTemplate("public", -1, DDConfig.getMaxPocketSize(), true); // TODO: config option for getLargest
} }
public void saveSchematic(Schematic schematic, String name) { public void saveSchematic(Schematic schematic, String name) {

View file

@ -17,7 +17,7 @@ import net.minecraft.server.management.PlayerList;
import net.minecraftforge.fml.common.FMLCommonHandler; import net.minecraftforge.fml.common.FMLCommonHandler;
//ref: https://github.com/WayofTime/BloodMagic/blob/1.11/src/main/java/WayofTime/bloodmagic/ritual/portal/Teleports.java //ref: https://github.com/WayofTime/BloodMagic/blob/1.11/src/main/java/WayofTime/bloodmagic/ritual/portal/Teleports.java
public class TeleporterDimDoors extends Teleporter { public class TeleporterDimDoors extends Teleporter { // TODO
/** /**
* Teleporter isn't static, so TeleporterDimDoors can't be static, so we're * Teleporter isn't static, so TeleporterDimDoors can't be static, so we're
@ -80,7 +80,7 @@ public class TeleporterDimDoors extends Teleporter {
int oldDimID = entity.dimension; int oldDimID = entity.dimension;
WorldServer oldWorldserver = DimDoors.proxy.getWorldServer(oldDimID); WorldServer oldWorldserver = DimDoors.proxy.getWorldServer(oldDimID);
WorldServer newWorldserver = DimDoors.proxy.getWorldServer(newDimID); WorldServer newWorldserver = DimDoors.proxy.getWorldServer(newDimID);
if (entity instanceof EntityPlayerMP) { // TODO: this was EntityPlayer, but I changed this to EntityPlayerMP because that's what the cast assumes if (entity instanceof EntityPlayerMP) {
DimDoors.log(TeleporterDimDoors.class, "Teleporting Player to new dimension."); DimDoors.log(TeleporterDimDoors.class, "Teleporting Player to new dimension.");
EntityPlayerMP player = (EntityPlayerMP) entity; EntityPlayerMP player = (EntityPlayerMP) entity;
float playerRotationYaw = player.rotationYaw; //@todo make this a parameter? float playerRotationYaw = player.rotationYaw; //@todo make this a parameter?
@ -137,7 +137,7 @@ public class TeleporterDimDoors extends Teleporter {
private void teleportLocal(Entity entity, BlockPos pos) { private void teleportLocal(Entity entity, BlockPos pos) {
WorldServer worldserver = (WorldServer) entity.world; WorldServer worldserver = (WorldServer) entity.world;
if (entity instanceof EntityPlayerMP) { // TODO: this was EntityPlayer, but I changed this to EntityPlayerMP because that's what the cast assumes if (entity instanceof EntityPlayerMP) {
DimDoors.log(TeleporterDimDoors.class, DimDoors.log(TeleporterDimDoors.class,
"Teleporting Player within same dimension."); "Teleporting Player within same dimension.");
EntityPlayerMP player = (EntityPlayerMP) entity; EntityPlayerMP player = (EntityPlayerMP) entity;

View file

@ -8,7 +8,7 @@ import lombok.Value;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
@Value @ToString @AllArgsConstructor @Builder(toBuilder = true) @Value @ToString @AllArgsConstructor @Builder(toBuilder = true)
public class VirtualLocation { public class VirtualLocation { // TODO: use BlockPos/Location
int dimID; int dimID;
int x; int x;
int y; int y;

View file

@ -3,10 +3,18 @@ package com.zixiken.dimdoors.shared.blocks;
import java.util.Random; import java.util.Random;
import com.zixiken.dimdoors.DimDoors; import com.zixiken.dimdoors.DimDoors;
import com.zixiken.dimdoors.shared.VirtualLocation;
import com.zixiken.dimdoors.shared.pockets.Pocket;
import com.zixiken.dimdoors.shared.pockets.PocketRegistry;
import com.zixiken.dimdoors.shared.pockets.PocketTemplate;
import com.zixiken.dimdoors.shared.rifts.RiftRegistry;
import com.zixiken.dimdoors.shared.tileentities.TileEntityEntranceRift; import com.zixiken.dimdoors.shared.tileentities.TileEntityEntranceRift;
import com.zixiken.dimdoors.shared.tileentities.TileEntityFloatingRift; import com.zixiken.dimdoors.shared.tileentities.TileEntityFloatingRift;
import com.zixiken.dimdoors.shared.tileentities.TileEntityVerticalEntranceRift; import com.zixiken.dimdoors.shared.tileentities.TileEntityVerticalEntranceRift;
import com.zixiken.dimdoors.shared.rifts.TileEntityRift; import com.zixiken.dimdoors.shared.rifts.TileEntityRift;
import com.zixiken.dimdoors.shared.util.Location;
import com.zixiken.dimdoors.shared.util.WorldUtils;
import com.zixiken.dimdoors.shared.world.DimDoorDimensions;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.BlockDoor; import net.minecraft.block.BlockDoor;
import net.minecraft.block.ITileEntityProvider; import net.minecraft.block.ITileEntityProvider;
@ -23,7 +31,8 @@ import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World; import net.minecraft.world.World;
public abstract class BlockDimDoorBase extends BlockDoor implements ITileEntityProvider { // TODO: implement RiftProvider as an interface of both doors and trapdoors public abstract class BlockDimDoorBase extends BlockDoor implements ITileEntityProvider {
// TODO: implement RiftProvider as an interface of both doors and trapdoors
public BlockDimDoorBase(Material material) { public BlockDimDoorBase(Material material) {
super(material); super(material);
@ -31,6 +40,7 @@ public abstract class BlockDimDoorBase extends BlockDoor implements ITileEntityP
@Override @Override
public void onEntityCollidedWithBlock(World worldIn, BlockPos pos, IBlockState state, Entity entityIn) { public void onEntityCollidedWithBlock(World worldIn, BlockPos pos, IBlockState state, Entity entityIn) {
if (worldIn.isRemote) return;
if (state.getValue(HALF) == EnumDoorHalf.UPPER) pos = pos.down(); if (state.getValue(HALF) == EnumDoorHalf.UPPER) pos = pos.down();
IBlockState doorState = worldIn.getBlockState(pos); IBlockState doorState = worldIn.getBlockState(pos);
if (!(doorState.getBlock() instanceof BlockDoor)) return; if (!(doorState.getBlock() instanceof BlockDoor)) return;
@ -104,17 +114,37 @@ public abstract class BlockDimDoorBase extends BlockDoor implements ITileEntityP
@Override @Override
public TileEntityVerticalEntranceRift createNewTileEntity(World worldIn, int meta) { public TileEntityVerticalEntranceRift createNewTileEntity(World worldIn, int meta) {
return new TileEntityVerticalEntranceRift(); TileEntityVerticalEntranceRift rift = new TileEntityVerticalEntranceRift();
rift.orientation = getStateFromMeta(meta).getValue(BlockDoor.FACING).getOpposite();
return rift;
} }
@Override @Override
public void onBlockAdded(World worldIn, BlockPos pos, IBlockState state) { public void onBlockAdded(World worldIn, BlockPos pos, IBlockState state) {
super.onBlockAdded(worldIn, pos, state); super.onBlockAdded(worldIn, pos, state);
if (hasTileEntity(state)) { if (hasTileEntity(state) && !PocketTemplate.schematicBeingPlaced) { // TODO: better check for schematicBeingPlaced (support other plugins such as WorldEdit, support doors being placed while schematics are being placed)
TileEntityVerticalEntranceRift rift = createNewTileEntity(worldIn, getMetaFromState(state)); TileEntityVerticalEntranceRift rift = createNewTileEntity(worldIn, getMetaFromState(state));
rift.orientation = state.getValue(BlockDoor.FACING).getOpposite();
worldIn.setTileEntity(pos, rift); // Set the virtual location based on where the door was placed
VirtualLocation virtualLocation = null;
if (DimDoorDimensions.isPocketDimension(WorldUtils.getDim(worldIn))) {
Pocket pocket = PocketRegistry.getForDim(WorldUtils.getDim(worldIn)).getPocketFromLocation(pos.getY(), pos.getY(), pos.getZ());
if (pocket != null) {
virtualLocation = pocket.getVirtualLocation();
} else {
virtualLocation = new VirtualLocation(0, 0, 0, 0, 0); // TODO: door was placed in a pocket dim but outside of a pocket...
}
}
if (virtualLocation == null) {
virtualLocation = new VirtualLocation(WorldUtils.getDim(worldIn), pos.getX(), pos.getY(), pos.getZ(), 0);
}
rift.setVirtualLocation(virtualLocation);
// Configure the rift to its default functionality
setupRift(rift); setupRift(rift);
// Set the tile entity and register it
worldIn.setTileEntity(pos, rift);
rift.markDirty(); rift.markDirty();
rift.register(); rift.register();
} }
@ -125,9 +155,10 @@ public abstract class BlockDimDoorBase extends BlockDoor implements ITileEntityP
if (!hasTileEntity(state)) return; if (!hasTileEntity(state)) return;
TileEntityEntranceRift rift = getRift(worldIn, pos, state); TileEntityEntranceRift rift = getRift(worldIn, pos, state);
super.breakBlock(worldIn, pos, state); super.breakBlock(worldIn, pos, state);
if (rift.isPlaceRiftOnBreak()) { if (rift.isPlaceRiftOnBreak() || rift.isRegistered() && RiftRegistry.getRiftInfo(new Location(worldIn, pos)).getSources().size() > 0 && !rift.isAlwaysDelete()) {
TileEntityRift newRift = new TileEntityFloatingRift(); TileEntityRift newRift = new TileEntityFloatingRift();
newRift.copyFrom(rift); newRift.copyFrom(rift);
newRift.updateAvailableLinks();
worldIn.setBlockState(rift.getPos(), ModBlocks.RIFT.getDefaultState()); worldIn.setBlockState(rift.getPos(), ModBlocks.RIFT.getDefaultState());
worldIn.setTileEntity(rift.getPos(), newRift); worldIn.setTileEntity(rift.getPos(), newRift);
} else { } else {

View file

@ -2,6 +2,7 @@ package com.zixiken.dimdoors.shared.blocks;
import com.zixiken.dimdoors.DimDoors; import com.zixiken.dimdoors.DimDoors;
import com.zixiken.dimdoors.shared.items.ModItems; import com.zixiken.dimdoors.shared.items.ModItems;
import com.zixiken.dimdoors.shared.rifts.RiftDestination;
import com.zixiken.dimdoors.shared.tileentities.TileEntityVerticalEntranceRift; import com.zixiken.dimdoors.shared.tileentities.TileEntityVerticalEntranceRift;
import net.minecraft.block.material.Material; import net.minecraft.block.material.Material;
import net.minecraft.item.Item; import net.minecraft.item.Item;
@ -26,6 +27,7 @@ public class BlockDimDoorIron extends BlockDimDoorBase {
@Override @Override
protected void setupRift(TileEntityVerticalEntranceRift rift) { protected void setupRift(TileEntityVerticalEntranceRift rift) {
// TODO RiftDestination.NewPublicDestination destination = RiftDestination.NewPublicDestination.builder().build();
rift.setSingleDestination(destination);
} }
} }

View file

@ -2,6 +2,7 @@ package com.zixiken.dimdoors.shared.blocks;
import com.zixiken.dimdoors.DimDoors; import com.zixiken.dimdoors.DimDoors;
import com.zixiken.dimdoors.shared.items.ModItems; import com.zixiken.dimdoors.shared.items.ModItems;
import com.zixiken.dimdoors.shared.rifts.RiftDestination;
import com.zixiken.dimdoors.shared.tileentities.TileEntityVerticalEntranceRift; import com.zixiken.dimdoors.shared.tileentities.TileEntityVerticalEntranceRift;
import net.minecraft.block.material.Material; import net.minecraft.block.material.Material;
import net.minecraft.item.Item; import net.minecraft.item.Item;
@ -27,6 +28,7 @@ public class BlockDimDoorPersonal extends BlockDimDoorBase {
@Override @Override
protected void setupRift(TileEntityVerticalEntranceRift rift) { protected void setupRift(TileEntityVerticalEntranceRift rift) {
// TODO RiftDestination.PrivateDestination destination = RiftDestination.PrivateDestination.builder().build();
rift.setSingleDestination(destination);
} }
} }

View file

@ -52,7 +52,7 @@ public class PocketCommand extends CommandBase {
PocketTemplate template = SchematicHandler.INSTANCE.getTemplate(args[0], args[1]); PocketTemplate template = SchematicHandler.INSTANCE.getTemplate(args[0], args[1]);
Pocket pocket = PocketGenerator.generatePocketFromTemplate(dim, 0, template, new VirtualLocation(0, 0, 0, 0,0)); Pocket pocket = PocketGenerator.generatePocketFromTemplate(dim, 0, template, new VirtualLocation(0, 0, 0, 0,0));
// TODO: options for linking back/not setting entrance // TODO: options for linking back/not setting entrance
pocket.selectEntrance(); pocket.setup();
TileEntityRift entrance = (TileEntityRift) player.world.getTileEntity(pocket.getEntrance().getPos()); TileEntityRift entrance = (TileEntityRift) player.world.getTileEntity(pocket.getEntrance().getPos());
entrance.teleportTo(player); entrance.teleportTo(player);
} else { } else {

View file

@ -12,11 +12,8 @@ import com.zixiken.dimdoors.shared.util.MathUtils;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTBase; import net.minecraft.nbt.*;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity;
import net.minecraft.nbt.NBTTagInt;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.nbt.NBTTagString;
/** /**
* *
@ -27,14 +24,13 @@ public class Pocket { // TODO: better visibilities
@Getter int id; // Not saved @Getter int id; // Not saved
@Getter /*private*/ int dimID; // Not saved @Getter /*private*/ int dimID; // Not saved
@Getter private int x; // Grid x @Getter private int x; // Grid x TODO: rename to gridX and gridY
@Getter private int z; // Grid y @Getter private int z; // Grid y
@Getter private int depth;
@Getter @Setter private int size; // In chunks TODO: non chunk-based size, better bounds such as minX, minZ, maxX, maxZ, etc. @Getter @Setter private int size; // In chunks TODO: non chunk-based size, better bounds such as minX, minZ, maxX, maxZ, etc.
@Getter @Setter private VirtualLocation virtualLocation; // The non-pocket dimension from which this dungeon was created @Getter @Setter private VirtualLocation virtualLocation; // The non-pocket dimension from which this dungeon was created
private List<Integer> riftIDs;
private List<String> playerUUIDs; private List<String> playerUUIDs;
@Getter Location entrance; @Getter Location entrance;
@Getter List<Location> riftLocations;
private Pocket() {} private Pocket() {}
@ -43,59 +39,54 @@ public class Pocket { // TODO: better visibilities
this.dimID = dimID; this.dimID = dimID;
this.x = x; this.x = x;
this.z = z; this.z = z;
this.depth = depth;
riftIDs = new ArrayList<>();
playerUUIDs = new ArrayList<>(); playerUUIDs = new ArrayList<>();
riftLocations = new ArrayList<>();
} }
static Pocket readFromNBT(NBTTagCompound pocketNBT) { static Pocket readFromNBT(NBTTagCompound nbt) {
Pocket pocket = new Pocket(); Pocket pocket = new Pocket();
pocket.id = pocketNBT.getInteger("id"); pocket.id = nbt.getInteger("id");
pocket.x = pocketNBT.getInteger("x"); pocket.x = nbt.getInteger("x");
pocket.z = pocketNBT.getInteger("z"); pocket.z = nbt.getInteger("z");
pocket.depth = pocketNBT.getInteger("depth"); pocket.size = nbt.getInteger("size");
pocket.size = pocketNBT.getInteger("size"); if (nbt.hasKey("virtualLocation")) pocket.virtualLocation = VirtualLocation.readFromNBT(nbt.getCompoundTag("virtualLocation"));
pocket.virtualLocation = VirtualLocation.readFromNBT(pocketNBT.getCompoundTag("originalDim"));
pocket.riftIDs = new ArrayList<>();
NBTTagList riftIDsTagList = (NBTTagList) pocketNBT.getTag("riftIDs");
for (int i = 0; i < riftIDsTagList.tagCount(); i++) {
pocket.riftIDs.add(riftIDsTagList.getIntAt(i));
}
pocket.playerUUIDs = new ArrayList<>(); pocket.playerUUIDs = new ArrayList<>();
NBTTagList playersTagList = (NBTTagList) pocketNBT.getTag("playerUUIDs"); NBTTagList playerUUIDsNBT = (NBTTagList) nbt.getTag("playerUUIDs");
for (int i = 0; i < playersTagList.tagCount(); i++) { for (int i = 0; i < playerUUIDsNBT.tagCount(); i++) { // TODO: convert to foreach
pocket.playerUUIDs.add(playersTagList.getStringTagAt(i)); pocket.playerUUIDs.add(playerUUIDsNBT.getStringTagAt(i));
}
pocket.riftLocations = new ArrayList<>();
NBTTagList riftLocationsNBT = (NBTTagList) nbt.getTag("riftLocations");
for (NBTBase riftLocationNBT : riftLocationsNBT) {
pocket.riftLocations.add(Location.readFromNBT((NBTTagCompound) riftLocationNBT));
} }
return pocket; return pocket;
} }
static NBTBase writeToNBT(Pocket pocket) { static NBTBase writeToNBT(Pocket pocket) {
NBTTagCompound pocketNBT = new NBTTagCompound(); NBTTagCompound nbt = new NBTTagCompound();
pocketNBT.setInteger("id", pocket.id); nbt.setInteger("id", pocket.id);
pocketNBT.setInteger("x", pocket.x); nbt.setInteger("x", pocket.x);
pocketNBT.setInteger("z", pocket.z); nbt.setInteger("z", pocket.z);
pocketNBT.setInteger("depth", pocket.depth); nbt.setInteger("size", pocket.size);
pocketNBT.setInteger("size", pocket.size); if (pocket.virtualLocation != null) nbt.setTag("virtualLocation", pocket.virtualLocation.writeToNBT());
pocketNBT.setTag("originalDim", pocket.virtualLocation.writeToNBT());
NBTTagList riftIDsTagList = new NBTTagList(); NBTTagList playerUUIDsNBT = new NBTTagList();
for (int i = 0; i < pocket.riftIDs.size(); i++) {
NBTTagInt doorTag = new NBTTagInt(pocket.riftIDs.get(i));
riftIDsTagList.appendTag(doorTag);
}
pocketNBT.setTag("riftIDs", riftIDsTagList);
NBTTagList playersTagList = new NBTTagList();
for (int i = 0; i < pocket.playerUUIDs.size(); i++) { for (int i = 0; i < pocket.playerUUIDs.size(); i++) {
NBTTagString playerTag = new NBTTagString(pocket.playerUUIDs.get(i)); playerUUIDsNBT.appendTag(new NBTTagString(pocket.playerUUIDs.get(i)));
playersTagList.appendTag(playerTag);
} }
pocketNBT.setTag("playerUUIDs", playersTagList); nbt.setTag("playerUUIDs", playerUUIDsNBT);
return pocketNBT; NBTTagList riftLocationsNBT = new NBTTagList();
for (Location loc : pocket.riftLocations) {
riftLocationsNBT.appendTag(Location.writeToNBT(loc));
}
nbt.setTag("riftLocations", riftLocationsNBT);
return nbt;
} }
boolean isLocationWithinPocketBounds(int locX, int locY, int locZ, int gridSize) { boolean isLocationWithinPocketBounds(int locX, int locY, int locZ, int gridSize) {
@ -121,10 +112,19 @@ public class Pocket { // TODO: better visibilities
} }
public List<TileEntityRift> getRifts() { public List<TileEntityRift> getRifts() {
return null; // TODO List<TileEntityRift> rifts = new ArrayList<>(riftLocations.size()); // TODO: make immutable
for (Location riftLocation : riftLocations) {
TileEntity tileEntity = riftLocation.getWorld().getTileEntity(riftLocation.getPos());
if (tileEntity instanceof TileEntityRift) {
rifts.add((TileEntityRift) tileEntity);
} else {
throw new RuntimeException("The rift locations array was wrong, check the schematic placing function to see why!");
}
}
return rifts;
} }
public void selectEntrance() { // Always call after creating a pocket except when building the pocket TODO: more general setup method public void setup() { // Always call after creating a pocket except when building the pocket
List<TileEntityRift> rifts = getRifts(); List<TileEntityRift> rifts = getRifts();
HashMap<Integer, Float> entranceIndexWeights = new HashMap<>(); HashMap<Integer, Float> entranceIndexWeights = new HashMap<>();
@ -142,9 +142,10 @@ public class Pocket { // TODO: better visibilities
if (entranceIndexWeights.size() == 0) return; if (entranceIndexWeights.size() == 0) return;
int selectedEntranceIndex = MathUtils.weightedRandom(entranceIndexWeights); int selectedEntranceIndex = MathUtils.weightedRandom(entranceIndexWeights);
// Replace entrances with appropriate destinations
index = 0; index = 0;
for (TileEntityRift rift : rifts) { // Replace entrances with appropriate items for (TileEntityRift rift : rifts) {
Iterator<WeightedRiftDestination> destIterator = rift.getDestinations().iterator(); ListIterator<WeightedRiftDestination> destIterator = rift.getDestinations().listIterator();
while (destIterator.hasNext()) { while (destIterator.hasNext()) {
WeightedRiftDestination wdest = destIterator.next(); WeightedRiftDestination wdest = destIterator.next();
RiftDestination dest = wdest.getDestination(); RiftDestination dest = wdest.getDestination();
@ -154,32 +155,43 @@ public class Pocket { // TODO: better visibilities
entrance = new Location(rift.getWorld(), rift.getPos()); entrance = new Location(rift.getWorld(), rift.getPos());
List<WeightedRiftDestination> ifDestinations = ((RiftDestination.PocketEntranceDestination) dest).getIfDestinations(); List<WeightedRiftDestination> ifDestinations = ((RiftDestination.PocketEntranceDestination) dest).getIfDestinations();
for (WeightedRiftDestination ifDestination : ifDestinations) { for (WeightedRiftDestination ifDestination : ifDestinations) {
rift.addDestination(ifDestination.getDestination(), ifDestination.getWeight() / wdest.getWeight(), ifDestination.getGroup()); destIterator.add(new WeightedRiftDestination(ifDestination.getDestination(), ifDestination.getWeight() / wdest.getWeight(), ifDestination.getGroup()));
destIterator.previous(); // An entrance destination shouldn't be in an if/otherwise destination, but just in case, pass over it too
} }
} else { } else {
List<WeightedRiftDestination> otherwiseDestinations = ((RiftDestination.PocketEntranceDestination) dest).getOtherwiseDestinations(); List<WeightedRiftDestination> otherwiseDestinations = ((RiftDestination.PocketEntranceDestination) dest).getOtherwiseDestinations();
for (WeightedRiftDestination otherwiseDestination : otherwiseDestinations) { for (WeightedRiftDestination otherwiseDestination : otherwiseDestinations) {
rift.addDestination(otherwiseDestination.getDestination(), otherwiseDestination.getWeight() / wdest.getWeight(), otherwiseDestination.getGroup()); destIterator.add(new WeightedRiftDestination(otherwiseDestination.getDestination(), otherwiseDestination.getWeight() / wdest.getWeight(), otherwiseDestination.getGroup()));
destIterator.previous(); // An entrance destination shouldn't be in an if/otherwise destination, but just in case, pass over it too
} }
} }
index++; index++;
} }
} }
} }
// set virtual locations and register rifts
for (TileEntityRift rift : rifts) {
// TODO: put a rift on door break?
rift.setVirtualLocation(virtualLocation);
rift.register();
}
} }
public void linkPocketTo(RiftDestination linkTo) { public void linkPocketTo(RiftDestination linkTo) {
List<TileEntityRift> rifts = getRifts(); List<TileEntityRift> rifts = getRifts();
for (TileEntityRift rift : rifts) { // Link pocket exits back // Link pocket exits back
Iterator<WeightedRiftDestination> destIterator = rift.getDestinations().iterator(); for (TileEntityRift rift : rifts) {
ListIterator<WeightedRiftDestination> destIterator = rift.getDestinations().listIterator();
while (destIterator.hasNext()) { while (destIterator.hasNext()) {
WeightedRiftDestination wdest = destIterator.next(); WeightedRiftDestination wdest = destIterator.next();
RiftDestination dest = wdest.getDestination(); RiftDestination dest = wdest.getDestination();
if (dest.getType() == RiftDestination.EnumType.POCKET_EXIT) { if (dest.getType() == RiftDestination.EnumType.POCKET_EXIT) {
destIterator.remove(); destIterator.remove();
linkTo.withOldDestination(dest); destIterator.add(new WeightedRiftDestination(linkTo.withOldDestination(dest), wdest.getWeight(), wdest.getGroup()));
rift.addDestination(linkTo, wdest.getWeight(), wdest.getGroup()); rift.notifyStateChanged();
rift.markDirty();
} }
} }
} }

View file

@ -24,8 +24,8 @@ public class PocketGenerator {
} }
public static Pocket generatePublicPocket(VirtualLocation virtualLocation) { public static Pocket generatePublicPocket(VirtualLocation virtualLocation) {
PocketTemplate pocketTemplate = SchematicHandler.INSTANCE.getPersonalPocketTemplate(); PocketTemplate pocketTemplate = SchematicHandler.INSTANCE.getPublicPocketTemplate();
return generatePocketFromTemplate(DimDoorDimensions.getPrivateDimID(), 0, pocketTemplate, virtualLocation); return generatePocketFromTemplate(DimDoorDimensions.getPublicDimID(), 0, pocketTemplate, virtualLocation);
} }
/** /**

View file

@ -2,6 +2,7 @@ package com.zixiken.dimdoors.shared.pockets;
import com.zixiken.dimdoors.shared.tileentities.TileEntityVerticalEntranceRift; import com.zixiken.dimdoors.shared.tileentities.TileEntityVerticalEntranceRift;
import com.zixiken.dimdoors.shared.rifts.TileEntityRift; import com.zixiken.dimdoors.shared.rifts.TileEntityRift;
import com.zixiken.dimdoors.shared.util.Location;
import com.zixiken.dimdoors.shared.util.Schematic; import com.zixiken.dimdoors.shared.util.Schematic;
import com.zixiken.dimdoors.DimDoors; import com.zixiken.dimdoors.DimDoors;
import com.zixiken.dimdoors.shared.blocks.BlockDimDoorBase; import com.zixiken.dimdoors.shared.blocks.BlockDimDoorBase;
@ -33,6 +34,7 @@ public class PocketTemplate { //there is exactly one pocket placer for each diff
@Getter private final int minDepth; @Getter private final int minDepth;
@Getter private final int maxDepth; @Getter private final int maxDepth;
private final float[] weights; //weights for chanced generation of dungeons per depth level | weights[0] is the weight for depth "minDepth" private final float[] weights; //weights for chanced generation of dungeons per depth level | weights[0] is the weight for depth "minDepth"
public static boolean schematicBeingPlaced = false;
//this class should contain the actual schematic info, as well as some of the Json info (placement of Rifts and stuff) //this class should contain the actual schematic info, as well as some of the Json info (placement of Rifts and stuff)
public PocketTemplate(String groupName, String name, Schematic schematic, int size, int minDepth, int maxDepth, float[] weights) { public PocketTemplate(String groupName, String name, Schematic schematic, int size, int minDepth, int maxDepth, float[] weights) {
@ -57,8 +59,8 @@ public class PocketTemplate { //there is exactly one pocket placer for each diff
return weights[weights.length - 1]; // return last weight return weights[weights.length - 1]; // return last weight
} }
public Pocket place(Pocket pocket, int yBase) { //returns the riftID of the entrance DimDoor public Pocket place(Pocket pocket, int yBase) { //returns the riftID of the entrance DimDoor TODO: use place method in schematic
pocket.setSize(size); // TODO: check that this works properly pocket.setSize(size);
int gridSize = PocketRegistry.getForDim(pocket.dimID).getGridSize(); int gridSize = PocketRegistry.getForDim(pocket.dimID).getGridSize();
int dimID = pocket.dimID; int dimID = pocket.dimID;
int xBase = pocket.getX() * gridSize * 16; int xBase = pocket.getX() * gridSize * 16;
@ -74,6 +76,7 @@ public class PocketTemplate { //there is exactly one pocket placer for each diff
WorldServer world = DimDoors.proxy.getWorldServer(dimID); WorldServer world = DimDoors.proxy.getWorldServer(dimID);
//Place the Dungeon content structure //Place the Dungeon content structure
schematicBeingPlaced = true; // TODO: Find a better system. What happens if the world is left before schematic is placed and this static field stays true?
List<IBlockState> palette = schematic.getPallette(); List<IBlockState> palette = schematic.getPallette();
int[][][] blockData = schematic.getBlockData(); int[][][] blockData = schematic.getBlockData();
for (int x = 0; x < blockData.length; x++) { for (int x = 0; x < blockData.length; x++) {
@ -83,32 +86,27 @@ public class PocketTemplate { //there is exactly one pocket placer for each diff
} }
} }
} }
schematicBeingPlaced = false;
//Load TileEntity Data //Load TileEntity Data
List<TileEntityRift> rifts = new ArrayList<>(); List<Location> riftLocations = new ArrayList<>();
for (NBTTagCompound tileEntityNBT : schematic.getTileEntities()) { for (NBTTagCompound tileEntityNBT : schematic.getTileEntities()) {
BlockPos pos = new BlockPos(xBase + tileEntityNBT.getInteger("x"), yBase + tileEntityNBT.getInteger("y"), zBase + tileEntityNBT.getInteger("z")); BlockPos pos = new BlockPos(xBase + tileEntityNBT.getInteger("x"), yBase + tileEntityNBT.getInteger("y"), zBase + tileEntityNBT.getInteger("z"));
DimDoors.log(getClass(), "Re-loading tile-entity at blockPos: " + pos); DimDoors.log(getClass(), "Re-loading tile-entity at blockPos: " + pos);
TileEntity tileEntity = world.getTileEntity(pos); TileEntity tileEntity = world.getTileEntity(pos);
if (tileEntity != null) { if (tileEntity != null) {
if (tileEntity instanceof TileEntityRift) { tileEntity.readFromNBT(tileEntityNBT);
DimDoors.log(getClass(), "Rift found in schematic: " + pos); tileEntity.setWorld(world); // TODO: necessary?
TileEntityRift rift = (TileEntityRift) tileEntity;
rifts.add(rift);
} else {
try {
tileEntity.readFromNBT(tileEntityNBT); //this reads in the wrong blockPos
} catch(Exception e) {
DimDoors.warn(getClass(), "Loading in the data for TileEntity of type " + tileEntity + " went wrong. Details: " + e.getLocalizedMessage());
}
}
tileEntity.setPos(pos); //correct the position tileEntity.setPos(pos); //correct the position
if (tileEntity instanceof TileEntityRift) {
DimDoors.log(getClass(), "Rift found in schematic at " + pos);
riftLocations.add(new Location(world, pos));
}
tileEntity.markDirty(); tileEntity.markDirty();
} }
} }
pocket.riftLocations = riftLocations;
// TODO: rifts!
return pocket; return pocket;
} }
} }

View file

@ -1,28 +1,56 @@
package com.zixiken.dimdoors.shared.rifts; package com.zixiken.dimdoors.shared.rifts;
import com.zixiken.dimdoors.shared.util.INBTStorable; import com.zixiken.dimdoors.shared.util.INBTStorable;
import com.zixiken.dimdoors.shared.util.Location;
import com.zixiken.dimdoors.shared.util.NBTUtils;
import lombok.*; import lombok.*;
import lombok.experimental.Wither; import lombok.experimental.Wither;
import net.minecraft.nbt.NBTBase; import net.minecraft.nbt.NBTBase;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList; import net.minecraft.nbt.NBTTagList;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3i;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.UUID;
@Getter @ToString @EqualsAndHashCode @AllArgsConstructor(access = AccessLevel.PRIVATE) @Getter @ToString @EqualsAndHashCode @AllArgsConstructor(access = AccessLevel.PRIVATE)
public /*abstract*/ class RiftDestination implements INBTStorable { // TODO: fix lombok and make this abstract public /*abstract*/ class RiftDestination implements INBTStorable { // TODO: fix lombok and make this abstract
@Getter private EnumType type; @Getter private EnumType type;
@Wither @Getter private RiftDestination oldDestination; @Getter protected RiftDestination oldDestination;
public enum EnumType { public enum EnumType {
RELATIVE, LOCAL, GLOBAL, NEW_PUBLIC, PRIVATE, LIMBO, RANDOM_RIFT_LINK, POCKET_ENTRANCE, POCKET_EXIT, PRIVATE_POCKET_EXIT, ESCAPE; RELATIVE, LOCAL, GLOBAL, NEW_PUBLIC, PRIVATE, LIMBO, AVAILABLE_LINK, POCKET_ENTRANCE, POCKET_EXIT, PRIVATE_POCKET_EXIT, ESCAPE;
} }
private RiftDestination() {} private RiftDestination() {
if (this instanceof RelativeDestination) {
type = EnumType.RELATIVE;
} else if (this instanceof LocalDestination) {
type = EnumType.LOCAL;
} else if (this instanceof GlobalDestination) {
type = EnumType.GLOBAL;
} else if (this instanceof NewPublicDestination) {
type = EnumType.NEW_PUBLIC;
} else if (this instanceof PrivateDestination) {
type = EnumType.PRIVATE;
} else if (this instanceof LimboDestination) {
type = EnumType.LIMBO;
} else if (this instanceof AvailableLinkDestination) {
type = EnumType.AVAILABLE_LINK;
} else if (this instanceof PocketEntranceDestination) {
type = EnumType.POCKET_ENTRANCE;
} else if (this instanceof PocketExitDestination) {
type = EnumType.POCKET_EXIT;
} else if (this instanceof PrivatePocketExitDestination) {
type = EnumType.PRIVATE_POCKET_EXIT;
} else if (this instanceof EscapeDestination) {
type = EnumType.ESCAPE;
}
}
public static RiftDestination readDestinationNBT(NBTTagCompound nbt) { // TODO: store old AVAILABLE_LINK
public static RiftDestination readDestinationNBT(NBTTagCompound nbt) { // TODO: store old RANDOM_RIFT_LINK
RiftDestination destination = null; RiftDestination destination = null;
EnumType type = EnumType.valueOf(nbt.getString("type")); EnumType type = EnumType.valueOf(nbt.getString("type"));
switch (type) { switch (type) {
@ -32,6 +60,9 @@ public /*abstract*/ class RiftDestination implements INBTStorable { // TODO: fix
case LOCAL: case LOCAL:
destination = new LocalDestination(); destination = new LocalDestination();
break; break;
case GLOBAL:
destination = new GlobalDestination();
break;
case NEW_PUBLIC: case NEW_PUBLIC:
destination = new NewPublicDestination(); destination = new NewPublicDestination();
break; break;
@ -41,8 +72,8 @@ public /*abstract*/ class RiftDestination implements INBTStorable { // TODO: fix
case LIMBO: case LIMBO:
destination = new LimboDestination(); destination = new LimboDestination();
break; break;
case RANDOM_RIFT_LINK: case AVAILABLE_LINK:
destination = new RandomRiftLinkDestination(); destination = new AvailableLinkDestination();
break; break;
case POCKET_ENTRANCE: case POCKET_ENTRANCE:
destination = new PocketEntranceDestination(); destination = new PocketEntranceDestination();
@ -62,6 +93,45 @@ public /*abstract*/ class RiftDestination implements INBTStorable { // TODO: fix
return destination; return destination;
} }
public RiftDestination withOldDestination(RiftDestination oldDestination) {
RiftDestination dest = null;
if (this instanceof RelativeDestination) { // TODO: use type switch
dest = ((RelativeDestination) this).toBuilder().build();
dest.oldDestination = oldDestination;
} else if (this instanceof LocalDestination) {
dest = ((LocalDestination) this).toBuilder().build();
dest.oldDestination = oldDestination;
} else if (this instanceof GlobalDestination) {
dest = ((GlobalDestination) this).toBuilder().build();
dest.oldDestination = oldDestination;
} else if (this instanceof NewPublicDestination) {
dest = ((NewPublicDestination) this).toBuilder().build();
dest.oldDestination = oldDestination;
} else if (this instanceof PrivateDestination) {
dest = ((PrivateDestination) this).toBuilder().build();
dest.oldDestination = oldDestination;
} else if (this instanceof LimboDestination) {
dest = ((LimboDestination) this).toBuilder().build();
dest.oldDestination = oldDestination;
} else if (this instanceof AvailableLinkDestination) {
dest = ((AvailableLinkDestination) this).toBuilder().build();
dest.oldDestination = oldDestination;
} else if (this instanceof PocketEntranceDestination) {
dest = ((PocketEntranceDestination) this).toBuilder().build();
dest.oldDestination = oldDestination;
} else if (this instanceof PocketExitDestination) {
dest = ((PocketExitDestination) this).toBuilder().build();
dest.oldDestination = oldDestination;
} else if (this instanceof PrivatePocketExitDestination) {
dest = ((PrivatePocketExitDestination) this).toBuilder().build();
dest.oldDestination = oldDestination;
} else if (this instanceof EscapeDestination) {
dest = ((EscapeDestination) this).toBuilder().build();
dest.oldDestination = oldDestination;
}
return dest;
}
@Override @Override
public void readFromNBT(NBTTagCompound nbt) { public void readFromNBT(NBTTagCompound nbt) {
if (nbt.hasKey("oldDestination")) oldDestination = readDestinationNBT(nbt.getCompoundTag("oldDestination")); if (nbt.hasKey("oldDestination")) oldDestination = readDestinationNBT(nbt.getCompoundTag("oldDestination"));
@ -70,97 +140,73 @@ public /*abstract*/ class RiftDestination implements INBTStorable { // TODO: fix
@Override @Override
public NBTTagCompound writeToNBT(NBTTagCompound nbt) { public NBTTagCompound writeToNBT(NBTTagCompound nbt) {
if (oldDestination != null) nbt.setTag("oldDestination", oldDestination.writeToNBT(new NBTTagCompound())); if (oldDestination != null) nbt.setTag("oldDestination", oldDestination.writeToNBT(new NBTTagCompound()));
nbt.setString("type", type.name());
return nbt; return nbt;
} }
@Getter @AllArgsConstructor @lombok.Builder(toBuilder = true) @Getter @AllArgsConstructor @lombok.Builder(toBuilder = true)
public static class RelativeDestination extends RiftDestination { // TODO: use Vec3i public static class RelativeDestination extends RiftDestination { // TODO: use Vec3i
private int xOffset; private Vec3i offset;
private int yOffset;
private int zOffset;
private RelativeDestination() {} private RelativeDestination() {}
@Override @Override
public void readFromNBT(NBTTagCompound nbt) { public void readFromNBT(NBTTagCompound nbt) {
super.readFromNBT(nbt); super.readFromNBT(nbt);
xOffset = nbt.getInteger("xOffset"); offset = NBTUtils.readVec3i(nbt.getCompoundTag("offset"));
yOffset = nbt.getInteger("yOffset");
zOffset = nbt.getInteger("zOffset");
} }
@Override @Override
public NBTTagCompound writeToNBT(NBTTagCompound nbt) { public NBTTagCompound writeToNBT(NBTTagCompound nbt) {
nbt = super.writeToNBT(nbt); nbt = super.writeToNBT(nbt);
nbt.setString("type", EnumType.RELATIVE.name()); nbt.setTag("offset", NBTUtils.writeVec3i(offset));
nbt.setInteger("xOffset", xOffset);
nbt.setInteger("yOffset", yOffset);
nbt.setInteger("yOffset", zOffset);
return nbt; return nbt;
} }
} }
@Getter @AllArgsConstructor @lombok.Builder(toBuilder = true) @Getter @AllArgsConstructor @lombok.Builder(toBuilder = true)
public static class LocalDestination extends RiftDestination { // TODO: use BlockPos public static class LocalDestination extends RiftDestination { // TODO: use BlockPos
private int x; private BlockPos pos;
private int y;
private int z;
private LocalDestination() {} private LocalDestination() {}
@Override @Override
public void readFromNBT(NBTTagCompound nbt) { public void readFromNBT(NBTTagCompound nbt) {
super.readFromNBT(nbt); super.readFromNBT(nbt);
x = nbt.getInteger("x"); pos = new BlockPos(NBTUtils.readVec3i(nbt.getCompoundTag("pos")));
y = nbt.getInteger("y");
z = nbt.getInteger("z");
} }
@Override @Override
public NBTTagCompound writeToNBT(NBTTagCompound nbt) { public NBTTagCompound writeToNBT(NBTTagCompound nbt) {
nbt = super.writeToNBT(nbt); nbt = super.writeToNBT(nbt);
nbt.setString("type", EnumType.LOCAL.name()); nbt.setTag("pos", NBTUtils.writeVec3i(pos));
nbt.setInteger("x", x);
nbt.setInteger("y", y);
nbt.setInteger("y", z);
return nbt; return nbt;
} }
} }
@Getter @AllArgsConstructor @lombok.Builder(toBuilder = true) @Getter @AllArgsConstructor @lombok.Builder(toBuilder = true)
public static class GlobalDestination extends RiftDestination { // TODO: use Location public static class GlobalDestination extends RiftDestination { // TODO: location directly in nbt like minecraft?
private int dim; private Location loc;
private int x;
private int y;
private int z;
private GlobalDestination() {}; private GlobalDestination() {};
@Override @Override
public void readFromNBT(NBTTagCompound nbt) { public void readFromNBT(NBTTagCompound nbt) {
super.readFromNBT(nbt); super.readFromNBT(nbt);
dim = nbt.getInteger("dim"); loc = Location.readFromNBT(nbt.getCompoundTag("loc"));
x = nbt.getInteger("x");
y = nbt.getInteger("y");
z = nbt.getInteger("z");
} }
@Override @Override
public NBTTagCompound writeToNBT(NBTTagCompound nbt) { public NBTTagCompound writeToNBT(NBTTagCompound nbt) {
nbt = super.writeToNBT(nbt); nbt = super.writeToNBT(nbt);
nbt.setString("type", EnumType.GLOBAL.name()); nbt.setTag("loc", Location.writeToNBT(loc));
nbt.setInteger("dim", dim);
nbt.setInteger("x", x);
nbt.setInteger("y", y);
nbt.setInteger("y", z);
return nbt; return nbt;
} }
} }
@Getter @AllArgsConstructor @lombok.Builder(toBuilder = true) @Getter @AllArgsConstructor @lombok.Builder(toBuilder = true)
public static class NewPublicDestination extends RiftDestination { public static class NewPublicDestination extends RiftDestination { // TODO: more config options such as non-default size, etc.
//private NewPublicDestination() {} //private NewPublicDestination() {}
@Override @Override
@ -171,7 +217,6 @@ public /*abstract*/ class RiftDestination implements INBTStorable { // TODO: fix
@Override @Override
public NBTTagCompound writeToNBT(NBTTagCompound nbt) { public NBTTagCompound writeToNBT(NBTTagCompound nbt) {
nbt = super.writeToNBT(nbt); nbt = super.writeToNBT(nbt);
nbt.setString("type", EnumType.NEW_PUBLIC.name());
return nbt; return nbt;
} }
} }
@ -189,7 +234,6 @@ public /*abstract*/ class RiftDestination implements INBTStorable { // TODO: fix
@Override @Override
public NBTTagCompound writeToNBT(NBTTagCompound nbt) { public NBTTagCompound writeToNBT(NBTTagCompound nbt) {
nbt = super.writeToNBT(nbt); nbt = super.writeToNBT(nbt);
nbt.setString("type", EnumType.PRIVATE.name());
return nbt; return nbt;
} }
} }
@ -207,13 +251,12 @@ public /*abstract*/ class RiftDestination implements INBTStorable { // TODO: fix
@Override @Override
public NBTTagCompound writeToNBT(NBTTagCompound nbt) { public NBTTagCompound writeToNBT(NBTTagCompound nbt) {
nbt = super.writeToNBT(nbt); nbt = super.writeToNBT(nbt);
nbt.setString("type", EnumType.PRIVATE.name());
return nbt; return nbt;
} }
} }
@Getter @AllArgsConstructor @lombok.Builder(toBuilder = true) @Getter @AllArgsConstructor @lombok.Builder(toBuilder = true)
public static class RandomRiftLinkDestination extends RiftDestination { // TODO public static class AvailableLinkDestination extends RiftDestination { // TODO
private float newDungeonRiftProbability; private float newDungeonRiftProbability;
private float depthPenalization; // TODO: these make the equation assymetric private float depthPenalization; // TODO: these make the equation assymetric
private float distancePenalization; private float distancePenalization;
@ -224,9 +267,14 @@ public /*abstract*/ class RiftDestination implements INBTStorable { // TODO: fix
private boolean unstable; private boolean unstable;
private float entranceLinkWeight; private float entranceLinkWeight;
private float floatingRiftWeight; private float floatingRiftWeight;
private boolean noLinkBack;
// private int maxLinks;
@Builder.Default private UUID uuid = UUID.randomUUID();
// TODO: add a "safe" option to link only to a rift destination that has a non-zero weight // TODO: add a "safe" option to link only to a rift destination that has a non-zero weight
private RandomRiftLinkDestination() {} private AvailableLinkDestination() {}
@Override @Override
public void readFromNBT(NBTTagCompound nbt) { public void readFromNBT(NBTTagCompound nbt) {
@ -238,12 +286,14 @@ public /*abstract*/ class RiftDestination implements INBTStorable { // TODO: fix
dungeonRiftsOnly = nbt.getBoolean("dungeonRiftsOnly"); dungeonRiftsOnly = nbt.getBoolean("dungeonRiftsOnly");
overworldRifts = nbt.getBoolean("overworldRifts"); overworldRifts = nbt.getBoolean("overworldRifts");
unstable = nbt.getBoolean("unstable"); unstable = nbt.getBoolean("unstable");
noLinkBack = nbt.getBoolean("noLinkBack");
// maxLinks = nbt.getInteger("maxLinks");
uuid = nbt.getUniqueId("uuid");
} }
@Override @Override
public NBTTagCompound writeToNBT(NBTTagCompound nbt) { public NBTTagCompound writeToNBT(NBTTagCompound nbt) {
nbt = super.writeToNBT(nbt); nbt = super.writeToNBT(nbt);
nbt.setString("type", EnumType.RANDOM_RIFT_LINK.name());
nbt.setFloat("newDungeonRiftProbability", newDungeonRiftProbability); nbt.setFloat("newDungeonRiftProbability", newDungeonRiftProbability);
nbt.setFloat("depthPenalization", depthPenalization); nbt.setFloat("depthPenalization", depthPenalization);
nbt.setFloat("distancePenalization", distancePenalization); nbt.setFloat("distancePenalization", distancePenalization);
@ -251,6 +301,9 @@ public /*abstract*/ class RiftDestination implements INBTStorable { // TODO: fix
nbt.setBoolean("dungeonRiftsOnly", dungeonRiftsOnly); nbt.setBoolean("dungeonRiftsOnly", dungeonRiftsOnly);
nbt.setBoolean("overworldRifts", overworldRifts); nbt.setBoolean("overworldRifts", overworldRifts);
nbt.setBoolean("unstable", unstable); nbt.setBoolean("unstable", unstable);
nbt.setBoolean("noLinkBack", noLinkBack);
// nbt.setInteger("maxLinks", maxLinks);
nbt.setUniqueId("uuid", uuid);
return nbt; return nbt;
} }
} }
@ -258,8 +311,8 @@ public /*abstract*/ class RiftDestination implements INBTStorable { // TODO: fix
@Getter @AllArgsConstructor @lombok.Builder(toBuilder = true) @Getter @AllArgsConstructor @lombok.Builder(toBuilder = true)
public static class PocketEntranceDestination extends RiftDestination { public static class PocketEntranceDestination extends RiftDestination {
private float weight; private float weight;
private List<WeightedRiftDestination> ifDestinations = new LinkedList<>(); @Builder.Default private List<WeightedRiftDestination> ifDestinations = new LinkedList<>(); // TODO addIfDestination method in builder
private List<WeightedRiftDestination> otherwiseDestinations = new LinkedList<>(); @Builder.Default private List<WeightedRiftDestination> otherwiseDestinations = new LinkedList<>(); // TODO addIfDestination method in builder
private PocketEntranceDestination() {} private PocketEntranceDestination() {}
@ -268,13 +321,15 @@ public /*abstract*/ class RiftDestination implements INBTStorable { // TODO: fix
super.readFromNBT(nbt); super.readFromNBT(nbt);
weight = nbt.getFloat("weight"); weight = nbt.getFloat("weight");
ifDestinations = new LinkedList<>();
NBTTagList ifDestinationsNBT = (NBTTagList) nbt.getTag("ifDestinations"); NBTTagList ifDestinationsNBT = (NBTTagList) nbt.getTag("ifDestinations");
for (NBTBase ifDestinationNBT : ifDestinationsNBT) { for (NBTBase ifDestinationNBT : ifDestinationsNBT) {
WeightedRiftDestination ifDestination = new WeightedRiftDestination(); WeightedRiftDestination ifDestination = new WeightedRiftDestination();
ifDestination.readFromNBT((NBTTagCompound) ifDestinationNBT); ifDestination.readFromNBT((NBTTagCompound) ifDestinationNBT);
otherwiseDestinations.add(ifDestination); ifDestinations.add(ifDestination);
} }
otherwiseDestinations = new LinkedList<>();
NBTTagList otherwiseDestinationsNBT = (NBTTagList) nbt.getTag("otherwiseDestinations"); NBTTagList otherwiseDestinationsNBT = (NBTTagList) nbt.getTag("otherwiseDestinations");
for (NBTBase otherwiseDestinationNBT : otherwiseDestinationsNBT) { for (NBTBase otherwiseDestinationNBT : otherwiseDestinationsNBT) {
WeightedRiftDestination otherwiseDestination = new WeightedRiftDestination(); WeightedRiftDestination otherwiseDestination = new WeightedRiftDestination();
@ -286,7 +341,6 @@ public /*abstract*/ class RiftDestination implements INBTStorable { // TODO: fix
@Override @Override
public NBTTagCompound writeToNBT(NBTTagCompound nbt) { public NBTTagCompound writeToNBT(NBTTagCompound nbt) {
nbt = super.writeToNBT(nbt); nbt = super.writeToNBT(nbt);
nbt.setString("type", EnumType.POCKET_ENTRANCE.name());
nbt.setFloat("weight", weight); nbt.setFloat("weight", weight);
NBTTagList ifDestinationsNBT = new NBTTagList(); NBTTagList ifDestinationsNBT = new NBTTagList();
@ -318,7 +372,6 @@ public /*abstract*/ class RiftDestination implements INBTStorable { // TODO: fix
@Override @Override
public NBTTagCompound writeToNBT(NBTTagCompound nbt) { public NBTTagCompound writeToNBT(NBTTagCompound nbt) {
nbt = super.writeToNBT(nbt); nbt = super.writeToNBT(nbt);
nbt.setString("type", EnumType.POCKET_EXIT.name());
return nbt; return nbt;
} }
} }
@ -336,7 +389,6 @@ public /*abstract*/ class RiftDestination implements INBTStorable { // TODO: fix
@Override @Override
public NBTTagCompound writeToNBT(NBTTagCompound nbt) { public NBTTagCompound writeToNBT(NBTTagCompound nbt) {
nbt = super.writeToNBT(nbt); nbt = super.writeToNBT(nbt);
nbt.setString("type", EnumType.PRIVATE_POCKET_EXIT.name());
return nbt; return nbt;
} }
} }
@ -352,7 +404,6 @@ public /*abstract*/ class RiftDestination implements INBTStorable { // TODO: fix
@Override @Override
public NBTTagCompound writeToNBT(NBTTagCompound nbt) { public NBTTagCompound writeToNBT(NBTTagCompound nbt) {
nbt = super.writeToNBT(nbt); nbt = super.writeToNBT(nbt);
nbt.setString("type", EnumType.ESCAPE.name());
return nbt; return nbt;
} }
} }

View file

@ -6,10 +6,7 @@ import com.zixiken.dimdoors.shared.rifts.RiftRegistry.RiftInfo.AvailableLinkInfo
import com.zixiken.dimdoors.shared.util.INBTStorable; import com.zixiken.dimdoors.shared.util.INBTStorable;
import com.zixiken.dimdoors.shared.util.Location; import com.zixiken.dimdoors.shared.util.Location;
import com.zixiken.dimdoors.shared.util.WorldUtils; import com.zixiken.dimdoors.shared.util.WorldUtils;
import lombok.AllArgsConstructor; import lombok.*;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.experimental.Wither; import lombok.experimental.Wither;
import net.minecraft.nbt.NBTBase; import net.minecraft.nbt.NBTBase;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
@ -33,35 +30,47 @@ public class RiftRegistry extends WorldSavedData {
@Getter private int dim; @Getter private int dim;
private World world; private World world;
@lombok.AllArgsConstructor @lombok.NoArgsConstructor @lombok.EqualsAndHashCode @lombok.AllArgsConstructor @lombok.EqualsAndHashCode @lombok.Builder(toBuilder = true)
public static class RiftInfo implements com.zixiken.dimdoors.shared.util.INBTStorable { public static class RiftInfo implements com.zixiken.dimdoors.shared.util.INBTStorable {
@Getter private List<AvailableLinkInfo> availableLinks = new LinkedList<>(); @Builder.Default @Getter private Set<AvailableLinkInfo> availableLinks = new HashSet<>(); // ignore intellij warnings, builder needs these
@Getter private Set<Location> sources = new HashSet<>(); @Builder.Default @Getter private Set<Location> sources = new HashSet<>();
@Getter private Set<Location> destinations = new HashSet<>(); @Builder.Default @Getter private Set<Location> destinations = new HashSet<>();
@AllArgsConstructor @NoArgsConstructor @EqualsAndHashCode @AllArgsConstructor @NoArgsConstructor @EqualsAndHashCode @Builder(toBuilder = true)
public static class AvailableLinkInfo implements INBTStorable { public static class AvailableLinkInfo implements INBTStorable {
@Getter private float weight; @Getter @Setter private float weight;
@Getter private VirtualLocation virtualLocation; @Getter private VirtualLocation virtualLocation;
@Getter @Wither private Location location; @Getter @Wither private Location location;
@Getter private UUID uuid;
@Override @Override
public void readFromNBT(NBTTagCompound nbt) { public void readFromNBT(NBTTagCompound nbt) {
weight = nbt.getFloat("weight"); weight = nbt.getFloat("weight");
virtualLocation = VirtualLocation.readFromNBT(nbt.getCompoundTag("virtualLocation")); virtualLocation = VirtualLocation.readFromNBT(nbt.getCompoundTag("virtualLocation"));
uuid = nbt.getUniqueId("uuid");
} }
@Override @Override
public NBTTagCompound writeToNBT(NBTTagCompound nbt) { public NBTTagCompound writeToNBT(NBTTagCompound nbt) {
nbt.setFloat("weight", weight); nbt.setFloat("weight", weight);
nbt.setTag("virtualLocation", virtualLocation.writeToNBT()); nbt.setTag("virtualLocation", virtualLocation.writeToNBT());
nbt.setUniqueId("uuid", uuid);
return nbt; return nbt;
} }
} }
public RiftInfo() {
availableLinks = new HashSet<>();
sources = new HashSet<>();
destinations = new HashSet<>();
}
@Override @Override
public void readFromNBT(NBTTagCompound nbt) { public void readFromNBT(NBTTagCompound nbt) {
NBTTagList availableLinksNBT = (NBTTagList) nbt.getTag("availableLinks"); NBTTagList availableLinksNBT = (NBTTagList) nbt.getTag("availableLinks");
if (availableLinksNBT == null) {
throw new RuntimeException();
}
for (NBTBase availableLinkNBT : availableLinksNBT) { for (NBTBase availableLinkNBT : availableLinksNBT) {
AvailableLinkInfo link = new AvailableLinkInfo(); AvailableLinkInfo link = new AvailableLinkInfo();
link.readFromNBT((NBTTagCompound) availableLinkNBT); link.readFromNBT((NBTTagCompound) availableLinkNBT);
@ -147,7 +156,7 @@ public class RiftRegistry extends WorldSavedData {
NBTTagCompound riftNBTC = (NBTTagCompound) riftNBT; NBTTagCompound riftNBTC = (NBTTagCompound) riftNBT;
Location location = Location.readFromNBT(riftNBTC.getCompoundTag("location")); Location location = Location.readFromNBT(riftNBTC.getCompoundTag("location"));
RiftInfo riftInfo = new RiftInfo(); RiftInfo riftInfo = new RiftInfo();
riftInfo.readFromNBT(nbt); riftInfo.readFromNBT(riftNBTC);
rifts.put(location, riftInfo); rifts.put(location, riftInfo);
} }
} }
@ -210,7 +219,7 @@ public class RiftRegistry extends WorldSavedData {
destinationRegistry.rifts.get(destination).sources.remove(rift); destinationRegistry.rifts.get(destination).sources.remove(rift);
destinationRegistry.markDirty(); destinationRegistry.markDirty();
TileEntityRift riftEntity = (TileEntityRift) destinationRegistry.world.getTileEntity(destination.getPos()); TileEntityRift riftEntity = (TileEntityRift) destinationRegistry.world.getTileEntity(destination.getPos());
riftEntity.checkIfNeeded(); riftEntity.allSourcesGone();
} }
registry.markDirty(); registry.markDirty();
} }
@ -239,12 +248,28 @@ public class RiftRegistry extends WorldSavedData {
registry.markDirty(); registry.markDirty();
} }
public void removeAvailableLink(Location rift, AvailableLinkInfo link) { public static void removeAvailableLink(Location rift, AvailableLinkInfo link) {
RiftRegistry registry = getRegistry(rift); RiftRegistry registry = getRegistry(rift);
registry.rifts.get(rift).availableLinks.remove(link); registry.rifts.get(rift).availableLinks.remove(link);
registry.markDirty(); registry.markDirty();
} }
public static void clearAvailableLinks(Location rift) {
RiftRegistry registry = getRegistry(rift);
registry.rifts.get(rift).availableLinks.clear();
registry.markDirty();
}
public static void removeAvailableLinkByUUID(Location rift, UUID uuid) {
RiftRegistry registry = getRegistry(rift);
for (AvailableLinkInfo link : registry.rifts.get(rift).availableLinks) {
if (link.uuid.equals(uuid)) {
removeAvailableLink(rift, link);
return;
}
}
}
public static RiftRegistry getRegistry(Location rift) { public static RiftRegistry getRegistry(Location rift) {
return getForDim(rift.getDimID()); return getForDim(rift.getDimID());
} }

View file

@ -1,6 +1,7 @@
package com.zixiken.dimdoors.shared.rifts; package com.zixiken.dimdoors.shared.rifts;
import com.zixiken.dimdoors.DimDoors; import com.zixiken.dimdoors.DimDoors;
import com.zixiken.dimdoors.shared.TeleporterDimDoors;
import com.zixiken.dimdoors.shared.VirtualLocation; import com.zixiken.dimdoors.shared.VirtualLocation;
import com.zixiken.dimdoors.shared.pockets.Pocket; import com.zixiken.dimdoors.shared.pockets.Pocket;
import com.zixiken.dimdoors.shared.pockets.PocketGenerator; import com.zixiken.dimdoors.shared.pockets.PocketGenerator;
@ -16,6 +17,7 @@ import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.entity.IEntityOwnable; import net.minecraft.entity.IEntityOwnable;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.nbt.NBTBase; import net.minecraft.nbt.NBTBase;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList; import net.minecraft.nbt.NBTTagList;
@ -26,28 +28,26 @@ import net.minecraft.util.ITickable;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World; import net.minecraft.world.World;
import javax.annotation.Nonnull;
import java.util.*; import java.util.*;
public abstract class TileEntityRift extends TileEntity implements ITickable { // TODO: implement ITeleportSource and ITeleportDestination public abstract class TileEntityRift extends TileEntity implements ITickable { // TODO: implement ITeleportSource and ITeleportDestination
@Getter protected VirtualLocation virtualLocation; // location can be null @Getter protected VirtualLocation virtualLocation;
@Getter protected List<WeightedRiftDestination> destinations; // must be non-null // @Nonnull @Getter protected List<WeightedRiftDestination> destinations;
@Getter protected boolean makeDestinationPermanent; // @Getter protected boolean makeDestinationPermanent;
@Getter protected int freeLinks; @Getter protected boolean preserveRotation;
@Getter protected boolean preserveRotation; // @Getter protected float yaw;
@Getter protected float yaw; // @Getter protected float pitch;
@Getter protected float pitch; // @Getter protected boolean alwaysDelete; // Delete the rift when an entrance rift is broken even if the state was changed or destinations link there.
@Getter protected boolean alwaysDelete; // @Getter protected float chaosWeight;
// TODO: option to convert to door on teleportTo? // TODO: option to convert to door on teleportTo?
// TODO: chaos door link weights?
protected boolean riftStateChanged; // not saved protected boolean riftStateChanged; // not saved
public TileEntityRift() { public TileEntityRift() {
destinations = new ArrayList<>(); destinations = new ArrayList<>();
makeDestinationPermanent = true; makeDestinationPermanent = true;
freeLinks = 1;
preserveRotation = true; preserveRotation = true;
pitch = 0; pitch = 0;
alwaysDelete = false; alwaysDelete = false;
@ -57,7 +57,6 @@ public abstract class TileEntityRift extends TileEntity implements ITickable { /
virtualLocation = oldRift.virtualLocation; virtualLocation = oldRift.virtualLocation;
destinations = oldRift.destinations; destinations = oldRift.destinations;
makeDestinationPermanent = oldRift.makeDestinationPermanent; makeDestinationPermanent = oldRift.makeDestinationPermanent;
freeLinks = oldRift.freeLinks;
preserveRotation = oldRift.preserveRotation; preserveRotation = oldRift.preserveRotation;
yaw = oldRift.yaw; yaw = oldRift.yaw;
pitch = oldRift.pitch; pitch = oldRift.pitch;
@ -65,10 +64,6 @@ public abstract class TileEntityRift extends TileEntity implements ITickable { /
markDirty(); markDirty();
} }
public boolean isEntrance() {
return false;
}
@Override @Override
public void readFromNBT(NBTTagCompound nbt) { public void readFromNBT(NBTTagCompound nbt) {
super.readFromNBT(nbt); super.readFromNBT(nbt);
@ -87,6 +82,8 @@ public abstract class TileEntityRift extends TileEntity implements ITickable { /
preserveRotation = nbt.getBoolean("preserveRotation"); preserveRotation = nbt.getBoolean("preserveRotation");
yaw = nbt.getFloat("yaw"); yaw = nbt.getFloat("yaw");
pitch = nbt.getFloat("pitch"); pitch = nbt.getFloat("pitch");
alwaysDelete = nbt.getBoolean("alwaysDelete");
chaosWeight = nbt.getFloat("chaosWeight");
} }
@Override @Override
@ -97,7 +94,7 @@ public abstract class TileEntityRift extends TileEntity implements ITickable { /
NBTTagList destinationsNBT = new NBTTagList(); NBTTagList destinationsNBT = new NBTTagList();
for (WeightedRiftDestination destination : destinations) { for (WeightedRiftDestination destination : destinations) {
destinationsNBT.appendTag(destination.writeToNBT(nbt)); destinationsNBT.appendTag(destination.writeToNBT(new NBTTagCompound()));
} }
nbt.setTag("destinations", destinationsNBT); nbt.setTag("destinations", destinationsNBT);
@ -105,12 +102,16 @@ public abstract class TileEntityRift extends TileEntity implements ITickable { /
nbt.setBoolean("preserveRotation", preserveRotation); nbt.setBoolean("preserveRotation", preserveRotation);
nbt.setFloat("yaw", yaw); nbt.setFloat("yaw", yaw);
nbt.setFloat("pitch", pitch); nbt.setFloat("pitch", pitch);
nbt.setBoolean("alwaysDelete", alwaysDelete);
nbt.setFloat("chaosWeight", chaosWeight);
return nbt; return nbt;
} }
public void setVirtualLocation(VirtualLocation virtualLocation) { public void setVirtualLocation(VirtualLocation virtualLocation) {
this.virtualLocation = virtualLocation; this.virtualLocation = virtualLocation;
updateAvailableLinks();
// TODO: update available link virtual locations
markDirty(); markDirty();
} }
@ -137,32 +138,9 @@ public abstract class TileEntityRift extends TileEntity implements ITickable { /
Iterator<WeightedRiftDestination> destinationIterator = destinations.iterator(); Iterator<WeightedRiftDestination> destinationIterator = destinations.iterator();
while (destinationIterator.hasNext()) { while (destinationIterator.hasNext()) {
RiftDestination dest = destinationIterator.next().getDestination(); RiftDestination dest = destinationIterator.next().getDestination();
if (dest.getType() == EnumType.GLOBAL) { if (destinationToLocation(dest).equals(location)) {
GlobalDestination globalDest = (GlobalDestination) dest;
if (globalDest.getDim() == location.getDimID()
&& globalDest.getX() == location.getPos().getX()
&& globalDest.getY() == location.getPos().getY()
&& globalDest.getZ() == location.getPos().getZ()) {
unregisterDest(dest);
destinationIterator.remove(); destinationIterator.remove();
}
if (location.getDimID() == WorldUtils.getDim(world)) {
if (dest.getType() == EnumType.LOCAL) {
LocalDestination localDest = (LocalDestination) dest;
if (localDest.getX() == location.getPos().getX()
&& localDest.getY() == location.getPos().getY()
&& localDest.getZ() == location.getPos().getZ()) {
unregisterDest(dest); unregisterDest(dest);
destinationIterator.remove();
}
} else if (dest.getType() == EnumType.RELATIVE) {
RelativeDestination relativeDest = (RelativeDestination) dest;
if (location.getPos().equals(pos.add(relativeDest.getXOffset(), relativeDest.getYOffset(), relativeDest.getZOffset()))) {
unregisterDest(dest);
destinationIterator.remove();
}
}
}
} }
} }
markDirty(); markDirty();
@ -172,7 +150,7 @@ public abstract class TileEntityRift extends TileEntity implements ITickable { /
for (WeightedRiftDestination wdest : destinations) { for (WeightedRiftDestination wdest : destinations) {
unregisterDest(wdest.getDestination()); unregisterDest(wdest.getDestination());
} }
destinations = new ArrayList<>(); destinations.clear();
markDirty(); markDirty();
} }
@ -181,32 +159,65 @@ public abstract class TileEntityRift extends TileEntity implements ITickable { /
addDestination(destination, 1, 0); addDestination(destination, 1, 0);
} }
public Location translateDestCoordinates(RiftDestination dest) { public Location destinationToLocation(RiftDestination dest) {
switch (dest.getType()) { // TODO: these need a superclass and a single translation method switch (dest.getType()) { // TODO: these need a superclass and a single translation method
case RELATIVE: case RELATIVE:
RelativeDestination relativeDest = (RelativeDestination) dest; RelativeDestination relativeDest = (RelativeDestination) dest;
return new Location(world, pos.add(relativeDest.getXOffset(), relativeDest.getYOffset(), relativeDest.getZOffset())); return new Location(world, pos.add(relativeDest.getOffset()));
case LOCAL: case LOCAL:
LocalDestination localDest = (LocalDestination) dest; LocalDestination localDest = (LocalDestination) dest;
return new Location(world, new BlockPos(localDest.getX(), localDest.getY(), localDest.getZ())); return new Location(world, localDest.getPos());
case GLOBAL: case GLOBAL:
GlobalDestination globalDest = (GlobalDestination) dest; GlobalDestination globalDest = (GlobalDestination) dest;
return new Location(globalDest.getDim(), new BlockPos(globalDest.getX(), globalDest.getY(), globalDest.getZ())); return globalDest.getLoc();
} }
return null; return null;
} }
public void registerDest(RiftDestination dest) { public void registerDest(RiftDestination dest) {
Location destLoc = translateDestCoordinates(dest); if (!isRegistered()) return;
Location destLoc = destinationToLocation(dest);
if (destLoc != null) RiftRegistry.addLink(new Location(world, pos), destLoc); if (destLoc != null) RiftRegistry.addLink(new Location(world, pos), destLoc);
if (dest.getType() == EnumType.AVAILABLE_LINK) {
AvailableLinkDestination linkDest = (AvailableLinkDestination) dest;
AvailableLinkInfo linkInfo = AvailableLinkInfo.builder()
.weight(isEntrance() ? linkDest.getEntranceLinkWeight() : linkDest.getFloatingRiftWeight())
.virtualLocation(virtualLocation)
.uuid(linkDest.getUuid())
.build();
RiftRegistry.addAvailableLink(new Location(world, pos), linkInfo);
}
}
public void updateAvailableLinks() {
if (!isRegistered()) return;
RiftRegistry.clearAvailableLinks(new Location(world, pos));
for (WeightedRiftDestination wdest : destinations) {
RiftDestination dest = wdest.getDestination();
if (dest.getType() == EnumType.AVAILABLE_LINK) {
AvailableLinkDestination linkDest = (AvailableLinkDestination) dest;
AvailableLinkInfo linkInfo = AvailableLinkInfo.builder()
.weight(isEntrance() ? linkDest.getEntranceLinkWeight() : linkDest.getFloatingRiftWeight())
.virtualLocation(virtualLocation)
.uuid(linkDest.getUuid())
.build();
RiftRegistry.addAvailableLink(new Location(world, pos), linkInfo);
}
}
} }
public void unregisterDest(RiftDestination dest) { public void unregisterDest(RiftDestination dest) {
Location destLoc = translateDestCoordinates(dest); if (!isRegistered()) return;
Location destLoc = destinationToLocation(dest);
if (destLoc != null) RiftRegistry.removeLink(new Location(world, pos), destLoc); if (destLoc != null) RiftRegistry.removeLink(new Location(world, pos), destLoc);
} }
public void register() { // registers or reregisters the rift public boolean isRegistered() {
return world != null && RiftRegistry.getRiftInfo(new Location(world, pos)) != null;
}
// Make sure virtualLocation != null before calling!
public void register() { // registers or reregisters the rift TODO: what if it's already registered?
Location loc = new Location(world, pos); Location loc = new Location(world, pos);
RiftRegistry.addRift(loc); RiftRegistry.addRift(loc);
for (WeightedRiftDestination weightedDest : destinations) { for (WeightedRiftDestination weightedDest : destinations) {
@ -215,17 +226,20 @@ public abstract class TileEntityRift extends TileEntity implements ITickable { /
} }
public void unregister() { public void unregister() {
if (!isRegistered()) return;
RiftRegistry.removeRift(new Location(world, pos)); RiftRegistry.removeRift(new Location(world, pos));
// TODO: inform pocket that entrance was destroyed (we'll probably need an isPrivate field on the pocket) // TODO: inform pocket that entrance was destroyed (we'll probably need an isPrivate field on the pocket)
} }
public void teleportTo(Entity entity) { // TODO: new velocity angle if !preserveRotation? public void teleportTo(Entity entity) { // TODO: new velocity angle if !preserveRotation?
entity.setWorld(world); float newYaw = entity.rotationYaw;
if (preserveRotation) { float newPitch = entity.rotationYaw;
entity.setPosition(pos.getX(), pos.getY(), pos.getZ()); if (!preserveRotation) {
} else { newYaw = yaw;
entity.setPositionAndRotation(pos.getX(), pos.getY(), pos.getZ(), yaw, pitch); newPitch = pitch;
} }
TeleporterDimDoors.instance().teleport(entity, new Location(world, pos));
entity.setPositionAndRotation(pos.getX(), pos.getY(), pos.getZ(), newYaw, newPitch);
int dim = WorldUtils.getDim(world); int dim = WorldUtils.getDim(world);
if (entity instanceof EntityPlayer && DimDoorDimensions.isPocketDimension(dim)) { // TODO if (entity instanceof EntityPlayer && DimDoorDimensions.isPocketDimension(dim)) { // TODO
@ -233,7 +247,7 @@ public abstract class TileEntityRift extends TileEntity implements ITickable { /
} }
} }
public boolean teleport(Entity entity) { public boolean teleport(Entity entity) { try { // TODO: return failiure message string rather than boolean
riftStateChanged = false; riftStateChanged = false;
if (destinations.size() == 0) return false; if (destinations.size() == 0) return false;
@ -244,37 +258,25 @@ public abstract class TileEntityRift extends TileEntity implements ITickable { /
WeightedRiftDestination weightedDestination = MathUtils.weightedRandom(weightMap); WeightedRiftDestination weightedDestination = MathUtils.weightedRandom(weightMap);
int group = weightedDestination.getGroup(); int group = weightedDestination.getGroup();
if(makeDestinationPermanent) { if(makeDestinationPermanent) {
List<WeightedRiftDestination> list = new ArrayList<>(); destinations.removeIf(wdest -> wdest.getGroup() != group);
for (WeightedRiftDestination otherDestination : destinations) {
if (otherDestination.getGroup() == group) {
list.add(otherDestination);
}
}
destinations = list;
markDirty(); markDirty();
} }
RiftDestination dest = weightedDestination.getDestination(); RiftDestination dest = weightedDestination.getDestination();
Location destLoc; Location destLoc;
GlobalDestination destHere = new GlobalDestination(WorldUtils.getDim(world), pos.getX(), pos.getY(), pos.getZ()); GlobalDestination destHere = new GlobalDestination(new Location(world, pos)); // TODO: local if possible
switch (dest.getType()) { switch (dest.getType()) {
case RELATIVE: case RELATIVE:
RelativeDestination relativeDest = (RelativeDestination) dest;
destLoc = new Location(world, pos.add(relativeDest.getXOffset(), relativeDest.getYOffset(), relativeDest.getZOffset()));
break;
case LOCAL: case LOCAL:
LocalDestination localDest = (LocalDestination) dest;
destLoc = new Location(world, localDest.getX(), localDest.getY(), localDest.getZ());
break;
case GLOBAL: case GLOBAL:
GlobalDestination globalDest = (GlobalDestination) dest; destLoc = destinationToLocation(dest);
destLoc = new Location(globalDest.getDim(), globalDest.getX(), globalDest.getY(), globalDest.getZ());
break; break;
case NEW_PUBLIC: case NEW_PUBLIC:
Pocket publicPocket = PocketGenerator.generatePublicPocket(virtualLocation.toBuilder().depth(-1).build()); // TODO: random transform Pocket publicPocket = PocketGenerator.generatePublicPocket(virtualLocation != null ? virtualLocation.toBuilder().depth(-1).build() : null); // TODO: random transform
publicPocket.selectEntrance(); publicPocket.setup();
publicPocket.linkPocketTo(destHere); publicPocket.linkPocketTo(destHere);
destLoc = publicPocket.getEntrance(); destLoc = publicPocket.getEntrance();
makeDestinationPermanent(weightedDestination, destLoc); if (destLoc != null) makeDestinationPermanent(weightedDestination, destLoc);
break; break;
case PRIVATE: // TODO: move logic to PrivatePocketTeleportDestination case PRIVATE: // TODO: move logic to PrivatePocketTeleportDestination
String uuid = null; String uuid = null;
@ -285,8 +287,8 @@ public abstract class TileEntityRift extends TileEntity implements ITickable { /
RiftRegistry privateRiftRegistry = RiftRegistry.getForDim(DimDoorDimensions.getPrivateDimID()); RiftRegistry privateRiftRegistry = RiftRegistry.getForDim(DimDoorDimensions.getPrivateDimID());
Pocket privatePocket = privatePocketRegistry.getPocket(privatePocketRegistry.getPrivatePocketID(uuid)); Pocket privatePocket = privatePocketRegistry.getPocket(privatePocketRegistry.getPrivatePocketID(uuid));
if (privatePocket == null) { // generate the private pocket and get its entrance if (privatePocket == null) { // generate the private pocket and get its entrance
privatePocket = PocketGenerator.generatePrivatePocket(virtualLocation.toBuilder().depth(-2).build()); // set to where the pocket was first created TODO: private pocket deletion privatePocket = PocketGenerator.generatePrivatePocket(virtualLocation != null ? virtualLocation.toBuilder().depth(-2).build() : null); // set to where the pocket was first created TODO: private pocket deletion
privatePocket.selectEntrance(); privatePocket.setup();
destLoc = privatePocket.getEntrance(); destLoc = privatePocket.getEntrance();
} else { } else {
destLoc = privateRiftRegistry.getPrivatePocketEntrance(uuid); // get the last used entrance destLoc = privateRiftRegistry.getPrivatePocketEntrance(uuid); // get the last used entrance
@ -314,26 +316,45 @@ public abstract class TileEntityRift extends TileEntity implements ITickable { /
break; break;
case LIMBO: // TODO: move logic to LimboTeleportDestination case LIMBO: // TODO: move logic to LimboTeleportDestination
throw new RuntimeException("Not yet implemented!"); // TODO: random coordinates based on VirtualLocation throw new RuntimeException("Not yet implemented!"); // TODO: random coordinates based on VirtualLocation
case RANDOM_RIFT_LINK: // TODO: chaos door case AVAILABLE_LINK: // TODO: chaos door
RandomRiftLinkDestination randomDest = (RandomRiftLinkDestination) dest; AvailableLinkDestination linkDest = (AvailableLinkDestination) dest;
Map<Location, Float> possibleDestWeightMap = new HashMap<>(); Map<AvailableLinkInfo, Float> possibleDestWeightMap = new HashMap<>();
for (AvailableLinkInfo link : RiftRegistry.getAvailableLinks()) { for (AvailableLinkInfo link : RiftRegistry.getAvailableLinks()) {
VirtualLocation otherVLoc = link.getVirtualLocation(); VirtualLocation otherVLoc = link.getVirtualLocation();
float weight2 = link.getWeight();
if (weight2 == 0) continue;
double depthDiff = Math.abs(virtualLocation.getDepth() - otherVLoc.getDepth()); double depthDiff = Math.abs(virtualLocation.getDepth() - otherVLoc.getDepth());
double distanceSq = new BlockPos(virtualLocation.getX(), virtualLocation.getY(), virtualLocation.getZ()) double distanceSq = new BlockPos(virtualLocation.getX(), virtualLocation.getY(), virtualLocation.getZ())
.distanceSq(new BlockPos(otherVLoc.getX(), otherVLoc.getY(), otherVLoc.getZ())); .distanceSq(new BlockPos(otherVLoc.getX(), otherVLoc.getY(), otherVLoc.getZ()));
float distanceExponent = randomDest.getDistancePenalization(); float distanceExponent = linkDest.getDistancePenalization();
float depthExponent = randomDest.getDepthPenalization(); float depthExponent = linkDest.getDepthPenalization();
float closenessExponent = randomDest.getClosenessPenalization(); float closenessExponent = linkDest.getClosenessPenalization();
float weight2 = link.getWeight();
float weight = (float) Math.abs(weight2/(Math.pow(depthDiff, depthExponent) * Math.pow(distanceSq, 0.5 * distanceExponent))); // TODO: fix formula float weight = (float) Math.abs(weight2/(Math.pow(depthDiff, depthExponent) * Math.pow(distanceSq, 0.5 * distanceExponent))); // TODO: fix formula
float currentWeight = possibleDestWeightMap.get(link.getLocation()); float currentWeight = possibleDestWeightMap.get(link);
possibleDestWeightMap.put(link.getLocation(), currentWeight + weight); possibleDestWeightMap.put(link, currentWeight + weight);
} }
destLoc = MathUtils.weightedRandom(possibleDestWeightMap); AvailableLinkInfo selectedLink = MathUtils.weightedRandom(possibleDestWeightMap);
if (!randomDest.isUnstable()) makeDestinationPermanent(weightedDestination, destLoc); destLoc = selectedLink.getLocation();
if (!linkDest.isUnstable()) makeDestinationPermanent(weightedDestination, destLoc);
TileEntityRift destRift = (TileEntityRift) destLoc.getWorld().getTileEntity(destLoc.getPos()); // Link the other rift back if necessary
ListIterator<WeightedRiftDestination> wdestIterator = destRift.destinations.listIterator();
WeightedRiftDestination selectedWDest = null;
while (wdestIterator.hasNext()) {
WeightedRiftDestination wdest = wdestIterator.next();
RiftDestination otherDest = wdest.getDestination();
if (otherDest.getType() == EnumType.AVAILABLE_LINK && ((AvailableLinkDestination) otherDest).getUuid() == selectedLink.getUuid()) {
selectedWDest = wdest;
wdestIterator.remove();
break;
}
}
AvailableLinkDestination selectedAvailableLinkDest = (AvailableLinkDestination) selectedWDest.getDestination();
if (!selectedAvailableLinkDest.isNoLinkBack()) {
destRift.makeDestinationPermanent(selectedWDest, new Location(world, pos));
}
break; break;
case POCKET_ENTRANCE: case POCKET_ENTRANCE:
case POCKET_EXIT: case POCKET_EXIT:
@ -344,26 +365,54 @@ public abstract class TileEntityRift extends TileEntity implements ITickable { /
default: default:
throw new RuntimeException("That rift type is not implemented in TileRiftEntity.teleport, this is a bug."); throw new RuntimeException("That rift type is not implemented in TileRiftEntity.teleport, this is a bug.");
} }
if (destLoc == null) {
if (entity instanceof EntityPlayer) DimDoors.chat((EntityPlayer) entity, "The destination was null. Either this is a bug in TileEntityRift.java, or the pocket does not have an entrance!");
return false;
}
TileEntity tileEntityAtLoc = destLoc.getWorld().getTileEntity(destLoc.getPos()); TileEntity tileEntityAtLoc = destLoc.getWorld().getTileEntity(destLoc.getPos());
if (!(tileEntityAtLoc instanceof TileEntityRift)) throw new RuntimeException("The rift referenced by this rift does not exist, this is a bug."); if (!(tileEntityAtLoc instanceof TileEntityRift)) throw new RuntimeException("The rift referenced by this rift does not exist, this is a bug.");
TileEntityRift destRift = (TileEntityRift) tileEntityAtLoc; TileEntityRift destRift = (TileEntityRift) tileEntityAtLoc;
destRift.teleportTo(entity); destRift.teleportTo(entity);
return true; return true;
} catch (Exception e) {
if (entity instanceof EntityPlayer) DimDoors.chat((EntityPlayer) entity, "There was an exception while teleporting!");
e.printStackTrace();
return false;
}
} }
private void makeDestinationPermanent(WeightedRiftDestination weightedDestination, Location destLoc) { private void makeDestinationPermanent(WeightedRiftDestination weightedDestination, Location destLoc) {
riftStateChanged = true; riftStateChanged = true;
GlobalDestination newDest = new GlobalDestination(destLoc.getDimID(), destLoc.getPos().getX(), destLoc.getPos().getY(), destLoc.getPos().getZ()); // TODO: RelativeDestination instead? RiftDestination newDest;
destinations.add(new WeightedRiftDestination(newDest, weightedDestination.getWeight(), weightedDestination.getGroup())); if (WorldUtils.getDim(world) == destLoc.getDimID()) {
newDest = new LocalDestination(destLoc.getPos()); // TODO: RelativeDestination instead?
} else {
newDest = new GlobalDestination(destLoc);
}
newDest = newDest.withOldDestination(weightedDestination.getDestination());
destinations.remove(weightedDestination); destinations.remove(weightedDestination);
destinations.add(new WeightedRiftDestination(newDest, weightedDestination.getWeight(), weightedDestination.getGroup()));
markDirty(); markDirty();
} }
public void destinationGone(Location loc) { public void destinationGone(Location loc) {
destinations.removeIf(weightedRiftDestination -> loc.equals(translateDestCoordinates(weightedRiftDestination.getDestination()))); ListIterator<WeightedRiftDestination> wdestIterator = destinations.listIterator();
while (wdestIterator.hasNext()) {
WeightedRiftDestination wdest = wdestIterator.next();
RiftDestination dest = wdest.getDestination();
if (loc.equals(destinationToLocation(dest))) {
wdestIterator.remove();
RiftDestination oldDest = dest.getOldDestination();
if (oldDest != null) {
wdestIterator.add(new WeightedRiftDestination(oldDest, wdest.getWeight(), wdest.getGroup()));
}
}
}
destinations.removeIf(weightedRiftDestination -> loc.equals(destinationToLocation(weightedRiftDestination.getDestination())));
} }
public void checkIfNeeded() { public void allSourcesGone() {
// TODO // TODO
} }
@ -382,6 +431,11 @@ public abstract class TileEntityRift extends TileEntity implements ITickable { /
deserializeNBT(tag); deserializeNBT(tag);
} }
public void notifyStateChanged() {
riftStateChanged = true;
markDirty();
}
@Override @Override
public SPacketUpdateTileEntity getUpdatePacket() { public SPacketUpdateTileEntity getUpdatePacket() {
return new SPacketUpdateTileEntity(getPos(), 1, serializeNBT()); return new SPacketUpdateTileEntity(getPos(), 1, serializeNBT());
@ -391,4 +445,6 @@ public abstract class TileEntityRift extends TileEntity implements ITickable { /
public void onDataPacket(NetworkManager net, SPacketUpdateTileEntity pkt) { public void onDataPacket(NetworkManager net, SPacketUpdateTileEntity pkt) {
deserializeNBT(pkt.getNbtCompound()); deserializeNBT(pkt.getNbtCompound());
} }
public abstract boolean isEntrance(); // TODO: replace with chooseWeight function
} }

View file

@ -6,22 +6,25 @@ import lombok.Getter;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import java.util.UUID;
@NoArgsConstructor @AllArgsConstructor @NoArgsConstructor @AllArgsConstructor
public class WeightedRiftDestination implements INBTStorable { public class
WeightedRiftDestination implements INBTStorable { // TODO: generics
@Getter private RiftDestination destination; @Getter private RiftDestination destination;
@Getter private float weight; @Getter private float weight;
@Getter private int group; @Getter private int group;
@Override @Override
public void readFromNBT(NBTTagCompound nbt) { public void readFromNBT(NBTTagCompound nbt) {
destination = RiftDestination.readDestinationNBT(nbt.getCompoundTag("destination")); destination = RiftDestination.readDestinationNBT(nbt); // TODO: subtag?
weight = nbt.getFloat("weight"); weight = nbt.getFloat("weight");
group = nbt.getInteger("group"); group = nbt.getInteger("group");
} }
@Override @Override
public NBTTagCompound writeToNBT(NBTTagCompound nbt) { public NBTTagCompound writeToNBT(NBTTagCompound nbt) {
nbt.setTag("destination", destination.writeToNBT(nbt)); nbt = destination.writeToNBT(nbt);
nbt.setFloat("weight", weight); nbt.setFloat("weight", weight);
nbt.setInteger("group", group); nbt.setInteger("group", group);
return nbt; return nbt;

View file

@ -45,15 +45,10 @@ public abstract class TileEntityEntranceRift extends TileEntityRift {
public void setPlaceRiftOnBreak(boolean placeRiftOnBreak) { this.placeRiftOnBreak = placeRiftOnBreak; markDirty(); } public void setPlaceRiftOnBreak(boolean placeRiftOnBreak) { this.placeRiftOnBreak = placeRiftOnBreak; markDirty(); }
@Override
public boolean isEntrance() {
return true;
}
@Override @Override
public boolean teleport(Entity entity) { public boolean teleport(Entity entity) {
boolean status = super.teleport(entity); boolean status = super.teleport(entity);
if (riftStateChanged /*|| TODO: get links from registry */) { if (riftStateChanged && !alwaysDelete) {
placeRiftOnBreak = true; placeRiftOnBreak = true;
markDirty(); markDirty();
} }
@ -76,4 +71,9 @@ public abstract class TileEntityEntranceRift extends TileEntityRift {
} }
return new RGBA(red, green, blue, 1); return new RGBA(red, green, blue, 1);
} }
@Override
public boolean isEntrance() {
return true;
}
} }

View file

@ -124,4 +124,9 @@ public class TileEntityFloatingRift extends TileEntityRift implements ITickable
return nbt; return nbt;
} }
@Override
public boolean isEntrance() {
return false;
}
} }

View file

@ -1,5 +1,7 @@
package com.zixiken.dimdoors.shared.tileentities; package com.zixiken.dimdoors.shared.tileentities;
import com.zixiken.dimdoors.shared.TeleporterDimDoors;
import com.zixiken.dimdoors.shared.util.Location;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumFacing;
@ -36,6 +38,4 @@ public class TileEntityVerticalEntranceRift extends TileEntityEntranceRift { //
BlockPos offsetPos = entity.getPosition().offset(orientation); BlockPos offsetPos = entity.getPosition().offset(orientation);
entity.setPositionAndRotation(offsetPos.getX(), offsetPos.getY(), offsetPos.getZ(), orientation.getHorizontalAngle(), 0); // TODO: let TileEntityRift handle rotation? entity.setPositionAndRotation(offsetPos.getX(), offsetPos.getY(), offsetPos.getZ(), orientation.getHorizontalAngle(), 0); // TODO: let TileEntityRift handle rotation?
} }
} }

View file

@ -4,6 +4,9 @@ import com.zixiken.dimdoors.DimDoors;
import com.zixiken.dimdoors.shared.SchematicHandler; import com.zixiken.dimdoors.shared.SchematicHandler;
import com.zixiken.dimdoors.shared.blocks.BlockFabric; import com.zixiken.dimdoors.shared.blocks.BlockFabric;
import com.zixiken.dimdoors.shared.blocks.ModBlocks; import com.zixiken.dimdoors.shared.blocks.ModBlocks;
import com.zixiken.dimdoors.shared.rifts.RiftDestination;
import com.zixiken.dimdoors.shared.rifts.TileEntityRift;
import com.zixiken.dimdoors.shared.rifts.WeightedRiftDestination;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.BlockDoor; import net.minecraft.block.BlockDoor;
import net.minecraft.block.state.IBlockState; import net.minecraft.block.state.IBlockState;
@ -18,14 +21,14 @@ import java.util.ArrayList;
* @author Robijnvogel * @author Robijnvogel
*/ */
public class DefaultSchematicGenerator { public class DefaultSchematicGenerator {
public static void tempGenerateDefaultSchematics() { public static void generateDefaultSchematics() {
for (int pocketSize = 0; pocketSize < 8; pocketSize++) { for (int pocketSize = 0; pocketSize < 8; pocketSize++) {
generateDefaultSchematic("defaultPublic", pocketSize, ModBlocks.FABRIC.getDefaultState().withProperty(BlockFabric.TYPE, BlockFabric.EnumType.REALITY), ModBlocks.DIMENSIONAL_DOOR); generateDefaultSchematic("defaultPublic", pocketSize, ModBlocks.FABRIC.getDefaultState().withProperty(BlockFabric.TYPE, BlockFabric.EnumType.REALITY), ModBlocks.DIMENSIONAL_DOOR, RiftDestination.PocketExitDestination.builder().build());
generateDefaultSchematic("defaultPrivate", pocketSize, ModBlocks.FABRIC.getDefaultState().withProperty(BlockFabric.TYPE, BlockFabric.EnumType.ALTERED), ModBlocks.PERSONAL_DIMENSIONAL_DOOR); generateDefaultSchematic("defaultPrivate", pocketSize, ModBlocks.FABRIC.getDefaultState().withProperty(BlockFabric.TYPE, BlockFabric.EnumType.ALTERED), ModBlocks.PERSONAL_DIMENSIONAL_DOOR, RiftDestination.PrivatePocketExitDestination.builder().build());
} }
} }
private static void generateDefaultSchematic(String baseName, int pocketSize, IBlockState innerWallBlockState, Block doorBlock) { private static void generateDefaultSchematic(String baseName, int pocketSize, IBlockState innerWallBlockState, Block doorBlock, RiftDestination exitDest) {
int maxbound = (pocketSize + 1) * 16 - 1; int maxbound = (pocketSize + 1) * 16 - 1;
Schematic schematic = new Schematic(); Schematic schematic = new Schematic();
@ -74,11 +77,14 @@ public class DefaultSchematicGenerator {
} }
schematic.tileEntities = new ArrayList<>(); schematic.tileEntities = new ArrayList<>();
// TODO: DimDoors.proxy.getDefWorld() prevents running this before world load TileEntityRift rift = (TileEntityRift) doorBlock.createTileEntity(null, doorBlock.getDefaultState());
TileEntity tileEntity = doorBlock.createTileEntity(DimDoors.proxy.getWorldServer(0), doorBlock.getDefaultState()); rift.setSingleDestination(RiftDestination.PocketEntranceDestination.builder()
NBTTagCompound tileNBT = tileEntity.serializeNBT(); .ifDestinations(MathUtils.listFrom(new WeightedRiftDestination(exitDest, 1, 0)))
.build());
NBTTagCompound tileNBT = rift.serializeNBT();
tileNBT.setInteger("x", (maxbound - 1) / 2); tileNBT.setInteger("x", (maxbound - 1) / 2);
tileNBT.setInteger("y", 6); tileNBT.setInteger("y", 5);
tileNBT.setInteger("z", 4); tileNBT.setInteger("z", 4);
schematic.tileEntities.add(tileNBT); schematic.tileEntities.add(tileNBT);

View file

@ -1,5 +1,7 @@
package com.zixiken.dimdoors.shared.util; package com.zixiken.dimdoors.shared.util;
import java.util.ArrayList;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Random; import java.util.Random;
@ -73,4 +75,10 @@ public class MathUtils {
} }
return null; return null;
} }
public static <T> List<T> listFrom(T element) {
List<T> list = new ArrayList<>();
list.add(element);
return list;
}
} }

View file

@ -1,6 +1,7 @@
package com.zixiken.dimdoors.shared.util; package com.zixiken.dimdoors.shared.util;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.math.Vec3i;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@ -20,4 +21,16 @@ public class NBTUtils {
} }
return tagCompound; return tagCompound;
} }
public static Vec3i readVec3i(NBTTagCompound nbt) {
return new Vec3i(nbt.getInteger("x"), nbt.getInteger("y"), nbt.getInteger("z"));
}
public static NBTTagCompound writeVec3i(Vec3i vec) {
NBTTagCompound nbt = new NBTTagCompound();
nbt.setInteger("x", vec.getX());
nbt.setInteger("y", vec.getY());
nbt.setInteger("z", vec.getZ());
return nbt;
}
} }

View file

@ -1,11 +1,17 @@
package com.zixiken.dimdoors.shared.util; package com.zixiken.dimdoors.shared.util;
import com.zixiken.dimdoors.DimDoors;
import com.zixiken.dimdoors.shared.world.DimDoorDimensions;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.common.DimensionManager; import net.minecraftforge.common.DimensionManager;
public class WorldUtils { public class WorldUtils {
public static World getWorld(int dim) { public static World getWorld(int dim) {
return DimensionManager.getWorld(dim); World world = DimDoors.proxy.getWorldServer(dim);
if (world == null) {
throw new RuntimeException("Something went wrong!");
}
return world;
} }
public static int getDim(World world) { public static int getDim(World world) {

View file

@ -12,7 +12,7 @@
"mcversion": "1.12.2", "mcversion": "1.12.2",
"url": "https://github.com/DimensionalDevelopment/DimDoors", "url": "https://github.com/DimensionalDevelopment/DimDoors",
"updateUrl": "", "updateUrl": "",
"authorList": [ "StevenRS11", "SenseiKiwi", "Zixiken", "WaterPicker", "Robijnvogel" ], "authorList": [ "StevenRS11", "SenseiKiwi", "Zixiken", "WaterPicker", "Robijnvogel", "ZombieHDGaming", "Runemoro" ],
"parent":"", "parent":"",
"screenshots": [], "screenshots": [],
"dependencies": [ "forge" ] "dependencies": [ "forge" ]