Many fixes
This commit is contained in:
parent
efd787ef46
commit
7260e08648
40 changed files with 295 additions and 141 deletions
|
@ -30,4 +30,28 @@ public final class NBTUtils {
|
|||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
public static NBTTagCompound writeToNBTNormal(Object obj, NBTTagCompound nbt) {
|
||||
try {
|
||||
Class<?> objClass = obj.getClass();
|
||||
Class<?> nbtWriter = Class.forName(objClass.getPackage().getName() + "." + objClass.getSimpleName() + "NBTWriter");
|
||||
Method write = nbtWriter.getMethod("writeToNBT", objClass, NBTTagCompound.class);
|
||||
write.invoke(null, obj, nbt);
|
||||
return nbt;
|
||||
} catch (ClassNotFoundException|NoSuchMethodException|IllegalAccessException|InvocationTargetException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static <T> T readFromNBTNormal(T obj, NBTTagCompound nbt) {
|
||||
try {
|
||||
Class<?> objClass = obj.getClass();
|
||||
Class<?> nbtWriter = Class.forName(objClass.getPackage().getName() + "." + objClass.getSimpleName() + "NBTWriter");
|
||||
Method read = nbtWriter.getMethod("readFromNBT", objClass, NBTTagCompound.class);
|
||||
read.invoke(null, obj, nbt);
|
||||
} catch (ClassNotFoundException|NoSuchMethodException|IllegalAccessException|InvocationTargetException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,8 +5,8 @@ import org.jgrapht.Graph;
|
|||
public final class GraphUtils {
|
||||
public static <V, E> void replaceVertex(Graph<V, E> graph, V vertex, V replace) {
|
||||
graph.addVertex(replace);
|
||||
for (E edge : graph.outgoingEdgesOf(vertex)) graph.addEdge(replace, graph.getEdgeTarget(edge), edge);
|
||||
for (E edge : graph.incomingEdgesOf(vertex)) graph.addEdge(graph.getEdgeSource(edge), replace, edge);
|
||||
for (E edge : graph.outgoingEdgesOf(vertex)) graph.addEdge(replace, graph.getEdgeTarget(edge));
|
||||
for (E edge : graph.incomingEdgesOf(vertex)) graph.addEdge(graph.getEdgeSource(edge), replace);
|
||||
graph.removeVertex(vertex);
|
||||
}
|
||||
|
||||
|
|
|
@ -57,9 +57,9 @@ public abstract class CommonProxy {
|
|||
SchematicHandler.INSTANCE.loadSchematics();
|
||||
}
|
||||
|
||||
public void registerTileEntities() { // TODO: new registry system
|
||||
GameRegistry.registerTileEntity(TileEntityEntranceRift.class, "EntranceRift");
|
||||
GameRegistry.registerTileEntity(TileEntityFloatingRift.class, "FloatingRift");
|
||||
public void registerTileEntities() {
|
||||
GameRegistry.registerTileEntity(TileEntityEntranceRift.class, "dimdoors:entrance_rift");
|
||||
GameRegistry.registerTileEntity(TileEntityFloatingRift.class, "dimdoors:floating_rift");
|
||||
}
|
||||
|
||||
public abstract boolean isClient();
|
||||
|
|
|
@ -42,9 +42,9 @@ public final class EventHandler {
|
|||
}
|
||||
|
||||
@SubscribeEvent(priority = EventPriority.LOWEST)
|
||||
public static void onDimensionChange(PlayerEvent.PlayerChangedDimensionEvent event) {
|
||||
public static void onDimensionChange(PlayerEvent.PlayerChangedDimensionEvent event) { // TODO: what about non-players (EntityTravelToDimensionEvent)?
|
||||
// TODO: PocketLib compatibility
|
||||
if (ModDimensions.isDimDoorsPocketDimension(event.fromDim) && !ModDimensions.isDimDoorsPocketDimension(event.toDim)) {
|
||||
if (!ModDimensions.isDimDoorsPocketDimension(event.fromDim) && ModDimensions.isDimDoorsPocketDimension(event.toDim)) {
|
||||
RiftRegistry.instance().setOverworldRift(event.player.getUniqueID(), null);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,8 +37,7 @@ public class BlockDimensionalDoorGold extends BlockDimensionalDoor {
|
|||
public void setupRift(TileEntityEntranceRift rift) {
|
||||
rift.setProperties(LinkProperties.builder()
|
||||
.groups(new HashSet<>(Arrays.asList(0, 1)))
|
||||
.linksRemaining(1)
|
||||
.replaceDestination(UUID.randomUUID()).build());
|
||||
.linksRemaining(1).build());
|
||||
rift.setDestination(AvailableLinkDestination.builder()
|
||||
.acceptedGroups(Collections.singleton(0))
|
||||
.coordFactor(1)
|
||||
|
|
|
@ -66,8 +66,8 @@ public class ItemRiftSignature extends Item {
|
|||
sourceWorld.setBlockState(target.getLocation().getPos(), ModBlocks.RIFT.getDefaultState());
|
||||
TileEntityRift rift1 = (TileEntityRift) target.getLocation().getTileEntity();
|
||||
rift1.setDestination(new GlobalDestination(new Location(world, pos)));
|
||||
rift1.register();
|
||||
rift1.setRotation(target.getYaw(), 0);
|
||||
rift1.register();
|
||||
}
|
||||
|
||||
// Place a rift at the target point
|
||||
|
|
|
@ -76,17 +76,16 @@ import java.util.List;
|
|||
public void setup() { // Always call after creating a pocket except when building the pocket
|
||||
List<TileEntityRift> rifts = getRifts();
|
||||
|
||||
HashMap<TileEntityRift, Float> entranceIndexWeights = new HashMap<>();
|
||||
HashMap<TileEntityRift, Float> entranceWeights = new HashMap<>();
|
||||
|
||||
for (TileEntityRift rift : rifts) { // Find an entrance
|
||||
if (rift.getDestination() instanceof PocketEntranceDestination) {
|
||||
entranceIndexWeights.put(rift, ((PocketEntranceDestination) rift.getDestination()).getWeight());
|
||||
rift.markDirty();
|
||||
entranceWeights.put(rift, ((PocketEntranceDestination) rift.getDestination()).getWeight());
|
||||
}
|
||||
}
|
||||
|
||||
if (entranceIndexWeights.size() == 0) return;
|
||||
TileEntityRift selectedEntrance = MathUtils.weightedRandom(entranceIndexWeights);
|
||||
if (entranceWeights.size() == 0) return;
|
||||
TileEntityRift selectedEntrance = MathUtils.weightedRandom(entranceWeights);
|
||||
|
||||
// Replace entrances with appropriate destinations
|
||||
for (TileEntityRift rift : rifts) {
|
||||
|
|
|
@ -32,7 +32,7 @@ PocketRegistry extends WorldSavedData { // TODO: unregister pocket entrances, pr
|
|||
@Saved @Getter /*package-private*/ int maxPocketSize;
|
||||
@Saved @Getter /*package-private*/ int privatePocketSize;
|
||||
@Saved @Getter /*package-private*/ int publicPocketSize;
|
||||
@Saved /*package-private*/ BiMap<UUID, Integer> privatePocketMap; // Player UUID -> Pocket ID, in pocket dim only TODO: move this out of pocketlib
|
||||
@Saved /*package-private*/ BiMap<String, Integer> privatePocketMap; // Player UUID -> Pocket ID, in pocket dim only TODO: move this out of pocketlib
|
||||
@Saved @Getter /*package-private*/ Map<Integer, Pocket> pockets; // TODO: remove getter?
|
||||
@Saved @Getter /*package-private*/ int nextID;
|
||||
|
||||
|
@ -158,17 +158,17 @@ PocketRegistry extends WorldSavedData { // TODO: unregister pocket entrances, pr
|
|||
|
||||
// TODO: these should be per-map rather than per-world
|
||||
public int getPrivatePocketID(UUID playerUUID) {
|
||||
Integer id = privatePocketMap.get(playerUUID);
|
||||
Integer id = privatePocketMap.get(playerUUID.toString());
|
||||
if (id == null) return -1;
|
||||
return id;
|
||||
}
|
||||
|
||||
public UUID getPrivatePocketOwner(int id) {
|
||||
return privatePocketMap.inverse().get(id);
|
||||
return UUID.fromString(privatePocketMap.inverse().get(id));
|
||||
}
|
||||
|
||||
public void setPrivatePocketID(UUID playerUUID, int id) {
|
||||
privatePocketMap.put(playerUUID, id);
|
||||
privatePocketMap.put(playerUUID.toString(), id);
|
||||
markDirty();
|
||||
}
|
||||
|
||||
|
|
|
@ -48,7 +48,7 @@ public class PocketTemplate {
|
|||
DimDoors.log.info("Placing new pocket using schematic " + schematic.schematicName + " at x = " + xBase + ", z = " + zBase);
|
||||
|
||||
WorldServer world = WorldUtils.getWorld(dim);
|
||||
Schematic.place(schematic, world, xBase, 0, zBase);
|
||||
Schematic.place(schematic, world, xBase, yBase, zBase);
|
||||
|
||||
// Set pocket riftLocations
|
||||
pocket.riftLocations = new ArrayList<>();
|
||||
|
|
|
@ -49,16 +49,18 @@ public abstract class RiftDestination implements INBTStorable {
|
|||
|
||||
public abstract boolean teleport(RotatedLocation rift, Entity entity);
|
||||
|
||||
public Location getFixedTarget(Location location) {
|
||||
public Location getFixedTarget(Location location) { // TODO: this should only be available for local/global/relative destinations, maybe make a superclass for them
|
||||
return null;
|
||||
}
|
||||
|
||||
public void register(Location location) {
|
||||
RiftRegistry.instance().addLink(location, getFixedTarget(location));
|
||||
Location fixedTarget = getFixedTarget(location);
|
||||
if (fixedTarget != null) RiftRegistry.instance().addLink(location, getFixedTarget(location));
|
||||
}
|
||||
|
||||
public void unregister(Location location) {
|
||||
RiftRegistry.instance().removeLink(location, getFixedTarget(location));
|
||||
Location fixedTarget = getFixedTarget(location);
|
||||
if (fixedTarget != null) RiftRegistry.instance().removeLink(location, fixedTarget);
|
||||
}
|
||||
|
||||
public boolean keepAfterTargetGone(Location location, Location target) {
|
||||
|
|
|
@ -11,6 +11,7 @@ import net.minecraft.tileentity.TileEntity;
|
|||
import net.minecraft.util.ITickable;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.DimensionManager;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import org.dimdev.annotatednbt.NBTSerializable;
|
||||
|
@ -29,9 +30,9 @@ import javax.annotation.Nonnull;
|
|||
|
||||
@NBTSerializable public abstract class TileEntityRift extends TileEntity implements ITickable { // TODO: implement ITeleportSource and ITeleportDestination
|
||||
|
||||
@Saved @Nonnull @Getter protected RiftDestination destination;
|
||||
/*@Saved*/ @Nonnull @Getter protected RiftDestination destination;
|
||||
@Saved @Getter protected boolean relativeRotation;
|
||||
@Saved @Getter protected float yaw;
|
||||
@Saved @Getter public float yaw;
|
||||
@Saved @Getter protected float pitch;
|
||||
@Saved @Getter protected boolean alwaysDelete; // Delete the rift when an entrances rift is broken even if the state was changed or destinations link there.
|
||||
@Saved @Getter protected boolean forcedColor;
|
||||
|
@ -57,9 +58,17 @@ import javax.annotation.Nonnull;
|
|||
}
|
||||
|
||||
// NBT
|
||||
@Override public void readFromNBT(NBTTagCompound nbt) { super.readFromNBT(nbt); NBTUtils.readFromNBT(this, nbt); }
|
||||
@Override public void readFromNBT(NBTTagCompound nbt) {
|
||||
super.readFromNBT(nbt);
|
||||
NBTUtils.readFromNBT(this, nbt);
|
||||
destination = nbt.hasKey("destination") ? RiftDestination.readDestinationNBT(nbt.getCompoundTag("destination")) : null;
|
||||
}
|
||||
|
||||
@Override public NBTTagCompound writeToNBT(NBTTagCompound nbt) { nbt = super.writeToNBT(nbt); return NBTUtils.writeToNBT(this, nbt); }
|
||||
@Override public NBTTagCompound writeToNBT(NBTTagCompound nbt) {
|
||||
nbt = super.writeToNBT(nbt);
|
||||
if (destination != null) nbt.setTag("destination", destination.writeToNBT(new NBTTagCompound()));
|
||||
return NBTUtils.writeToNBT(this, nbt);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTTagCompound getUpdateTag() {
|
||||
|
@ -108,10 +117,13 @@ import javax.annotation.Nonnull;
|
|||
}
|
||||
|
||||
public void setDestination(RiftDestination destination) {
|
||||
if (this.destination != null) {
|
||||
if (this.destination != null && isRegistered()) {
|
||||
this.destination.unregister(new Location(world, pos));
|
||||
}
|
||||
this.destination = destination;
|
||||
if (destination != null) {
|
||||
if (isRegistered()) destination.register(new Location(world, pos));
|
||||
}
|
||||
markDirty();
|
||||
updateColor();
|
||||
}
|
||||
|
@ -136,14 +148,16 @@ import javax.annotation.Nonnull;
|
|||
// Registry TODO: merge most of these into one single updateRegistry() method
|
||||
|
||||
public boolean isRegistered() {
|
||||
return RiftRegistry.instance().isRiftAt(new Location(world, pos));
|
||||
// The DimensionManager.getWorld(0) != null check is to be able to run this without having to start minecraft
|
||||
// (for GeneratePocketSchematics, for example)
|
||||
return DimensionManager.getWorld(0) != null && RiftRegistry.instance().isRiftAt(new Location(world, pos));
|
||||
}
|
||||
|
||||
public void register() {
|
||||
if (isRegistered()) return;
|
||||
Location loc = new Location(world, pos);
|
||||
RiftRegistry.instance().addRift(loc);
|
||||
destination.register(new Location(world, pos));
|
||||
if (destination != null) destination.register(new Location(world, pos));
|
||||
updateProperties();
|
||||
updateColor();
|
||||
}
|
||||
|
@ -167,7 +181,10 @@ import javax.annotation.Nonnull;
|
|||
}
|
||||
|
||||
public void targetGone(Location loc) {
|
||||
if (!destination.keepAfterTargetGone(new Location(world, pos), loc)) setDestination(null);
|
||||
if (!destination.keepAfterTargetGone(new Location(world, pos), loc)) {
|
||||
destination = null;
|
||||
markDirty();
|
||||
}
|
||||
updateColor();
|
||||
}
|
||||
|
||||
|
@ -187,14 +204,7 @@ import javax.annotation.Nonnull;
|
|||
|
||||
// Attempt a teleport
|
||||
try {
|
||||
if (destination.teleport(new RotatedLocation(new Location(world, pos), yaw, pitch), entity)) {
|
||||
// Set last used rift for players (don't set for other entities to avoid filling the registry too much)
|
||||
// TODO: it should maybe be set for some non-player entities too
|
||||
if (!ModDimensions.isDimDoorsPocketDimension(WorldUtils.getDim(world)) && entity instanceof EntityPlayer) {
|
||||
RiftRegistry.instance().setOverworldRift(entity.getUniqueID(), new Location(world, pos));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return destination.teleport(new RotatedLocation(new Location(world, pos), yaw, pitch), entity);
|
||||
} catch (Exception e) {
|
||||
DimDoors.sendMessage(entity, "There was an exception while teleporting!");
|
||||
DimDoors.log.error("Teleporting failed with the following exception: ", e);
|
||||
|
@ -202,12 +212,12 @@ import javax.annotation.Nonnull;
|
|||
return false;
|
||||
}
|
||||
|
||||
public void teleportTo(Entity entity, float fromYaw, float fromPitch) {
|
||||
if (relativeRotation) {
|
||||
TeleportUtils.teleport(entity, new Location(world, pos), yaw + entity.rotationYaw - fromYaw, pitch + entity.rotationPitch - fromPitch);
|
||||
} else {
|
||||
TeleportUtils.teleport(entity, new Location(world, pos), yaw, pitch);
|
||||
}
|
||||
public void teleportTo(Entity entity, float fromYaw, float fromPitch) { // TODO
|
||||
//if (relativeRotation) {
|
||||
// TeleportUtils.teleport(entity, new Location(world, pos), yaw + entity.rotationYaw - fromYaw, pitch + entity.rotationPitch - fromPitch);
|
||||
//} else {
|
||||
TeleportUtils.teleport(entity, new Location(world, pos), yaw, pitch);
|
||||
//}
|
||||
}
|
||||
|
||||
public void teleportTo(Entity entity) {
|
||||
|
@ -215,6 +225,7 @@ import javax.annotation.Nonnull;
|
|||
}
|
||||
|
||||
public void updateColor() {
|
||||
//DimDoors.log.info("Updating color of rift at " + new Location(world, pos));
|
||||
if (forcedColor) return;
|
||||
if (!isRegistered()) {
|
||||
color = new RGBA(0, 0, 0, 1);
|
||||
|
@ -222,7 +233,7 @@ import javax.annotation.Nonnull;
|
|||
color = new RGBA(0.7f, 0.7f, 0.7f, 1);
|
||||
} else {
|
||||
RGBA newColor = destination.getColor(new Location(world, pos));
|
||||
if (!color.equals(newColor)) {
|
||||
if (color == null && newColor != null || !color.equals(newColor)) {
|
||||
color = newColor;
|
||||
markDirty();
|
||||
}
|
||||
|
@ -231,7 +242,6 @@ import javax.annotation.Nonnull;
|
|||
|
||||
@Override
|
||||
public void markDirty() {
|
||||
if (!forcedColor) updateColor();
|
||||
super.markDirty();
|
||||
}
|
||||
|
||||
|
|
|
@ -29,7 +29,6 @@ import org.dimdev.dimdoors.shared.tileentities.TileEntityFloatingRift;
|
|||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
@Getter @AllArgsConstructor @Builder(toBuilder = true) @ToString
|
||||
@NBTSerializable public class AvailableLinkDestination extends RiftDestination {
|
||||
|
@ -40,7 +39,7 @@ import java.util.UUID;
|
|||
@Saved protected double negativeDepthFactor;
|
||||
@Saved protected Set<Integer> acceptedGroups; // TODO: this should be immutable
|
||||
@Saved protected boolean noLink;
|
||||
@Builder.Default @Saved protected boolean noLinkBack;
|
||||
@Saved protected boolean noLinkBack;
|
||||
// TODO: better depth calculation
|
||||
|
||||
public AvailableLinkDestination() {}
|
||||
|
@ -135,7 +134,7 @@ import java.util.UUID;
|
|||
TileEntityRift thisRift = (TileEntityRift) location.getLocation().getTileEntity();
|
||||
TileEntityFloatingRift riftEntity = (TileEntityFloatingRift) world.getTileEntity(pos);
|
||||
// TODO: Should the rift not be configured like the other link
|
||||
riftEntity.setProperties(thisRift.getProperties().toBuilder().linksRemaining(1).id(UUID.randomUUID()).build());
|
||||
riftEntity.setProperties(thisRift.getProperties().toBuilder().linksRemaining(1).build());
|
||||
|
||||
if (!noLinkBack && !riftEntity.getProperties().oneWay) linkRifts(selectedLink, location.getLocation());
|
||||
if (!noLink) linkRifts(location.getLocation(), selectedLink);
|
||||
|
@ -149,7 +148,7 @@ import java.util.UUID;
|
|||
// Link the pocket back
|
||||
TileEntityRift thisRift = (TileEntityRift) location.getLocation().getTileEntity();
|
||||
TileEntityRift riftEntity = (TileEntityRift) pocket.getEntrance().getTileEntity();
|
||||
LinkProperties newLink = thisRift.getProperties().toBuilder().linksRemaining(0).id(UUID.randomUUID()).build();
|
||||
LinkProperties newLink = thisRift.getProperties().toBuilder().linksRemaining(0).build();
|
||||
pocket.linkPocketTo(new GlobalDestination(!noLinkBack && !riftEntity.getProperties().oneWay ? location.getLocation() : null), newLink); // TODO: linkId
|
||||
|
||||
// Link the rift if necessary and teleport the entity
|
||||
|
|
|
@ -11,16 +11,23 @@ public abstract class LinkingDestination extends RiftDestination {
|
|||
|
||||
private RiftDestination wrappedDestination;
|
||||
|
||||
@Override public void readFromNBT(NBTTagCompound nbt) { super.readFromNBT(nbt); }
|
||||
@Override public NBTTagCompound writeToNBT(NBTTagCompound nbt) { nbt = super.writeToNBT(nbt); return nbt; }
|
||||
@Override public void readFromNBT(NBTTagCompound nbt) {
|
||||
super.readFromNBT(nbt);
|
||||
wrappedDestination = nbt.hasKey("wrappedDestination") ? RiftDestination.readDestinationNBT(nbt.getCompoundTag("wrappedDestination")) : null;
|
||||
}
|
||||
@Override public NBTTagCompound writeToNBT(NBTTagCompound nbt) {
|
||||
nbt = super.writeToNBT(nbt);
|
||||
if (wrappedDestination != null) nbt.setTag("wrappedDestination", wrappedDestination.writeToNBT(new NBTTagCompound()));
|
||||
return nbt;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean teleport(RotatedLocation loc, Entity entity) {
|
||||
if (wrappedDestination != null) wrappedDestination.teleport(loc, entity);
|
||||
if (wrappedDestination != null) return wrappedDestination.teleport(loc, entity);
|
||||
|
||||
Location linkTarget = makeLinkTarget(loc, entity);
|
||||
if (linkTarget != null) {
|
||||
wrappedDestination = new GlobalDestination();
|
||||
wrappedDestination = new GlobalDestination(linkTarget);
|
||||
wrappedDestination.register(loc.getLocation());
|
||||
|
||||
wrappedDestination.teleport(loc, entity);
|
||||
|
|
|
@ -17,14 +17,23 @@ import org.dimdev.dimdoors.shared.rifts.RiftDestination;
|
|||
@Getter @AllArgsConstructor @Builder(toBuilder = true) @ToString
|
||||
@NBTSerializable public class PocketEntranceDestination extends RiftDestination { // TODO: not exactly a destination
|
||||
@Builder.Default @Saved protected float weight = 1;
|
||||
@Saved protected RiftDestination ifDestination;
|
||||
@Saved protected RiftDestination otherwiseDestination;
|
||||
@Saved boolean hasBeenChosen;
|
||||
/*@Saved*/ protected RiftDestination ifDestination;
|
||||
/*@Saved*/ protected RiftDestination otherwiseDestination;
|
||||
|
||||
public PocketEntranceDestination() {}
|
||||
|
||||
@Override public void readFromNBT(NBTTagCompound nbt) { super.readFromNBT(nbt); NBTUtils.readFromNBT(this, nbt); }
|
||||
@Override public NBTTagCompound writeToNBT(NBTTagCompound nbt) { nbt = super.writeToNBT(nbt); return NBTUtils.writeToNBT(this, nbt); }
|
||||
@Override public void readFromNBT(NBTTagCompound nbt) {
|
||||
super.readFromNBT(nbt);
|
||||
ifDestination = nbt.hasKey("ifDestination") ? RiftDestination.readDestinationNBT(nbt.getCompoundTag("ifDestination")) : null;
|
||||
otherwiseDestination = nbt.hasKey("otherwiseDestination") ? RiftDestination.readDestinationNBT(nbt.getCompoundTag("otherwiseDestination")) : null;
|
||||
NBTUtils.readFromNBT(this, nbt);
|
||||
}
|
||||
@Override public NBTTagCompound writeToNBT(NBTTagCompound nbt) {
|
||||
nbt = super.writeToNBT(nbt);
|
||||
if (ifDestination != null) nbt.setTag("ifDestination", ifDestination.writeToNBT(new NBTTagCompound()));
|
||||
if (otherwiseDestination != null) nbt.setTag("otherwiseDestination", otherwiseDestination.writeToNBT(new NBTTagCompound()));
|
||||
return NBTUtils.writeToNBT(this, nbt);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean teleport(RotatedLocation loc, Entity entity) {
|
||||
|
|
|
@ -9,8 +9,9 @@ import org.dimdev.dimdoors.shared.VirtualLocation;
|
|||
import org.dimdev.dimdoors.shared.pockets.Pocket;
|
||||
import org.dimdev.dimdoors.shared.pockets.PocketGenerator;
|
||||
|
||||
@Getter @AllArgsConstructor @NoArgsConstructor @Builder(toBuilder = true) @ToString
|
||||
@Getter @AllArgsConstructor @Builder(toBuilder = true) @ToString
|
||||
public class PublicPocketDestination extends LinkingDestination {
|
||||
// public PublicPocketDestination() {}
|
||||
|
||||
@Override public void readFromNBT(NBTTagCompound nbt) { super.readFromNBT(nbt); }
|
||||
@Override public NBTTagCompound writeToNBT(NBTTagCompound nbt) { nbt = super.writeToNBT(nbt); return nbt; }
|
||||
|
@ -20,12 +21,11 @@ public class PublicPocketDestination extends LinkingDestination {
|
|||
VirtualLocation riftVirtualLocation = VirtualLocation.fromLocation(loc.getLocation());
|
||||
VirtualLocation newVirtualLocation = null;
|
||||
if (riftVirtualLocation != null) {
|
||||
int depth = Math.min(riftVirtualLocation.getDepth(), 1);
|
||||
int depth = Math.max(riftVirtualLocation.getDepth(), 1);
|
||||
newVirtualLocation = riftVirtualLocation.toBuilder().depth(depth).build();
|
||||
}
|
||||
Pocket pocket = PocketGenerator.generatePublicPocket(newVirtualLocation);
|
||||
pocket.setup();
|
||||
|
||||
pocket.linkPocketTo(new GlobalDestination(loc.getLocation()), null);
|
||||
|
||||
return pocket.getEntrance();
|
||||
|
|
|
@ -1,27 +1,20 @@
|
|||
package org.dimdev.dimdoors.shared.rifts.registry;
|
||||
|
||||
import lombok.*;
|
||||
import lombok.experimental.Wither;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import org.dimdev.annotatednbt.NBTSerializable;
|
||||
import org.dimdev.annotatednbt.Saved;
|
||||
import org.dimdev.ddutils.Location;
|
||||
import org.dimdev.ddutils.nbt.INBTStorable;
|
||||
import org.dimdev.ddutils.nbt.NBTUtils;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
@NBTSerializable @AllArgsConstructor @NoArgsConstructor @EqualsAndHashCode @Builder(toBuilder = true) @ToString
|
||||
public class LinkProperties implements INBTStorable {
|
||||
@Wither public Location rift;
|
||||
|
||||
@Saved @Builder.Default public UUID id = UUID.randomUUID();
|
||||
@Saved @Builder.Default public float floatingWeight = 1;
|
||||
@Saved @Builder.Default public float entranceWeight = 1;
|
||||
@Saved @Builder.Default public Set<Integer> groups = new HashSet<>();
|
||||
@Saved public UUID replaceDestination;
|
||||
@Saved @Builder.Default public int linksRemaining = 1;
|
||||
@Saved @Builder.Default public boolean oneWay = false;
|
||||
|
||||
|
|
|
@ -2,12 +2,18 @@ package org.dimdev.dimdoors.shared.rifts.registry;
|
|||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.ToString;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import org.dimdev.annotatednbt.NBTSerializable;
|
||||
import org.dimdev.annotatednbt.Saved;
|
||||
import org.dimdev.ddutils.nbt.NBTUtils;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@AllArgsConstructor @NoArgsConstructor
|
||||
@AllArgsConstructor @NoArgsConstructor @ToString
|
||||
@NBTSerializable public class PlayerRiftPointer extends RegistryVertex {
|
||||
@Saved public UUID player;
|
||||
|
||||
@Override public void readFromNBT(NBTTagCompound nbt) { super.readFromNBT(nbt); NBTUtils.readFromNBT(this, nbt); }
|
||||
@Override public NBTTagCompound writeToNBT(NBTTagCompound nbt) { nbt = super.writeToNBT(nbt); return NBTUtils.writeToNBT(this, nbt); }
|
||||
}
|
||||
|
|
|
@ -2,11 +2,17 @@ package org.dimdev.dimdoors.shared.rifts.registry;
|
|||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.ToString;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import org.dimdev.annotatednbt.NBTSerializable;
|
||||
import org.dimdev.annotatednbt.Saved;
|
||||
import org.dimdev.ddutils.nbt.NBTUtils;
|
||||
|
||||
@AllArgsConstructor @NoArgsConstructor @NBTSerializable
|
||||
public class PocketEntrancePointer extends RegistryVertex { // TODO: PocketRiftPointer superclass?
|
||||
@AllArgsConstructor @NoArgsConstructor @ToString
|
||||
@NBTSerializable public class PocketEntrancePointer extends RegistryVertex { // TODO: PocketRiftPointer superclass?
|
||||
@Saved public int pocketDim;
|
||||
@Saved public int pocketId;
|
||||
|
||||
@Override public void readFromNBT(NBTTagCompound nbt) { super.readFromNBT(nbt); NBTUtils.readFromNBT(this, nbt); }
|
||||
@Override public NBTTagCompound writeToNBT(NBTTagCompound nbt) { nbt = super.writeToNBT(nbt); return NBTUtils.writeToNBT(this, nbt); }
|
||||
}
|
||||
|
|
|
@ -1,26 +1,40 @@
|
|||
package org.dimdev.dimdoors.shared.rifts.registry;
|
||||
|
||||
import lombok.ToString;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import org.dimdev.annotatednbt.NBTSerializable;
|
||||
import org.dimdev.annotatednbt.Saved;
|
||||
import org.dimdev.ddutils.nbt.INBTStorable;
|
||||
import org.dimdev.ddutils.nbt.NBTUtils;
|
||||
import org.dimdev.dimdoors.DimDoors;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public abstract class RegistryVertex {
|
||||
@ToString
|
||||
@NBTSerializable public abstract class RegistryVertex implements INBTStorable {
|
||||
public int dim; // The dimension to store this object in. Links are stored in both registries.
|
||||
@Saved public UUID id = UUID.randomUUID(); // Used to create pointers to registry vertices. Should not be used for anything other than saving.
|
||||
|
||||
public void sourceGone(RegistryVertex source) {
|
||||
DimDoors.log.info("Notified vertex " + this + " that source " + source + " is gone");
|
||||
RiftRegistry.instance().markSubregistryDirty(dim);
|
||||
}
|
||||
|
||||
public void targetGone(RegistryVertex target) {
|
||||
DimDoors.log.info("Notified vertex " + this + " that target " + target + " is gone");
|
||||
RiftRegistry.instance().markSubregistryDirty(dim);
|
||||
}
|
||||
|
||||
public void sourceAdded(RegistryVertex to) {
|
||||
public void sourceAdded(RegistryVertex source) {
|
||||
DimDoors.log.info("Notified vertex " + this + " that source " + source + " was added");
|
||||
RiftRegistry.instance().markSubregistryDirty(dim);
|
||||
}
|
||||
|
||||
public void targetAdded(RegistryVertex to) {
|
||||
public void targetAdded(RegistryVertex target) {
|
||||
DimDoors.log.info("Notified vertex " + this + " that target " + target + " was added");
|
||||
RiftRegistry.instance().markSubregistryDirty(dim);
|
||||
}
|
||||
|
||||
@Override public void readFromNBT(NBTTagCompound nbt) { NBTUtils.readFromNBT(this, nbt); }
|
||||
@Override public NBTTagCompound writeToNBT(NBTTagCompound nbt) { return NBTUtils.writeToNBT(this, nbt); }
|
||||
}
|
||||
|
|
|
@ -2,12 +2,16 @@ package org.dimdev.dimdoors.shared.rifts.registry;
|
|||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.ToString;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import org.dimdev.annotatednbt.NBTSerializable;
|
||||
import org.dimdev.annotatednbt.Saved;
|
||||
import org.dimdev.ddutils.Location;
|
||||
import org.dimdev.ddutils.nbt.NBTUtils;
|
||||
import org.dimdev.dimdoors.DimDoors;
|
||||
import org.dimdev.dimdoors.shared.rifts.TileEntityRift;
|
||||
|
||||
@NoArgsConstructor @AllArgsConstructor
|
||||
@NoArgsConstructor @AllArgsConstructor @ToString
|
||||
@NBTSerializable public class Rift extends RegistryVertex {
|
||||
public @Saved Location location;
|
||||
public @Saved boolean isFloating;
|
||||
|
@ -25,7 +29,6 @@ import org.dimdev.dimdoors.shared.rifts.TileEntityRift;
|
|||
if (source instanceof Rift) {
|
||||
riftTileEntity.sourceGone(((Rift) source).location);
|
||||
}
|
||||
riftTileEntity.updateColor();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -38,20 +41,19 @@ import org.dimdev.dimdoors.shared.rifts.TileEntityRift;
|
|||
riftTileEntity.updateColor();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sourceAdded(RegistryVertex source) {
|
||||
super.sourceAdded(source);
|
||||
public void targetChanged(RegistryVertex target) {
|
||||
DimDoors.log.info("Rift " + this + " notified of target " + target + " having changed. Updating color.");
|
||||
((TileEntityRift) location.getTileEntity()).updateColor();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void targetAdded(RegistryVertex target) {
|
||||
super.targetAdded(target);
|
||||
((TileEntityRift) location.getTileEntity()).updateColor();
|
||||
}
|
||||
|
||||
public void markDirty() {
|
||||
public void markDirty() { // TODO: better name
|
||||
RiftRegistry.instance().markSubregistryDirty(dim);
|
||||
((TileEntityRift) location.getTileEntity()).updateColor();
|
||||
for (Location location : RiftRegistry.instance().getSources(location)) {
|
||||
RiftRegistry.instance().getRift(location).targetChanged(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override public void readFromNBT(NBTTagCompound nbt) { super.readFromNBT(nbt); NBTUtils.readFromNBT(this, nbt); }
|
||||
@Override public NBTTagCompound writeToNBT(NBTTagCompound nbt) { nbt = super.writeToNBT(nbt); return NBTUtils.writeToNBT(this, nbt); }
|
||||
}
|
||||
|
|
|
@ -1,3 +1,32 @@
|
|||
package org.dimdev.dimdoors.shared.rifts.registry;
|
||||
|
||||
public class RiftPlaceholder extends Rift {} // TODO: don't extend rift
|
||||
import lombok.ToString;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import org.dimdev.annotatednbt.NBTSerializable;
|
||||
import org.dimdev.dimdoors.DimDoors;
|
||||
|
||||
@ToString
|
||||
@NBTSerializable public class RiftPlaceholder extends Rift { // TODO: don't extend rift
|
||||
|
||||
@Override public void sourceGone(RegistryVertex source) {}
|
||||
|
||||
@Override public void targetGone(RegistryVertex target) {}
|
||||
|
||||
@Override public void sourceAdded(RegistryVertex source) {}
|
||||
|
||||
@Override public void targetAdded(RegistryVertex target) {}
|
||||
|
||||
@Override public void targetChanged(RegistryVertex target) {}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound nbt) {
|
||||
DimDoors.log.warn("Reading a rift placeholder from NBT!");
|
||||
super.readFromNBT(nbt);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTTagCompound writeToNBT(NBTTagCompound nbt) {
|
||||
DimDoors.log.warn("Writing a rift placeholder from NBT!");
|
||||
return super.writeToNBT(nbt);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,7 +8,6 @@ import net.minecraft.world.storage.WorldSavedData;
|
|||
import net.minecraftforge.common.DimensionManager;
|
||||
import org.dimdev.ddutils.Location;
|
||||
import org.dimdev.ddutils.WorldUtils;
|
||||
import org.dimdev.ddutils.nbt.NBTUtils;
|
||||
import org.dimdev.dimdoors.DimDoors;
|
||||
import org.dimdev.dimdoors.ddutils.GraphUtils;
|
||||
import org.dimdev.dimdoors.shared.pockets.Pocket;
|
||||
|
@ -59,7 +58,8 @@ public class RiftRegistry extends WorldSavedData {
|
|||
// Read rifts in this dimension
|
||||
NBTTagList riftsNBT = (NBTTagList) nbt.getTag("rifts");
|
||||
for (NBTBase riftNBT : riftsNBT) {
|
||||
Rift rift = NBTUtils.readFromNBT(new Rift(), (NBTTagCompound) riftNBT);
|
||||
Rift rift = new Rift();
|
||||
rift.readFromNBT((NBTTagCompound) riftNBT);
|
||||
rift.dim = dim;
|
||||
graph.addVertex(rift);
|
||||
uuidMap.put(rift.id, rift);
|
||||
|
@ -68,7 +68,8 @@ public class RiftRegistry extends WorldSavedData {
|
|||
|
||||
NBTTagList pocketsNBT = (NBTTagList) nbt.getTag("pockets");
|
||||
for (NBTBase pocketNBT : pocketsNBT) {
|
||||
PocketEntrancePointer pocket = NBTUtils.readFromNBT(new PocketEntrancePointer(), (NBTTagCompound) pocketNBT);
|
||||
PocketEntrancePointer pocket = new PocketEntrancePointer();
|
||||
pocket.readFromNBT((NBTTagCompound) pocketNBT);
|
||||
pocket.dim = dim;
|
||||
graph.addVertex(pocket);
|
||||
uuidMap.put(pocket.id, pocket);
|
||||
|
@ -96,7 +97,7 @@ public class RiftRegistry extends WorldSavedData {
|
|||
NBTTagList pocketsNBT = new NBTTagList();
|
||||
for (RegistryVertex vertex : graph.vertexSet()) {
|
||||
if (vertex.dim == dim) {
|
||||
NBTTagCompound vertexNBT = NBTUtils.writeToNBT(vertex, new NBTTagCompound());
|
||||
NBTTagCompound vertexNBT = vertex.writeToNBT(new NBTTagCompound());
|
||||
if (vertex instanceof Rift) {
|
||||
riftsNBT.appendTag(vertexNBT);
|
||||
} else if (vertex instanceof PocketEntrancePointer) {
|
||||
|
@ -118,11 +119,10 @@ public class RiftRegistry extends WorldSavedData {
|
|||
NBTTagCompound linkNBT = new NBTTagCompound();
|
||||
linkNBT.setUniqueId("from", from.id);
|
||||
linkNBT.setUniqueId("to", to.id);
|
||||
NBTUtils.writeToNBT(edge, linkNBT); // Write in both registries, we might want to notify when there's a missing world later
|
||||
linksNBT.appendTag(linkNBT);
|
||||
}
|
||||
}
|
||||
nbt.setTag("links", riftsNBT);
|
||||
nbt.setTag("links", linksNBT);
|
||||
|
||||
return nbt;
|
||||
}
|
||||
|
@ -227,7 +227,8 @@ public class RiftRegistry extends WorldSavedData {
|
|||
// </editor-fold>
|
||||
|
||||
public boolean isRiftAt(Location location) {
|
||||
return locationMap.get(location) != null;
|
||||
Rift possibleRift = locationMap.get(location);
|
||||
return possibleRift != null && !(possibleRift instanceof RiftPlaceholder);
|
||||
}
|
||||
|
||||
public Rift getRift(Location location) {
|
||||
|
@ -236,11 +237,27 @@ public class RiftRegistry extends WorldSavedData {
|
|||
return rift;
|
||||
}
|
||||
|
||||
private Rift getRiftOrPlaceholder(Location location) {
|
||||
Rift rift = locationMap.get(location);
|
||||
if (rift == null) {
|
||||
DimDoors.log.info("Creating a rift placeholder at " + location);
|
||||
rift = new RiftPlaceholder();
|
||||
rift.dim = location.getDim();
|
||||
rift.location = location;
|
||||
locationMap.put(location, rift);
|
||||
uuidMap.put(rift.id, rift);
|
||||
graph.addVertex(rift);
|
||||
markSubregistryDirty(rift.dim);
|
||||
}
|
||||
return rift;
|
||||
}
|
||||
|
||||
public void addRift(Location location) {
|
||||
DimDoors.log.info("Adding rift at " + location);
|
||||
RegistryVertex currentRift = getRift(location);
|
||||
RegistryVertex currentRift = locationMap.get(location);
|
||||
Rift rift;
|
||||
if (currentRift instanceof RiftPlaceholder) {
|
||||
DimDoors.log.info("Converting a rift placeholder at " + location + " into a rift");
|
||||
rift = new Rift(location);
|
||||
rift.dim = location.getDim();
|
||||
rift.id = currentRift.id;
|
||||
|
@ -262,18 +279,37 @@ public class RiftRegistry extends WorldSavedData {
|
|||
|
||||
Rift rift = getRift(location);
|
||||
|
||||
// Notify the adjacent vertices of the change
|
||||
for (DefaultEdge edge : graph.incomingEdgesOf(rift)) graph.getEdgeSource(edge).targetGone(rift);
|
||||
for (DefaultEdge edge : graph.outgoingEdgesOf(rift)) graph.getEdgeTarget(edge).sourceGone(rift);
|
||||
Set<DefaultEdge> incomingEdges = graph.incomingEdgesOf(rift);
|
||||
Set<DefaultEdge> outgoingEdges = graph.outgoingEdgesOf(rift);
|
||||
|
||||
graph.removeVertex(rift);
|
||||
locationMap.remove(location);
|
||||
uuidMap.remove(rift.id);
|
||||
rift.markDirty();
|
||||
markSubregistryDirty(rift.dim);
|
||||
|
||||
// Notify the adjacent vertices of the change
|
||||
for (DefaultEdge edge : incomingEdges) graph.getEdgeSource(edge).targetGone(rift);
|
||||
for (DefaultEdge edge : outgoingEdges) graph.getEdgeTarget(edge).sourceGone(rift);
|
||||
}
|
||||
|
||||
private void addEdge(RegistryVertex from, RegistryVertex to) {
|
||||
graph.addEdge(from, to);
|
||||
if (from instanceof PlayerRiftPointer) {
|
||||
markDirty();
|
||||
} else if (from instanceof Rift) {
|
||||
((Rift) from).markDirty();
|
||||
} else {
|
||||
markSubregistryDirty(from.dim);
|
||||
}
|
||||
if (to instanceof Rift) {
|
||||
((Rift) to).markDirty();
|
||||
} else {
|
||||
markSubregistryDirty(to.dim);
|
||||
}
|
||||
}
|
||||
|
||||
private void removeEdge(RegistryVertex from, RegistryVertex to) {
|
||||
graph.removeEdge(from, to);
|
||||
if (from instanceof PlayerRiftPointer) {
|
||||
markDirty();
|
||||
} else {
|
||||
|
@ -284,15 +320,17 @@ public class RiftRegistry extends WorldSavedData {
|
|||
|
||||
public void addLink(Location locationFrom, Location locationTo) {
|
||||
DimDoors.log.info("Adding link " + locationFrom + " -> " + locationTo);
|
||||
Rift from = getRift(locationFrom);
|
||||
|
||||
Rift to = getRift(locationTo);
|
||||
Rift from = getRiftOrPlaceholder(locationFrom);
|
||||
Rift to = getRiftOrPlaceholder(locationTo);
|
||||
|
||||
addEdge(from, to);
|
||||
|
||||
// Notify the linked vertices of the change
|
||||
from.targetAdded(to);
|
||||
to.sourceAdded(from);
|
||||
if (!(from instanceof RiftPlaceholder) && !(to instanceof RiftPlaceholder)) {
|
||||
from.targetAdded(to);
|
||||
to.sourceAdded(from);
|
||||
}
|
||||
}
|
||||
|
||||
public void removeLink(Location locationFrom, Location locationTo) {
|
||||
|
@ -301,7 +339,7 @@ public class RiftRegistry extends WorldSavedData {
|
|||
Rift from = getRift(locationFrom);
|
||||
Rift to = getRift(locationTo);
|
||||
|
||||
addEdge(from, to);
|
||||
removeEdge(from, to);
|
||||
|
||||
// Notify the linked vertices of the change
|
||||
from.targetGone(to);
|
||||
|
@ -356,15 +394,18 @@ public class RiftRegistry extends WorldSavedData {
|
|||
|
||||
private void setPlayerRiftPointer(UUID playerUUID, Location rift, Map<UUID, PlayerRiftPointer> map) {
|
||||
PlayerRiftPointer pointer = map.get(playerUUID);
|
||||
if (pointer == null) {
|
||||
if (pointer != null) {
|
||||
graph.removeVertex(pointer);
|
||||
map.remove(playerUUID);
|
||||
uuidMap.remove(pointer.id);
|
||||
}
|
||||
if (rift != null) {
|
||||
pointer = new PlayerRiftPointer(playerUUID);
|
||||
graph.addVertex(pointer);
|
||||
map.put(playerUUID, pointer);
|
||||
uuidMap.put(pointer.id, pointer);
|
||||
} else {
|
||||
graph.removeAllEdges(graph.outgoingEdgesOf(pointer));
|
||||
addEdge(pointer, getRift(rift));
|
||||
}
|
||||
addEdge(pointer, getRift(rift));
|
||||
}
|
||||
|
||||
public void setLastPrivatePocketEntrance(UUID playerUUID, Location rift) {
|
||||
|
@ -375,7 +416,7 @@ public class RiftRegistry extends WorldSavedData {
|
|||
public Location getPrivatePocketExit(UUID playerUUID) {
|
||||
PlayerRiftPointer entrancePointer = lastPrivatePocketExits.get(playerUUID);
|
||||
Rift entrance = (Rift) GraphUtils.followPointer(graph, entrancePointer);
|
||||
return entrance.location;
|
||||
return entrance != null ? entrance.location : null;
|
||||
}
|
||||
|
||||
public void setLastPrivatePocketExit(UUID playerUUID, Location rift) {
|
||||
|
@ -399,7 +440,7 @@ public class RiftRegistry extends WorldSavedData {
|
|||
}
|
||||
|
||||
public Set<Location> getTargets(Location location) {
|
||||
return graph.outgoingEdgesOf(locationMap.get(location)).stream()
|
||||
return graph.outgoingEdgesOf(getRift(location)).stream()
|
||||
.map(graph::getEdgeTarget)
|
||||
.map(Rift.class::cast)
|
||||
.map(rift -> rift.location)
|
||||
|
@ -407,7 +448,7 @@ public class RiftRegistry extends WorldSavedData {
|
|||
}
|
||||
|
||||
public Set<Location> getSources(Location location) {
|
||||
return graph.incomingEdgesOf(locationMap.get(location)).stream()
|
||||
return graph.incomingEdgesOf(getRift(location)).stream()
|
||||
.map(graph::getEdgeTarget)
|
||||
.map(Rift.class::cast)
|
||||
.map(rift -> rift.location)
|
||||
|
|
|
@ -65,6 +65,14 @@ import java.util.Random;
|
|||
return status;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void teleportTo(Entity entity, float fromYaw, float fromPitch) {
|
||||
if (relativeRotation) {
|
||||
TeleportUtils.teleport(entity, new Location(world, pos.offset(orientation, tpOffset)), orientation.getHorizontalAngle() + entity.rotationYaw - fromYaw, entity.rotationPitch - fromPitch);
|
||||
} else {
|
||||
TeleportUtils.teleport(entity, new Location(world, pos.offset(orientation, tpOffset)), orientation.getHorizontalAngle(), 0);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void teleportTo(Entity entity) {
|
||||
TeleportUtils.teleport(entity, new Location(world, pos.offset(orientation, tpOffset)), orientation.getHorizontalAngle(), 0);
|
||||
|
|
|
@ -4,7 +4,10 @@ import net.minecraft.block.Block;
|
|||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.tileentity.*;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.util.text.TextComponentString;
|
||||
import net.minecraftforge.fml.common.registry.ForgeRegistries;
|
||||
import org.dimdev.ddutils.schem.Schematic;
|
||||
import org.dimdev.dimdoors.DimDoors;
|
||||
|
@ -33,7 +36,7 @@ public final class SchematicConverter {
|
|||
Schematic schematic = new Schematic();
|
||||
|
||||
schematic.version = 1; //already the default value
|
||||
schematic.author = "DimDoors"; // TODO: didn't the old schematics have an author?
|
||||
schematic.author = "DimDoors"; // Old schematics didn't have an author
|
||||
schematic.schematicName = name.equals("") ? "Unknown" : name;
|
||||
schematic.creationDate = System.currentTimeMillis();
|
||||
schematic.requiredMods = new String[]{DimDoors.MODID};
|
||||
|
@ -128,46 +131,49 @@ public final class SchematicConverter {
|
|||
NBTTagList tileEntitiesNBT = (NBTTagList) nbt.getTag("TileEntities");
|
||||
for (int i = 0; i < tileEntitiesNBT.tagCount(); i++) {
|
||||
NBTTagCompound tileEntityNBT = tileEntitiesNBT.getCompoundTagAt(i);
|
||||
int x = tileEntityNBT.getInteger("x");
|
||||
int y = tileEntityNBT.getInteger("y");
|
||||
int z = tileEntityNBT.getInteger("z");
|
||||
switch (tileEntityNBT.getString("id")) {
|
||||
case "TileEntityDimDoor":
|
||||
tileEntityNBT = new NBTTagCompound();
|
||||
tileEntityNBT.setString("id", "EntranceRift");
|
||||
tileEntityNBT.setInteger("x", x);
|
||||
tileEntityNBT.setInteger("y", y);
|
||||
tileEntityNBT.setInteger("z", z);
|
||||
// TODO
|
||||
break;
|
||||
case "TileEntityRift":
|
||||
tileEntityNBT = new NBTTagCompound();
|
||||
tileEntityNBT.setString("id", "FloatingRift");
|
||||
tileEntityNBT.setInteger("x", x);
|
||||
tileEntityNBT.setInteger("y", y);
|
||||
tileEntityNBT.setInteger("z", z);
|
||||
// TODO
|
||||
break;
|
||||
continue;
|
||||
case "Sign":
|
||||
DimDoors.log.info("Sign: "
|
||||
+ tileEntityNBT.getString("Text1") + "|"
|
||||
+ tileEntityNBT.getString("Text2") + "|"
|
||||
+ tileEntityNBT.getString("Text3") + "|"
|
||||
+ tileEntityNBT.getString("Text4"));
|
||||
tileEntityNBT.setString("Text1", "{\"text\":\"" + tileEntityNBT.getString("Text1") + "\"}");
|
||||
tileEntityNBT.setString("Text2", "{\"text\":\"" + tileEntityNBT.getString("Text2") + "\"}");
|
||||
tileEntityNBT.setString("Text3", "{\"text\":\"" + tileEntityNBT.getString("Text3") + "\"}");
|
||||
tileEntityNBT.setString("Text4", "{\"text\":\"" + tileEntityNBT.getString("Text4") + "\"}");
|
||||
tileEntityNBT.setString("Text1", ITextComponent.Serializer.componentToJson(new TextComponentString(tileEntityNBT.getString("Text1"))));
|
||||
tileEntityNBT.setString("Text2", ITextComponent.Serializer.componentToJson(new TextComponentString(tileEntityNBT.getString("Text2"))));
|
||||
tileEntityNBT.setString("Text3", ITextComponent.Serializer.componentToJson(new TextComponentString(tileEntityNBT.getString("Text3"))));
|
||||
tileEntityNBT.setString("Text4", ITextComponent.Serializer.componentToJson(new TextComponentString(tileEntityNBT.getString("Text4"))));
|
||||
break;
|
||||
case "Chest":
|
||||
// TODO
|
||||
break;
|
||||
default:
|
||||
DimDoors.log.info("TileEntity found: " + tileEntityNBT.getString("id"));
|
||||
break;
|
||||
}
|
||||
tileEntityNBT.setString("id", translateId(tileEntityNBT.getString("id")).toString());
|
||||
schematic.tileEntities.add(tileEntityNBT);
|
||||
}
|
||||
|
||||
// TODO: entities (and replace end portal frame with monoliths)
|
||||
|
||||
return schematic;
|
||||
}
|
||||
|
||||
private static ResourceLocation translateId(String id) { // TODO
|
||||
switch (id) {
|
||||
case "Sign":
|
||||
return TileEntity.getKey(TileEntitySign.class);
|
||||
case "Music":
|
||||
return TileEntity.getKey(TileEntityNote.class);
|
||||
case "Trap":
|
||||
return TileEntity.getKey(TileEntityDispenser.class);
|
||||
case "Comparator":
|
||||
return TileEntity.getKey(TileEntityComparator.class);
|
||||
case "Hopper":
|
||||
return TileEntity.getKey(TileEntityHopper.class);
|
||||
case "Furnace":
|
||||
return TileEntity.getKey(TileEntityFurnace.class);
|
||||
case "Chest":
|
||||
return TileEntity.getKey(TileEntityChest.class);
|
||||
default:
|
||||
throw new RuntimeException("Tile entity ID " + id + " not supported by conversion code");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in a new issue