Registry rewrite part 1
This commit is contained in:
parent
79cc174daf
commit
7ac9865cd3
54 changed files with 902 additions and 2019 deletions
src/main/java/com/zixiken/dimdoors
DimDoors.java
client
shared
DDConfig.javaDDEventHandler.javaDDProxyCommon.javaDDSavedData.javaPocket.javaPocketRegistry.javaPocketSavedData.javaRayTraceHelper.javaRiftRegistry.javaRiftSavedData.javaSchematicHandler.java
blocks
BlockDimDoorBase.javaBlockDimDoorGold.javaBlockDimDoorPersonal.javaBlockDimDoorUnstable.javaBlockDimDoorWarp.javaBlockDimTrapdoor.javaBlockRift.javaModBlocks.java
commands
items
pockets
EnumPocketType.javaGridUtils.javaPocket.javaPocketGenerator.javaPocketRegistry.javaPocketTemplate.java
tileentities
DDTileEntityBase.javaTileEntityDimDoor.javaTileEntityDimDoorGold.javaTileEntityDimDoorPersonal.javaTileEntityDimDoorUnstable.javaTileEntityDimDoorWarp.javaTileEntityEntranceRift.javaTileEntityFloatingRift.javaTileEntityHorizontalEntranceRift.javaTileEntityRift.javaTileEntityTransTrapdoor.javaTileEntityVerticalEntranceRift.java
util
world
|
@ -4,11 +4,7 @@ import com.zixiken.dimdoors.shared.commands.PocketCommand;
|
|||
import com.zixiken.dimdoors.shared.commands.TeleportCommand;
|
||||
import com.zixiken.dimdoors.shared.DDConfig;
|
||||
import com.zixiken.dimdoors.shared.DDProxyCommon;
|
||||
import com.zixiken.dimdoors.shared.PocketRegistry;
|
||||
import com.zixiken.dimdoors.shared.items.ModItems;
|
||||
import com.zixiken.dimdoors.shared.RiftRegistry;
|
||||
import com.zixiken.dimdoors.shared.SchematicHandler;
|
||||
import com.zixiken.dimdoors.shared.util.DefaultSchematicGenerator;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
@ -59,9 +55,7 @@ public class DimDoors {
|
|||
@Mod.EventHandler
|
||||
public void serverLoad(FMLServerStartingEvent event) {
|
||||
registerCommands(event);
|
||||
RiftRegistry.INSTANCE.reset();
|
||||
PocketRegistry.INSTANCE.reset();
|
||||
|
||||
// RiftRegistry.INSTANCE.reset();
|
||||
//DefaultSchematicGenerator.tempGenerateDefaultSchematics();
|
||||
}
|
||||
|
||||
|
|
|
@ -5,9 +5,9 @@ import com.zixiken.dimdoors.shared.DDProxyCommon;
|
|||
import com.zixiken.dimdoors.shared.ModelManager;
|
||||
import com.zixiken.dimdoors.shared.entities.MobMonolith;
|
||||
import com.zixiken.dimdoors.shared.entities.RenderMobObelisk;
|
||||
import com.zixiken.dimdoors.shared.tileentities.TileEntityDimDoor;
|
||||
import com.zixiken.dimdoors.shared.tileentities.TileEntityRift;
|
||||
import com.zixiken.dimdoors.shared.tileentities.TileEntityTransTrapdoor;
|
||||
import com.zixiken.dimdoors.shared.tileentities.TileEntityVerticalEntranceRift;
|
||||
import com.zixiken.dimdoors.shared.tileentities.TileEntityFloatingRift;
|
||||
import com.zixiken.dimdoors.shared.tileentities.TileEntityHorizontalEntranceRift;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.world.WorldServer;
|
||||
|
@ -37,9 +37,9 @@ public class DDProxyClient extends DDProxyCommon {
|
|||
}
|
||||
|
||||
public void registerRenderers() {
|
||||
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityDimDoor.class, new RenderDimDoor());
|
||||
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityTransTrapdoor.class, new RenderTransTrapdoor());
|
||||
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityRift.class, new RenderRift());
|
||||
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityVerticalEntranceRift.class, new RenderDimDoor());
|
||||
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityHorizontalEntranceRift.class, new RenderTransTrapdoor());
|
||||
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityFloatingRift.class, new RenderRift());
|
||||
RenderingRegistry.registerEntityRenderingHandler(MobMonolith.class, manager -> new RenderMobObelisk(manager, 0.5f));
|
||||
}
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ import java.util.Random;
|
|||
|
||||
import com.zixiken.dimdoors.DimDoors;
|
||||
import com.zixiken.dimdoors.shared.blocks.BlockDimDoorBase;
|
||||
import com.zixiken.dimdoors.shared.tileentities.TileEntityDimDoor;
|
||||
import com.zixiken.dimdoors.shared.tileentities.TileEntityVerticalEntranceRift;
|
||||
import net.minecraft.client.renderer.*;
|
||||
import net.minecraft.client.renderer.vertex.*;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
|
@ -19,7 +19,7 @@ import net.minecraft.util.ResourceLocation;
|
|||
|
||||
import static org.lwjgl.opengl.GL11.*;
|
||||
|
||||
public class RenderDimDoor extends TileEntitySpecialRenderer<TileEntityDimDoor> {
|
||||
public class RenderDimDoor extends TileEntitySpecialRenderer<TileEntityVerticalEntranceRift> {
|
||||
|
||||
private FloatBuffer buffer = GLAllocation.createDirectFloatBuffer(16);
|
||||
private ResourceLocation warpPath = new ResourceLocation(DimDoors.MODID + ":textures/other/warp.png");
|
||||
|
@ -29,7 +29,7 @@ public class RenderDimDoor extends TileEntitySpecialRenderer<TileEntityDimDoor>
|
|||
/**
|
||||
* Renders the dimdoor.
|
||||
*/
|
||||
public void renderDimDoorTileEntity(TileEntityDimDoor tile, double x, double y, double z) {
|
||||
public void renderDimDoorTileEntity(TileEntityVerticalEntranceRift tile, double x, double y, double z) {
|
||||
GL11.glDisable(GL11.GL_LIGHTING);
|
||||
Random rand = new Random(31100L);
|
||||
|
||||
|
@ -115,7 +115,7 @@ public class RenderDimDoor extends TileEntitySpecialRenderer<TileEntityDimDoor>
|
|||
BufferBuilder worldRenderer = tessellator.getBuffer();
|
||||
worldRenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION);
|
||||
|
||||
float[] color = tile.getRenderColor(rand);
|
||||
float[] color = tile.getEntranceRenderColor(rand);
|
||||
GlStateManager.color(color[0] * var17, color[1] * var17, color[2] * var17, color[3]);
|
||||
|
||||
switch (orientation) {
|
||||
|
@ -190,7 +190,7 @@ public class RenderDimDoor extends TileEntitySpecialRenderer<TileEntityDimDoor>
|
|||
return buffer;
|
||||
}
|
||||
|
||||
private void renderKeyHole(TileEntityDimDoor tile, double x, double y, double z, int i) {
|
||||
private void renderKeyHole(TileEntityVerticalEntranceRift tile, double x, double y, double z, int i) {
|
||||
EnumFacing rotation = EnumFacing.getHorizontal((tile.orientation.getHorizontalIndex() + 3) % 4);
|
||||
|
||||
GlStateManager.pushMatrix();
|
||||
|
@ -255,7 +255,7 @@ public class RenderDimDoor extends TileEntitySpecialRenderer<TileEntityDimDoor>
|
|||
}
|
||||
|
||||
@Override
|
||||
public void render(TileEntityDimDoor te, double x, double y, double z, float partialTicks, int destroyStage, float alpha) {
|
||||
public void render(TileEntityVerticalEntranceRift te, double x, double y, double z, float partialTicks, int destroyStage, float alpha) {
|
||||
World world = te.getWorld();
|
||||
BlockPos pos = te.getPos();
|
||||
((BlockDimDoorBase) world.getBlockState(pos).getBlock()).updateAttachedTile(world, pos);
|
||||
|
|
|
@ -4,7 +4,7 @@ import com.flowpowered.math.TrigMath;
|
|||
import com.flowpowered.math.vector.Vector3f;
|
||||
import com.flowpowered.math.vector.Vector4f;
|
||||
import com.zixiken.dimdoors.DimDoors;
|
||||
import com.zixiken.dimdoors.shared.tileentities.TileEntityRift;
|
||||
import com.zixiken.dimdoors.shared.tileentities.TileEntityFloatingRift;
|
||||
import net.minecraft.client.renderer.BufferBuilder;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
|
@ -14,7 +14,7 @@ import net.minecraft.util.ResourceLocation;
|
|||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
|
||||
public class RenderRift extends TileEntitySpecialRenderer<TileEntityRift> {
|
||||
public class RenderRift extends TileEntitySpecialRenderer<TileEntityFloatingRift> {
|
||||
private static ResourceLocation tesseract_path = new ResourceLocation(DimDoors.MODID + ":textures/other/tesseract.png");
|
||||
|
||||
private static Vector4f[] tesseract = {
|
||||
|
@ -145,7 +145,7 @@ public class RenderRift extends TileEntitySpecialRenderer<TileEntityRift> {
|
|||
* Renders the rift.
|
||||
*/
|
||||
@Override
|
||||
public void render(TileEntityRift te, double x, double y, double z, float partialTicks, int destroyStage, float alpha) {
|
||||
public void render(TileEntityFloatingRift te, double x, double y, double z, float partialTicks, int destroyStage, float alpha) {
|
||||
double radian = update(partialTicks) * TrigMath.DEG_TO_RAD;
|
||||
|
||||
GlStateManager.enableLighting();
|
||||
|
|
|
@ -4,8 +4,8 @@ import java.nio.FloatBuffer;
|
|||
import java.util.Random;
|
||||
|
||||
import com.zixiken.dimdoors.DimDoors;
|
||||
import com.zixiken.dimdoors.shared.blocks.BlockTransTrapdoor;
|
||||
import com.zixiken.dimdoors.shared.tileentities.TileEntityTransTrapdoor;
|
||||
import com.zixiken.dimdoors.shared.blocks.BlockDimTrapdoor;
|
||||
import com.zixiken.dimdoors.shared.tileentities.TileEntityHorizontalEntranceRift;
|
||||
import net.minecraft.block.BlockTrapDoor;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.Minecraft;
|
||||
|
@ -22,7 +22,7 @@ import net.minecraftforge.fml.relauncher.SideOnly;
|
|||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class RenderTransTrapdoor extends TileEntitySpecialRenderer<TileEntityTransTrapdoor> {
|
||||
public class RenderTransTrapdoor extends TileEntitySpecialRenderer<TileEntityHorizontalEntranceRift> {
|
||||
|
||||
private FloatBuffer buffer = GLAllocation.createDirectFloatBuffer(16);
|
||||
private ResourceLocation riftPath = new ResourceLocation(DimDoors.MODID + ":textures/other/rift.png");
|
||||
|
@ -31,7 +31,7 @@ public class RenderTransTrapdoor extends TileEntitySpecialRenderer<TileEntityTra
|
|||
/**
|
||||
* Renders the dimdoor.
|
||||
*/
|
||||
public void renderTransTrapdoorTileEntity(TileEntityTransTrapdoor tile, double x, double y, double z, float partialTicks, float alpha) {
|
||||
public void renderTransTrapdoorTileEntity(TileEntityHorizontalEntranceRift tile, double x, double y, double z, float partialTicks, float alpha) {
|
||||
GlStateManager.disableLighting();
|
||||
Random random = new Random(31100L);
|
||||
IBlockState state = tile.getWorld().getBlockState(tile.getPos());
|
||||
|
@ -103,7 +103,7 @@ public class RenderTransTrapdoor extends TileEntitySpecialRenderer<TileEntityTra
|
|||
BufferBuilder worldrenderer = tessellator.getBuffer();
|
||||
worldrenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_COLOR);
|
||||
|
||||
if (BlockTransTrapdoor.isTrapdoorSetLow(state)) {
|
||||
if (BlockDimTrapdoor.isTrapdoorSetLow(state)) {
|
||||
if (state.getValue(BlockTrapDoor.OPEN)) {
|
||||
worldrenderer.pos(x, y + 0.2, z).color(r, g, b, 1.0F).endVertex();
|
||||
worldrenderer.pos(x, y + 0.2, z + 1).color(r, g, b, 1.0F).endVertex();
|
||||
|
@ -150,7 +150,7 @@ public class RenderTransTrapdoor extends TileEntitySpecialRenderer<TileEntityTra
|
|||
}
|
||||
|
||||
@Override
|
||||
public void render(TileEntityTransTrapdoor te, double x, double y, double z, float partialTicks, int destroyStage, float alpha) {
|
||||
public void render(TileEntityHorizontalEntranceRift te, double x, double y, double z, float partialTicks, int destroyStage, float alpha) {
|
||||
renderTransTrapdoorTileEntity(te, x, y, z, partialTicks, alpha);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,15 +1,7 @@
|
|||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package com.zixiken.dimdoors.shared;
|
||||
|
||||
import com.zixiken.dimdoors.DimDoors;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import lombok.Getter;
|
||||
import net.minecraftforge.common.config.Configuration;
|
||||
|
@ -23,7 +15,7 @@ import scala.actors.threadpool.Arrays;
|
|||
*/
|
||||
public class DDConfig {
|
||||
|
||||
public static final boolean HAVE_CONFIG_DEFAULTS_BEEN_CHECKED_FOR_CORRECTNESS = false; //@todo check this at each non-alpha release. This field does not have a use in the mod itself, but should ensure that the developers of this mod, don't forget to reset the config defaults to the right values before releasing a non-alpha release
|
||||
public static final boolean HAVE_CONFIG_DEFAULTS_BEEN_CHECKED_FOR_CORRECTNESS = false; //@todo check this at each non-alpha release. This field does not have a use in the mod itself, but should ensure that the developers of this mod, don't forget to resetToConfigDefaults the config defaults to the right values before releasing a non-alpha release
|
||||
|
||||
public static File configurationFolder;
|
||||
@Getter private static int pocketGridSize = 32;
|
||||
|
@ -31,10 +23,6 @@ public class DDConfig {
|
|||
@Getter private static int privatePocketSize = 3;
|
||||
@Getter private static int publicPocketSize = 2;
|
||||
@Getter private static int baseDimID = 684;
|
||||
private static String[] dungeonSchematicNames = {
|
||||
"default_dungeon_normal",
|
||||
"default_dungeon_nether"
|
||||
}; //@todo set default dungeon names
|
||||
@Getter private static int maxDungeonDepth = 100;
|
||||
@Getter private static int owCoordinateOffsetBase = 64;
|
||||
@Getter private static double owCoordinateOffsetPower = 1.3;
|
||||
|
@ -66,16 +54,13 @@ public class DDConfig {
|
|||
config.load();
|
||||
|
||||
// Setup general
|
||||
config.addCustomCategoryComment("aa_general", "General configuration options.");
|
||||
Property prop = config.get("aa_general", "baseDimID", baseDimID,
|
||||
config.addCustomCategoryComment("general", "General configuration options.");
|
||||
Property prop = config.get("general", "baseDimID", baseDimID,
|
||||
"Dimension ID of the first Dimensional Doors dimension. Other dimensions will use consecutive IDs. NB: If you change this after creating a world, you may lose these dimensions. [default: 684]");
|
||||
baseDimID = prop.getInt(baseDimID);
|
||||
|
||||
//Dungeons
|
||||
config.addCustomCategoryComment("dungeons", "The following options will determine the depths, wandering offsets and contents of Dungeon Pockets.");
|
||||
prop = config.get("dungeons", "dungeonSchematicNames", dungeonSchematicNames,
|
||||
"List of names of Dungeon Pockets' jSon- file names excluding extension. Custom json and schematic files can be dropped in the corresponding config folders.");
|
||||
dungeonSchematicNames = prop.getStringList();
|
||||
|
||||
maxDungeonDepth = setConfigIntWithMaxAndMin(config, "dungeons", "maxDungeonDepth", maxDungeonDepth,
|
||||
"Sets the maximum (deepest) depth that a dungeon pocket can be at. [min: 1, max: 32, default: 8]", 1, 32);
|
||||
|
|
|
@ -1,11 +1,7 @@
|
|||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package com.zixiken.dimdoors.shared;
|
||||
|
||||
import com.zixiken.dimdoors.DimDoors;
|
||||
import com.zixiken.dimdoors.shared.pockets.PocketRegistry;
|
||||
import com.zixiken.dimdoors.shared.util.Location;
|
||||
import com.zixiken.dimdoors.shared.world.DimDoorDimensions;
|
||||
import net.minecraft.entity.Entity;
|
||||
|
@ -44,7 +40,8 @@ public class DDEventHandler {
|
|||
if (entity instanceof EntityPlayerMP) {
|
||||
EntityPlayerMP player = (EntityPlayerMP) entity;
|
||||
World world = entity.world;
|
||||
if (!world.isRemote && !player.isDead && !PocketRegistry.INSTANCE.isPlayerAllowedToBeHere(player, Location.getLocation(player))) {
|
||||
int dimID = world.provider.getDimension();
|
||||
if (!world.isRemote && !player.isDead && DimDoorDimensions.isPocketDimensionID(dimID) && !PocketRegistry.getForDim(dimID).isPlayerAllowedToBeHere(player, Location.getLocation(player))) {
|
||||
// TODO: Avoid players even getting here by making a maximum build distance that's smaller than the pocket size
|
||||
// TODO: This doesn't really work yet.
|
||||
// DimDoors.chat(player, "You travelled too far into the void and have been sent to Limbo.");
|
||||
|
|
|
@ -30,13 +30,9 @@ public abstract class DDProxyCommon implements IDDProxy {
|
|||
|
||||
DimDoorDimensions.init();
|
||||
|
||||
GameRegistry.registerTileEntity(TileEntityDimDoor.class, "TileEntityDimDoor"); // TODO: use new registry
|
||||
GameRegistry.registerTileEntity(TileEntityRift.class, "TileEntityRift");
|
||||
GameRegistry.registerTileEntity(TileEntityTransTrapdoor.class, "TileEntityTransTrapdoor");
|
||||
GameRegistry.registerTileEntity(TileEntityDimDoorGold.class, "TileEntityDimDoorGold");
|
||||
GameRegistry.registerTileEntity(TileEntityDimDoorPersonal.class, "TileEntityDimDoorPersonal");
|
||||
GameRegistry.registerTileEntity(TileEntityDimDoorUnstable.class, "TileEntityDimDoorUnstable");
|
||||
GameRegistry.registerTileEntity(TileEntityDimDoorWarp.class, "TileEntityDimDoorWarp");
|
||||
GameRegistry.registerTileEntity(TileEntityVerticalEntranceRift.class, "TileEntityVerticalEntranceRift"); // TODO: use new registry
|
||||
GameRegistry.registerTileEntity(TileEntityFloatingRift.class, "TileEntityFloatingRift");
|
||||
GameRegistry.registerTileEntity(TileEntityHorizontalEntranceRift.class, "TileEntityHorizontalEntranceRift");
|
||||
|
||||
EntityRegistry.registerModEntity(new ResourceLocation(DimDoors.MODID, "mob_monolith"), MobMonolith.class, "monolith", 0, DimDoors.instance, 70, 1, true);
|
||||
EntityRegistry.registerEgg(new ResourceLocation(DimDoors.MODID, "mob_monolith"), 0, 0xffffff);
|
||||
|
@ -49,8 +45,8 @@ public abstract class DDProxyCommon implements IDDProxy {
|
|||
|
||||
public void updateDoorTE(BlockDimDoorBase door, World world, BlockPos pos) {
|
||||
TileEntity tile = world.getTileEntity(pos);
|
||||
if (tile instanceof TileEntityDimDoor) {
|
||||
TileEntityDimDoor dimTile = (TileEntityDimDoor) tile;
|
||||
if (tile instanceof TileEntityVerticalEntranceRift) {
|
||||
TileEntityVerticalEntranceRift dimTile = (TileEntityVerticalEntranceRift) tile;
|
||||
IBlockState state = world.getBlockState(pos.down());
|
||||
dimTile.orientation = state.getBlock() instanceof BlockDimDoorBase
|
||||
? state.getValue(BlockDoor.FACING).getOpposite()
|
||||
|
|
|
@ -1,26 +0,0 @@
|
|||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package com.zixiken.dimdoors.shared;
|
||||
|
||||
import java.io.File;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.storage.WorldSavedData;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Robijnvogel
|
||||
*/
|
||||
abstract class DDSavedData extends WorldSavedData {
|
||||
|
||||
public DDSavedData(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
public File getSaveLocation(World world) {
|
||||
File saveDir = world.getSaveHandler().getWorldDirectory();
|
||||
return new File(saveDir, "dimdoors/");
|
||||
}
|
||||
}
|
|
@ -1,205 +0,0 @@
|
|||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package com.zixiken.dimdoors.shared;
|
||||
|
||||
import com.zixiken.dimdoors.DimDoors;
|
||||
import com.zixiken.dimdoors.shared.tileentities.DDTileEntityBase;
|
||||
import com.zixiken.dimdoors.shared.tileentities.TileEntityDimDoorWarp;
|
||||
import com.zixiken.dimdoors.shared.util.Location;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.nbt.NBTBase;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagInt;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.nbt.NBTTagString;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.WorldServer;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Robijnvogel
|
||||
*/
|
||||
public class Pocket {
|
||||
|
||||
private int id; //this gets reset every server-load
|
||||
private final int size; //in chunks 0 -> 1*1 chunk, 1 -> 2*2 chunks
|
||||
private final int depth;
|
||||
private final EnumPocketType typeID; // dungeon, pocket, or personal pocket
|
||||
private final int x; //pocket-relative 0 coordinate, should be at x * PocketRegistry.INSTANCE.gridSize * 16
|
||||
private final int z; //pocket-relative 0 coordinate, should be at z * PocketRegistry.INSTANCE.gridSize * 16
|
||||
private final List<String> playerUUIDs;
|
||||
private final List<Integer> riftIDs; //@todo these aren't being used after the entrance door has been paired, I believe
|
||||
private final Location depthZeroLocation;
|
||||
//when adding any new variables, don't forget to add them to the write and load functions
|
||||
|
||||
public Pocket(int size, int depth, EnumPocketType typeID, int x, int z, List<Integer> riftIDs, Location depthZeroLocation) {
|
||||
this.size = size;
|
||||
this.depth = depth;
|
||||
this.typeID = typeID;
|
||||
this.x = x;
|
||||
this.z = z;
|
||||
this.riftIDs = riftIDs;
|
||||
this.depthZeroLocation = depthZeroLocation;
|
||||
playerUUIDs = new ArrayList<>();
|
||||
}
|
||||
|
||||
public int getID() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public int getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
public int getZ() {
|
||||
return z;
|
||||
}
|
||||
|
||||
public int getEntranceDoorID() {
|
||||
if (riftIDs.isEmpty()) {
|
||||
return -1;
|
||||
} else if (riftIDs.size() == 1) {
|
||||
return riftIDs.get(0);
|
||||
} else {
|
||||
int index = findWarpDoorIndex(riftIDs);
|
||||
if (index == -1) {
|
||||
Random random = new Random();
|
||||
index = random.nextInt(riftIDs.size());
|
||||
}
|
||||
return riftIDs.get(index);
|
||||
}
|
||||
}
|
||||
|
||||
public void setID(int newID) {
|
||||
id = newID;
|
||||
|
||||
//propagate this id to the rifts in this pocket
|
||||
for (int riftID : riftIDs) {
|
||||
Location riftLocation = RiftRegistry.INSTANCE.getRiftLocation(riftID);
|
||||
WorldServer worldServer = DimDoors.proxy.getWorldServer(riftLocation.getDimensionID());
|
||||
if (!worldServer.isRemote) {
|
||||
DDTileEntityBase rift = (DDTileEntityBase) riftLocation.getTileEntity();
|
||||
rift.setPocket(id, typeID); //set the rift's pocket id to this pocket's pocket id;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static Pocket readFromNBT(NBTTagCompound pocketNBT) {
|
||||
int size = pocketNBT.getInteger("size");
|
||||
int depth = pocketNBT.getInteger("depth");
|
||||
EnumPocketType typeID = EnumPocketType.getFromInt(pocketNBT.getInteger("typeID"));
|
||||
int x = pocketNBT.getInteger("x");
|
||||
int z = pocketNBT.getInteger("z");
|
||||
List<Integer> riftIDs = new ArrayList<>();
|
||||
NBTTagList doorsTagList = (NBTTagList) pocketNBT.getTag("doorIDs");
|
||||
for (int i = 0; i < doorsTagList.tagCount(); i++) {
|
||||
int doorID = doorsTagList.getIntAt(i);
|
||||
riftIDs.add(doorID);
|
||||
}
|
||||
Location depthZeroLocation = Location.readFromNBT(pocketNBT.getCompoundTag("depthZeroLocation"));
|
||||
|
||||
Pocket pocket = new Pocket(size, depth, typeID, x, z, riftIDs, depthZeroLocation);
|
||||
|
||||
pocket.setID(pocketNBT.getInteger("id")); //basically re-register the pocket
|
||||
NBTTagList playersTagList = (NBTTagList) pocketNBT.getTag("playerUUIDs");
|
||||
for (int i = 0; i < playersTagList.tagCount(); i++) {
|
||||
String playerUUID = playersTagList.getStringTagAt(i);
|
||||
pocket.playerUUIDs.add(playerUUID);
|
||||
}
|
||||
return pocket;
|
||||
}
|
||||
|
||||
static NBTBase writeToNBT(Pocket pocket) {
|
||||
NBTTagCompound pocketNBT = new NBTTagCompound();
|
||||
pocketNBT.setInteger("id", pocket.id);
|
||||
pocketNBT.setInteger("size", pocket.size);
|
||||
pocketNBT.setInteger("depth", pocket.depth);
|
||||
pocketNBT.setInteger("typeID", pocket.typeID.getIntValue());
|
||||
pocketNBT.setInteger("x", pocket.x);
|
||||
pocketNBT.setInteger("z", pocket.z);
|
||||
|
||||
NBTTagList doorsTagList = new NBTTagList();
|
||||
for (int i = 0; i < pocket.riftIDs.size(); i++) {
|
||||
NBTTagInt doorTag = new NBTTagInt(pocket.riftIDs.get(i));
|
||||
doorsTagList.appendTag(doorTag);
|
||||
}
|
||||
pocketNBT.setTag("doorIDs", doorsTagList);
|
||||
|
||||
NBTTagCompound depthZeroLocCompound = Location.writeToNBT(pocket.depthZeroLocation);
|
||||
pocketNBT.setTag("depthZeroLocation", depthZeroLocCompound);
|
||||
|
||||
NBTTagList playersTagList = new NBTTagList();
|
||||
for (int i = 0; i < pocket.playerUUIDs.size(); i++) {
|
||||
NBTTagString playerTag = new NBTTagString(pocket.playerUUIDs.get(i));
|
||||
playersTagList.appendTag(playerTag);
|
||||
}
|
||||
pocketNBT.setTag("playerUUIDs", playersTagList);
|
||||
|
||||
return pocketNBT;
|
||||
}
|
||||
|
||||
private static int findWarpDoorIndex(List<Integer> riftIDs) { //used to find the entrance door to this pocket
|
||||
int index = -1;
|
||||
for (int i = 0; i < riftIDs.size(); i++) {
|
||||
int riftID = riftIDs.get(i);
|
||||
//DimDoors.log(Pocket.class, "findWarpDoorIndex: i = " + i + " riftID = " + riftID); //for troubleshooting purposes
|
||||
TileEntity tileEntity = RiftRegistry.INSTANCE.getRiftLocation(riftID).getTileEntity();
|
||||
if (tileEntity instanceof TileEntityDimDoorWarp) {
|
||||
index = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return index;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the depth
|
||||
*/
|
||||
public int getDepth() {
|
||||
return depth;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the depthZeroLocation
|
||||
*/
|
||||
public Location getDepthZeroLocation() {
|
||||
return depthZeroLocation;
|
||||
}
|
||||
|
||||
public void addRiftID(int id) {
|
||||
riftIDs.add(id);
|
||||
}
|
||||
|
||||
public void validatePlayerEntry(EntityPlayer player) {
|
||||
String playerUUID = player.getCachedUniqueIdString();
|
||||
if (!playerUUIDs.contains(playerUUID)) { //the 'contains' method uses the 'equals' method to check, so for Strings, this should work.
|
||||
playerUUIDs.add(playerUUID);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isPlayerAllowedInPocket(EntityPlayer player) {
|
||||
String playerUUID = player.getCachedUniqueIdString();
|
||||
return playerUUIDs.contains(playerUUID);
|
||||
}
|
||||
|
||||
public void setDepthZeroLocation(Location teleportTargetLocation) {
|
||||
depthZeroLocation.loadfrom(teleportTargetLocation);
|
||||
}
|
||||
|
||||
boolean isLocationWithinPocketBounds(final Location location, final int gridSize) {
|
||||
int locX = location.getPos().getX();
|
||||
int locZ = location.getPos().getY();
|
||||
// pocket bounds
|
||||
int pocMinX = x * gridSize;
|
||||
int pocMinZ = z * gridSize;
|
||||
int pocMaxX = pocMinX + (size + 1) * 16;
|
||||
int pocMaxZ = pocMinX + (size + 1) * 16;
|
||||
return pocMinX <= locX && pocMinZ <= locZ && locX < pocMaxX && locZ < pocMaxZ;
|
||||
}
|
||||
}
|
|
@ -1,277 +0,0 @@
|
|||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package com.zixiken.dimdoors.shared;
|
||||
|
||||
import com.zixiken.dimdoors.shared.util.Location;
|
||||
import com.zixiken.dimdoors.DimDoors;
|
||||
import com.zixiken.dimdoors.shared.util.RandomUtils;
|
||||
import com.zixiken.dimdoors.shared.world.DimDoorDimensions;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import lombok.Getter;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Robijnvogel
|
||||
*/
|
||||
public class PocketRegistry {
|
||||
|
||||
public static final PocketRegistry INSTANCE = new PocketRegistry();
|
||||
|
||||
// Privates
|
||||
//Need to be saved:
|
||||
@Getter private int gridSize; //determines how much pockets in their dimension are spaced
|
||||
@Getter private int maxPocketSize;
|
||||
@Getter private int privatePocketSize;
|
||||
@Getter private int publicPocketSize;
|
||||
private final Map<EnumPocketType, Integer> nextUnusedIDs;
|
||||
private final Map<String, Integer> privatePockets; //maps the UUID's of players to their private pocket's ID (ID for EnumPocketType.PRIVATE in pocketLists)
|
||||
private final Map<EnumPocketType, Map<Integer, Pocket>> pocketLists;
|
||||
private final List<Map<Integer, Pocket>> pocketListsPerDepth; //@todo not being used or saved yet.
|
||||
|
||||
// Methods
|
||||
private PocketRegistry() {
|
||||
nextUnusedIDs = new HashMap<>();
|
||||
for (EnumPocketType pocketType : EnumPocketType.values()) {
|
||||
nextUnusedIDs.put(pocketType, 0);
|
||||
}
|
||||
privatePockets = new HashMap<>();
|
||||
pocketLists = new HashMap<>();
|
||||
for (EnumPocketType pocketType : EnumPocketType.values()) {
|
||||
pocketLists.put(pocketType, new HashMap<>());
|
||||
}
|
||||
pocketListsPerDepth = new ArrayList<>();
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
for (EnumPocketType pocketType : EnumPocketType.values()) {
|
||||
nextUnusedIDs.put(pocketType, 0);
|
||||
}
|
||||
for (EnumPocketType pocketType : EnumPocketType.values()) {
|
||||
pocketLists.get(pocketType).clear();
|
||||
}
|
||||
gridSize = DDConfig.getPocketGridSize();
|
||||
maxPocketSize = DDConfig.getMaxPocketSize();
|
||||
privatePocketSize = DDConfig.getPrivatePocketSize();
|
||||
publicPocketSize = DDConfig.getPublicPocketSize();
|
||||
PocketSavedData.get(DimDoors.getDefWorld()).markDirty();
|
||||
}
|
||||
|
||||
public void readFromNBT(NBTTagCompound nbt) {
|
||||
if (nbt.hasKey("gridSize")) {
|
||||
gridSize = nbt.getInteger("gridSize");
|
||||
maxPocketSize = nbt.getInteger("maxPocketSize");
|
||||
privatePocketSize = nbt.getInteger("privatePocketSize");
|
||||
publicPocketSize = nbt.getInteger("publicPocketSize");
|
||||
if (nbt.hasKey("nextUnusedIDs")) {
|
||||
NBTTagCompound nextUnusedIDTagCompound = nbt.getCompoundTag("nextUnusedIDs");
|
||||
for (EnumPocketType pocketType : EnumPocketType.values()) {
|
||||
String tagListName = pocketType.toString();
|
||||
if (nextUnusedIDTagCompound.hasKey(tagListName)) {
|
||||
int nextUnusedID = nextUnusedIDTagCompound.getInteger(tagListName);
|
||||
nextUnusedIDs.put(pocketType, nextUnusedID);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (nbt.hasKey("privatePockets")) {
|
||||
NBTTagCompound privatePocketsTagCompound = nbt.getCompoundTag("privatePockets");
|
||||
privatePockets.clear();
|
||||
for (String uuid : privatePocketsTagCompound.getKeySet()) {
|
||||
privatePockets.put(uuid, privatePocketsTagCompound.getInteger(uuid));
|
||||
}
|
||||
}
|
||||
if (nbt.hasKey("pocketData")) {
|
||||
NBTTagCompound pocketsTagCompound = nbt.getCompoundTag("pocketData");
|
||||
pocketLists.clear();
|
||||
for (EnumPocketType pocketType : EnumPocketType.values()) {
|
||||
String tagListName = pocketType.toString();
|
||||
if (pocketsTagCompound.hasKey(tagListName)) {
|
||||
Map<Integer, Pocket> pocketList = new HashMap<>();
|
||||
NBTTagList pocketTagList = (NBTTagList) pocketsTagCompound.getTag(tagListName);
|
||||
for (int j = 0; j < pocketTagList.tagCount(); j++) { //@todo this defeats the purpose of a Map over a List (pocketList)
|
||||
NBTTagCompound pocketTag = pocketTagList.getCompoundTagAt(j);
|
||||
pocketList.put(j, Pocket.readFromNBT(pocketTag));
|
||||
}
|
||||
pocketLists.put(pocketType, pocketList);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else { //load privates from config
|
||||
reset();
|
||||
}
|
||||
}
|
||||
|
||||
public void writeToNBT(NBTTagCompound nbt) {
|
||||
nbt.setInteger("gridSize", gridSize);
|
||||
nbt.setInteger("maxPocketSize", maxPocketSize);
|
||||
nbt.setInteger("privatePocketSize", privatePocketSize);
|
||||
nbt.setInteger("publicPocketSize", publicPocketSize);
|
||||
|
||||
NBTTagCompound nextUnusedIDTagCompound = new NBTTagCompound();
|
||||
for (EnumPocketType pocketType : nextUnusedIDs.keySet()) {
|
||||
nextUnusedIDTagCompound.setInteger(pocketType.toString(), nextUnusedIDs.get(pocketType));
|
||||
}
|
||||
nbt.setTag("nextUnusedIDs", nextUnusedIDTagCompound);
|
||||
|
||||
NBTTagCompound privatePocketsTagCompound = new NBTTagCompound();
|
||||
for (String uuid : privatePockets.keySet()) {
|
||||
privatePocketsTagCompound.setInteger(uuid, privatePockets.get(uuid));
|
||||
}
|
||||
nbt.setTag("privatePockets", privatePocketsTagCompound);
|
||||
|
||||
NBTTagCompound pocketsTagCompound = new NBTTagCompound();
|
||||
for (EnumPocketType pocketType : pocketLists.keySet()) {
|
||||
Map<Integer, Pocket> pocketList = pocketLists.get(pocketType);
|
||||
NBTTagList pocketTagList = new NBTTagList();
|
||||
for (int i : pocketList.keySet()) {
|
||||
pocketTagList.appendTag(Pocket.writeToNBT(pocketList.get(i)));
|
||||
}
|
||||
pocketsTagCompound.setTag(pocketType.toString(), pocketTagList);
|
||||
}
|
||||
nbt.setTag("pocketData", pocketsTagCompound);
|
||||
}
|
||||
|
||||
public void registerNewPocket(Pocket pocket, EnumPocketType pocketType) {
|
||||
int assignedID = nextUnusedIDs.get(pocketType);
|
||||
pocketLists.get(pocketType).put(assignedID, pocket);
|
||||
pocket.setID(assignedID);
|
||||
|
||||
nextUnusedIDs.put(pocketType, assignedID + 1); //increase the counter
|
||||
PocketSavedData.get(DimDoors.getDefWorld()).markDirty(); //Notify that this needs to be saved on world save
|
||||
}
|
||||
|
||||
public void removePocket(int pocketID, EnumPocketType pocketType) { //probably will never ever get used, but meh...
|
||||
Map<Integer, Pocket> pocketList = pocketLists.get(pocketType);
|
||||
if (pocketList.containsKey(pocketID)) {
|
||||
pocketList.remove(pocketID);
|
||||
PocketSavedData.get(DimDoors.getDefWorld()).markDirty(); //Notify that this needs to be saved on world save
|
||||
}
|
||||
}
|
||||
|
||||
public Pocket getPocket(int id, EnumPocketType pocketType) {
|
||||
return pocketLists.get(pocketType).get(id); // TODO: null pointer
|
||||
}
|
||||
|
||||
public Pocket generateRandomPocketAt(EnumPocketType typeID, int depth, Location origRiftLocation) {
|
||||
// Correcting the depth. Just in case...
|
||||
if (typeID == EnumPocketType.DUNGEON) {
|
||||
if (depth <= 0) {
|
||||
depth = 1;
|
||||
} else if (depth > DDConfig.getMaxDungeonDepth()) {
|
||||
depth = DDConfig.getMaxDungeonDepth();
|
||||
}
|
||||
} else {
|
||||
depth = 0;
|
||||
}
|
||||
|
||||
// Fetch the pocket template
|
||||
PocketTemplate pocketTemplate;
|
||||
switch (typeID) {
|
||||
case DUNGEON:
|
||||
pocketTemplate = SchematicHandler.INSTANCE.getDungeonTemplate(depth / 50, depth);
|
||||
break;
|
||||
case PUBLIC:
|
||||
pocketTemplate = SchematicHandler.INSTANCE.getPublicPocketTemplate();
|
||||
break;
|
||||
case PRIVATE:
|
||||
default:
|
||||
pocketTemplate = SchematicHandler.INSTANCE.getPersonalPocketTemplate();
|
||||
break;
|
||||
}
|
||||
return generatePocketAt(typeID, depth, origRiftLocation, pocketTemplate);
|
||||
}
|
||||
|
||||
public Pocket generatePocketAt(EnumPocketType typeID, int depth, Location origRiftLocation, PocketTemplate pocketTemplate) {
|
||||
//Getting the physical grid-location and the Overworld coordinates
|
||||
Location shortenedLocation = getGenerationlocation(nextUnusedIDs.get(typeID), typeID);
|
||||
int shortenedX = shortenedLocation.getPos().getX();
|
||||
int shortenedZ = shortenedLocation.getPos().getZ();
|
||||
int dimID = shortenedLocation.getDimensionID();
|
||||
Location depthZeroLocation;
|
||||
switch (typeID) {
|
||||
case DUNGEON:
|
||||
depthZeroLocation = RandomUtils.transformLocationRandomly(DDConfig.getOwCoordinateOffsetBase(), DDConfig.getOwCoordinateOffsetPower(), depth, origRiftLocation);
|
||||
break;
|
||||
case PUBLIC:
|
||||
depthZeroLocation = RandomUtils.transformLocationRandomly(DDConfig.getOwCoordinateOffsetBase(), DDConfig.getOwCoordinateOffsetPower(), 1, origRiftLocation);
|
||||
break;
|
||||
case PRIVATE:
|
||||
default:
|
||||
depthZeroLocation = origRiftLocation;
|
||||
break;
|
||||
}
|
||||
|
||||
Pocket pocket = pocketTemplate.place(shortenedX, 0, shortenedZ, gridSize, dimID, nextUnusedIDs.get(typeID), depth, typeID, depthZeroLocation);
|
||||
registerNewPocket(pocket, typeID);
|
||||
return pocket;
|
||||
}
|
||||
|
||||
public int getPrivateDimDoorID(String playerUUID) {
|
||||
if (!privatePockets.containsKey(playerUUID)) {
|
||||
//generate a new private pocket
|
||||
int doorID = generateRandomPocketAt(EnumPocketType.PRIVATE, 0, new Location(0, 0, 0, 0)).getEntranceDoorID(); //Location doesn't really matter in this case
|
||||
privatePockets.put(playerUUID, doorID);
|
||||
return doorID;
|
||||
}
|
||||
return privatePockets.get(playerUUID);
|
||||
}
|
||||
|
||||
private Location getGenerationlocation(final int nextUnusedID, EnumPocketType typeID) {
|
||||
int x;
|
||||
int y = 0;
|
||||
int z;
|
||||
int dimID = DimDoorDimensions.getPocketDimensionType(typeID).getId();
|
||||
if (nextUnusedID == 0) {
|
||||
x = 0;
|
||||
z = 0;
|
||||
} else {
|
||||
int radius = (int) Math.sqrt(nextUnusedID); //casting to int rounds down the double resulting from taking the square root
|
||||
int radiusNumber = nextUnusedID - radius * radius;
|
||||
double splitter = (double) radiusNumber / (double) radius; //always between 0 and 2
|
||||
DimDoors.log(getClass(), "id is " + nextUnusedID);
|
||||
DimDoors.log(getClass(), "Radius is " + radius);
|
||||
DimDoors.log(getClass(), "Radius number is " + radiusNumber);
|
||||
DimDoors.log(getClass(), "Splitter is " + splitter);
|
||||
x = splitter <= 1.0 ? radius : radius - (radiusNumber - radius);
|
||||
z = splitter >= 1.0 ? radius : radiusNumber;
|
||||
}
|
||||
return new Location(dimID, x, y, z);
|
||||
}
|
||||
|
||||
public int getPocketIDFromCoords(Location location) {
|
||||
final int dimID = location.getDimensionID();
|
||||
if (DimDoorDimensions.isPocketDimensionID(dimID)) {
|
||||
int x = location.getPos().getX();
|
||||
int z = location.getPos().getZ();
|
||||
int shortX = x / (gridSize * 16);
|
||||
int shortZ = z / (gridSize * 16);
|
||||
if (shortX >= shortZ) {
|
||||
return shortX * shortX + shortZ;
|
||||
} else {
|
||||
return (shortZ + 2) * shortZ - shortX;
|
||||
}
|
||||
}
|
||||
return -1; //not in a pocket dimension
|
||||
}
|
||||
|
||||
public boolean isPlayerAllowedToBeHere(final EntityPlayerMP player, final Location location) {
|
||||
int pocketID = getPocketIDFromCoords(location);
|
||||
if (pocketID < 0) { // not in a pocket dimension
|
||||
return true;
|
||||
} else {
|
||||
EnumPocketType type = DimDoorDimensions.getPocketType(location.getDimensionID());
|
||||
Pocket pocket = pocketLists.get(type).get(pocketID);
|
||||
if (pocket == null) return true; // TODO: why is this happening?
|
||||
return pocket.isPlayerAllowedInPocket(player) && pocket.isLocationWithinPocketBounds(location, gridSize);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,65 +0,0 @@
|
|||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package com.zixiken.dimdoors.shared;
|
||||
|
||||
import java.io.File;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.storage.MapStorage;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Robijnvogel
|
||||
*/
|
||||
public class PocketSavedData extends DDSavedData {
|
||||
|
||||
private static final String DATA_NAME = "dimdoors_PocketSavedData";
|
||||
|
||||
public PocketSavedData() {
|
||||
super(DATA_NAME);
|
||||
}
|
||||
|
||||
public PocketSavedData(String s) {
|
||||
super(s);
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getSaveLocation(World world) {
|
||||
return new File(super.getSaveLocation(world), "pockets.nbt");
|
||||
}
|
||||
|
||||
public static PocketSavedData get(World world) {
|
||||
MapStorage storage = world.getMapStorage();
|
||||
PocketSavedData instance = (PocketSavedData) storage.getOrLoadData(PocketSavedData.class, DATA_NAME);
|
||||
|
||||
if (instance == null) {
|
||||
instance = new PocketSavedData();
|
||||
storage.setData(DATA_NAME, instance);
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTTagCompound writeToNBT(NBTTagCompound nbt) {
|
||||
|
||||
NBTTagCompound pockets = new NBTTagCompound();
|
||||
PocketRegistry.INSTANCE.writeToNBT(pockets);
|
||||
nbt.setTag("pockets", pockets);
|
||||
|
||||
return nbt;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound nbt) {
|
||||
// Load NBT
|
||||
if (nbt != null) {
|
||||
if (nbt.hasKey("pockets")) {
|
||||
NBTTagCompound pockets = nbt.getCompoundTag("pockets");
|
||||
PocketRegistry.INSTANCE.readFromNBT(pockets);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,18 +1,18 @@
|
|||
package com.zixiken.dimdoors.shared;
|
||||
|
||||
import com.zixiken.dimdoors.shared.tileentities.DDTileEntityBase;
|
||||
import com.zixiken.dimdoors.shared.tileentities.TileEntityRift;
|
||||
import com.zixiken.dimdoors.shared.tileentities.TileEntityFloatingRift;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.util.math.RayTraceResult;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class RayTraceHelper {
|
||||
public static boolean isRift(RayTraceResult hit, World world) {
|
||||
return isNotNull(hit) && hit.typeOfHit == RayTraceResult.Type.BLOCK && world.getTileEntity(hit.getBlockPos()) instanceof TileEntityRift;
|
||||
return isNotNull(hit) && hit.typeOfHit == RayTraceResult.Type.BLOCK && world.getTileEntity(hit.getBlockPos()) instanceof TileEntityFloatingRift;
|
||||
}
|
||||
|
||||
public static boolean isAbstractRift(RayTraceResult hit, World world) {
|
||||
return isNotNull(hit) && hit.typeOfHit == RayTraceResult.Type.BLOCK && world.getTileEntity(hit.getBlockPos()) instanceof DDTileEntityBase;
|
||||
return isNotNull(hit) && hit.typeOfHit == RayTraceResult.Type.BLOCK && world.getTileEntity(hit.getBlockPos()) instanceof TileEntityRift;
|
||||
}
|
||||
|
||||
public static boolean isLivingEntity(RayTraceResult hit) {
|
||||
|
|
|
@ -1,441 +0,0 @@
|
|||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package com.zixiken.dimdoors.shared;
|
||||
|
||||
import com.zixiken.dimdoors.shared.tileentities.TileEntityDimDoorUnstable;
|
||||
import com.zixiken.dimdoors.shared.util.Location;
|
||||
import com.zixiken.dimdoors.DimDoors;
|
||||
import com.zixiken.dimdoors.shared.tileentities.DDTileEntityBase;
|
||||
import com.zixiken.dimdoors.shared.tileentities.TileEntityDimDoorPersonal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Robijnvogel
|
||||
*/
|
||||
public class RiftRegistry {
|
||||
|
||||
private int lastGeneratedEntranceDoorID = -1;
|
||||
private DDTileEntityBase lastBrokenRift = null; //@todo, redo this functionality in a more refined way
|
||||
public static final RiftRegistry INSTANCE = new RiftRegistry();
|
||||
|
||||
// Privates
|
||||
private int nextRiftID;
|
||||
private int maximumDungeonDepth = 2; //@todo make this configurable
|
||||
private final Map<Integer, Location> rifts; //maps all rifts in the world to their ID //@todo, make this a List of (comparable) locations?
|
||||
private final List<Integer> personalDoors; //list of all personal door rifts in the world, by riftID
|
||||
private final List<Integer> unpairedRifts; //list of all pairable rifts in the world that are not paired, by riftID
|
||||
private final List<List<Integer>> unpairedRiftsPerDepth; //List of all "unpairedRiftList s" per Dungeon Depth. Depth 0 is anything outside the dungeon dimension
|
||||
//@todo somehow remove rifts from these lists even if they are removed in creative
|
||||
|
||||
//when adding any new variables, don't forget to add them to the write and load functions
|
||||
// Methods
|
||||
private RiftRegistry() {
|
||||
nextRiftID = 0;
|
||||
rifts = new HashMap<>();
|
||||
personalDoors = new ArrayList<>(); //@todo read from and write to NBT
|
||||
unpairedRifts = new ArrayList<>();
|
||||
unpairedRiftsPerDepth = new ArrayList<>();
|
||||
for (int i = 0; i <= maximumDungeonDepth; i++) {
|
||||
unpairedRiftsPerDepth.add(new ArrayList<>());
|
||||
}
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
nextRiftID = 0;
|
||||
rifts.clear();
|
||||
personalDoors.clear();
|
||||
unpairedRifts.clear();
|
||||
for (List<Integer> dimensionSpecificUnpairedRiftList : unpairedRiftsPerDepth) {
|
||||
dimensionSpecificUnpairedRiftList.clear();
|
||||
}
|
||||
lastBrokenRift = null;
|
||||
RiftSavedData.get(DimDoors.getDefWorld()).markDirty();
|
||||
}
|
||||
|
||||
public void readFromNBT(NBTTagCompound nbt) {
|
||||
nextRiftID = nbt.getInteger("nextUnusedID");
|
||||
|
||||
if (nbt.hasKey("riftList")) {
|
||||
NBTTagList riftsNBT = (NBTTagList) nbt.getTag("riftList");
|
||||
for (int i = 0; i < riftsNBT.tagCount(); i++) {
|
||||
NBTTagCompound riftTag = riftsNBT.getCompoundTagAt(i);
|
||||
int riftID = riftTag.getInteger("riftID");
|
||||
NBTTagCompound locationTag = riftTag.getCompoundTag("location");
|
||||
Location riftLocation = Location.readFromNBT(locationTag);
|
||||
rifts.put(riftID, riftLocation);
|
||||
}
|
||||
}
|
||||
|
||||
if (nbt.hasKey("personalDoorsList")) {
|
||||
NBTTagList persRiftsNBT = (NBTTagList) nbt.getTag("personalDoorsList");
|
||||
for (int i = 0; i < persRiftsNBT.tagCount(); i++) {
|
||||
NBTTagCompound riftTag = persRiftsNBT.getCompoundTagAt(i);
|
||||
int riftID = riftTag.getInteger("riftID");
|
||||
personalDoors.add(riftID);
|
||||
}
|
||||
}
|
||||
|
||||
if (nbt.hasKey("unpairedRiftList")) {
|
||||
NBTTagList unpRiftsNBT = (NBTTagList) nbt.getTag("unpairedRiftList");
|
||||
for (int i = 0; i < unpRiftsNBT.tagCount(); i++) {
|
||||
NBTTagCompound riftTag = unpRiftsNBT.getCompoundTagAt(i);
|
||||
int riftID = riftTag.getInteger("riftID");
|
||||
unpairedRifts.add(riftID);
|
||||
}
|
||||
}
|
||||
|
||||
if (nbt.hasKey("unpairedDepthRiftList")) {
|
||||
unpairedRiftsPerDepth.clear(); //because its "maximum depth" (or in other words, "size()") could be re-determined by this action
|
||||
|
||||
NBTTagList riftListsNBT = (NBTTagList) nbt.getTag("unpairedDepthRiftList");
|
||||
maximumDungeonDepth = riftListsNBT.tagCount(); //makes sure both are synched
|
||||
for (int i = 0; i < riftListsNBT.tagCount(); i++) {
|
||||
unpairedRiftsPerDepth.add(new ArrayList<>());
|
||||
NBTTagList riftsNBT = (NBTTagList) riftListsNBT.get(i);
|
||||
for (int j = 0; j < riftsNBT.tagCount(); j++) {
|
||||
NBTTagCompound riftTag = riftsNBT.getCompoundTagAt(j);
|
||||
int riftID = riftTag.getInteger("riftID");
|
||||
unpairedRiftsPerDepth.get(i).add(riftID);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void writeToNBT(NBTTagCompound nbt) {
|
||||
lastBrokenRift = null; //@todo this really should not be a part of this method, but I do not know of a better way to guaranteedly dereference it once every so often.
|
||||
nbt.setInteger("maximumDungeonDepth", maximumDungeonDepth);
|
||||
nbt.setInteger("nextUnusedID", nextRiftID);
|
||||
|
||||
NBTTagList riftsNBT = new NBTTagList();
|
||||
for (Map.Entry<Integer, Location> entry : rifts.entrySet()) {
|
||||
NBTTagCompound riftTag = new NBTTagCompound();
|
||||
riftTag.setInteger("riftID", entry.getKey());
|
||||
riftTag.setTag("location", Location.writeToNBT(entry.getValue()));
|
||||
riftsNBT.appendTag(riftTag);
|
||||
}
|
||||
nbt.setTag("riftList", riftsNBT);
|
||||
|
||||
NBTTagList personalDoorsNBT = new NBTTagList();
|
||||
for (int riftID : personalDoors) {
|
||||
NBTTagCompound riftTag = new NBTTagCompound();
|
||||
riftTag.setInteger("riftID", riftID);
|
||||
personalDoorsNBT.appendTag(riftTag);
|
||||
}
|
||||
nbt.setTag("personalDoorsList", personalDoorsNBT);
|
||||
|
||||
NBTTagList unpairedRiftsNBT = new NBTTagList();
|
||||
for (int riftID : unpairedRifts) {
|
||||
NBTTagCompound riftTag = new NBTTagCompound();
|
||||
riftTag.setInteger("riftID", riftID);
|
||||
unpairedRiftsNBT.appendTag(riftTag);
|
||||
}
|
||||
nbt.setTag("unpairedRiftList", unpairedRiftsNBT);
|
||||
|
||||
NBTTagList unpairedRiftListsNBT = new NBTTagList();
|
||||
for (List<Integer> unpairedRiftListAtDepth : unpairedRiftsPerDepth) {
|
||||
NBTTagList unpairedRiftsNBT2 = new NBTTagList();
|
||||
for (int riftID : unpairedRiftListAtDepth) {
|
||||
NBTTagCompound riftTag = new NBTTagCompound();
|
||||
riftTag.setInteger("riftID", riftID);
|
||||
unpairedRiftsNBT2.appendTag(riftTag);
|
||||
}
|
||||
unpairedRiftListsNBT.appendTag(unpairedRiftsNBT2);
|
||||
}
|
||||
nbt.setTag("unpairedDepthRiftList", unpairedRiftListsNBT);
|
||||
}
|
||||
|
||||
public int registerNewRift(DDTileEntityBase rift, final int depth) {
|
||||
Location riftLocation = Location.getLocation(rift);
|
||||
final int assignedID = nextRiftID;
|
||||
DimDoors.log(getClass(), "Starting registering rift as ID: " + assignedID);
|
||||
|
||||
rifts.put(assignedID, riftLocation);
|
||||
if (rift instanceof TileEntityDimDoorPersonal || rift instanceof TileEntityDimDoorUnstable) {
|
||||
if (rift instanceof TileEntityDimDoorPersonal) {
|
||||
personalDoors.add(assignedID);
|
||||
}
|
||||
} else {
|
||||
DimDoors.log(getClass(), "Registering rift in unpairedRiftRegistry. ID = " + assignedID + " at depth: " + depth);
|
||||
unpairedRifts.add(assignedID);
|
||||
registerUnpairedRiftAtDepth(assignedID, depth);
|
||||
}
|
||||
|
||||
nextRiftID++;
|
||||
RiftSavedData.get(DimDoors.getDefWorld()).markDirty(); //Notify that this needs to be saved on world save
|
||||
return assignedID;
|
||||
}
|
||||
|
||||
public void unregisterRift(int riftID) {
|
||||
DimDoors.log(getClass(), "unregistering rift " + riftID);
|
||||
unpair(riftID);
|
||||
|
||||
unRegisterUnpairedRiftAtDepth(riftID); //@todo, will this crash if it doesn't find that value?
|
||||
unpairedRifts.remove((Integer) riftID);
|
||||
personalDoors.remove((Integer) riftID);
|
||||
rifts.remove(riftID);
|
||||
RiftSavedData.get(DimDoors.getDefWorld()).markDirty(); //Notify that this needs to be saved on world save
|
||||
}
|
||||
|
||||
void registerUnpairedRiftAtDepth(int riftID, int depth) {
|
||||
if (depth < maximumDungeonDepth) {
|
||||
List<Integer> unpairedRiftListAtDepth = unpairedRiftsPerDepth.get(depth);
|
||||
unpairedRiftListAtDepth.add(riftID);
|
||||
}
|
||||
}
|
||||
|
||||
void unRegisterUnpairedRiftAtDepth(int riftID) {
|
||||
TileEntity tileEntity = rifts.get(riftID).getTileEntity();
|
||||
if (tileEntity instanceof DDTileEntityBase) {
|
||||
DDTileEntityBase rift = (DDTileEntityBase) tileEntity;
|
||||
unRegisterUnpairedRiftAtDepth(rift);
|
||||
}
|
||||
}
|
||||
|
||||
void unRegisterUnpairedRiftAtDepth(DDTileEntityBase rift) {
|
||||
int depth = rift.getDepth();
|
||||
DimDoors.log(getClass(), "unregistering rift "+ rift.getRiftID() + " as unpaired at depth " + depth);
|
||||
if (depth < maximumDungeonDepth) {
|
||||
List<Integer> unpairedRiftListAtDepth = unpairedRiftsPerDepth.get(depth);
|
||||
unpairedRiftListAtDepth.remove((Integer) rift.getRiftID());
|
||||
}
|
||||
}
|
||||
|
||||
public Location getRiftLocation(int id) {
|
||||
return rifts.get(id);
|
||||
}
|
||||
|
||||
public void pair(int riftID, int riftID2) {
|
||||
if (riftID < 0 || riftID2 < 0) {
|
||||
return; //@todo throw a proper error
|
||||
}
|
||||
Location location = rifts.get(riftID);
|
||||
TileEntity tileEntity = location.getTileEntity(); //@todo this method might need to be in another class?
|
||||
if (tileEntity instanceof DDTileEntityBase) {
|
||||
DDTileEntityBase rift = (DDTileEntityBase) tileEntity;
|
||||
DimDoors.log(getClass(), "RiftRegistry trying to connect rift " + riftID + " to rift " + riftID2 + ".");
|
||||
boolean alreadyPaired = rift.pair(riftID2);
|
||||
if (!alreadyPaired) {
|
||||
DimDoors.log(getClass(), "RiftRegistry unregistering rift " + riftID + " from unPairedRiftRegistry.");
|
||||
unpairedRifts.remove((Integer) riftID);
|
||||
unRegisterUnpairedRiftAtDepth(riftID);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void unpair(int riftID) {
|
||||
if (riftID < 0) {
|
||||
return;
|
||||
}
|
||||
Location location = rifts.get(riftID);
|
||||
if (location == null) {
|
||||
DimDoors.warn(getClass(), "RiftID with null location: rift " + riftID);
|
||||
} else {
|
||||
TileEntity tileEntity = location.getTileEntity();
|
||||
if (tileEntity instanceof DDTileEntityBase) {
|
||||
DDTileEntityBase rift = (DDTileEntityBase) tileEntity;
|
||||
boolean alreadyUnPaired = rift.unpair();
|
||||
if (!alreadyUnPaired) {
|
||||
unpairedRifts.add(riftID);
|
||||
registerUnpairedRiftAtDepth(riftID, rift.getDepth());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setLastChangedRift(DDTileEntityBase origRift) {
|
||||
lastBrokenRift = origRift;
|
||||
}
|
||||
|
||||
public DDTileEntityBase getLastChangedRift() {
|
||||
return lastBrokenRift;
|
||||
}
|
||||
|
||||
public boolean teleportEntityToRift(Entity entity, int pairedRiftID) { //@todo implement this code in the sending rift tiles instead
|
||||
DimDoors.log(getClass(), "RiftID of rift that the entity trying to teleport to is " + pairedRiftID + ".");
|
||||
if (pairedRiftID < 0) {
|
||||
DimDoors.warn(getClass(), "RiftID of rift that entity " + entity + " is trying to teleport to seems to be lower than 0 and it shouldn't.");
|
||||
return false;
|
||||
}
|
||||
Location destinationRiftLocation = getRiftLocation(pairedRiftID);
|
||||
DDTileEntityBase destinationRift = (DDTileEntityBase) destinationRiftLocation.getTileEntity();
|
||||
if (destinationRift == null) {
|
||||
DimDoors.warn(getClass(), "The rift that an entity is trying to teleport to seems to be null.");
|
||||
}
|
||||
return TeleporterDimDoors.instance().teleport(entity, destinationRift.getTeleportTargetLocation());
|
||||
}
|
||||
|
||||
//@todo are we ever going to use this method?
|
||||
public int getRandomUnpairedRiftID(int origRiftID) {
|
||||
if (!unpairedRifts.isEmpty()) {
|
||||
int numberOfUnpairedRifts = unpairedRifts.size();
|
||||
if (numberOfUnpairedRifts != 1) {//should not only be the "original Rift" then
|
||||
Random random = new Random();
|
||||
int indexOforigRiftID = unpairedRifts.indexOf(origRiftID);
|
||||
int randomRiftIDIndex = random.nextInt(numberOfUnpairedRifts - 1); //-1 because we do not want to include the key of the original rift, so it will not randomly pair to itself
|
||||
if (randomRiftIDIndex >= indexOforigRiftID) {
|
||||
randomRiftIDIndex++;
|
||||
}
|
||||
return unpairedRifts.get(randomRiftIDIndex);
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public int getRandomUnpairedRiftIDAtDepth(int origRiftID, int depth) {
|
||||
int returnID = -1;
|
||||
|
||||
//After using a command to generate a particular schematic as a pocket to be the next non-random Golden (and randomly Iron) Dimdoor destination
|
||||
if (lastGeneratedEntranceDoorID != -1) {
|
||||
returnID = lastGeneratedEntranceDoorID;
|
||||
lastGeneratedEntranceDoorID = -1;
|
||||
return returnID;
|
||||
}
|
||||
|
||||
if (unpairedRiftsPerDepth.size() > depth) {
|
||||
List<Integer> rifts = unpairedRiftsPerDepth.get(depth);
|
||||
int numberOfUnpairedRifts = rifts.size();
|
||||
if (numberOfUnpairedRifts > 1) {
|
||||
DimDoors.log(getClass(), "There's more than 1 unpaired rift at this depth.");
|
||||
Random random = new Random();
|
||||
int randomRiftIDIndex;
|
||||
boolean origRiftIsOnSameDepth = rifts.contains(origRiftID);
|
||||
if (origRiftIsOnSameDepth) {
|
||||
int indexOfOrigRiftID = rifts.indexOf(origRiftID);
|
||||
randomRiftIDIndex = random.nextInt(numberOfUnpairedRifts - 1); //-1 because we do not want to include the key of the original rift, so it will not randomly pair to itself
|
||||
if (randomRiftIDIndex >= indexOfOrigRiftID) {
|
||||
randomRiftIDIndex++;
|
||||
}
|
||||
} else {
|
||||
randomRiftIDIndex = random.nextInt(numberOfUnpairedRifts);
|
||||
}
|
||||
returnID = rifts.get(randomRiftIDIndex);
|
||||
}
|
||||
}
|
||||
DimDoors.log(getClass(), "Rift to pair to was chosen: returnID = " + returnID);
|
||||
return returnID;
|
||||
}
|
||||
|
||||
public int getRandomUnpairedRiftIDAroundDepth(int origRiftID, int depth) {
|
||||
int returnID = -1;
|
||||
if (unpairedRiftsPerDepth.size() > depth) {
|
||||
int[] weights = getWeightSizeProducts(unpairedRiftsPerDepth, depth - 2, new int[]{15, 25, 30, 20, 10}); //@todo put these values in config
|
||||
if (getArraySum(weights) == 0) {
|
||||
//@todo there is no unpaired rift around those depths
|
||||
} else {
|
||||
int chosenDepth = pickRandom(weights) + depth - 2;
|
||||
returnID = getRandomUnpairedRiftIDAtDepth(origRiftID, chosenDepth);
|
||||
}
|
||||
}
|
||||
return returnID;
|
||||
}
|
||||
|
||||
public int[] getWeightSizeProducts(List<List<Integer>> nestedList, int minListIndex, int[] weights) { //@todo put this in a utility class
|
||||
int[] returnArray = new int[weights.length];
|
||||
for (int i = 0; i < weights.length; i++) {
|
||||
int listIndex = minListIndex + i;
|
||||
if (listIndex > 0 && listIndex < nestedList.size()) {
|
||||
returnArray[i] = nestedList.get(listIndex).size() * weights[i];
|
||||
} else {
|
||||
returnArray[i] = 0;
|
||||
}
|
||||
}
|
||||
return returnArray;
|
||||
}
|
||||
|
||||
private int getArraySum(int[] integers) { //@todo put this in a utility class
|
||||
int returnValue = 0;
|
||||
for (int i : integers) {
|
||||
returnValue += i;
|
||||
}
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
private int pickRandom(int[] integers) { //@todo put this in a utility class
|
||||
Random random = new Random();
|
||||
int pointer = random.nextInt(getArraySum(integers));
|
||||
for (int i = 0; i < integers.length; i++) {
|
||||
if (pointer < integers[i]) {
|
||||
return i;
|
||||
}
|
||||
pointer -= integers[i];
|
||||
}
|
||||
return -1; //should not be reachable if implementation is correct and getArraySum(integers) does not return 0
|
||||
}
|
||||
|
||||
public int getRandomNonPersonalRiftID() {
|
||||
List<Integer> nonPersonalRiftIDs = new ArrayList<>(rifts.keySet());
|
||||
for (int persRiftID : personalDoors) {
|
||||
//DimDoors.log(this.getClass(), "Removing personal rift: " + persRiftID + " from nonPersonalRiftIDs. nPRI size = " + nonPersonalRiftIDs.size());
|
||||
nonPersonalRiftIDs.remove((Integer) persRiftID);
|
||||
//DimDoors.log(this.getClass(), "Removed personal rift: " + persRiftID + " from nonPersonalRiftIDs. nPRI size = " + nonPersonalRiftIDs.size());
|
||||
}
|
||||
if (nonPersonalRiftIDs.size() > 0) {
|
||||
Random random = new Random();
|
||||
int index = random.nextInt(nonPersonalRiftIDs.size());
|
||||
return nonPersonalRiftIDs.get(index);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public Location getTeleportLocation(int riftId) {
|
||||
if (riftId < 0) {
|
||||
DimDoors.warn(getClass(), "RiftID of rift that entity is trying to teleport to seems to be lower than 0 and it shouldn't.");
|
||||
return null;
|
||||
}
|
||||
Location destinationRiftLocation = getRiftLocation(riftId);
|
||||
DDTileEntityBase destinationRift = (DDTileEntityBase) destinationRiftLocation.getTileEntity();
|
||||
if (destinationRift == null) {
|
||||
DimDoors.warn(getClass(), "The rift that an entity is trying to teleport to seems to be null. RiftID: " + riftId + ". Expecting to crash in 3... 2... 1..");
|
||||
}
|
||||
return destinationRift.getTeleportTargetLocation();
|
||||
}
|
||||
|
||||
public void validatePlayerPocketEntry(Entity entity, int riftID) {
|
||||
if (entity instanceof EntityPlayer && riftID >= 0) {
|
||||
Location riftLocation = getRiftLocation(riftID);
|
||||
if (riftLocation != null) {
|
||||
TileEntity tileEntity = riftLocation.getTileEntity();
|
||||
if (tileEntity instanceof DDTileEntityBase) {
|
||||
DDTileEntityBase rift = (DDTileEntityBase) tileEntity;
|
||||
EntityPlayer player = (EntityPlayer) entity;
|
||||
rift.validatePlayerPocketEntry(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void unregisterLastChangedRift() {
|
||||
if (lastBrokenRift != null) {
|
||||
RiftRegistry.INSTANCE.unregisterRift(lastBrokenRift.getRiftID());
|
||||
//@todo The rest is all pretty Crude. The only reason why this is needed, is because Vanilla Minecraft keeps destroying the rift blocks, before they can place down their TileEntities, if a player breaks them in creative.
|
||||
RiftRegistry.INSTANCE.unRegisterUnpairedRiftAtDepth(lastBrokenRift);
|
||||
lastBrokenRift.unpair();
|
||||
lastBrokenRift = null;
|
||||
}
|
||||
}
|
||||
|
||||
public int getPocketID(int riftID) {
|
||||
DDTileEntityBase rift = (DDTileEntityBase) rifts.get(riftID).getTileEntity();
|
||||
return rift.getPocketID();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param id the lastGeneratedEntranceDoorID to set
|
||||
*/
|
||||
public void setLastGeneratedEntranceDoorID(int id) {
|
||||
lastGeneratedEntranceDoorID = id;
|
||||
}
|
||||
}
|
|
@ -1,65 +0,0 @@
|
|||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package com.zixiken.dimdoors.shared;
|
||||
|
||||
import java.io.File;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.storage.MapStorage;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Robijnvogel
|
||||
*/
|
||||
public class RiftSavedData extends DDSavedData {
|
||||
|
||||
private static final String DATA_NAME = "dimdoors_RiftSavedData";
|
||||
|
||||
public RiftSavedData() {
|
||||
super(DATA_NAME);
|
||||
}
|
||||
|
||||
public RiftSavedData(String s) {
|
||||
super(s);
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getSaveLocation(World world) {
|
||||
return new File(super.getSaveLocation(world), "rifts.nbt");
|
||||
}
|
||||
|
||||
public static RiftSavedData get(World world) {
|
||||
MapStorage storage = world.getMapStorage();
|
||||
RiftSavedData instance = (RiftSavedData) storage.getOrLoadData(RiftSavedData.class, DATA_NAME);
|
||||
|
||||
if (instance == null) {
|
||||
instance = new RiftSavedData();
|
||||
storage.setData(DATA_NAME, instance);
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTTagCompound writeToNBT(NBTTagCompound nbt) {
|
||||
|
||||
NBTTagCompound rifts = new NBTTagCompound();
|
||||
RiftRegistry.INSTANCE.writeToNBT(rifts);
|
||||
nbt.setTag("rifts", rifts);
|
||||
|
||||
return nbt;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound nbt) {
|
||||
// Load NBT
|
||||
if (nbt != null) {
|
||||
if (nbt.hasKey("rifts")) {
|
||||
NBTTagCompound rifts = nbt.getCompoundTag("rifts");
|
||||
RiftRegistry.INSTANCE.readFromNBT(rifts);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,10 +1,7 @@
|
|||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package com.zixiken.dimdoors.shared;
|
||||
|
||||
import com.zixiken.dimdoors.shared.pockets.EnumPocketType;
|
||||
import com.zixiken.dimdoors.shared.pockets.PocketTemplate;
|
||||
import com.zixiken.dimdoors.shared.util.MathUtils;
|
||||
import com.zixiken.dimdoors.shared.util.Schematic;
|
||||
import com.google.gson.JsonArray;
|
||||
|
@ -33,8 +30,8 @@ import org.apache.commons.io.IOUtils;
|
|||
*
|
||||
* @author Robijnvogel
|
||||
*/
|
||||
public class SchematicHandler {
|
||||
public static final SchematicHandler INSTANCE = new SchematicHandler();
|
||||
public class SchematicHandler { // TODO: make this more general (not dimdoors-related)
|
||||
public static final SchematicHandler INSTANCE = new SchematicHandler(); // TODO: make static
|
||||
|
||||
private List<PocketTemplate> templates;
|
||||
private Map<String, Map<String, Integer>> nameMap; // group -> name -> index in templates
|
||||
|
@ -162,7 +159,6 @@ public class SchematicHandler {
|
|||
List<PocketTemplate> pocketTemplates = new ArrayList<>();
|
||||
|
||||
final String directory = jsonTemplate.get("group").getAsString();
|
||||
final EnumPocketType pocketType = EnumPocketType.getFromInt(jsonTemplate.get("pocketType").getAsInt());
|
||||
final JsonArray variations = jsonTemplate.getAsJsonArray("variations");
|
||||
|
||||
//convert the variations arraylist to a list of pocket templates
|
||||
|
@ -177,7 +173,7 @@ public class SchematicHandler {
|
|||
for (int j = 0; j < weightsJsonArray.size(); j++) {
|
||||
weights[j] = weightsJsonArray.get(j).getAsInt();
|
||||
}
|
||||
PocketTemplate pocketTemplate = new PocketTemplate(directory, variantName, variationSize, pocketType, minDepth, maxDepth, weights);
|
||||
PocketTemplate pocketTemplate = new PocketTemplate(directory, variantName, variationSize, minDepth, maxDepth, weights);
|
||||
pocketTemplates.add(pocketTemplate);
|
||||
}
|
||||
|
||||
|
@ -185,7 +181,7 @@ public class SchematicHandler {
|
|||
}
|
||||
|
||||
private void constructNameMap() {
|
||||
nameMap = new HashMap<String, Map<String, Integer>>();
|
||||
nameMap = new HashMap<>();
|
||||
//to prevent having to use too many getters
|
||||
String bufferedDirectory = null;
|
||||
Map<String, Integer> bufferedMap = null;
|
||||
|
@ -215,7 +211,7 @@ public class SchematicHandler {
|
|||
}
|
||||
|
||||
public ArrayList<String> getTemplateNames(String group) {
|
||||
return new ArrayList<>(nameMap.get(group).keySet());
|
||||
return new ArrayList<>(nameMap.get(group).keySet()); // TODO: null pointer here
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -288,12 +284,6 @@ public class SchematicHandler {
|
|||
return getRandomTemplate("private", -1, DDConfig.getMaxPocketSize(), true); // TODO: config option for getLargest
|
||||
}
|
||||
|
||||
public PocketTemplate getDungeonTemplate(float netherProbability, int depth) {
|
||||
Random random = new Random();
|
||||
String group = (random.nextFloat() < netherProbability) ? "nether" : "ruins";
|
||||
return getRandomTemplate(group, depth, DDConfig.getMaxPocketSize(), false);
|
||||
}
|
||||
|
||||
public void saveSchematic(Schematic schematic, String name) {
|
||||
NBTTagCompound schematicNBT = Schematic.saveToNBT(schematic);
|
||||
File saveFolder = new File(DDConfig.configurationFolder, "/Schematics/Saved");
|
||||
|
|
|
@ -3,9 +3,8 @@ package com.zixiken.dimdoors.shared.blocks;
|
|||
import java.util.Random;
|
||||
|
||||
import com.zixiken.dimdoors.DimDoors;
|
||||
import com.zixiken.dimdoors.shared.RiftRegistry;
|
||||
import com.zixiken.dimdoors.shared.tileentities.DDTileEntityBase;
|
||||
import com.zixiken.dimdoors.shared.tileentities.TileEntityDimDoor;
|
||||
import com.zixiken.dimdoors.shared.tileentities.TileEntityVerticalEntranceRift;
|
||||
import com.zixiken.dimdoors.shared.tileentities.TileEntityRift;
|
||||
import net.minecraft.block.BlockDoor;
|
||||
import net.minecraft.block.ITileEntityProvider;
|
||||
import net.minecraft.block.material.Material;
|
||||
|
@ -113,12 +112,12 @@ public abstract class BlockDimDoorBase extends BlockDoor implements IDimDoor, IT
|
|||
|
||||
@Override
|
||||
public TileEntity createNewTileEntity(World worldIn, int meta) { //gets called upon world load as well
|
||||
return new TileEntityDimDoor();
|
||||
return new TileEntityVerticalEntranceRift();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enterDimDoor(World world, BlockPos pos, Entity entity) {
|
||||
DDTileEntityBase riftTile = getRiftTile(world, pos, world.getBlockState(pos));
|
||||
TileEntityRift riftTile = getRiftTile(world, pos, world.getBlockState(pos));
|
||||
riftTile.isTeleporting = true; //flick trigger switch
|
||||
riftTile.teleportingEntity = entity;
|
||||
}
|
||||
|
@ -140,35 +139,35 @@ public abstract class BlockDimDoorBase extends BlockDoor implements IDimDoor, IT
|
|||
|
||||
@Override
|
||||
public void breakBlock(World worldIn, BlockPos pos, IBlockState state) {
|
||||
DDTileEntityBase origRift = null;
|
||||
TileEntityRift origRift = null;
|
||||
boolean isTopHalf = state.getValue(BlockDoor.HALF) == EnumDoorHalf.UPPER;
|
||||
boolean shouldPlaceRift = false;
|
||||
if (isTopHalf) {
|
||||
origRift = (DDTileEntityBase) worldIn.getTileEntity(pos);
|
||||
if (origRift.isPaired()) {
|
||||
shouldPlaceRift = true;
|
||||
RiftRegistry.INSTANCE.setLastChangedRift(origRift); //@todo this is a crude workaround
|
||||
} else {
|
||||
RiftRegistry.INSTANCE.unregisterRift(origRift.getRiftID());
|
||||
}
|
||||
origRift = (TileEntityRift) worldIn.getTileEntity(pos);
|
||||
//if (origRift.isPaired()) {
|
||||
// shouldPlaceRift = true;
|
||||
// RiftRegistry.INSTANCE.setLastChangedRift(origRift); // TODO
|
||||
//} else {
|
||||
// RiftRegistry.INSTANCE.unregisterRift(origRift.getRiftID());
|
||||
//}
|
||||
}
|
||||
super.breakBlock(worldIn, pos, state);
|
||||
if (shouldPlaceRift) {
|
||||
worldIn.setBlockState(pos, ModBlocks.RIFT.getDefaultState());
|
||||
DDTileEntityBase newRift = (DDTileEntityBase) worldIn.getTileEntity(pos);
|
||||
newRift.loadDataFrom(origRift); //@todo this does not work here, or does it?
|
||||
TileEntityRift newRift = (TileEntityRift) worldIn.getTileEntity(pos);
|
||||
newRift.copyFrom(origRift); //@todo this does not work here, or does it?
|
||||
}
|
||||
}
|
||||
|
||||
//returns the DDTileEntityBase that is the tile entity belonging to the door block "state" at this "pos" in the "world"
|
||||
public DDTileEntityBase getRiftTile(World world, BlockPos pos, IBlockState state) {
|
||||
//returns the TileEntityRift that is the tile entity belonging to the door block "state" at this "pos" in the "world"
|
||||
public TileEntityRift getRiftTile(World world, BlockPos pos, IBlockState state) {
|
||||
TileEntity tileEntity;
|
||||
if (state.getValue(BlockDoor.HALF) == EnumDoorHalf.LOWER) {
|
||||
tileEntity = world.getTileEntity(pos.up());
|
||||
} else {
|
||||
tileEntity = world.getTileEntity(pos);
|
||||
}
|
||||
return (DDTileEntityBase) tileEntity;
|
||||
return (TileEntityRift) tileEntity;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -2,7 +2,7 @@ package com.zixiken.dimdoors.shared.blocks;
|
|||
|
||||
import com.zixiken.dimdoors.DimDoors;
|
||||
import com.zixiken.dimdoors.shared.items.ModItems;
|
||||
import com.zixiken.dimdoors.shared.tileentities.TileEntityDimDoorGold;
|
||||
import com.zixiken.dimdoors.shared.tileentities.TileEntityVerticalEntranceRift;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
@ -27,6 +27,6 @@ public class BlockDimDoorGold extends BlockDimDoorBase {
|
|||
|
||||
@Override
|
||||
public TileEntity createNewTileEntity(World worldIn, int meta) {
|
||||
return new TileEntityDimDoorGold();
|
||||
return new TileEntityVerticalEntranceRift();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ package com.zixiken.dimdoors.shared.blocks;
|
|||
|
||||
import com.zixiken.dimdoors.DimDoors;
|
||||
import com.zixiken.dimdoors.shared.items.ModItems;
|
||||
import com.zixiken.dimdoors.shared.tileentities.TileEntityDimDoorPersonal;
|
||||
import com.zixiken.dimdoors.shared.tileentities.TileEntityVerticalEntranceRift;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
@ -27,6 +27,6 @@ public class BlockDimDoorPersonal extends BlockDimDoorBase {
|
|||
|
||||
@Override
|
||||
public TileEntity createNewTileEntity(World worldIn, int meta) {
|
||||
return new TileEntityDimDoorPersonal();
|
||||
return new TileEntityVerticalEntranceRift();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,8 +2,9 @@ package com.zixiken.dimdoors.shared.blocks;
|
|||
|
||||
import com.zixiken.dimdoors.DimDoors;
|
||||
import com.zixiken.dimdoors.shared.items.ModItems;
|
||||
import com.zixiken.dimdoors.shared.tileentities.TileEntityDimDoorUnstable;
|
||||
import java.util.Random;
|
||||
|
||||
import com.zixiken.dimdoors.shared.tileentities.TileEntityVerticalEntranceRift;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.init.Items;
|
||||
|
@ -36,6 +37,6 @@ public class BlockDimDoorUnstable extends BlockDimDoorBase {
|
|||
|
||||
@Override
|
||||
public TileEntity createNewTileEntity(World worldIn, int meta) {
|
||||
return new TileEntityDimDoorUnstable();
|
||||
return new TileEntityVerticalEntranceRift();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ package com.zixiken.dimdoors.shared.blocks;
|
|||
|
||||
import com.zixiken.dimdoors.DimDoors;
|
||||
import com.zixiken.dimdoors.shared.items.ModItems;
|
||||
import com.zixiken.dimdoors.shared.tileentities.TileEntityDimDoorWarp;
|
||||
import com.zixiken.dimdoors.shared.tileentities.TileEntityVerticalEntranceRift;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
@ -27,6 +27,6 @@ public class BlockDimDoorWarp extends BlockDimDoorBase {
|
|||
|
||||
@Override
|
||||
public TileEntity createNewTileEntity(World worldIn, int meta) {
|
||||
return new TileEntityDimDoorWarp();
|
||||
return new TileEntityVerticalEntranceRift();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ package com.zixiken.dimdoors.shared.blocks;
|
|||
import java.util.Random;
|
||||
|
||||
import com.zixiken.dimdoors.DimDoors;
|
||||
import com.zixiken.dimdoors.shared.tileentities.TileEntityTransTrapdoor;
|
||||
import com.zixiken.dimdoors.shared.tileentities.TileEntityHorizontalEntranceRift;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockTrapDoor;
|
||||
import net.minecraft.block.ITileEntityProvider;
|
||||
|
@ -25,11 +25,11 @@ import net.minecraft.world.World;
|
|||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
public class BlockTransTrapdoor extends BlockTrapDoor implements IDimDoor, ITileEntityProvider {
|
||||
public class BlockDimTrapdoor extends BlockTrapDoor implements IDimDoor, ITileEntityProvider {
|
||||
|
||||
public static final String ID = "dimensional_trapdoor";
|
||||
|
||||
public BlockTransTrapdoor() {
|
||||
public BlockDimTrapdoor() {
|
||||
super(Material.WOOD);
|
||||
setCreativeTab(DimDoors.dimDoorsCreativeTab);
|
||||
setHardness(1.0F);
|
||||
|
@ -78,7 +78,7 @@ public class BlockTransTrapdoor extends BlockTrapDoor implements IDimDoor, ITile
|
|||
|
||||
@Override
|
||||
public TileEntity createNewTileEntity(World worldIn, int meta) {
|
||||
return new TileEntityTransTrapdoor();
|
||||
return new TileEntityHorizontalEntranceRift();
|
||||
}
|
||||
|
||||
@Override
|
|
@ -1,11 +1,9 @@
|
|||
package com.zixiken.dimdoors.shared.blocks;
|
||||
|
||||
import com.zixiken.dimdoors.DimDoors;
|
||||
import com.zixiken.dimdoors.client.ClosingRiftFX;
|
||||
import com.zixiken.dimdoors.shared.RiftRegistry;
|
||||
import com.zixiken.dimdoors.shared.items.ModItems;
|
||||
import com.zixiken.dimdoors.shared.tileentities.DDTileEntityBase;
|
||||
import com.zixiken.dimdoors.shared.tileentities.TileEntityRift;
|
||||
import com.zixiken.dimdoors.shared.tileentities.TileEntityFloatingRift;
|
||||
|
||||
import java.util.*;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockLiquid;
|
||||
|
@ -28,7 +26,6 @@ import net.minecraft.util.math.RayTraceResult;
|
|||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.fluids.IFluidBlock;
|
||||
import net.minecraftforge.fml.client.FMLClientHandler;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
|
@ -41,7 +38,7 @@ public class BlockRift extends Block implements ITileEntityProvider {
|
|||
private final ArrayList<Block> modBlocksImmuneToRift; // List of DD blocks immune to rifts
|
||||
|
||||
public BlockRift() {
|
||||
super(Material.LEAVES); //Fire is replacable. We do not want this block to be replacable. We do want to walf through it though...
|
||||
super(Material.LEAVES); //Fire is replacable. We do not want this block to be replacable. We do want to walk through it though...
|
||||
setTickRandomly(true);
|
||||
setHardness(1.0F);
|
||||
setUnlocalizedName(ID);
|
||||
|
@ -130,7 +127,7 @@ public class BlockRift extends Block implements ITileEntityProvider {
|
|||
}
|
||||
|
||||
/**
|
||||
* regulates the render effect, especially when multiple rifts start to link
|
||||
* regulates the renderDoorRift effect, especially when multiple rifts start to link
|
||||
* up. Has 3 main parts- Grows toward and away from nearest rift, bends
|
||||
* toward it, and a randomization function
|
||||
*/
|
||||
|
@ -141,20 +138,20 @@ public class BlockRift extends Block implements ITileEntityProvider {
|
|||
//TODO: implement the parts specified in the method comment?
|
||||
int x = pos.getX(), y = pos.getY(), z = pos.getZ();
|
||||
|
||||
TileEntityRift tile = (TileEntityRift) worldIn.getTileEntity(pos);
|
||||
TileEntityFloatingRift tile = (TileEntityFloatingRift) worldIn.getTileEntity(pos);
|
||||
//renders an extra little blob on top of the actual rift location so its easier to find.
|
||||
// Eventually will only render if the player has the goggles.
|
||||
// Eventually will only renderDoorRift if the player has the goggles.
|
||||
/*FMLClientHandler.instance().getClient().effectRenderer.addEffect(new GoggleRiftFX(
|
||||
worldIn,
|
||||
x + .5, y + .5, z + .5,
|
||||
rand.nextGaussian() * 0.01D, rand.nextGaussian() * 0.01D, rand.nextGaussian() * 0.01D));
|
||||
*/
|
||||
if (tile.shouldClose) {//renders an opposite color effect if it is being closed by the rift remover
|
||||
FMLClientHandler.instance().getClient().effectRenderer.addEffect(new ClosingRiftFX(
|
||||
worldIn,
|
||||
x + .5, y + .5, z + .5,
|
||||
rand.nextGaussian() * 0.01D, rand.nextGaussian() * 0.01D, rand.nextGaussian() * 0.01D));
|
||||
}
|
||||
//if (tile.shouldClose) {//renders an opposite color effect if it is being closed by the rift remover
|
||||
// FMLClientHandler.instance().getClient().effectRenderer.addEffect(new ClosingRiftFX(
|
||||
// worldIn,
|
||||
// x + .5, y + .5, z + .5,
|
||||
// rand.nextGaussian() * 0.01D, rand.nextGaussian() * 0.01D, rand.nextGaussian() * 0.01D));
|
||||
//} // TODO
|
||||
}
|
||||
|
||||
public boolean tryPlacingRift(World world, BlockPos pos) {
|
||||
|
@ -191,20 +188,13 @@ public class BlockRift extends Block implements ITileEntityProvider {
|
|||
|
||||
@Override
|
||||
public TileEntity createNewTileEntity(World worldIn, int meta) {
|
||||
return new TileEntityRift();
|
||||
return new TileEntityFloatingRift();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void breakBlock(World worldIn, BlockPos pos, IBlockState state) {
|
||||
TileEntityRift riftTile = (TileEntityRift) worldIn.getTileEntity(pos);
|
||||
if (riftTile == null || !riftTile.placingDoorOnRift) {
|
||||
DimDoors.log(getClass(), "Unregistering rift at position " + pos + ", because it is destroyed (creative) or has closed.");
|
||||
RiftRegistry.INSTANCE.unregisterLastChangedRift();
|
||||
} else {
|
||||
DimDoors.log(getClass(), "Not unregistering rift at position " + pos + ", because it is being replaced by a door.");
|
||||
riftTile.placingDoorOnRift = false; //probably not needed, but it shouldn't hurt to do this
|
||||
}
|
||||
worldIn.removeTileEntity(pos);
|
||||
TileEntityFloatingRift riftTile = (TileEntityFloatingRift) worldIn.getTileEntity(pos);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -212,7 +202,7 @@ public class BlockRift extends Block implements ITileEntityProvider {
|
|||
return false;
|
||||
}
|
||||
|
||||
public DDTileEntityBase getRiftTile(World world, BlockPos pos, IBlockState state) {
|
||||
return (DDTileEntityBase) world.getTileEntity(pos);
|
||||
public TileEntityFloatingRift getRiftTile(World world, BlockPos pos, IBlockState state) {
|
||||
return (TileEntityFloatingRift) world.getTileEntity(pos);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ public class ModBlocks {
|
|||
public static final BlockDimDoorUnstable UNSTABLE_DIMENSIONAL_DOOR = new BlockDimDoorUnstable();
|
||||
public static final BlockDimDoorTransient TRANSIENT_DIMENSIONAL_DOOR = new BlockDimDoorTransient();
|
||||
public static final BlockDimDoorWarp WARP_DIMENSIONAL_DOOR = new BlockDimDoorWarp();
|
||||
public static final BlockTransTrapdoor DIMENSIONAL_TRAPDOOR = new BlockTransTrapdoor();
|
||||
public static final BlockDimTrapdoor DIMENSIONAL_TRAPDOOR = new BlockDimTrapdoor();
|
||||
|
||||
// Blocks
|
||||
public static final BlockFabric FABRIC = new BlockFabric();
|
||||
|
|
|
@ -2,6 +2,7 @@ package com.zixiken.dimdoors.shared.commands;
|
|||
|
||||
import com.zixiken.dimdoors.DimDoors;
|
||||
import com.zixiken.dimdoors.shared.*;
|
||||
import com.zixiken.dimdoors.shared.pockets.*;
|
||||
import com.zixiken.dimdoors.shared.util.StringUtils;
|
||||
import com.zixiken.dimdoors.shared.util.Location;
|
||||
import com.zixiken.dimdoors.shared.world.DimDoorDimensions;
|
||||
|
@ -54,16 +55,15 @@ public class PocketCommand extends CommandBase {
|
|||
|
||||
int dimID = origLoc.getDimensionID();
|
||||
if (DimDoorDimensions.isPocketDimensionID(dimID)) {
|
||||
int pocketID = PocketRegistry.INSTANCE.getPocketIDFromCoords(origLoc);
|
||||
EnumPocketType type = DimDoorDimensions.getPocketType(dimID);
|
||||
Pocket oldPocket = PocketRegistry.INSTANCE.getPocket(pocketID, type);
|
||||
origLoc = oldPocket.getDepthZeroLocation();
|
||||
int pocketID = PocketRegistry.getForDim(dimID).getIDFromLocation(origLoc);
|
||||
Pocket oldPocket = PocketRegistry.getForDim(dimID).getPocket(pocketID);
|
||||
}
|
||||
|
||||
PocketTemplate template = SchematicHandler.INSTANCE.getTemplate(args[0], args[1]);
|
||||
Pocket pocket = PocketRegistry.INSTANCE.generatePocketAt(EnumPocketType.DUNGEON, 1, origLoc, template);
|
||||
int entranceDoorID = pocket.getEntranceDoorID();
|
||||
RiftRegistry.INSTANCE.setLastGeneratedEntranceDoorID(entranceDoorID);
|
||||
Pocket pocket = PocketGenerator.generatePocketFromTemplate(dimID, 0, template, 0);
|
||||
int entranceDoorID = pocket.getEntranceRiftID();
|
||||
//RiftRegistry.INSTANCE.setLastGeneratedEntranceDoorID(entranceDoorID);
|
||||
// TODO: teleport the player
|
||||
}
|
||||
} else {
|
||||
DimDoors.log("Not executing command /" + getName() + " because it wasn't sent by a player.");
|
||||
|
|
|
@ -6,8 +6,8 @@ import java.util.List;
|
|||
import com.zixiken.dimdoors.DimDoors;
|
||||
import com.zixiken.dimdoors.shared.blocks.BlockDimDoorBase;
|
||||
import com.zixiken.dimdoors.shared.RayTraceHelper;
|
||||
import com.zixiken.dimdoors.shared.tileentities.TileEntityDimDoor;
|
||||
import com.zixiken.dimdoors.shared.tileentities.TileEntityRift;
|
||||
import com.zixiken.dimdoors.shared.tileentities.TileEntityVerticalEntranceRift;
|
||||
import com.zixiken.dimdoors.shared.tileentities.TileEntityFloatingRift;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.util.ITooltipFlag;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
|
@ -114,8 +114,8 @@ public abstract class ItemDoorBase extends ItemDoor {
|
|||
boolean flag = i < 0 && hitZ < 0.5F || i > 0 && hitZ > 0.5F || j < 0 && hitX > 0.5F || j > 0 && hitX < 0.5F; //Vanilla Minecraft code not consistently using EnumFacing
|
||||
//fetch "the" tile entity at the top block of where the door is going to be placed
|
||||
TileEntity possibleOldRift = world.getTileEntity(pos.up());
|
||||
if (possibleOldRift instanceof TileEntityRift) {
|
||||
TileEntityRift oldRift = (TileEntityRift) possibleOldRift;
|
||||
if (possibleOldRift instanceof TileEntityFloatingRift) {
|
||||
TileEntityFloatingRift oldRift = (TileEntityFloatingRift) possibleOldRift;
|
||||
oldRift.placingDoorOnRift = true;
|
||||
}
|
||||
//place the door
|
||||
|
@ -126,10 +126,10 @@ public abstract class ItemDoorBase extends ItemDoor {
|
|||
stack.setCount(stack.getCount()-1);
|
||||
}
|
||||
|
||||
//fetch the TileEntityDimDoor at the top block of where the door has just been placed
|
||||
TileEntityDimDoor newTileEntityDimDoor = (TileEntityDimDoor) world.getTileEntity(pos.up());
|
||||
//fetch the TileEntityVerticalEntranceRift at the top block of where the door has just been placed
|
||||
TileEntityVerticalEntranceRift newTileEntityVerticalEntranceRift = (TileEntityVerticalEntranceRift) world.getTileEntity(pos.up());
|
||||
//set the tile-entity's initial data
|
||||
newTileEntityDimDoor.uponDoorPlacement(possibleOldRift);
|
||||
// newTileEntityVerticalEntranceRift.uponDoorPlacement(possibleOldRift); // TODO
|
||||
return EnumActionResult.SUCCESS;
|
||||
} else {
|
||||
return EnumActionResult.FAIL;
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
package com.zixiken.dimdoors.shared.items;
|
||||
|
||||
import com.zixiken.dimdoors.DimDoors;
|
||||
import com.zixiken.dimdoors.shared.tileentities.TileEntityFloatingRift;
|
||||
import com.zixiken.dimdoors.shared.util.Location;
|
||||
import com.zixiken.dimdoors.shared.RayTraceHelper;
|
||||
import com.zixiken.dimdoors.shared.TeleporterDimDoors;
|
||||
import com.zixiken.dimdoors.shared.tileentities.TileEntityRift;
|
||||
import net.minecraft.client.util.ITooltipFlag;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
@ -58,7 +58,7 @@ public class ItemRiftBlade extends ItemSword {
|
|||
//SchematicHandler.Instance.getPersonalPocketTemplate().place(0, 20, 0, 20, 0, 0, 1, EnumPocketType.DUNGEON); //this line can be activated for testing purposes
|
||||
RayTraceResult hit = rayTrace(worldIn, playerIn, true);
|
||||
if (RayTraceHelper.isRift(hit, worldIn)) {
|
||||
TileEntityRift rift = (TileEntityRift) worldIn.getTileEntity(hit.getBlockPos());
|
||||
TileEntityFloatingRift rift = (TileEntityFloatingRift) worldIn.getTileEntity(hit.getBlockPos());
|
||||
rift.isTeleporting = true;
|
||||
rift.teleportingEntity = playerIn;
|
||||
|
||||
|
|
|
@ -7,8 +7,8 @@ package com.zixiken.dimdoors.shared.items;
|
|||
|
||||
import com.zixiken.dimdoors.DimDoors;
|
||||
import com.zixiken.dimdoors.shared.RayTraceHelper;
|
||||
import com.zixiken.dimdoors.shared.RiftRegistry;
|
||||
import com.zixiken.dimdoors.shared.tileentities.DDTileEntityBase;
|
||||
import com.zixiken.dimdoors.shared.tileentities.TileEntityFloatingRift;
|
||||
|
||||
import java.util.HashSet;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
@ -53,7 +53,7 @@ public class ItemRiftConnectionTool extends ItemTool {
|
|||
|
||||
RayTraceResult hit = rayTrace(worldIn, playerIn, true);
|
||||
if (RayTraceHelper.isAbstractRift(hit, worldIn)) {
|
||||
DDTileEntityBase rift = (DDTileEntityBase) worldIn.getTileEntity(hit.getBlockPos());
|
||||
TileEntityFloatingRift rift = (TileEntityFloatingRift) worldIn.getTileEntity(hit.getBlockPos());
|
||||
if (playerIn.isSneaking()) {
|
||||
return selectRift(stack, worldIn, rift, playerIn); //new ActionResult(EnumActionResult.PASS, stack));
|
||||
}
|
||||
|
@ -64,27 +64,27 @@ public class ItemRiftConnectionTool extends ItemTool {
|
|||
return new ActionResult<>(EnumActionResult.FAIL, stack);
|
||||
}
|
||||
|
||||
private ActionResult<ItemStack> selectRift(ItemStack stack, World worldIn, DDTileEntityBase rift, EntityPlayer playerIn) {
|
||||
private ActionResult<ItemStack> selectRift(ItemStack stack, World worldIn, TileEntityFloatingRift rift, EntityPlayer playerIn) {
|
||||
NBTTagCompound compound = stack.getTagCompound();
|
||||
if (compound.getBoolean("isInConnectMode")) {
|
||||
if (compound.hasKey("RiftID")) {
|
||||
int primaryRiftID = compound.getInteger("RiftID");
|
||||
int secondaryRiftID = rift.getRiftID();
|
||||
DimDoors.chat(playerIn, "Pairing rift " + primaryRiftID
|
||||
+ " with rift " + secondaryRiftID + ".");
|
||||
RiftRegistry.INSTANCE.pair(primaryRiftID, secondaryRiftID);
|
||||
//int secondaryRiftID = rift.getRiftID(); TODO rift
|
||||
//DimDoors.chat(playerIn, "Pairing rift " + primaryRiftID
|
||||
// + " with rift " + secondaryRiftID + ".");
|
||||
//RiftRegistry.INSTANCE.pair(primaryRiftID, secondaryRiftID); TODO rift
|
||||
compound.removeTag("RiftID");
|
||||
stack.damageItem(1, playerIn);
|
||||
} else {
|
||||
int riftID = rift.getRiftID();
|
||||
compound.setInteger("RiftID", riftID);
|
||||
DimDoors.chat(playerIn, "Rift " + riftID + " stored for connecting.");
|
||||
//int riftID = rift.getRiftID();
|
||||
//compound.setInteger("RiftID", riftID);
|
||||
//DimDoors.chat(playerIn, "Rift " + riftID + " stored for connecting.");
|
||||
}
|
||||
} else {
|
||||
if (!worldIn.isRemote) {
|
||||
int riftID = rift.getRiftID();
|
||||
RiftRegistry.INSTANCE.unpair(riftID);
|
||||
DimDoors.chat(playerIn, "Rift " + riftID + " and its paired rift are now disconnected.");
|
||||
//int riftID = rift.getRiftID();
|
||||
//RiftRegistry.INSTANCE.unpair(riftID);
|
||||
//DimDoors.chat(playerIn, "Rift " + riftID + " and its paired rift are now disconnected.");
|
||||
}
|
||||
stack.damageItem(1, playerIn);
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package com.zixiken.dimdoors.shared;
|
||||
package com.zixiken.dimdoors.shared.pockets;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -13,7 +13,7 @@ public enum EnumPocketType {
|
|||
|
||||
PRIVATE, PUBLIC, DUNGEON;
|
||||
|
||||
static EnumPocketType getFromInt(int integer) {
|
||||
public static EnumPocketType getFromInt(int integer) {
|
||||
switch (integer) {
|
||||
case 0:
|
||||
return EnumPocketType.PRIVATE;
|
||||
|
@ -25,7 +25,7 @@ public enum EnumPocketType {
|
|||
}
|
||||
}
|
||||
|
||||
int getIntValue() {
|
||||
public int getIntValue() {
|
||||
switch (this) {
|
||||
case PRIVATE:
|
||||
return 0;
|
|
@ -0,0 +1,46 @@
|
|||
package com.zixiken.dimdoors.shared.pockets;
|
||||
|
||||
import lombok.Value;
|
||||
|
||||
public class GridUtils {
|
||||
@Value
|
||||
public static class GridPos {
|
||||
private int x;
|
||||
private int z;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates the grid position for a certain element number in the grid.
|
||||
*
|
||||
* @param num The element's number in the grid
|
||||
* @return The location on the grid
|
||||
*/
|
||||
public static GridPos numToPos(int num) { // TODO: alternate the sign on every number to have negative coords too
|
||||
// Grows by adding two sides to a square, keeping both x and z positive
|
||||
int layer = (int) Math.sqrt(num); // The layer of the square, the innermost being layer 0
|
||||
int layerNumber = num - layer * layer; // The number of the spot on that layer
|
||||
// | First Side | Second Side |
|
||||
int x = layerNumber <= layer ? layer : layer - (layerNumber - layer);
|
||||
int z = layerNumber <= layer ? layerNumber : layer;
|
||||
|
||||
return new GridPos(x, z);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates the element number
|
||||
*
|
||||
* @param pos The location on the grid
|
||||
* @return The location on the grid
|
||||
*/
|
||||
public static int posToNum(GridPos pos) { // TODO: comments
|
||||
int x = pos.getX();
|
||||
int z = pos.getZ();
|
||||
if (x >= z) {
|
||||
return x * x + z;
|
||||
} else {
|
||||
return (z + 2) * z - z;
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: add more modes, such as spiral, triangle, etc.?
|
||||
}
|
139
src/main/java/com/zixiken/dimdoors/shared/pockets/Pocket.java
Normal file
139
src/main/java/com/zixiken/dimdoors/shared/pockets/Pocket.java
Normal file
|
@ -0,0 +1,139 @@
|
|||
package com.zixiken.dimdoors.shared.pockets;
|
||||
|
||||
import com.zixiken.dimdoors.shared.util.Location;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.nbt.NBTBase;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagInt;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.nbt.NBTTagString;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Robijnvogel
|
||||
*/
|
||||
public class Pocket { // TODO: better visibilities
|
||||
|
||||
@Getter int id; // Not saved
|
||||
@Getter /*private*/ int dimID; // Not saved
|
||||
|
||||
@Getter private int x; // Grid x
|
||||
@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 originalDim; // The non-pocket dimension from which this dungeon was created
|
||||
private List<Integer> riftIDs;
|
||||
private List<String> playerUUIDs;
|
||||
|
||||
private Pocket() {}
|
||||
|
||||
Pocket(int id, int dimID, int x, int z, int depth) {
|
||||
this.id = id;
|
||||
this.dimID = dimID;
|
||||
this.x = x;
|
||||
this.z = z;
|
||||
this.depth = depth;
|
||||
riftIDs = new ArrayList<>();
|
||||
playerUUIDs = new ArrayList<>();
|
||||
}
|
||||
|
||||
static Pocket readFromNBT(NBTTagCompound pocketNBT) {
|
||||
Pocket pocket = new Pocket();
|
||||
pocket.id = pocketNBT.getInteger("id");
|
||||
pocket.x = pocketNBT.getInteger("x");
|
||||
pocket.z = pocketNBT.getInteger("z");
|
||||
pocket.depth = pocketNBT.getInteger("depth");
|
||||
pocket.size = pocketNBT.getInteger("size");
|
||||
pocket.originalDim = pocketNBT.getInteger("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<>();
|
||||
NBTTagList playersTagList = (NBTTagList) pocketNBT.getTag("playerUUIDs");
|
||||
for (int i = 0; i < playersTagList.tagCount(); i++) {
|
||||
pocket.playerUUIDs.add(playersTagList.getStringTagAt(i));
|
||||
}
|
||||
|
||||
return pocket;
|
||||
}
|
||||
|
||||
static NBTBase writeToNBT(Pocket pocket) {
|
||||
NBTTagCompound pocketNBT = new NBTTagCompound();
|
||||
pocketNBT.setInteger("id", pocket.id);
|
||||
pocketNBT.setInteger("x", pocket.x);
|
||||
pocketNBT.setInteger("z", pocket.z);
|
||||
pocketNBT.setInteger("depth", pocket.depth);
|
||||
pocketNBT.setInteger("size", pocket.size);
|
||||
pocketNBT.setInteger("originalDim", pocket.originalDim);
|
||||
|
||||
NBTTagList riftIDsTagList = 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++) {
|
||||
NBTTagString playerTag = new NBTTagString(pocket.playerUUIDs.get(i));
|
||||
playersTagList.appendTag(playerTag);
|
||||
}
|
||||
pocketNBT.setTag("playerUUIDs", playersTagList);
|
||||
|
||||
return pocketNBT;
|
||||
}
|
||||
|
||||
public void addRiftID(int id) {
|
||||
riftIDs.add(id);
|
||||
}
|
||||
|
||||
public int getEntranceRiftID() {
|
||||
if (riftIDs.isEmpty()) {
|
||||
return -1;
|
||||
} else if (riftIDs.size() == 1) {
|
||||
return riftIDs.get(0);
|
||||
} else {
|
||||
for (Integer riftID : riftIDs) {
|
||||
//TileEntity tileEntity = RiftRegistry.INSTANCE.getRiftLocation(riftID).getTileEntity(); // TODO rift
|
||||
//if (tileEntity instanceof TileEntityDimDoorWarp) {
|
||||
// return riftID;
|
||||
//}
|
||||
}
|
||||
Random random = new Random(); // TODO: weighted random?
|
||||
return riftIDs.get(random.nextInt(riftIDs.size()));
|
||||
}
|
||||
}
|
||||
|
||||
boolean isLocationWithinPocketBounds(final Location location, final int gridSize) {
|
||||
int locX = location.getPos().getX();
|
||||
int locZ = location.getPos().getY();
|
||||
// pocket bounds
|
||||
int pocMinX = x * gridSize;
|
||||
int pocMinZ = z * gridSize;
|
||||
int pocMaxX = pocMinX + (size + 1) * 16;
|
||||
int pocMaxZ = pocMinX + (size + 1) * 16;
|
||||
return pocMinX <= locX && pocMinZ <= locZ && locX < pocMaxX && locZ < pocMaxZ;
|
||||
}
|
||||
|
||||
public void validatePlayerEntry(EntityPlayer player) { // TODO
|
||||
String playerUUID = player.getCachedUniqueIdString();
|
||||
if (!playerUUIDs.contains(playerUUID)) {
|
||||
playerUUIDs.add(playerUUID);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isPlayerAllowedInPocket(EntityPlayer player) { // TODO
|
||||
String playerUUID = player.getCachedUniqueIdString();
|
||||
return playerUUIDs.contains(playerUUID);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
package com.zixiken.dimdoors.shared.pockets;
|
||||
|
||||
import com.zixiken.dimdoors.DimDoors;
|
||||
import com.zixiken.dimdoors.shared.*;
|
||||
import com.zixiken.dimdoors.shared.world.DimDoorDimensions;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class PocketGenerator {
|
||||
|
||||
public static Pocket generatePocketFromTemplate(int dimID, int depth, PocketTemplate pocketTemplate, int originalDim) {
|
||||
DimDoors.log("depth = " + depth + " originalDim = " + originalDim);
|
||||
|
||||
PocketRegistry registry = PocketRegistry.getForDim(dimID);
|
||||
Pocket pocket = registry.newPocket(depth);
|
||||
pocketTemplate.place(pocket, 0); // TODO: config option for yBase or maybe param?
|
||||
pocket.setOriginalDim(originalDim);
|
||||
return pocket;
|
||||
}
|
||||
|
||||
public Pocket generatePrivatePocket(int originalDim) {
|
||||
PocketTemplate pocketTemplate = SchematicHandler.INSTANCE.getPersonalPocketTemplate();
|
||||
return generatePocketFromTemplate(DimDoorDimensions.getPrivateDimID(), 0, pocketTemplate, originalDim);
|
||||
}
|
||||
|
||||
public Pocket generatePublicPocket(int originalDim) {
|
||||
PocketTemplate pocketTemplate = SchematicHandler.INSTANCE.getPersonalPocketTemplate();
|
||||
return generatePocketFromTemplate(DimDoorDimensions.getPrivateDimID(), 0, pocketTemplate, originalDim);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a dungeon pocket at a certain depth.
|
||||
*
|
||||
* @param depth The depth of the dungeon
|
||||
* @param originalDim The non-pocket dimension from which this dungeon was created
|
||||
* @return The newly-generated dungeon pocket
|
||||
*/
|
||||
public Pocket generateDungeonPocket(int depth, int originalDim) { // TODO: Add rift for linking!
|
||||
float netherProbability = originalDim == -1 ? 1 : (float) depth / 50; // TODO: improve nether probability
|
||||
Random random = new Random();
|
||||
String group = random.nextFloat() < netherProbability ? "nether" : "ruins";
|
||||
PocketTemplate pocketTemplate = SchematicHandler.INSTANCE.getRandomTemplate(group, depth, DDConfig.getMaxPocketSize(), false);
|
||||
|
||||
return generatePocketFromTemplate(DimDoorDimensions.getDungeonDimID(), depth, pocketTemplate, originalDim);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,241 @@
|
|||
package com.zixiken.dimdoors.shared.pockets;
|
||||
|
||||
import com.zixiken.dimdoors.shared.DDConfig;
|
||||
import com.zixiken.dimdoors.shared.util.Location;
|
||||
import com.zixiken.dimdoors.DimDoors;
|
||||
import com.zixiken.dimdoors.shared.util.NBTUtils;
|
||||
import com.zixiken.dimdoors.shared.util.WorldUtils;
|
||||
import com.zixiken.dimdoors.shared.world.DimDoorDimensions;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import lombok.Getter;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.world.storage.MapStorage;
|
||||
import net.minecraft.world.storage.WorldSavedData;
|
||||
|
||||
public class PocketRegistry extends WorldSavedData {
|
||||
|
||||
private static final String DATA_NAME = DimDoors.MODID + "_pockets";
|
||||
@Getter private static final int DATA_VERSION = 0; // IMPORTANT: Update this and upgradeRegistry when making changes.
|
||||
|
||||
@Getter private int gridSize; // Determines how much pockets in their dimension are spaced
|
||||
@Getter private int maxPocketSize;
|
||||
@Getter private int privatePocketSize;
|
||||
@Getter private int publicPocketSize;
|
||||
private Map<String, Integer> privatePocketMap; // Player UUID -> Pocket ID
|
||||
@Getter private Map<Integer, Pocket> pockets; // TODO: remove getter?
|
||||
|
||||
@Getter private int dimID;
|
||||
@Getter private int nextFreeID;
|
||||
|
||||
public PocketRegistry() {
|
||||
super(DATA_NAME);
|
||||
}
|
||||
|
||||
public PocketRegistry(String s) {
|
||||
super(s);
|
||||
}
|
||||
|
||||
public static PocketRegistry getForDim(int dimID) {
|
||||
if (!DimDoorDimensions.isPocketDimensionID(dimID)) throw new UnsupportedOperationException("PocketRegistry is only available for pocket dimensions!");
|
||||
|
||||
MapStorage storage = WorldUtils.getWorld(dimID).getPerWorldStorage();
|
||||
PocketRegistry instance = (PocketRegistry) storage.getOrLoadData(PocketRegistry.class, DATA_NAME);
|
||||
|
||||
if (instance == null) {
|
||||
instance = new PocketRegistry();
|
||||
instance.initNewRegistry();
|
||||
storage.setData(DATA_NAME, instance);
|
||||
}
|
||||
|
||||
instance.dimID = dimID;
|
||||
return instance;
|
||||
}
|
||||
|
||||
public void initNewRegistry() {
|
||||
gridSize = DDConfig.getPocketGridSize();
|
||||
maxPocketSize = DDConfig.getMaxPocketSize();
|
||||
privatePocketSize = DDConfig.getPrivatePocketSize();
|
||||
publicPocketSize = DDConfig.getPublicPocketSize();
|
||||
|
||||
nextFreeID = 0;
|
||||
pockets = new HashMap<>();
|
||||
privatePocketMap = new HashMap<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound nbt) {
|
||||
Integer version = nbt.getInteger("version");
|
||||
if (version == null || version != DATA_VERSION) {
|
||||
if (upgradeRegistry(nbt, version == null ? -1 : version)) {
|
||||
markDirty();
|
||||
} else {
|
||||
DimDoors.warn("Failed to upgrade the pocket registry, you'll have to recreate your world!");
|
||||
throw new RuntimeException("Couldn't upgrade registry"); // TODO: better exceptions
|
||||
}
|
||||
}
|
||||
|
||||
gridSize = nbt.getInteger("gridSize");
|
||||
maxPocketSize = nbt.getInteger("maxPocketSize");
|
||||
privatePocketSize = nbt.getInteger("privatePocketSize");
|
||||
publicPocketSize = nbt.getInteger("publicPocketSize");
|
||||
privatePocketMap = NBTUtils.readMapStringInteger(nbt.getCompoundTag("privatePocketMap"));
|
||||
|
||||
NBTTagList pocketsTagList = (NBTTagList) nbt.getTag("pockets");
|
||||
pockets = new HashMap<>();
|
||||
for (int id = 0; id < pocketsTagList.tagCount(); id++) { // TODO: convert to map to be able to skip IDs efficiently
|
||||
NBTTagCompound pocketTag = pocketsTagList.getCompoundTagAt(id);
|
||||
if (!pocketTag.getBoolean("nullPocket")) {
|
||||
Pocket pocket = Pocket.readFromNBT(pocketTag);
|
||||
pockets.put(id, pocket);
|
||||
}
|
||||
}
|
||||
|
||||
for (Pocket pocket : pockets.values()) {
|
||||
pocket.dimID = dimID;
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean upgradeRegistry(NBTTagCompound nbt, int oldVersion) {
|
||||
if (oldVersion > DATA_VERSION) throw new RuntimeException("Upgrade the mod!"); // TODO: better exceptions
|
||||
switch (oldVersion) {
|
||||
case -1: // No version tag
|
||||
return false;
|
||||
case 0:
|
||||
// Upgrade to 1 or return false
|
||||
case 1:
|
||||
// Upgrade to 2 or return false
|
||||
case 2:
|
||||
// Upgrade to 3 or return false
|
||||
// ...
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTTagCompound writeToNBT(NBTTagCompound nbt) {
|
||||
nbt.setInteger("version", DATA_VERSION);
|
||||
|
||||
nbt.setInteger("gridSize", gridSize);
|
||||
nbt.setInteger("maxPocketSize", maxPocketSize);
|
||||
nbt.setInteger("privatePocketSize", privatePocketSize);
|
||||
nbt.setInteger("publicPocketSize", publicPocketSize);
|
||||
nbt.setTag("privatePocketMap", NBTUtils.writeMapStringInteger(privatePocketMap));
|
||||
|
||||
NBTTagList pocketsTagList = new NBTTagList();
|
||||
for (int i = 0; i < nextFreeID; i++) {
|
||||
Pocket pocket = pockets.get(i);
|
||||
if (pocket == null) {
|
||||
NBTTagCompound nullPocket = new NBTTagCompound();
|
||||
nullPocket.setBoolean("nullPocket", true);
|
||||
pocketsTagList.appendTag(nullPocket);
|
||||
} else {
|
||||
pocketsTagList.appendTag(Pocket.writeToNBT(pocket));
|
||||
}
|
||||
}
|
||||
nbt.setTag("pockets", pocketsTagList);
|
||||
|
||||
return nbt;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new blank pocket.
|
||||
*
|
||||
* @return The newly created Pocket
|
||||
*/
|
||||
public Pocket newPocket(int depth) {
|
||||
Pocket pocket = null;
|
||||
while(pocket == null) pocket = newPocket(nextFreeID++, depth); // TODO: config option to reuse IDs (start at 0 rather than nextFreePocket)
|
||||
return pocket;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new pocket with a specific ID. IMPORTANT: This generates data for all pockets with an ID below, so don't set
|
||||
* too high!
|
||||
*
|
||||
* @return The newly created Pocket, or null if that ID is taken already.
|
||||
*/
|
||||
public Pocket newPocket(int id, int depth) {
|
||||
if (pockets.get(id) != null) return null;
|
||||
GridUtils.GridPos pos = getGridPosFromID(id);
|
||||
Pocket pocket = new Pocket(id, dimID, pos.getX(), pos.getZ(), depth);
|
||||
pockets.put(id, pocket);
|
||||
if (id >= nextFreeID) nextFreeID = id + 1;
|
||||
markDirty();
|
||||
return pocket;
|
||||
}
|
||||
|
||||
public void removePocket(int id) {
|
||||
pockets.remove(id);
|
||||
markDirty();
|
||||
}
|
||||
|
||||
// TODO: Lookup functions such as getPocketByType/Depth/etc.
|
||||
|
||||
/**
|
||||
* Gets the pocket with a certain ID, or null if there is no pocket with that ID.
|
||||
*
|
||||
* @return The pocket with that ID, or null if there was no pocket with that ID.
|
||||
*/
|
||||
public Pocket getPocket(int id) {
|
||||
return pockets.get(id);
|
||||
}
|
||||
|
||||
public int getPrivatePocketID(String playerUUID) {
|
||||
Integer id = privatePocketMap.get(playerUUID);
|
||||
if (id == null) return -1;
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setPrivatePocketID(String playerUUID, int id) {
|
||||
privatePocketMap.put(playerUUID, id);
|
||||
}
|
||||
|
||||
public GridUtils.GridPos getGridPosFromID(int id) {
|
||||
return GridUtils.numToPos(id);
|
||||
}
|
||||
|
||||
public int getIDFromGridPos(GridUtils.GridPos pos) {
|
||||
return GridUtils.posToNum(pos);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates the default Location where a pocket should be based on the ID. Use this only for placing
|
||||
* pockets, and use Pocket.getGridPos() for getting the position
|
||||
*
|
||||
* @param id The ID of the pocket
|
||||
* @return The Location of the pocket
|
||||
*/
|
||||
public Location getLocationFromID(int id) {
|
||||
GridUtils.GridPos pos = getGridPosFromID(id);
|
||||
return new Location(dimID, pos.getX() * gridSize * 16, 0, pos.getZ() * gridSize * 16);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates the ID of a pocket based on the Location.
|
||||
*
|
||||
* @param location The location of the pocket
|
||||
* @return The ID of the pocket, or -1 if there is no pocket at that location
|
||||
*/
|
||||
public int getIDFromLocation(Location location) {
|
||||
if (location != null && location.getDimensionID() != dimID) throw new RuntimeException("Wrong registry for this world!");
|
||||
int x = location.getPos().getX();
|
||||
int z = location.getPos().getZ();
|
||||
int id = getIDFromGridPos(new GridUtils.GridPos(x / (gridSize * 16), z / (gridSize * 16)));
|
||||
return pockets.containsKey(id) ? id : -1;
|
||||
}
|
||||
|
||||
public boolean isPlayerAllowedToBeHere(EntityPlayerMP player, Location location) { // TODO see getLocationFromID
|
||||
int pocketID = getIDFromLocation(location);
|
||||
if (pocketID == -1) { // outside of a pocket
|
||||
return false;
|
||||
} else {
|
||||
Pocket pocket = pockets.get(pocketID);
|
||||
return pocket.isPlayerAllowedInPocket(player) && pocket.isLocationWithinPocketBounds(location, gridSize);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -3,18 +3,17 @@
|
|||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package com.zixiken.dimdoors.shared;
|
||||
package com.zixiken.dimdoors.shared.pockets;
|
||||
|
||||
import com.zixiken.dimdoors.shared.tileentities.TileEntityVerticalEntranceRift;
|
||||
import com.zixiken.dimdoors.shared.tileentities.TileEntityRift;
|
||||
import com.zixiken.dimdoors.shared.util.Schematic;
|
||||
import com.zixiken.dimdoors.DimDoors;
|
||||
import com.zixiken.dimdoors.shared.blocks.BlockDimDoorBase;
|
||||
import com.zixiken.dimdoors.shared.tileentities.DDTileEntityBase;
|
||||
import com.zixiken.dimdoors.shared.tileentities.TileEntityDimDoor;
|
||||
import com.zixiken.dimdoors.shared.util.Location;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
|
@ -29,21 +28,19 @@ import net.minecraft.world.WorldServer;
|
|||
*/
|
||||
public class PocketTemplate { //there is exactly one pocket placer for each different schematic that is loaded into the game (a Json might load several schematics though)
|
||||
|
||||
// TODO: access levels
|
||||
//generation parameters
|
||||
@Getter @Setter(value = AccessLevel.PACKAGE) private Schematic schematic; // TODO: access level
|
||||
@Getter @Setter private Schematic schematic;
|
||||
@Getter private final int size;
|
||||
@Getter private final EnumPocketType typeID;
|
||||
//selection parameters
|
||||
@Getter private final String groupName;
|
||||
@Getter private final String name;
|
||||
private String variantType;
|
||||
@Getter private final int minDepth;
|
||||
@Getter private final int maxDepth;
|
||||
private final int[] weights; //weights for chanced generation of dungeons per depth level | weights[0] is the weight for depth "minDepth"
|
||||
|
||||
//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,
|
||||
EnumPocketType typeID, int minDepth, int maxDepth, int[] weights) {
|
||||
public PocketTemplate(String groupName, String name, Schematic schematic, int size, int minDepth, int maxDepth, int[] weights) {
|
||||
this.groupName = groupName;
|
||||
this.name = name;
|
||||
this.weights = weights; //chance that this Pocket will get generated
|
||||
|
@ -51,15 +48,13 @@ public class PocketTemplate { //there is exactly one pocket placer for each diff
|
|||
this.maxDepth = maxDepth; //to this pocket depth
|
||||
this.size = size; //size of pocket in chunks (0 -> 1*1 chunk, 1 -> 2*2 chunks etc.)
|
||||
this.schematic = schematic;
|
||||
this.typeID = typeID;
|
||||
}
|
||||
|
||||
public PocketTemplate(String groupName, String name, int size,
|
||||
EnumPocketType typeID, int minDepth, int maxDepth, int[] weights) {
|
||||
this(groupName, name, null, size, typeID, minDepth, maxDepth, weights);
|
||||
public PocketTemplate(String groupName, String name, int size, int minDepth, int maxDepth, int[] weights) {
|
||||
this(groupName, name, null, size, minDepth, maxDepth, weights);
|
||||
}
|
||||
|
||||
int getWeight(int depth) {
|
||||
public int getWeight(int depth) {
|
||||
int index = depth - minDepth;
|
||||
if (index >= 0 && index < weights.length) {
|
||||
return weights[index];
|
||||
|
@ -67,10 +62,12 @@ public class PocketTemplate { //there is exactly one pocket placer for each diff
|
|||
return weights[weights.length - 1]; // return last weight
|
||||
}
|
||||
|
||||
//@todo make sure that the "pocketID" parameter gets used, or remove it.
|
||||
public Pocket place(int shortenedX, int yBase, int shortenedZ, int gridSize, int dimID, int pocketID, int depth, EnumPocketType pocketTypeID, Location depthZeroLocation) { //returns the riftID of the entrance DimDoor
|
||||
int xBase = shortenedX * gridSize * 16;
|
||||
int zBase = shortenedZ * gridSize * 16;
|
||||
public Pocket place(Pocket pocket, int yBase) { //returns the riftID of the entrance DimDoor
|
||||
pocket.setSize(size); // TODO: check that this works properly
|
||||
int gridSize = PocketRegistry.getForDim(pocket.dimID).getGridSize();
|
||||
int dimID = pocket.dimID;
|
||||
int xBase = pocket.getX() * gridSize * 16;
|
||||
int zBase = pocket.getZ() * gridSize * 16;
|
||||
DimDoors.log(getClass(), "Placing new pocket at x = " + xBase + ", z = " + zBase);
|
||||
DimDoors.log(getClass(), "Name of new pocket schematic is " + schematic.getSchematicName());
|
||||
|
||||
|
@ -93,17 +90,17 @@ public class PocketTemplate { //there is exactly one pocket placer for each diff
|
|||
}
|
||||
|
||||
//Load TileEntity Data
|
||||
List<DDTileEntityBase> rifts = new ArrayList<>();
|
||||
List<TileEntityRift> rifts = new ArrayList<>();
|
||||
for (NBTTagCompound tileEntityNBT : schematic.getTileEntities()) {
|
||||
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);
|
||||
TileEntity tileEntity = world.getTileEntity(pos);
|
||||
if (tileEntity != null) {
|
||||
if (tileEntity instanceof DDTileEntityBase) {
|
||||
if (tileEntity instanceof TileEntityRift) {
|
||||
DimDoors.log(getClass(), "Rift found in schematic: " + pos);
|
||||
DDTileEntityBase rift = (DDTileEntityBase) tileEntity;
|
||||
TileEntityRift rift = (TileEntityRift) tileEntity;
|
||||
rifts.add(rift);
|
||||
if (rift instanceof TileEntityDimDoor) {
|
||||
if (rift instanceof TileEntityVerticalEntranceRift) {
|
||||
DimDoors.proxy.updateDoorTE((BlockDimDoorBase) world.getBlockState(pos).getBlock(), world, pos);
|
||||
}
|
||||
} else {
|
||||
|
@ -118,16 +115,8 @@ public class PocketTemplate { //there is exactly one pocket placer for each diff
|
|||
}
|
||||
}
|
||||
|
||||
List<Integer> riftIDs = new ArrayList<>();
|
||||
for (DDTileEntityBase rift : rifts) {
|
||||
rift.register(depth);
|
||||
rift.setIsInPocket();
|
||||
rift.setPocket(pocketID, pocketTypeID);
|
||||
rift.setDepth(depth);
|
||||
// TODO: rifts!
|
||||
|
||||
riftIDs.add(rift.getRiftID());
|
||||
}
|
||||
|
||||
return new Pocket(size, depth, pocketTypeID, shortenedX, shortenedZ, riftIDs, depthZeroLocation);
|
||||
return pocket;
|
||||
}
|
||||
}
|
|
@ -1,200 +0,0 @@
|
|||
package com.zixiken.dimdoors.shared.tileentities;
|
||||
|
||||
import com.zixiken.dimdoors.DimDoors;
|
||||
import com.zixiken.dimdoors.shared.EnumPocketType;
|
||||
import com.zixiken.dimdoors.shared.Pocket;
|
||||
import com.zixiken.dimdoors.shared.PocketRegistry;
|
||||
import com.zixiken.dimdoors.shared.util.Location;
|
||||
import com.zixiken.dimdoors.shared.RiftRegistry;
|
||||
import java.util.Random;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.ITickable;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public abstract class DDTileEntityBase extends TileEntity implements ITickable {
|
||||
|
||||
//Short life fields
|
||||
public boolean isTeleporting = false;
|
||||
public Entity teleportingEntity;
|
||||
|
||||
//Class specific value fields
|
||||
protected boolean canRiftBePaired = true;
|
||||
|
||||
//Need to be saved:
|
||||
protected boolean isPaired = false;
|
||||
protected int riftID = -1; //should not start at 0
|
||||
protected int pairedRiftID = -1;
|
||||
protected boolean isInPocket = false;
|
||||
protected int pocketID = -1;
|
||||
protected EnumPocketType pocketType;
|
||||
protected int depth = 0; //depth of the pocket it is in (not in a pocket -> 0)
|
||||
|
||||
/**
|
||||
*
|
||||
* @param rand
|
||||
* @return an array of floats representing RGBA color where 1.0 = 255.
|
||||
*/
|
||||
public abstract float[] getRenderColor(Random rand);
|
||||
|
||||
@Override
|
||||
public boolean shouldRefresh(World world, BlockPos pos, IBlockState oldState, IBlockState newSate) {
|
||||
return oldState.getBlock() != newSate.getBlock();
|
||||
}
|
||||
|
||||
public boolean pair(int otherRiftID) { //should only ever be called from the RiftRegistry.pair method
|
||||
if (isPaired) {
|
||||
if (otherRiftID == pairedRiftID) {
|
||||
return true;
|
||||
} else {
|
||||
RiftRegistry.INSTANCE.unpair(pairedRiftID);
|
||||
}
|
||||
}
|
||||
pairedRiftID = otherRiftID;
|
||||
isPaired = true;
|
||||
RiftRegistry.INSTANCE.pair(pairedRiftID, riftID); //make sure it gets paired the other way around
|
||||
markDirty();
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean unpair() { //should only ever be called from the RiftRegistry.unpair method
|
||||
if (!isPaired) {
|
||||
return true;
|
||||
} else {
|
||||
isPaired = false;
|
||||
RiftRegistry.INSTANCE.unpair(pairedRiftID);
|
||||
markDirty();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void register(int depth) {
|
||||
//if (riftID == -1) { //this check only causes problems?
|
||||
riftID = RiftRegistry.INSTANCE.registerNewRift(this, depth);
|
||||
DimDoors.log(getClass(), "Finished registering rift as ID: " + riftID);
|
||||
|
||||
markDirty();
|
||||
//}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound compound) {
|
||||
super.readFromNBT(compound);
|
||||
try {
|
||||
isPaired = compound.getBoolean("isPaired");
|
||||
riftID = compound.getInteger("riftID");
|
||||
pairedRiftID = compound.getInteger("pairedRiftID");
|
||||
isInPocket = compound.getBoolean("isInPocket");
|
||||
pocketID = compound.getInteger("pocketID");
|
||||
if (compound.hasKey("pocketType")) {
|
||||
pocketType = EnumPocketType.valueOf(compound.getString("pocketType"));
|
||||
}
|
||||
depth = compound.getInteger("depth");
|
||||
} catch (Exception e) {
|
||||
//reading these values should only fail on loading old saves, or loading old schematics, in which case the default values will do
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTTagCompound writeToNBT(NBTTagCompound nbt) {
|
||||
super.writeToNBT(nbt);
|
||||
nbt.setBoolean("isPaired", isPaired);
|
||||
nbt.setInteger("riftID", riftID);
|
||||
nbt.setInteger("pairedRiftID", pairedRiftID);
|
||||
nbt.setBoolean("isInPocket", isInPocket);
|
||||
nbt.setInteger("pocketID", pocketID);
|
||||
if (pocketType != null) {
|
||||
nbt.setString("pocketType", pocketType.name());
|
||||
}
|
||||
nbt.setInteger("depth", depth);
|
||||
return nbt;
|
||||
}
|
||||
|
||||
public void loadDataFrom(DDTileEntityBase rift2) {
|
||||
if (rift2 != null && rift2.riftID != -1) {
|
||||
isPaired = rift2.isPaired;
|
||||
riftID = rift2.riftID; //should not start at 0
|
||||
pairedRiftID = rift2.pairedRiftID;
|
||||
|
||||
isInPocket = rift2.isInPocket;
|
||||
pocketID = rift2.pocketID;
|
||||
pocketType = rift2.pocketType;
|
||||
depth = rift2.depth;
|
||||
|
||||
markDirty();
|
||||
}
|
||||
}
|
||||
|
||||
public int getRiftID() {
|
||||
return riftID;
|
||||
}
|
||||
|
||||
public int getPairedRiftID() {
|
||||
return pairedRiftID;
|
||||
}
|
||||
|
||||
public boolean isPaired() {
|
||||
return isPaired;
|
||||
}
|
||||
|
||||
public int getDepth() {
|
||||
return depth;
|
||||
}
|
||||
|
||||
public Location getTeleportTargetLocation() {
|
||||
return new Location(getWorld().provider.getDimension(), getPos());
|
||||
}
|
||||
|
||||
public abstract boolean tryTeleport(Entity entity);
|
||||
|
||||
public void setPocket(int id, EnumPocketType type) {
|
||||
pocketID = id;
|
||||
pocketType = type;
|
||||
isInPocket = true;
|
||||
markDirty();
|
||||
}
|
||||
|
||||
public void setIsInPocket() {
|
||||
isInPocket = true;
|
||||
markDirty();
|
||||
}
|
||||
|
||||
public void setDepth(int depth) {
|
||||
this.depth = depth;
|
||||
markDirty();
|
||||
}
|
||||
|
||||
protected EnumPocketType getPocketType() {
|
||||
return pocketType;
|
||||
}
|
||||
|
||||
public void validatePlayerPocketEntry(EntityPlayer player) {
|
||||
if (isInPocket && pocketType != EnumPocketType.PRIVATE) {
|
||||
Pocket pocket = PocketRegistry.INSTANCE.getPocket(pocketID, pocketType);
|
||||
pocket.validatePlayerEntry(player);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
if (isTeleporting && teleportingEntity != null) {
|
||||
if (!tryTeleport(teleportingEntity)) {
|
||||
if (teleportingEntity instanceof EntityPlayer) {
|
||||
EntityPlayer entityPlayer = (EntityPlayer) teleportingEntity;
|
||||
DimDoors.chat(entityPlayer, "Teleporting failed, but since mod is still in alpha, stuff like that might simply happen.");
|
||||
// TODO: It's normal for teleportation to sometimes fail, for example for an unlinked warp door. Change this to an exception-based system to print error only when it really fails?
|
||||
}
|
||||
}
|
||||
isTeleporting = false;
|
||||
teleportingEntity = null;
|
||||
}
|
||||
}
|
||||
|
||||
public int getPocketID() {
|
||||
return isInPocket ? pocketID : -1;
|
||||
}
|
||||
}
|
|
@ -1,148 +0,0 @@
|
|||
package com.zixiken.dimdoors.shared.tileentities;
|
||||
|
||||
import com.zixiken.dimdoors.DimDoors;
|
||||
import com.zixiken.dimdoors.shared.DDConfig;
|
||||
import com.zixiken.dimdoors.shared.EnumPocketType;
|
||||
import com.zixiken.dimdoors.shared.Pocket;
|
||||
import com.zixiken.dimdoors.shared.PocketRegistry;
|
||||
import com.zixiken.dimdoors.shared.blocks.BlockDimDoor;
|
||||
import com.zixiken.dimdoors.shared.util.Location;
|
||||
import com.zixiken.dimdoors.shared.RiftRegistry;
|
||||
import com.zixiken.dimdoors.shared.TeleporterDimDoors;
|
||||
import com.zixiken.dimdoors.shared.util.RandomUtils;
|
||||
import com.zixiken.dimdoors.shared.world.DimDoorDimensions;
|
||||
import java.util.Random;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
|
||||
public class TileEntityDimDoor extends DDTileEntityBase {
|
||||
|
||||
public boolean doorIsOpen = false;
|
||||
public EnumFacing orientation = EnumFacing.SOUTH;
|
||||
public byte lockStatus = 0;
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound nbt) {
|
||||
super.readFromNBT(nbt);
|
||||
|
||||
try {
|
||||
doorIsOpen = nbt.getBoolean("doorIsOpen");
|
||||
orientation = EnumFacing.getFront(nbt.getInteger("orientation"));
|
||||
lockStatus = nbt.getByte("lockStatus");
|
||||
} catch (Exception e) {
|
||||
DimDoors.warn(getClass(), "An error occured while trying to read this object from NBT.");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTTagCompound writeToNBT(NBTTagCompound nbt) {
|
||||
super.writeToNBT(nbt);
|
||||
|
||||
nbt.setBoolean("doorIsOpen", doorIsOpen);
|
||||
nbt.setInteger("orientation", orientation.getIndex());
|
||||
nbt.setByte("lockStatus", lockStatus);
|
||||
return nbt;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float[] getRenderColor(Random rand) {
|
||||
float[] rgbaColor = {1, 1, 1, 1};
|
||||
if (world.provider.getDimension() == -1) {
|
||||
rgbaColor[0] = rand.nextFloat() * 0.5F + 0.4F;
|
||||
rgbaColor[1] = rand.nextFloat() * 0.05F;
|
||||
rgbaColor[2] = rand.nextFloat() * 0.05F;
|
||||
} else {
|
||||
rgbaColor[0] = rand.nextFloat() * 0.5F + 0.1F;
|
||||
rgbaColor[1] = rand.nextFloat() * 0.4F + 0.4F;
|
||||
rgbaColor[2] = rand.nextFloat() * 0.6F + 0.5F;
|
||||
}
|
||||
|
||||
return rgbaColor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Location getTeleportTargetLocation() {
|
||||
return new Location(getWorld().provider.getDimension(), getPos().offset(orientation).down());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean tryTeleport(Entity entity) {
|
||||
int otherRiftID;
|
||||
if (!isPaired()) {
|
||||
otherRiftID = getNewTeleportDestination();
|
||||
} else {
|
||||
otherRiftID = getPairedRiftID();
|
||||
}
|
||||
Location tpLocation = RiftRegistry.INSTANCE.getTeleportLocation(otherRiftID);
|
||||
if (tpLocation == null) {
|
||||
DimDoors.warn(getClass(), "Location of rift teleporting to is null.");
|
||||
return false;
|
||||
}
|
||||
RiftRegistry.INSTANCE.validatePlayerPocketEntry(entity, otherRiftID);
|
||||
return TeleporterDimDoors.instance().teleport(entity, tpLocation); //@todo this seems to return false?
|
||||
}
|
||||
|
||||
public void uponDoorPlacement(@Nullable TileEntity possibleOldRift) {
|
||||
if (possibleOldRift instanceof DDTileEntityBase) {
|
||||
DDTileEntityBase oldRift = (DDTileEntityBase) possibleOldRift;
|
||||
//load data from old rift (that must already have been registered)
|
||||
loadDataFrom(oldRift);
|
||||
} else {
|
||||
Location locationOfThisRift = new Location(world, pos);
|
||||
pocketID = PocketRegistry.INSTANCE.getPocketIDFromCoords(locationOfThisRift);
|
||||
|
||||
if (pocketID >= 0) {
|
||||
isInPocket = true;
|
||||
pocketType = DimDoorDimensions.getPocketType(locationOfThisRift.getDimensionID());
|
||||
Pocket pocket = PocketRegistry.INSTANCE.getPocket(pocketID, pocketType);
|
||||
depth = pocket.getDepth();
|
||||
}
|
||||
//default data and set register this rift in the registry
|
||||
register(depth); //depth is 0 by default; registration sets this rift's riftID
|
||||
|
||||
if (pocketID >= 0) {
|
||||
Pocket pocket = PocketRegistry.INSTANCE.getPocket(pocketID, pocketType);
|
||||
pocket.addRiftID(riftID); //@todo not used yet?
|
||||
}
|
||||
}
|
||||
//storing the orientation inside the tile-entity, because that thing can actually save the orientation in the worldsave, unlike the block itself, which fail at that stuff somehow
|
||||
orientation = getWorld().getBlockState(getPos()).getValue(BlockDimDoor.FACING).getOpposite(); //@todo since this is used to determine the render of the "portal, this gets reset to the "wrong" side every time the door gets updated
|
||||
}
|
||||
|
||||
protected int getNewTeleportDestination() {
|
||||
int otherRiftID;
|
||||
Location locationOfThisRift = RiftRegistry.INSTANCE.getRiftLocation(riftID); //returns null if this rift isn't registered
|
||||
|
||||
if (isInPocket && pocketType == EnumPocketType.DUNGEON) {
|
||||
Location origLocation = PocketRegistry.INSTANCE.getPocket(pocketID, pocketType).getDepthZeroLocation();
|
||||
//choose between generating a new pocket or connecting to another door on a similar or close depth
|
||||
if (RandomUtils.weightedBoolean(20, 80)) { //@todo make this configurable
|
||||
otherRiftID = RiftRegistry.INSTANCE.getRandomUnpairedRiftIDAroundDepth(getRiftID(), depth);
|
||||
if (otherRiftID < 0) { //ergo: no other rift can be found
|
||||
//@todo, this should rarely happen. Put in an easter egg?
|
||||
otherRiftID = PocketRegistry.INSTANCE.generateRandomPocketAt(EnumPocketType.DUNGEON, getRandomlyTransFormedDepth(), origLocation).getEntranceDoorID();
|
||||
}
|
||||
} else {
|
||||
otherRiftID = PocketRegistry.INSTANCE.generateRandomPocketAt(EnumPocketType.DUNGEON, getRandomlyTransFormedDepth(), origLocation).getEntranceDoorID();
|
||||
}
|
||||
} else {
|
||||
otherRiftID = PocketRegistry.INSTANCE.generateRandomPocketAt(EnumPocketType.PUBLIC, 0, locationOfThisRift).getEntranceDoorID(); //@todo should this depth be 1 instead?
|
||||
}
|
||||
|
||||
if (otherRiftID < 0) {
|
||||
DimDoors.warn(getClass(), "No suitable destination rift was found. This probably means that a pocket was created without any Doors.");
|
||||
} else {
|
||||
//@todo (should the other rift get loaded?)
|
||||
RiftRegistry.INSTANCE.pair(getRiftID(), otherRiftID);
|
||||
}
|
||||
|
||||
return otherRiftID;
|
||||
}
|
||||
|
||||
protected int getRandomlyTransFormedDepth() {
|
||||
return RandomUtils.transformRandomly(depth, DDConfig.getDoorRelativeDepths(), DDConfig.getDoorRelativeDepthWeights());
|
||||
}
|
||||
}
|
|
@ -1,87 +0,0 @@
|
|||
package com.zixiken.dimdoors.shared.tileentities;
|
||||
|
||||
import com.zixiken.dimdoors.DimDoors;
|
||||
import com.zixiken.dimdoors.shared.EnumPocketType;
|
||||
import com.zixiken.dimdoors.shared.IChunkLoader;
|
||||
import com.zixiken.dimdoors.shared.PocketRegistry;
|
||||
import com.zixiken.dimdoors.shared.RiftRegistry;
|
||||
import com.zixiken.dimdoors.shared.util.Location;
|
||||
import com.zixiken.dimdoors.shared.world.DimDoorDimensions;
|
||||
import net.minecraftforge.common.ForgeChunkManager;
|
||||
import net.minecraftforge.common.ForgeChunkManager.Ticket;
|
||||
|
||||
public class TileEntityDimDoorGold extends TileEntityDimDoor implements IChunkLoader {
|
||||
|
||||
private Ticket chunkTicket;
|
||||
private boolean initialized = false;
|
||||
|
||||
@Override
|
||||
public boolean isInitialized() {
|
||||
return initialized;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(Ticket ticket) {
|
||||
initialized = true;
|
||||
chunkTicket = ticket;
|
||||
|
||||
/*
|
||||
// Only do anything if this function is running on the server side
|
||||
// NOTE: We don't have to check whether this block is the upper door
|
||||
// block or the lower one because only one of them should have a
|
||||
// link associated with it.
|
||||
if (!worldObj.isRemote) {
|
||||
DimData dimension = PocketManager.createDimensionData(worldObj);
|
||||
|
||||
// Check whether a ticket has already been assigned to this door
|
||||
if (chunkTicket == null) {
|
||||
// No ticket yet.
|
||||
// Check if this area should be loaded and request a new ticket.
|
||||
if (isValidChunkLoaderSetup(dimension)) {
|
||||
chunkTicket = ChunkLoaderHelper.createTicket(pos, worldObj);
|
||||
}
|
||||
} else {
|
||||
// A ticket has already been provided.
|
||||
// Check if this area should be loaded. If not, release the ticket.
|
||||
if (!isValidChunkLoaderSetup(dimension)) {
|
||||
ForgeChunkManager.releaseTicket(chunkTicket);
|
||||
chunkTicket = null;
|
||||
}
|
||||
}
|
||||
|
||||
// If chunkTicket isn't null at this point, then this is a valid door setup.
|
||||
// The last step is to request force loading of the pocket's chunks.
|
||||
if (chunkTicket != null) {
|
||||
ChunkLoaderHelper.forcePocketChunks(dimension, chunkTicket);
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invalidate() {
|
||||
ForgeChunkManager.releaseTicket(chunkTicket);
|
||||
super.invalidate();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getNewTeleportDestination() {
|
||||
//DimDoors.log(this.getClass(), "Trying to find suitable destination rift.");
|
||||
int otherRiftID = RiftRegistry.INSTANCE.getRandomUnpairedRiftIDAtDepth(getRiftID(), depth);
|
||||
if (otherRiftID < 0) {
|
||||
Location origLocation = RiftRegistry.INSTANCE.getRiftLocation(riftID);
|
||||
if (origLocation.getDimensionID() == DimDoorDimensions.getPocketDimensionType(EnumPocketType.DUNGEON).getId()) { //if this dimdoor is a pocket Dungeon
|
||||
origLocation = PocketRegistry.INSTANCE.getPocket(pocketID, pocketType).getDepthZeroLocation();
|
||||
}
|
||||
otherRiftID = PocketRegistry.INSTANCE.generateRandomPocketAt(EnumPocketType.DUNGEON, getRandomlyTransFormedDepth(), origLocation).getEntranceDoorID();
|
||||
}
|
||||
|
||||
if (otherRiftID < 0) {
|
||||
DimDoors.warn(getClass(), "No suitable destination rift was found. This probably means that a pocket was created without any Doors.");
|
||||
} else {
|
||||
RiftRegistry.INSTANCE.pair(getRiftID(), otherRiftID);
|
||||
}
|
||||
|
||||
return otherRiftID;
|
||||
}
|
||||
}
|
|
@ -1,47 +0,0 @@
|
|||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package com.zixiken.dimdoors.shared.tileentities;
|
||||
|
||||
import com.zixiken.dimdoors.shared.EnumPocketType;
|
||||
import com.zixiken.dimdoors.shared.PocketRegistry;
|
||||
import com.zixiken.dimdoors.shared.RiftRegistry;
|
||||
import com.zixiken.dimdoors.shared.TeleporterDimDoors;
|
||||
import com.zixiken.dimdoors.shared.util.Location;
|
||||
import com.zixiken.dimdoors.shared.world.DimDoorDimensions;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Robijnvogel
|
||||
*/
|
||||
public class TileEntityDimDoorPersonal extends TileEntityDimDoor {
|
||||
|
||||
public TileEntityDimDoorPersonal() {
|
||||
canRiftBePaired = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean tryTeleport(Entity entity) { //this door is never paired
|
||||
Location locationOfThisRift = RiftRegistry.INSTANCE.getRiftLocation(riftID);
|
||||
Location tpLocation;
|
||||
if (entity instanceof EntityPlayer) {
|
||||
EntityPlayer entityPlayer = (EntityPlayer) entity;
|
||||
if (locationOfThisRift.getDimensionID() == DimDoorDimensions.getPocketDimensionType(EnumPocketType.PRIVATE).getId()) {
|
||||
tpLocation = PocketRegistry.INSTANCE.getPocket(pocketID, EnumPocketType.PRIVATE).getDepthZeroLocation();
|
||||
} else {
|
||||
int otherDoorID = PocketRegistry.INSTANCE.getPrivateDimDoorID(entityPlayer.getCachedUniqueIdString());
|
||||
tpLocation = RiftRegistry.INSTANCE.getTeleportLocation(otherDoorID);
|
||||
int privatePocketID = RiftRegistry.INSTANCE.getPocketID(otherDoorID);
|
||||
PocketRegistry.INSTANCE.getPocket(privatePocketID, EnumPocketType.PRIVATE).setDepthZeroLocation(getTeleportTargetLocation());
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return TeleporterDimDoors.instance().teleport(entity, tpLocation);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,30 +0,0 @@
|
|||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package com.zixiken.dimdoors.shared.tileentities;
|
||||
|
||||
import com.zixiken.dimdoors.shared.RiftRegistry;
|
||||
import com.zixiken.dimdoors.shared.TeleporterDimDoors;
|
||||
import com.zixiken.dimdoors.shared.util.Location;
|
||||
import net.minecraft.entity.Entity;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Robijnvogel
|
||||
*/
|
||||
public class TileEntityDimDoorUnstable extends TileEntityDimDoor {
|
||||
|
||||
public TileEntityDimDoorUnstable() {
|
||||
canRiftBePaired = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean tryTeleport(Entity entity) { //this door is never paired
|
||||
int otherRiftID = RiftRegistry.INSTANCE.getRandomNonPersonalRiftID();
|
||||
Location tpLocation = RiftRegistry.INSTANCE.getTeleportLocation(otherRiftID);
|
||||
RiftRegistry.INSTANCE.validatePlayerPocketEntry(entity, otherRiftID);
|
||||
return TeleporterDimDoors.instance().teleport(entity, tpLocation);
|
||||
}
|
||||
}
|
|
@ -1,27 +0,0 @@
|
|||
package com.zixiken.dimdoors.shared.tileentities;
|
||||
|
||||
import com.zixiken.dimdoors.shared.Pocket;
|
||||
import com.zixiken.dimdoors.shared.PocketRegistry;
|
||||
import com.zixiken.dimdoors.shared.RiftRegistry;
|
||||
import com.zixiken.dimdoors.shared.TeleporterDimDoors;
|
||||
import com.zixiken.dimdoors.shared.util.Location;
|
||||
import net.minecraft.entity.Entity;
|
||||
|
||||
public class TileEntityDimDoorWarp extends TileEntityDimDoor {
|
||||
|
||||
@Override
|
||||
public boolean tryTeleport(Entity entity) {
|
||||
Location tpLocation;
|
||||
if (isPaired()) {
|
||||
int otherRiftID = getPairedRiftID();
|
||||
tpLocation = RiftRegistry.INSTANCE.getTeleportLocation(otherRiftID);
|
||||
RiftRegistry.INSTANCE.validatePlayerPocketEntry(entity, otherRiftID);
|
||||
} else if (!isInPocket) {
|
||||
return false;
|
||||
} else {
|
||||
Pocket pocket = PocketRegistry.INSTANCE.getPocket(pocketID, getPocketType());
|
||||
tpLocation = pocket.getDepthZeroLocation();
|
||||
}
|
||||
return TeleporterDimDoors.instance().teleport(entity, tpLocation);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
package com.zixiken.dimdoors.shared.tileentities;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public abstract class TileEntityEntranceRift extends TileEntityRift {
|
||||
// TODO: merge horizontal and vertical entrances' render code into one, and support custom sizes
|
||||
|
||||
public float[] getEntranceRenderColor(Random rand) { // Use RGBA instead? Would that be slow because of object creation?
|
||||
if (world.provider.getDimension() != -1) {
|
||||
float red = rand.nextFloat() * 0.5F + 0.4F;
|
||||
float green = rand.nextFloat() * 0.05F;
|
||||
float blue = rand.nextFloat() * 0.05F;
|
||||
return new float[] {red, green, blue, 1};
|
||||
} else {
|
||||
float red = rand.nextFloat() * 0.5F + 0.1F;
|
||||
float green = rand.nextFloat() * 0.4F + 0.4F;
|
||||
float blue = rand.nextFloat() * 0.6F + 0.5F;
|
||||
return new float[] {red, green, blue, 1};
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,126 @@
|
|||
package com.zixiken.dimdoors.shared.tileentities;
|
||||
|
||||
import com.zixiken.dimdoors.shared.blocks.ModBlocks;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.monster.EntityEnderman;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.ITickable;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
|
||||
public class TileEntityFloatingRift extends TileEntityRift implements ITickable {
|
||||
|
||||
private static final int ENDERMAN_SPAWNING_CHANCE = 1;
|
||||
private static final int MAX_ENDERMAN_SPAWNING_CHANCE = 32;
|
||||
private static final int HOSTILE_ENDERMAN_CHANCE = 1;
|
||||
private static final int MAX_HOSTILE_ENDERMAN_CHANCE = 3;
|
||||
private static final int UPDATE_PERIOD = 200; //10 seconds
|
||||
|
||||
public boolean placingDoorOnRift = false; //to track whether a Rift is getting broken because it is replaced by a door (do not unregister in this case) or because it is being broken another way (do unregister in this case)
|
||||
|
||||
private static final Random random = new Random();
|
||||
|
||||
//Need to be saved:
|
||||
private int updateTimer;
|
||||
public boolean shouldClose = false;
|
||||
public int spawnedEndermenID = 0;
|
||||
public float growth = 0;
|
||||
|
||||
public TileEntityFloatingRift() {
|
||||
updateTimer = random.nextInt(UPDATE_PERIOD);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
if (world.getBlockState(pos).getBlock() != ModBlocks.RIFT) {
|
||||
invalidate();
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if this rift should render white closing particles and
|
||||
// spread the closing effect to other rifts nearby.
|
||||
if (shouldClose) {
|
||||
closeRift();
|
||||
return;
|
||||
}
|
||||
|
||||
if (updateTimer >= UPDATE_PERIOD) {
|
||||
spawnEndermen();
|
||||
updateTimer = 0;
|
||||
} else if (updateTimer == UPDATE_PERIOD / 2) {
|
||||
updateNearestRift();
|
||||
}
|
||||
growth += 1F / (growth + 1);
|
||||
updateTimer++;
|
||||
}
|
||||
|
||||
private void spawnEndermen() {
|
||||
if (world.isRemote) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Ensure that this rift is only spawning one Enderman at a time, to prevent hordes of Endermen
|
||||
Entity entity = world.getEntityByID(spawnedEndermenID);
|
||||
if (entity instanceof EntityEnderman) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (random.nextInt(MAX_ENDERMAN_SPAWNING_CHANCE) < ENDERMAN_SPAWNING_CHANCE) {
|
||||
// Endermen will only spawn from groups of rifts
|
||||
if (updateNearestRift()) {
|
||||
List<EntityEnderman> list = world.getEntitiesWithinAABB(EntityEnderman.class,
|
||||
new AxisAlignedBB(pos.getX() - 9, pos.getY() - 3, pos.getZ() - 9, pos.getX() + 9, pos.getY() + 3, pos.getZ() + 9));
|
||||
|
||||
if (list.isEmpty()) {
|
||||
EntityEnderman enderman = new EntityEnderman(world);
|
||||
enderman.setLocationAndAngles(pos.getX() + 0.5, pos.getY() - 1, pos.getZ() + 0.5, 5, 6);
|
||||
world.spawnEntity(enderman);
|
||||
|
||||
if (random.nextInt(MAX_HOSTILE_ENDERMAN_CHANCE) < HOSTILE_ENDERMAN_CHANCE) {
|
||||
EntityPlayer player = world.getClosestPlayerToEntity(enderman, 50);
|
||||
if (player != null) {
|
||||
enderman.setAttackTarget(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void closeRift() {
|
||||
world.setBlockToAir(pos);
|
||||
growth--; //@todo?
|
||||
}
|
||||
|
||||
public boolean updateNearestRift() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldRenderInPass(int pass) {
|
||||
return pass == 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound nbt) {
|
||||
super.readFromNBT(nbt);
|
||||
updateTimer = nbt.getInteger("updateTimer");
|
||||
shouldClose = nbt.getBoolean("shouldClose");
|
||||
spawnedEndermenID = nbt.getInteger("spawnedEndermenID");
|
||||
growth = nbt.getFloat("growth");
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTTagCompound writeToNBT(NBTTagCompound nbt) {
|
||||
super.writeToNBT(nbt);
|
||||
nbt.setInteger("updateTimer", updateTimer);
|
||||
nbt.setBoolean("shouldClose", shouldClose);
|
||||
nbt.setInteger("spawnedEndermenID", spawnedEndermenID);
|
||||
nbt.setFloat("growth", growth);
|
||||
|
||||
return nbt;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
package com.zixiken.dimdoors.shared.tileentities;
|
||||
|
||||
public class TileEntityHorizontalEntranceRift extends TileEntityEntranceRift {
|
||||
|
||||
}
|
|
@ -1,161 +1,65 @@
|
|||
package com.zixiken.dimdoors.shared.tileentities;
|
||||
|
||||
import com.zixiken.dimdoors.DimDoors;
|
||||
import com.zixiken.dimdoors.shared.blocks.ModBlocks;
|
||||
import com.zixiken.dimdoors.shared.RiftRegistry;
|
||||
import com.zixiken.dimdoors.shared.TeleporterDimDoors;
|
||||
import com.zixiken.dimdoors.shared.util.Location;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.monster.EntityEnderman;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.ITickable;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class TileEntityRift extends DDTileEntityBase implements ITickable {
|
||||
public abstract class TileEntityRift extends TileEntity implements ITickable {
|
||||
|
||||
private static final int ENDERMAN_SPAWNING_CHANCE = 1;
|
||||
private static final int MAX_ENDERMAN_SPAWNING_CHANCE = 32;
|
||||
private static final int HOSTILE_ENDERMAN_CHANCE = 1;
|
||||
private static final int MAX_HOSTILE_ENDERMAN_CHANCE = 3;
|
||||
private static final int UPDATE_PERIOD = 200; //10 seconds
|
||||
public boolean isTeleporting = false;
|
||||
public Entity teleportingEntity;
|
||||
|
||||
public boolean placingDoorOnRift = false; //to track whether a Rift is getting broken because it is replaced by a door (do not unregister in this case) or because it is being broken another way (do unregister in this case)
|
||||
|
||||
private static final Random random = new Random();
|
||||
|
||||
//Need to be saved:
|
||||
private int updateTimer;
|
||||
public BlockPos offset = BlockPos.ORIGIN;
|
||||
public boolean shouldClose = false;
|
||||
public int spawnedEndermenID = 0;
|
||||
public int riftRotation = random.nextInt(360);
|
||||
public float growth = 0;
|
||||
|
||||
public TileEntityRift() {
|
||||
loadDataFrom(RiftRegistry.INSTANCE.getLastChangedRift()); //@todo this should absolutely not be done in this constructor...
|
||||
|
||||
// Vary the update times of rifts to prevent all the rifts in a cluster
|
||||
// from updating at the same time.
|
||||
updateTimer = random.nextInt(UPDATE_PERIOD);
|
||||
@Override
|
||||
public boolean shouldRefresh(World world, BlockPos pos, IBlockState oldState, IBlockState newSate) {
|
||||
return oldState.getBlock() != newSate.getBlock();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
if (world.getBlockState(pos).getBlock() != ModBlocks.RIFT) {
|
||||
invalidate();
|
||||
return;
|
||||
}
|
||||
public void readFromNBT(NBTTagCompound compound) {
|
||||
super.readFromNBT(compound);
|
||||
|
||||
// Check if this rift should render white closing particles and
|
||||
// spread the closing effect to other rifts nearby.
|
||||
if (shouldClose) {
|
||||
closeRift();
|
||||
return;
|
||||
}
|
||||
|
||||
if (updateTimer >= UPDATE_PERIOD) {
|
||||
spawnEndermen();
|
||||
updateTimer = 0;
|
||||
} else if (updateTimer == UPDATE_PERIOD / 2) {
|
||||
updateNearestRift();
|
||||
}
|
||||
growth += 1F / (growth + 1);
|
||||
updateTimer++;
|
||||
}
|
||||
|
||||
private void spawnEndermen() {
|
||||
if (world.isRemote) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Ensure that this rift is only spawning one Enderman at a time, to prevent hordes of Endermen
|
||||
Entity entity = world.getEntityByID(spawnedEndermenID);
|
||||
if (entity instanceof EntityEnderman) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (random.nextInt(MAX_ENDERMAN_SPAWNING_CHANCE) < ENDERMAN_SPAWNING_CHANCE) {
|
||||
// Endermen will only spawn from groups of rifts
|
||||
if (updateNearestRift()) {
|
||||
List<EntityEnderman> list = world.getEntitiesWithinAABB(EntityEnderman.class,
|
||||
new AxisAlignedBB(pos.getX() - 9, pos.getY() - 3, pos.getZ() - 9, pos.getX() + 9, pos.getY() + 3, pos.getZ() + 9));
|
||||
|
||||
if (list.isEmpty()) {
|
||||
EntityEnderman enderman = new EntityEnderman(world);
|
||||
enderman.setLocationAndAngles(pos.getX() + 0.5, pos.getY() - 1, pos.getZ() + 0.5, 5, 6);
|
||||
world.spawnEntity(enderman);
|
||||
|
||||
if (random.nextInt(MAX_HOSTILE_ENDERMAN_CHANCE) < HOSTILE_ENDERMAN_CHANCE) {
|
||||
EntityPlayer player = world.getClosestPlayerToEntity(enderman, 50);
|
||||
if (player != null) {
|
||||
enderman.setAttackTarget(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void closeRift() {
|
||||
world.setBlockToAir(pos);
|
||||
growth--; //@todo?
|
||||
}
|
||||
|
||||
public boolean updateNearestRift() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldRenderInPass(int pass) {
|
||||
return pass == 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound nbt) {
|
||||
super.readFromNBT(nbt);
|
||||
updateTimer = nbt.getInteger("updateTimer");
|
||||
offset = new BlockPos(nbt.getInteger("xOffset"), nbt.getInteger("yOffset"), nbt.getInteger("zOffset"));
|
||||
shouldClose = nbt.getBoolean("shouldClose");
|
||||
spawnedEndermenID = nbt.getInteger("spawnedEndermenID");
|
||||
riftRotation = nbt.getInteger("riftRotation");
|
||||
growth = nbt.getFloat("growth");
|
||||
// TODO
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTTagCompound writeToNBT(NBTTagCompound nbt) {
|
||||
super.writeToNBT(nbt);
|
||||
nbt.setInteger("updateTimer", updateTimer);
|
||||
nbt.setInteger("xOffset", offset.getX());
|
||||
nbt.setInteger("yOffset", offset.getY());
|
||||
nbt.setInteger("zOffset", offset.getZ());
|
||||
nbt.setBoolean("shouldClose", shouldClose);
|
||||
nbt.setInteger("spawnedEndermenID", spawnedEndermenID);
|
||||
nbt.setInteger("riftRotation", riftRotation);
|
||||
nbt.setFloat("growth", growth);
|
||||
|
||||
// TODO
|
||||
|
||||
return nbt;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float[] getRenderColor(Random rand) {
|
||||
return null;
|
||||
public void copyFrom(TileEntityRift otherRift) {
|
||||
// TODO
|
||||
|
||||
markDirty();
|
||||
}
|
||||
|
||||
public boolean teleport(Entity entity) {
|
||||
// TODO: this function will handle all the teleportation logic for all rifts, including
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean tryTeleport(Entity entity) {
|
||||
int otherRiftID;
|
||||
if (!isPaired()) {
|
||||
DimDoors.warn(getClass(), "Rift " + getRiftID() + " was not paired and thus, should not exist as a Rift, unless it was unpaired after the door was destroyed, in which case you should contact the developers and tell them to fix stuff.");
|
||||
return false;
|
||||
} else {
|
||||
otherRiftID = getPairedRiftID();
|
||||
public void update() {
|
||||
if (isTeleporting && teleportingEntity != null) {
|
||||
if (!teleport(teleportingEntity)) {
|
||||
if (teleportingEntity instanceof EntityPlayer) {
|
||||
EntityPlayer entityPlayer = (EntityPlayer) teleportingEntity;
|
||||
DimDoors.chat(entityPlayer, "Teleporting failed, but since mod is still in alpha, stuff like that might simply happen.");
|
||||
// TODO: It's normal for teleportation to sometimes fail, for example for an unlinked warp door. Change this to an exception-based system to print error only when it really fails?
|
||||
}
|
||||
}
|
||||
isTeleporting = false;
|
||||
teleportingEntity = null;
|
||||
}
|
||||
Location tpLocation = RiftRegistry.INSTANCE.getTeleportLocation(otherRiftID);
|
||||
RiftRegistry.INSTANCE.validatePlayerPocketEntry(entity, otherRiftID);
|
||||
return TeleporterDimDoors.instance().teleport(entity, tpLocation); //@todo this seems to return false?
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,48 +0,0 @@
|
|||
package com.zixiken.dimdoors.shared.tileentities;
|
||||
|
||||
import com.zixiken.dimdoors.shared.Pocket;
|
||||
import com.zixiken.dimdoors.shared.PocketRegistry;
|
||||
import com.zixiken.dimdoors.shared.RiftRegistry;
|
||||
import com.zixiken.dimdoors.shared.TeleporterDimDoors;
|
||||
import com.zixiken.dimdoors.shared.util.Location;
|
||||
import java.util.Random;
|
||||
import net.minecraft.entity.Entity;
|
||||
|
||||
public class TileEntityTransTrapdoor extends DDTileEntityBase {
|
||||
|
||||
@Override
|
||||
public float[] getRenderColor(Random rand) {
|
||||
float[] rgbaColor = {1, 1, 1, 1};
|
||||
if (world.provider.getDimension() == -1) {
|
||||
rgbaColor[0] = world.rand.nextFloat() * 0.5F + 0.4F;
|
||||
rgbaColor[1] = world.rand.nextFloat() * 0.05F;
|
||||
rgbaColor[2] = world.rand.nextFloat() * 0.05F;
|
||||
} else {
|
||||
rgbaColor[0] = world.rand.nextFloat() * 0.5F + 0.1F;
|
||||
rgbaColor[1] = world.rand.nextFloat() * 0.4F + 0.4F;
|
||||
rgbaColor[2] = world.rand.nextFloat() * 0.6F + 0.5F;
|
||||
}
|
||||
return rgbaColor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Location getTeleportTargetLocation() {
|
||||
return new Location(getWorld().provider.getDimension(), getPos().up());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean tryTeleport(Entity entity) {
|
||||
Location tpLocation;
|
||||
if (isPaired()) {
|
||||
int otherRiftID = getPairedRiftID();
|
||||
tpLocation = RiftRegistry.INSTANCE.getTeleportLocation(otherRiftID);
|
||||
RiftRegistry.INSTANCE.validatePlayerPocketEntry(entity, otherRiftID);
|
||||
} else if (!isInPocket) {
|
||||
return false;
|
||||
} else {
|
||||
Pocket pocket = PocketRegistry.INSTANCE.getPocket(pocketID, getPocketType());
|
||||
tpLocation = pocket.getDepthZeroLocation();
|
||||
}
|
||||
return TeleporterDimDoors.instance().teleport(entity, tpLocation);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
package com.zixiken.dimdoors.shared.tileentities;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
|
||||
public class TileEntityVerticalEntranceRift extends TileEntityEntranceRift {
|
||||
|
||||
public boolean doorIsOpen = false;
|
||||
public EnumFacing orientation = EnumFacing.SOUTH;
|
||||
public byte lockStatus = 0;
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound nbt) {
|
||||
super.readFromNBT(nbt);
|
||||
|
||||
doorIsOpen = nbt.getBoolean("doorIsOpen");
|
||||
orientation = EnumFacing.getFront(nbt.getInteger("orientation"));
|
||||
lockStatus = nbt.getByte("lockStatus");
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTTagCompound writeToNBT(NBTTagCompound nbt) {
|
||||
super.writeToNBT(nbt);
|
||||
|
||||
nbt.setBoolean("doorIsOpen", doorIsOpen);
|
||||
nbt.setInteger("orientation", orientation.getIndex());
|
||||
nbt.setByte("lockStatus", lockStatus);
|
||||
return nbt;
|
||||
}
|
||||
}
|
23
src/main/java/com/zixiken/dimdoors/shared/util/NBTUtils.java
Normal file
23
src/main/java/com/zixiken/dimdoors/shared/util/NBTUtils.java
Normal file
|
@ -0,0 +1,23 @@
|
|||
package com.zixiken.dimdoors.shared.util;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
public class NBTUtils {
|
||||
public static Map<String, Integer> readMapStringInteger(NBTTagCompound nbt) {
|
||||
HashMap<String, Integer> map = new HashMap<>();
|
||||
for (String str : nbt.getKeySet()) {
|
||||
map.put(str, nbt.getInteger(str));
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
public static NBTTagCompound writeMapStringInteger(Map<String, Integer> map) {
|
||||
NBTTagCompound tagCompound = new NBTTagCompound();
|
||||
for (String str : map.keySet()) {
|
||||
tagCompound.setInteger(str, map.get(str));
|
||||
}
|
||||
return tagCompound;
|
||||
}
|
||||
}
|
11
src/main/java/com/zixiken/dimdoors/shared/util/RGBA.java
Normal file
11
src/main/java/com/zixiken/dimdoors/shared/util/RGBA.java
Normal file
|
@ -0,0 +1,11 @@
|
|||
package com.zixiken.dimdoors.shared.util;
|
||||
|
||||
import lombok.Value;
|
||||
|
||||
@Value
|
||||
public class RGBA {
|
||||
float red;
|
||||
float green;
|
||||
float blue;
|
||||
float alpha;
|
||||
}
|
|
@ -12,20 +12,14 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import com.zixiken.dimdoors.shared.SchematicHandler;
|
||||
import com.zixiken.dimdoors.shared.blocks.BlockFabric;
|
||||
import com.zixiken.dimdoors.shared.blocks.ModBlocks;
|
||||
import lombok.Getter;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockDoor;
|
||||
import net.minecraft.block.properties.IProperty;
|
||||
import net.minecraft.block.state.BlockStateContainer;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.nbt.NBTTagString;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.fml.common.registry.ForgeRegistries;
|
||||
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
package com.zixiken.dimdoors.shared.util;
|
||||
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.DimensionManager;
|
||||
|
||||
public class WorldUtils {
|
||||
public static World getWorld(int dim) {
|
||||
return DimensionManager.getWorld(dim);
|
||||
}
|
||||
|
||||
public static int getDim(World world) {
|
||||
return world.provider.getDimension();
|
||||
}
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
package com.zixiken.dimdoors.shared.world;
|
||||
|
||||
import com.zixiken.dimdoors.shared.DDConfig;
|
||||
import com.zixiken.dimdoors.shared.EnumPocketType;
|
||||
import com.zixiken.dimdoors.shared.pockets.EnumPocketType;
|
||||
import com.zixiken.dimdoors.shared.world.limbodimension.WorldProviderLimbo;
|
||||
import com.zixiken.dimdoors.shared.world.pocketdimension.WorldProviderPersonalPocket;
|
||||
import com.zixiken.dimdoors.shared.world.pocketdimension.WorldProviderPublicPocket;
|
||||
|
@ -10,32 +10,40 @@ import java.util.ArrayList;
|
|||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import lombok.Getter;
|
||||
import net.minecraft.world.DimensionType;
|
||||
import net.minecraftforge.common.DimensionManager;
|
||||
|
||||
public class DimDoorDimensions {
|
||||
|
||||
public static DimensionType LIMBO = null;
|
||||
private static int minPocketDimID;
|
||||
private static int maxPocketDimID;
|
||||
@Getter private static int minPocketDimID;
|
||||
@Getter private static int maxPocketDimID;
|
||||
private static final List<EnumPocketType> pocketTypes = new ArrayList<>();
|
||||
private static final Map<EnumPocketType, DimensionType> pocketDimensionTypes = new HashMap<>();
|
||||
private static final List<DimensionType> CUSTOM = new ArrayList<>();
|
||||
|
||||
@Getter private static int limboDimID;
|
||||
@Getter private static int privateDimID;
|
||||
@Getter private static int publicDimID;
|
||||
@Getter private static int dungeonDimID;
|
||||
|
||||
public static void init() {
|
||||
int dimID = DDConfig.getBaseDimID();
|
||||
minPocketDimID = DDConfig.getBaseDimID();
|
||||
int dimID = minPocketDimID;
|
||||
LIMBO = DimensionType.register("Limbo", "_limbo", dimID, WorldProviderLimbo.class, false);
|
||||
dimID++; //@todo make this a loop over a function
|
||||
minPocketDimID = dimID;
|
||||
limboDimID = dimID++;
|
||||
pocketTypes.add(EnumPocketType.PRIVATE);
|
||||
pocketDimensionTypes.put(EnumPocketType.PRIVATE, DimensionType.register("Private", "_private", dimID, WorldProviderPersonalPocket.class, false));
|
||||
dimID++;
|
||||
privateDimID = dimID++;
|
||||
pocketTypes.add(EnumPocketType.PUBLIC);
|
||||
pocketDimensionTypes.put(EnumPocketType.PUBLIC, DimensionType.register("Public", "_public", dimID, WorldProviderPublicPocket.class, false));
|
||||
dimID++;
|
||||
publicDimID = dimID++;
|
||||
maxPocketDimID = dimID;
|
||||
pocketTypes.add(EnumPocketType.DUNGEON);
|
||||
pocketDimensionTypes.put(EnumPocketType.DUNGEON, DimensionType.register("Dungeon", "_dungeon", dimID, WorldProviderDungeonPocket.class, false));
|
||||
dungeonDimID = dimID;
|
||||
|
||||
registerDimension(LIMBO);
|
||||
for (EnumPocketType pocketType : pocketDimensionTypes.keySet()) {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package com.zixiken.dimdoors.shared.world.pocketdimension;
|
||||
|
||||
import com.zixiken.dimdoors.shared.EnumPocketType;
|
||||
import com.zixiken.dimdoors.shared.pockets.EnumPocketType;
|
||||
import com.zixiken.dimdoors.shared.world.DimDoorDimensions;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package com.zixiken.dimdoors.shared.world.pocketdimension;
|
||||
|
||||
import com.zixiken.dimdoors.client.CloudRenderBlank;
|
||||
import com.zixiken.dimdoors.shared.EnumPocketType;
|
||||
import com.zixiken.dimdoors.shared.pockets.EnumPocketType;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package com.zixiken.dimdoors.shared.world.pocketdimension;
|
||||
|
||||
import com.zixiken.dimdoors.client.CloudRenderBlank;
|
||||
import com.zixiken.dimdoors.shared.EnumPocketType;
|
||||
import com.zixiken.dimdoors.shared.pockets.EnumPocketType;
|
||||
import com.zixiken.dimdoors.shared.world.DimDoorDimensions;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
|
Loading…
Add table
Reference in a new issue