fixed rift serialization

This commit is contained in:
CreepyCre 2021-01-27 22:56:03 +01:00
parent 615aa06606
commit cf94db47d8
8 changed files with 18 additions and 19 deletions

View file

@ -27,8 +27,8 @@ public class ModBlockEntityTypes {
EntranceRiftBlockEntity::new, EntranceRiftBlockEntity::new,
ModBlocks.OAK_DIMENSIONAL_DOOR, ModBlocks.IRON_DIMENSIONAL_DOOR, ModBlocks.GOLD_DIMENSIONAL_DOOR, ModBlocks.QUARTZ_DIMENSIONAL_DOOR, ModBlocks.DIMENSIONAL_PORTAL); ModBlocks.OAK_DIMENSIONAL_DOOR, ModBlocks.IRON_DIMENSIONAL_DOOR, ModBlocks.GOLD_DIMENSIONAL_DOOR, ModBlocks.QUARTZ_DIMENSIONAL_DOOR, ModBlocks.DIMENSIONAL_PORTAL);
private static <E extends BlockEntity> BlockEntityType<E> register(String id, Supplier<? extends E> supplier, Block... blocks) { private static <E extends BlockEntity> BlockEntityType<E> register(String id, Supplier<E> supplier, Block... blocks) {
return Registry.register(Registry.BLOCK_ENTITY_TYPE, id, new BlockEntityType<>(supplier, Sets.newHashSet(blocks), null)); return Registry.register(Registry.BLOCK_ENTITY_TYPE, id, BlockEntityType.Builder.create(supplier, blocks).build(null));
} }
public static void init() { public static void init() {

View file

@ -46,6 +46,7 @@ public abstract class RiftBlockEntity extends BlockEntity implements BlockEntity
// NBT // NBT
@Override @Override
public void fromTag(BlockState state, CompoundTag nbt) { public void fromTag(BlockState state, CompoundTag nbt) {
super.fromTag(state, nbt);
this.deserialize(nbt); this.deserialize(nbt);
} }
@ -55,9 +56,8 @@ public abstract class RiftBlockEntity extends BlockEntity implements BlockEntity
@Override @Override
public CompoundTag toTag(CompoundTag tag) { public CompoundTag toTag(CompoundTag tag) {
this.serialize(tag); super.toTag(tag);
return this.serialize(tag);
return super.toTag(tag);
} }
public CompoundTag serialize(CompoundTag tag) { public CompoundTag serialize(CompoundTag tag) {

View file

@ -64,18 +64,19 @@ public class SchematicGenerator extends VirtualPocket {
@Override @Override
public Pocket prepareAndPlacePocket(PocketGenerationParameters parameters) { public Pocket prepareAndPlacePocket(PocketGenerationParameters parameters) {
ServerWorld world = parameters.getWorld(); ServerWorld world = parameters.getWorld();
VirtualLocation virtualLocation = parameters.getVirtualLocation(); VirtualLocation sourceVirtualLocation = parameters.getSourceVirtualLocation();
VirtualTarget linkTo = parameters.getLinkTo(); VirtualTarget linkTo = parameters.getLinkTo();
LinkProperties linkProperties = parameters.getLinkProperties(); LinkProperties linkProperties = parameters.getLinkProperties();
PocketTemplateV2 template = SchematicV2Handler.getInstance().getTemplates().get(templateID); PocketTemplateV2 template = SchematicV2Handler.getInstance().getTemplates().get(templateID);
if (template == null) throw new RuntimeException("Pocket template of id " + templateID + " not found!"); if (template == null) throw new RuntimeException("Pocket template of id " + templateID + " not found!");
LOGGER.info("Generating pocket from template " + template.getId() + " at virtual location " + virtualLocation);
Pocket pocket = DimensionalRegistry.getPocketDirectory(world.getRegistryKey()).newPocket(); Pocket pocket = DimensionalRegistry.getPocketDirectory(world.getRegistryKey()).newPocket();
LOGGER.info("Generating pocket from template " + template.getId() + " at location " + pocket.getOrigin());
template.place(pocket); template.place(pocket);
template.setup(pocket, linkTo, linkProperties); template.setup(pocket, linkTo, linkProperties);
pocket.virtualLocation = virtualLocation; pocket.virtualLocation = sourceVirtualLocation; //TODO: this makes very little sense
return pocket; return pocket;
} }

View file

@ -74,7 +74,7 @@ public class DepthDependentSelector extends VirtualPocket {
private VirtualPocket getNextPocket(PocketGenerationParameters parameters) { private VirtualPocket getNextPocket(PocketGenerationParameters parameters) {
for (Pair<String, VirtualPocket> pair : pocketList) { for (Pair<String, VirtualPocket> pair : pocketList) {
if (Pattern.compile(pair.getLeft()).matcher(String.valueOf(parameters.getVirtualLocation().getDepth())).matches()) { if (Pattern.compile(pair.getLeft()).matcher(String.valueOf(parameters.getSourceVirtualLocation().getDepth())).matches()) {
return pair.getRight(); return pair.getRight();
} }
} }

View file

@ -26,7 +26,7 @@ public class GlobalReference extends RiftReference {
public static CompoundTag toTag(GlobalReference virtualTarget) { public static CompoundTag toTag(GlobalReference virtualTarget) {
CompoundTag tag = new CompoundTag(); CompoundTag tag = new CompoundTag();
tag.put("target", Location.toTag(virtualTarget.location)); tag.put("target", Location.toTag(virtualTarget.getReferencedLocation()));
return tag; return tag;
} }

View file

@ -11,14 +11,13 @@ public abstract class RestoringTarget extends VirtualTarget {
@Override @Override
public Target receiveOther() { public Target receiveOther() {
if (this.getTarget() != null) { if (this.getTarget() != null) {
this.getTarget().location = this.location;
return this.getTarget(); return this.getTarget();
} }
Location linkTarget = this.makeLinkTarget(); Location linkTarget = this.makeLinkTarget();
if (linkTarget != null) { if (linkTarget != null) {
this.setTarget(RiftReference.tryMakeLocal(this.location, linkTarget)); this.setTarget(RiftReference.tryMakeLocal(this.location, linkTarget));
this.getTarget().setLocation(this.location); this.getTarget().setLocation(linkTarget);
this.getTarget().register(); this.getTarget().register();
return this.getTarget(); return this.getTarget();

View file

@ -8,14 +8,14 @@ import org.dimdev.dimdoors.world.pocket.VirtualLocation;
public class PocketGenerationParameters { public class PocketGenerationParameters {
private final ServerWorld world; private final ServerWorld world;
private final String group; private final String group;
private final VirtualLocation virtualLocation; private final VirtualLocation sourceVirtualLocation;
private final VirtualTarget linkTo; private final VirtualTarget linkTo;
private final LinkProperties linkProperties; private final LinkProperties linkProperties;
public PocketGenerationParameters(ServerWorld world, String group, VirtualLocation virtualLocation, VirtualTarget linkTo, LinkProperties linkProperties) { public PocketGenerationParameters(ServerWorld world, String group, VirtualLocation sourceVirtualLocation, VirtualTarget linkTo, LinkProperties linkProperties) {
this.world = world; this.world = world;
this.group = group; this.group = group;
this.virtualLocation = virtualLocation; this.sourceVirtualLocation = sourceVirtualLocation;
this.linkTo = linkTo; this.linkTo = linkTo;
this.linkProperties = linkProperties; this.linkProperties = linkProperties;
} }
@ -28,8 +28,8 @@ public class PocketGenerationParameters {
return group; return group;
} }
public VirtualLocation getVirtualLocation() { public VirtualLocation getSourceVirtualLocation() {
return virtualLocation; return sourceVirtualLocation;
} }
public VirtualTarget getLinkTo() { public VirtualTarget getLinkTo() {

View file

@ -77,8 +77,7 @@ public class VirtualLocation {
if (virtualLocation == null) { if (virtualLocation == null) {
return new VirtualLocation(OVERWORLD, location.getX(), location.getZ(), 5); return new VirtualLocation(OVERWORLD, location.getX(), location.getZ(), 5);
} }
return new VirtualLocation(location.getWorldId(), location.getX(), location.getZ(), virtualLocation.getDepth());
return virtualLocation;
} }
public Location projectToWorld(boolean acceptLimbo) { public Location projectToWorld(boolean acceptLimbo) {