Private pocket fixes

This commit is contained in:
Runemoro 2017-12-15 22:41:18 -05:00
parent 15eccab45a
commit c4a42cc76a
6 changed files with 62 additions and 4 deletions

View file

@ -30,5 +30,6 @@ public class BlockDimDoorPersonal extends BlockDimDoorBase {
protected void setupRift(TileEntityVerticalEntranceRift rift) {
RiftDestination.PrivateDestination destination = RiftDestination.PrivateDestination.builder().build();
rift.setSingleDestination(destination);
rift.setChaosWeight(0);
}
}

View file

@ -200,4 +200,6 @@ public class Pocket { // TODO: better visibilities
public void unlinkPocket() {
// TODO
}
// TODO: method to erase a pocket
}

View file

@ -13,7 +13,7 @@ public class PocketGenerator {
PocketRegistry registry = PocketRegistry.getForDim(dimID);
Pocket pocket = registry.newPocket(depth);
pocketTemplate.place(pocket, 0); // TODO: config option for yBase or maybe param?
pocketTemplate.place(pocket, 10); // Sky starts getting dark (because of void) below y = 10 TODO: config option for yBase or maybe param?
pocket.setVirtualLocation(virtualLocation);
return pocket;
}

View file

@ -194,6 +194,7 @@ public class PocketRegistry extends WorldSavedData {
public void setPrivatePocketID(String playerUUID, int id) {
privatePocketMap.put(playerUUID, id);
markDirty();
}
public GridUtils.GridPos getGridPosFromID(int id) {
@ -237,6 +238,7 @@ public class PocketRegistry extends WorldSavedData {
Pocket pocket = getPocketFromLocation(x, y, z);
if (pocket != null) {
pocket.allowPlayer(player);
markDirty();
}
}

View file

@ -25,7 +25,7 @@ public class RiftRegistry extends WorldSavedData {
@Getter private Map<Location, RiftInfo> rifts = new HashMap<>(); // TODO: store relative locations too (better location class supporting relative, etc)
@Getter private Map<String, Location> privatePocketEntrances = new HashMap<>(); // TODO: more general group-group linking
@Getter private Map<String, Location> escapeRift = new HashMap<>();
@Getter private Map<String, Location> escapeRifts = new HashMap<>();
@Getter private int dim;
private World world;
@ -159,6 +159,22 @@ public class RiftRegistry extends WorldSavedData {
riftInfo.readFromNBT(riftNBTC);
rifts.put(location, riftInfo);
}
NBTTagList privatePocketEntrancesNBT = (NBTTagList) nbt.getTag("privatePocketEntrances");
for (NBTBase privatePocketEntranceNBT : privatePocketEntrancesNBT) { // TODO: move to NBTUtils
NBTTagCompound privatePocketEntranceNBTC = (NBTTagCompound) privatePocketEntranceNBT;
String uuid = privatePocketEntranceNBTC.getString("uuid");
Location rift = Location.readFromNBT(privatePocketEntranceNBTC.getCompoundTag("location"));
privatePocketEntrances.put(uuid, rift);
}
NBTTagList escapeRiftsNBT = (NBTTagList) nbt.getTag("escapeRifts");
for (NBTBase escapeRiftNBT : escapeRiftsNBT) { // TODO: move to NBTUtils
NBTTagCompound escapeRiftNBTC = (NBTTagCompound) escapeRiftNBT;
String uuid = escapeRiftNBTC.getString("uuid");
Location rift = Location.readFromNBT(escapeRiftNBTC.getCompoundTag("location"));
escapeRifts.put(uuid, rift);
}
}
private static boolean upgradeRegistry(NBTTagCompound nbt, int oldVersion) {
@ -190,6 +206,26 @@ public class RiftRegistry extends WorldSavedData {
}
nbt.setTag("rifts", riftsNBT);
NBTTagList privatePocketEntrancesNBT = new NBTTagList();
for (HashMap.Entry<String, Location> privatePocketEntrance : privatePocketEntrances.entrySet()) { // TODO: move to NBTUtils
if (privatePocketEntrance.getValue() == null) continue;
NBTTagCompound privatePocketEntranceNBT = new NBTTagCompound();
privatePocketEntranceNBT.setString("uuid", privatePocketEntrance.getKey());
privatePocketEntranceNBT.setTag("location", Location.writeToNBT(privatePocketEntrance.getValue()));
riftsNBT.appendTag(privatePocketEntranceNBT);
}
nbt.setTag("privatePocketEntrances", privatePocketEntrancesNBT);
NBTTagList escapeRiftsNBT = new NBTTagList();
for (HashMap.Entry<String, Location> escapeRift : escapeRifts.entrySet()) {
if (escapeRift.getValue() == null) continue;
NBTTagCompound escapeRiftNBT = new NBTTagCompound();
escapeRiftNBT.setString("uuid", escapeRift.getKey());
escapeRiftNBT.setTag("location", Location.writeToNBT(escapeRift.getValue()));
riftsNBT.appendTag(escapeRiftNBT);
}
nbt.setTag("escapeRifts", escapeRiftsNBT);
return nbt;
}
@ -283,11 +319,11 @@ public class RiftRegistry extends WorldSavedData {
}
public static Location getEscapeRift(String playerUUID) { // TODO: since this is per-world, move to different registry?
return getForDim(0).escapeRift.get(playerUUID); // store in overworld, since that's where per-world player data is stored
return getForDim(0).escapeRifts.get(playerUUID); // store in overworld, since that's where per-world player data is stored
}
public static void setEscapeRift(String playerUUID, Location rift) {
getForDim(0).escapeRift.put(playerUUID, rift);
getForDim(0).escapeRifts.put(playerUUID, rift);
}
public static List<AvailableLinkInfo> getAvailableLinks() { // TODO: cache this

View file

@ -51,6 +51,7 @@ public abstract class TileEntityRift extends TileEntity implements ITickable { /
preserveRotation = true;
pitch = 0;
alwaysDelete = false;
chaosWeight = 1;
}
public void copyFrom(TileEntityRift oldRift) {
@ -289,11 +290,13 @@ public abstract class TileEntityRift extends TileEntity implements ITickable { /
if (privatePocket == null) { // generate the private pocket and get its entrance
privatePocket = PocketGenerator.generatePrivatePocket(virtualLocation != null ? virtualLocation.toBuilder().depth(-2).build() : null); // set to where the pocket was first created TODO: private pocket deletion
privatePocket.setup();
privatePocketRegistry.setPrivatePocketID(uuid, privatePocket.getId());
destLoc = privatePocket.getEntrance();
} else {
destLoc = privateRiftRegistry.getPrivatePocketEntrance(uuid); // get the last used entrance
if (destLoc == null) destLoc = privatePocket.getEntrance(); // if there's none, then set the target to the main entrance
}
privateRiftRegistry.setPrivatePocketEntrance(uuid, null); // forget the last entered entrance
} else {
return false; // TODO: There should be a way to get other entities into your private pocket, though. Add API for other mods.
}
@ -306,8 +309,12 @@ public abstract class TileEntityRift extends TileEntity implements ITickable { /
if (uuid != null) {
RiftRegistry privateRiftRegistry = RiftRegistry.getForDim(DimDoorDimensions.getPrivateDimID());
destLoc = RiftRegistry.getEscapeRift(uuid);
RiftRegistry.setEscapeRift(uuid, null); // forget the last used escape rift
if (dest.getType() == EnumType.PRIVATE_POCKET_EXIT) {
privateRiftRegistry.setPrivatePocketEntrance(uuid, new Location(world, pos)); // Remember which exit was used for next time the pocket is entered
} else if (dest.getType() == EnumType.ESCAPE) {
// TODO: teleport the player to random coordinates based on depth around destLoc
return true;
}
if (destLoc == null) return false; // TODO: The player probably teleported into the dungeon/private pocket and is now trying to escape... What should we do? Limbo?
} else {
@ -372,6 +379,10 @@ public abstract class TileEntityRift extends TileEntity implements ITickable { /
TileEntity tileEntityAtLoc = destLoc.getWorld().getTileEntity(destLoc.getPos());
if (!(tileEntityAtLoc instanceof TileEntityRift)) throw new RuntimeException("The rift referenced by this rift does not exist, this is a bug.");
TileEntityRift destRift = (TileEntityRift) tileEntityAtLoc;
if (entity instanceof EntityPlayer && !DimDoorDimensions.isPocketDimension(WorldUtils.getDim(world))) { // TODO: What about player-owned entities? We should store their exit rift separately to avoid having problems if they enter different rifts
String uuid = entity.getUniqueID().toString(); // TODO: More configuration on which worlds should be considered normal worlds. Other mods might add mostly void worlds, causing problems with random coordinates
RiftRegistry.setEscapeRift(uuid, new Location(world, pos));
}
destRift.teleportTo(entity);
return true;
@ -446,5 +457,11 @@ public abstract class TileEntityRift extends TileEntity implements ITickable { /
deserializeNBT(pkt.getNbtCompound());
}
public void setChaosWeight(int chaosWeight) {
this.chaosWeight = chaosWeight;
markDirty();
}
public abstract boolean isEntrance(); // TODO: replace with chooseWeight function
}