Unpaired rift at depth-registry implementation
-Implemented methods to register unpaired rifts at their pockets' respective depth -Added ItemDimDoorTrancient to make the riftblade's functionality consistent with the placement of dimdoors on rifts
This commit is contained in:
parent
10ddb6f825
commit
b2f47a6f7d
12 changed files with 142 additions and 91 deletions
|
@ -15,9 +15,9 @@ version = "3.0.0-a1"
|
|||
group= "com.zixiken.dimdoors" // http://maven.apache.org/guides/mini/guide-naming-conventions.html
|
||||
archivesBaseName = "dimdoors"
|
||||
|
||||
sourceCompatibility = targetCompatibility = "1.8" // Need this here so eclipse task generates correctly.
|
||||
sourceCompatibility = targetCompatibility = "1.6" // Need this here so eclipse task generates correctly.
|
||||
compileJava {
|
||||
sourceCompatibility = targetCompatibility = "1.8"
|
||||
sourceCompatibility = targetCompatibility = "1.6"
|
||||
}
|
||||
|
||||
minecraft {
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package com.zixiken.dimdoors.items;
|
||||
|
||||
import static com.zixiken.dimdoors.DimDoors.translateAndAdd;
|
||||
import com.zixiken.dimdoors.blocks.BlockDimDoorBase;
|
||||
import com.zixiken.dimdoors.blocks.ModBlocks;
|
||||
import java.util.List;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.ItemDoor;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Robijnvogel
|
||||
*/
|
||||
public class ItemDimDoorTransient extends ItemDoorBase {
|
||||
|
||||
public static final String ID = "itemDimDoorTransient";
|
||||
|
||||
public ItemDimDoorTransient() {
|
||||
super(ModBlocks.blockDimDoorTransient, ModItems.itemDimDoorTransient);
|
||||
setUnlocalizedName(ID);
|
||||
setRegistryName(ID);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addInformation(ItemStack stack, EntityPlayer playerIn, List<String> tooltip, boolean advanced) {
|
||||
translateAndAdd("info.transientDoor", tooltip);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected BlockDimDoorBase getDoorBlock() {
|
||||
return ModBlocks.blockDimDoorTransient;
|
||||
}
|
||||
|
||||
}
|
|
@ -7,6 +7,7 @@ import com.zixiken.dimdoors.DimDoors;
|
|||
import com.zixiken.dimdoors.blocks.BlockDimDoor;
|
||||
import com.zixiken.dimdoors.blocks.BlockDimDoorBase;
|
||||
import com.zixiken.dimdoors.blocks.ModBlocks;
|
||||
import com.zixiken.dimdoors.shared.RayTraceHelper;
|
||||
import com.zixiken.dimdoors.tileentities.DDTileEntityBase;
|
||||
import com.zixiken.dimdoors.tileentities.TileEntityDimDoor;
|
||||
import net.minecraft.block.Block;
|
||||
|
@ -68,14 +69,11 @@ public abstract class ItemDoorBase extends ItemDoor {
|
|||
return new ActionResult(EnumActionResult.FAIL, stack);
|
||||
}
|
||||
RayTraceResult hit = rayTrace(worldIn, playerIn, true);
|
||||
if (hit != null) {
|
||||
BlockPos pos = hit.getBlockPos();
|
||||
if (worldIn.getBlockState(pos).getBlock() == ModBlocks.blockRift) {
|
||||
EnumActionResult canDoorBePlacedOnGroundBelowRift
|
||||
= tryPlaceDoorOnTopOfBlock(stack, playerIn, worldIn, pos.down(2), hand,
|
||||
(float) hit.hitVec.xCoord, (float) hit.hitVec.yCoord, (float) hit.hitVec.zCoord); //stack may be changed by this method
|
||||
return new ActionResult(canDoorBePlacedOnGroundBelowRift, stack);
|
||||
}
|
||||
if (RayTraceHelper.isRift(hit, worldIn)) {
|
||||
EnumActionResult canDoorBePlacedOnGroundBelowRift
|
||||
= tryPlaceDoorOnTopOfBlock(stack, playerIn, worldIn, hit.getBlockPos().down(2), hand,
|
||||
(float) hit.hitVec.xCoord, (float) hit.hitVec.yCoord, (float) hit.hitVec.zCoord); //stack may be changed by this method
|
||||
return new ActionResult(canDoorBePlacedOnGroundBelowRift, stack);
|
||||
}
|
||||
return new ActionResult(EnumActionResult.FAIL, stack); //@todo, should return onItemUse(params) here? will door placement on block not work otherwise?
|
||||
}
|
||||
|
@ -101,7 +99,7 @@ public abstract class ItemDoorBase extends ItemDoor {
|
|||
}
|
||||
//pos = position of block, the door gets placed on
|
||||
|
||||
private EnumActionResult tryPlaceDoorOnTopOfBlock(ItemStack stack, EntityPlayer playerIn, World world, BlockPos pos, EnumHand hand, float hitX, float hitY, float hitZ) {
|
||||
static EnumActionResult tryPlaceDoorOnTopOfBlock(ItemStack stack, EntityPlayer playerIn, World world, BlockPos pos, EnumHand hand, float hitX, float hitY, float hitZ) {
|
||||
// Retrieve the actual door type that we want to use here.
|
||||
// It's okay if stack isn't an ItemDoor. In that case, the lookup will
|
||||
// return null, just as if the item was an unrecognized door type.
|
||||
|
|
|
@ -1,24 +1,14 @@
|
|||
package com.zixiken.dimdoors.items;
|
||||
|
||||
import com.zixiken.dimdoors.DimDoors;
|
||||
import com.zixiken.dimdoors.blocks.BlockDimDoor;
|
||||
import com.zixiken.dimdoors.blocks.BlockDimDoorTransient;
|
||||
import com.zixiken.dimdoors.blocks.ModBlocks;
|
||||
import com.zixiken.dimdoors.shared.Location;
|
||||
import com.zixiken.dimdoors.shared.RayTraceHelper;
|
||||
import com.zixiken.dimdoors.shared.RiftRegistry;
|
||||
import com.zixiken.dimdoors.shared.TeleportHelper;
|
||||
import com.zixiken.dimdoors.tileentities.DDTileEntityBase;
|
||||
import com.zixiken.dimdoors.tileentities.TileEntityDimDoor;
|
||||
import com.zixiken.dimdoors.tileentities.TileEntityRift;
|
||||
import net.minecraft.block.BlockDoor;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.ItemSword;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.EnumActionResult;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.math.*;
|
||||
import net.minecraft.world.World;
|
||||
|
@ -31,6 +21,7 @@ import java.util.List;
|
|||
* Created by Jared Johnson on 1/20/2017.
|
||||
*/
|
||||
public class ItemRiftBlade extends ItemSword {
|
||||
|
||||
public static final String ID = "itemRiftBlade";
|
||||
|
||||
public ItemRiftBlade() {
|
||||
|
@ -56,33 +47,25 @@ public class ItemRiftBlade extends ItemSword {
|
|||
|
||||
@Override
|
||||
public ActionResult<ItemStack> onItemRightClick(ItemStack stack, World world, EntityPlayer player, EnumHand hand) {
|
||||
if (world.isRemote) {
|
||||
return new ActionResult(EnumActionResult.FAIL, stack);
|
||||
}
|
||||
RayTraceResult hit = rayTrace(world, player, true);
|
||||
if (RayTraceHelper.isRift(hit, world)) {
|
||||
TileEntityRift rift = (TileEntityRift) world.getTileEntity(hit.getBlockPos());
|
||||
|
||||
ItemDoorBase.placeDoor(world, hit.getBlockPos().down(2), EnumFacing.fromAngle((double) player.rotationYaw), ModBlocks.blockDimDoorTransient, false);
|
||||
|
||||
DDTileEntityBase newTileEntityDimDoor = (DDTileEntityBase) world.getTileEntity(hit.getBlockPos());
|
||||
if (rift instanceof DDTileEntityBase) { //
|
||||
DDTileEntityBase oldRift = (DDTileEntityBase) rift;
|
||||
newTileEntityDimDoor.loadDataFrom(oldRift);
|
||||
} else {
|
||||
newTileEntityDimDoor.register();
|
||||
EnumActionResult canDoorBePlacedOnGroundBelowRift
|
||||
= ItemDimDoorTransient.tryPlaceDoorOnTopOfBlock(new ItemStack(ModItems.itemDimDoorTransient, 1, 0), player, world, hit.getBlockPos().down(2), hand,
|
||||
(float) hit.hitVec.xCoord, (float) hit.hitVec.yCoord, (float) hit.hitVec.zCoord); //stack may be changed by this method
|
||||
if (canDoorBePlacedOnGroundBelowRift == EnumActionResult.SUCCESS) {
|
||||
stack.damageItem(1, player);
|
||||
}
|
||||
if (newTileEntityDimDoor instanceof TileEntityDimDoor) {
|
||||
TileEntityDimDoor tileEntityDimDoor = (TileEntityDimDoor) newTileEntityDimDoor;
|
||||
tileEntityDimDoor.orientation
|
||||
= newTileEntityDimDoor.getWorld().getBlockState(newTileEntityDimDoor.getPos()).getValue(BlockDimDoor.FACING).getOpposite();
|
||||
//storing the orientation inside the tile-entity, because that thing can actually save the orientation in the worldsave, unlike the block itself, which fucks up somehow
|
||||
}
|
||||
|
||||
return new ActionResult<ItemStack>(EnumActionResult.PASS, stack);
|
||||
} if(RayTraceHelper.isLivingEntity(hit)) {
|
||||
TeleportHelper.teleport(player, new Location(world, hit.getBlockPos()));
|
||||
return new ActionResult<ItemStack>(EnumActionResult.PASS, stack);
|
||||
return new ActionResult(canDoorBePlacedOnGroundBelowRift, stack);
|
||||
|
||||
} else if (RayTraceHelper.isLivingEntity(hit)) {
|
||||
TeleportHelper.teleport(player, new Location(world, hit.getBlockPos())); //@todo teleport to a location 1 or 2 blocks distance from the entity
|
||||
return new ActionResult(EnumActionResult.PASS, stack);
|
||||
}
|
||||
|
||||
return new ActionResult<ItemStack>(EnumActionResult.FAIL, stack);
|
||||
return new ActionResult(EnumActionResult.FAIL, stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
package com.zixiken.dimdoors.items;
|
||||
|
||||
import com.zixiken.dimdoors.DimDoors;
|
||||
import com.zixiken.dimdoors.shared.RayTraceHelper;
|
||||
import com.zixiken.dimdoors.shared.RiftRegistry;
|
||||
import com.zixiken.dimdoors.tileentities.DDTileEntityBase;
|
||||
import java.util.HashSet;
|
||||
|
@ -50,7 +51,7 @@ public class ItemRiftConnectionTool extends ItemTool {
|
|||
}
|
||||
|
||||
RayTraceResult hit = rayTrace(worldIn, playerIn, true);
|
||||
if (hit != null && worldIn.getTileEntity(hit.getBlockPos()) instanceof DDTileEntityBase) {
|
||||
if (RayTraceHelper.isRift(hit, worldIn)) {
|
||||
DDTileEntityBase rift = (DDTileEntityBase) worldIn.getTileEntity(hit.getBlockPos());
|
||||
if (playerIn.isSneaking()) {
|
||||
return selectRift(stack, worldIn, rift, playerIn); //new ActionResult(EnumActionResult.PASS, stack));
|
||||
|
|
|
@ -10,6 +10,7 @@ public class ModItems {
|
|||
public static ItemDoorGold itemDoorGold;
|
||||
public static ItemWorldThread itemWorldThread;
|
||||
public static ItemDimDoor itemDimDoor;
|
||||
public static ItemDimDoorTransient itemDimDoorTransient;
|
||||
public static ItemDimDoorWarp itemDimDoorWarp;
|
||||
public static ItemStableFabric itemStableFabric;
|
||||
public static ItemDimDoorUnstable itemDimDoorChaos;
|
||||
|
@ -25,6 +26,7 @@ public class ModItems {
|
|||
GameRegistry.register(itemDoorGold = new ItemDoorGold());
|
||||
GameRegistry.register(itemDimDoorGold = new ItemDimDoorGold());
|
||||
GameRegistry.register(itemDimDoor = new ItemDimDoor());
|
||||
GameRegistry.register(itemDimDoorTransient = new ItemDimDoorTransient());
|
||||
GameRegistry.register(itemDimDoorWarp = new ItemDimDoorWarp());
|
||||
GameRegistry.register(itemStableFabric = new ItemStableFabric());
|
||||
GameRegistry.register(itemDimDoorChaos = new ItemDimDoorUnstable());
|
||||
|
|
|
@ -21,7 +21,7 @@ import net.minecraft.nbt.NBTTagString;
|
|||
*/
|
||||
class Pocket {
|
||||
|
||||
private int ID; //this gets reset every session
|
||||
private int ID; //this gets reset every server-load
|
||||
private final int size; //in chunks
|
||||
private final int depth;
|
||||
private final EnumPocketType typeID; // dungeon, pocket, or personal pocket
|
||||
|
@ -40,8 +40,8 @@ class Pocket {
|
|||
this.riftIDs = riftIDs;
|
||||
playerUUIDs = new ArrayList();
|
||||
PocketRegistry.Instance.registerNewPocket(this);
|
||||
|
||||
for(int riftID: riftIDs) {
|
||||
|
||||
for (int riftID : riftIDs) {
|
||||
DDTileEntityBase rift = (DDTileEntityBase) RiftRegistry.Instance.getRiftLocation(riftID).getTileEntity();
|
||||
rift.setPocketID(this.ID); //set the rift's pocket ID to this pocket's pocket ID;
|
||||
}
|
||||
|
@ -70,7 +70,7 @@ class Pocket {
|
|||
return riftIDs.get(index);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void setID(int newID) {
|
||||
ID = newID;
|
||||
}
|
||||
|
@ -94,7 +94,7 @@ class Pocket {
|
|||
String playerUUID = playersTagList.getStringTagAt(i);
|
||||
pocket.playerUUIDs.add(playerUUID);
|
||||
}
|
||||
|
||||
|
||||
PocketRegistry.Instance.registerNewPocket(pocket);
|
||||
}
|
||||
|
||||
|
@ -105,7 +105,7 @@ class Pocket {
|
|||
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));
|
||||
|
@ -118,7 +118,7 @@ class Pocket {
|
|||
NBTTagString playerTag = new NBTTagString(pocket.playerUUIDs.get(i));
|
||||
playersTagList.appendTag(playerTag);
|
||||
}
|
||||
|
||||
|
||||
pocketNBT.setTag("playerUUIDs", playersTagList);
|
||||
return pocketNBT;
|
||||
}
|
||||
|
|
|
@ -120,9 +120,8 @@ class PocketTemplate { //there is exactly one pocket placer for each different s
|
|||
|
||||
List<Integer> riftIDs = new ArrayList();
|
||||
for (DDTileEntityBase rift : rifts) {
|
||||
rift.setIsInDungeon(true);
|
||||
rift.register();
|
||||
RiftRegistry.Instance.registerRiftAtDepth(rift.getRiftID(), depth);
|
||||
rift.register(depth);
|
||||
rift.setIsInPocket();
|
||||
riftIDs.add(rift.getRiftID());
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package com.zixiken.dimdoors.shared;
|
||||
|
||||
import com.zixiken.dimdoors.tileentities.DDTileEntityBase;
|
||||
import com.zixiken.dimdoors.tileentities.TileEntityRift;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.util.math.RayTraceResult;
|
||||
|
|
|
@ -29,11 +29,11 @@ public class RiftRegistry {
|
|||
|
||||
// Privates
|
||||
private int nextRiftID;
|
||||
private int maximumDungeonDepth = 2;
|
||||
private int maximumDungeonDepth = 2; //@todo make this configurable
|
||||
private final Map<Integer, Location> riftList; //maps all rifts in the world to their ID //@todo, make this a List of (comparable) locations?
|
||||
//@todo somehow remove rifts from this list even if they are removed in creative
|
||||
private final Map<Integer, Location> unpairedRiftList; //maps of all rifts in the world that are not paired to their ID
|
||||
private final List<Map<Integer, Location>> unpairedDepthRiftList; //List of all "unpairedRiftList s" per Dungeon Depth. Depth 0 is almost anything outside the dungeon dimension
|
||||
private final List<Integer> unpairedRiftList; //maps of all rifts in the world that are not paired to their ID
|
||||
private final List<List<Integer>> unpairedDepthRiftList; //List of all "unpairedRiftList s" per Dungeon Depth. Depth 0 is almost anything outside the dungeon dimension
|
||||
//@todo, once we have a dungeon dimension this List should be implemented (for determining what doors an unpaired door can link to)
|
||||
//when adding any new variables, don't forget to add them to the write and load functions
|
||||
|
||||
|
@ -41,10 +41,10 @@ public class RiftRegistry {
|
|||
private RiftRegistry() {
|
||||
nextRiftID = 0;
|
||||
riftList = new HashMap();
|
||||
unpairedRiftList = new HashMap();
|
||||
unpairedRiftList = new ArrayList();
|
||||
unpairedDepthRiftList = new ArrayList();
|
||||
for (int i = 0; i < maximumDungeonDepth; i++) {
|
||||
unpairedDepthRiftList.add(new HashMap());
|
||||
unpairedDepthRiftList.add(new ArrayList());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -52,7 +52,7 @@ public class RiftRegistry {
|
|||
nextRiftID = 0;
|
||||
riftList.clear();
|
||||
unpairedRiftList.clear();
|
||||
for (Map<Integer, Location> dimensionSpecificUnpairedRiftList : unpairedDepthRiftList) {
|
||||
for (List<Integer> dimensionSpecificUnpairedRiftList : unpairedDepthRiftList) {
|
||||
dimensionSpecificUnpairedRiftList.clear();
|
||||
}
|
||||
lastBrokenRift = null;
|
||||
|
@ -77,9 +77,7 @@ public class RiftRegistry {
|
|||
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);
|
||||
unpairedRiftList.put(riftID, riftLocation);
|
||||
unpairedRiftList.add(riftID);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -89,14 +87,12 @@ public class RiftRegistry {
|
|||
NBTTagList riftListsNBT = (NBTTagList) nbt.getTag("unpairedDepthRiftList");
|
||||
maximumDungeonDepth = riftListsNBT.tagCount(); //makes sure both are synched
|
||||
for (int i = 0; i < riftListsNBT.tagCount(); i++) {
|
||||
unpairedDepthRiftList.add(new HashMap());
|
||||
unpairedDepthRiftList.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");
|
||||
NBTTagCompound locationTag = riftTag.getCompoundTag("location");
|
||||
Location riftLocation = Location.readFromNBT(locationTag);
|
||||
unpairedDepthRiftList.get(i).put(riftID, riftLocation);
|
||||
unpairedDepthRiftList.get(i).add(riftID);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -116,21 +112,19 @@ public class RiftRegistry {
|
|||
nbt.setTag("riftList", riftsNBT);
|
||||
|
||||
NBTTagList unpairedRiftsNBT = new NBTTagList();
|
||||
for (Map.Entry<Integer, Location> entry : unpairedRiftList.entrySet()) {
|
||||
for (int riftID : unpairedRiftList) {
|
||||
NBTTagCompound riftTag = new NBTTagCompound();
|
||||
riftTag.setInteger("riftID", entry.getKey());
|
||||
riftTag.setTag("location", Location.writeToNBT(entry.getValue()));
|
||||
riftTag.setInteger("riftID", riftID);
|
||||
unpairedRiftsNBT.appendTag(riftTag);
|
||||
}
|
||||
nbt.setTag("unpairedRiftList", unpairedRiftsNBT);
|
||||
|
||||
NBTTagList unpairedRiftListsNBT = new NBTTagList();
|
||||
for (Map<Integer, Location> arrayEntry : unpairedDepthRiftList) {
|
||||
for (List<Integer> unpairedRiftListAtDepth : unpairedDepthRiftList) {
|
||||
NBTTagList unpairedRiftsNBT2 = new NBTTagList();
|
||||
for (Map.Entry<Integer, Location> mapEntry : arrayEntry.entrySet()) {
|
||||
for (int riftID : unpairedRiftListAtDepth) {
|
||||
NBTTagCompound riftTag = new NBTTagCompound();
|
||||
riftTag.setInteger("riftID", mapEntry.getKey());
|
||||
riftTag.setTag("location", Location.writeToNBT(mapEntry.getValue()));
|
||||
riftTag.setInteger("riftID", riftID);
|
||||
unpairedRiftsNBT2.appendTag(riftTag);
|
||||
}
|
||||
unpairedRiftListsNBT.appendTag(unpairedRiftsNBT2);
|
||||
|
@ -138,11 +132,11 @@ public class RiftRegistry {
|
|||
nbt.setTag("unpairedDepthRiftList", unpairedRiftListsNBT);
|
||||
}
|
||||
|
||||
public int registerNewRift(DDTileEntityBase rift) {
|
||||
public int registerNewRift(DDTileEntityBase rift, int depth) {
|
||||
Location riftLocation = Location.getLocation(rift);
|
||||
riftList.put(nextRiftID, riftLocation);
|
||||
unpairedRiftList.put(nextRiftID, riftLocation);
|
||||
//@todo register the rift per dungeon depth as well
|
||||
unpairedRiftList.add(nextRiftID);
|
||||
registerRiftAtDepth(nextRiftID, depth);
|
||||
DimDoors.log(this.getClass(), "Rift registered as ID: " + nextRiftID);
|
||||
nextRiftID++;
|
||||
RiftSavedData.get(DimDoors.getDefWorld()).markDirty(); //Notify that this needs to be saved on world save
|
||||
|
@ -153,10 +147,31 @@ public class RiftRegistry {
|
|||
if (riftList.containsKey(riftID)) {
|
||||
unpair(riftID);
|
||||
riftList.remove(riftID);
|
||||
unpairedRiftList.remove((Integer) riftID);
|
||||
unRegisterRiftAtDepth(riftID);
|
||||
RiftSavedData.get(DimDoors.getDefWorld()).markDirty(); //Notify that this needs to be saved on world save
|
||||
}
|
||||
}
|
||||
|
||||
void registerRiftAtDepth(int riftID, int depth) {
|
||||
if (depth < maximumDungeonDepth) {
|
||||
List<Integer> unpairedRiftListAtDepth = unpairedDepthRiftList.get(depth);
|
||||
unpairedRiftListAtDepth.add(riftID);
|
||||
}
|
||||
}
|
||||
|
||||
void unRegisterRiftAtDepth(int riftID) {
|
||||
TileEntity tileEntity = riftList.get(riftID).getTileEntity();
|
||||
if (tileEntity instanceof DDTileEntityBase) {
|
||||
DDTileEntityBase rift = (DDTileEntityBase) tileEntity;
|
||||
int depth = rift.getDepth();
|
||||
if (depth < maximumDungeonDepth) {
|
||||
List<Integer> unpairedRiftListAtDepth = unpairedDepthRiftList.get(depth);
|
||||
unpairedRiftListAtDepth.remove((Integer) riftID);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Location getRiftLocation(int ID) {
|
||||
return riftList.get(ID);
|
||||
}
|
||||
|
@ -171,7 +186,8 @@ public class RiftRegistry {
|
|||
DDTileEntityBase rift = (DDTileEntityBase) tileEntity;
|
||||
rift.pair(riftID2);
|
||||
}
|
||||
unpairedRiftList.remove(riftID, location);
|
||||
unpairedRiftList.remove((Integer) riftID);
|
||||
//@todo remove the riftID from the depth list as well
|
||||
}
|
||||
|
||||
public void unpair(int riftID) {
|
||||
|
@ -187,7 +203,8 @@ public class RiftRegistry {
|
|||
DDTileEntityBase rift = (DDTileEntityBase) tileEntity;
|
||||
rift.unpair();
|
||||
}
|
||||
unpairedRiftList.put(riftID, location);
|
||||
unpairedRiftList.add(riftID);
|
||||
//@todo add the riftID from the depth list as well, maybe move this to the tileEntityRift class itself though?
|
||||
}
|
||||
|
||||
public void setLastChangedRift(DDTileEntityBase origRift) {
|
||||
|
@ -209,16 +226,15 @@ public class RiftRegistry {
|
|||
|
||||
public int getRandomUnpairedRiftID(int origRiftID) {
|
||||
if (!unpairedRiftList.isEmpty()) {
|
||||
int numberOfUnpairedRifts = unpairedRiftList.keySet().size();
|
||||
int numberOfUnpairedRifts = unpairedRiftList.size();
|
||||
if (numberOfUnpairedRifts != 1) {//should only be the "original Rift" then
|
||||
Random random = new Random();
|
||||
List<Integer> keys = new ArrayList(unpairedRiftList.keySet());
|
||||
int origRiftKey = keys.indexOf(origRiftID);
|
||||
int randomRiftKey = 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 (randomRiftKey >= origRiftKey) {
|
||||
randomRiftKey++;
|
||||
int indexOforigRiftID = unpairedRiftList.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 keys.get(randomRiftKey);
|
||||
return unpairedRiftList.get(randomRiftIDIndex);
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
|
|
|
@ -17,6 +17,7 @@ public abstract class DDTileEntityBase extends TileEntity {
|
|||
private int pairedRiftID = -1;
|
||||
private boolean isInPocket = false;
|
||||
private int pocketID = -1;
|
||||
private int depth = 0; //depth of the pocket it is in (not in a pocket -> 0)
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -53,9 +54,9 @@ public abstract class DDTileEntityBase extends TileEntity {
|
|||
this.markDirty();
|
||||
}
|
||||
|
||||
public void register() {
|
||||
public void register(int depth) {
|
||||
if (riftID == -1) {
|
||||
riftID = RiftRegistry.Instance.registerNewRift(this);
|
||||
riftID = RiftRegistry.Instance.registerNewRift(this, depth);
|
||||
this.markDirty();
|
||||
}
|
||||
}
|
||||
|
@ -71,7 +72,6 @@ public abstract class DDTileEntityBase extends TileEntity {
|
|||
pocketID = nbt.getInteger("pocketID");
|
||||
} catch (Exception e) {
|
||||
}
|
||||
register(); //only actually gets registered if riftID == -1
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -106,9 +106,21 @@ public abstract class DDTileEntityBase extends TileEntity {
|
|||
return isPaired;
|
||||
}
|
||||
|
||||
public int getDepth() {
|
||||
return depth;
|
||||
}
|
||||
|
||||
public Location getTeleportTargetLocation() {
|
||||
return new Location(this.getWorld().provider.getDimension(), this.getPos());
|
||||
}
|
||||
|
||||
public abstract boolean tryTeleport(Entity entity);
|
||||
|
||||
public void setPocketID(int ID) {
|
||||
pocketID = ID;
|
||||
}
|
||||
|
||||
public void setIsInPocket() {
|
||||
isInPocket = true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -79,7 +79,7 @@ public class TileEntityDimDoor extends DDTileEntityBase {
|
|||
loadDataFrom(oldRift);
|
||||
} else {
|
||||
//default data and set register this rift in the registry
|
||||
register();
|
||||
register(0); //@todo check if it's in a pocket and register it at that depth instead if applicable
|
||||
}
|
||||
//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
|
||||
this.orientation = this.getWorld().getBlockState(this.getPos()).getValue(BlockDimDoor.FACING).getOpposite();
|
||||
|
|
Loading…
Reference in a new issue