This commit is contained in:
CreepyCre 2021-04-11 19:15:57 +02:00
parent f8a83d4c3d
commit 712bb16d2f
92 changed files with 690 additions and 659 deletions
build.gradle
src/main
java/org/dimdev/dimdoors
api
block
client
command
entity
fluid
item
mixin
network/packet/s2c
pockets
rift
world
resources
data/dimdoors/dimension
dimdoors.mixins.json
schematics/org/dimdev/dimdoors/util/schematic

View file

@ -112,10 +112,10 @@ minecraft {
}
dependencies {
minecraft "com.mojang:minecraft:21w11a"
mappings "net.fabricmc:yarn:21w11a+build.4:v2"
minecraft "com.mojang:minecraft:21w14a"
mappings "net.fabricmc:yarn:21w14a+build.18:v2"
modImplementation "net.fabricmc:fabric-loader:0.11.3"
modImplementation "net.fabricmc.fabric-api:fabric-api:0.32.4+1.17"
modImplementation "net.fabricmc.fabric-api:fabric-api:0.32.7+1.17"
includeCompile("com.flowpowered", "flow-math", "1.0.3")
includeCompile("org.jgrapht", "jgrapht-core", "1.1.0")
includeCompile("com.github.DimensionalDevelopment", "poly2tri.java", "0.1.1")

View file

@ -21,7 +21,7 @@ import net.minecraft.util.Identifier;
@Environment(EnvType.CLIENT)
public final class DimensionalPortalRenderer {
public static final Identifier WARP_PATH;
private static final RenderPhase.class_5942 DIMENSIONAL_PORTAL_SHADER;
private static final RenderPhase.Shader DIMENSIONAL_PORTAL_SHADER;
private static final RenderLayer RENDER_LAYER;
private static final ModelPart MODEL;
private static final ModelPart TALL_MODEL;
@ -42,7 +42,7 @@ public final class DimensionalPortalRenderer {
static {
WARP_PATH = new Identifier("dimdoors:textures/other/warp.png");
DIMENSIONAL_PORTAL_SHADER = new RenderPhase.class_5942(ModShaders::getDimensionalPortal);
DIMENSIONAL_PORTAL_SHADER = new RenderPhase.Shader(ModShaders::getDimensionalPortal);
RENDER_LAYER = RenderLayerFactory.create(
"dimensional_portal",
VertexFormats.POSITION,
@ -51,12 +51,12 @@ public final class DimensionalPortalRenderer {
false,
false,
RenderLayer.MultiPhaseParameters.builder()
.method_34578(DIMENSIONAL_PORTAL_SHADER)
.method_34577(
RenderPhase.class_5940.method_34560()
.method_34563(EndPortalBlockEntityRenderer.SKY_TEXTURE, false, false)
.method_34563(WARP_PATH, false, false)
.method_34562()
.shader(DIMENSIONAL_PORTAL_SHADER)
.texture(
RenderPhase.Textures.create()
.add(EndPortalBlockEntityRenderer.SKY_TEXTURE, false, false)
.add(WARP_PATH, false, false)
.build()
)
.build(false)
);

View file

@ -1,19 +1,18 @@
package org.dimdev.dimdoors.api.util;
import net.minecraft.nbt.IntArrayTag;
import net.minecraft.nbt.NbtIntArray;
import net.minecraft.util.math.BlockBox;
import net.minecraft.util.math.ChunkPos;
import net.minecraft.util.math.Vec3i;
import net.minecraft.world.chunk.Chunk;
public class BlockBoxUtil {
// intersection might be non real box, check with isRealBox
public static BlockBox intersection(BlockBox box1, BlockBox box2) {
return new BlockBox(Math.max(box1.minX, box2.minX), Math.max(box1.minY, box2.minY), Math.max(box1.minZ, box2.minZ), Math.min(box1.maxX, box2.maxX), Math.min(box1.maxY, box2.maxY), Math.min(box1.maxZ, box2.maxZ));
public static NbtIntArray toNbt(BlockBox box) {
return new NbtIntArray(new int[]{box.getMinX(), box.getMinY(), box.getMinZ(), box.getMaxX(), box.getMaxY(), box.getMaxZ()});
}
public static boolean isRealBox(BlockBox box) {
return box.minX <= box.maxX && box.minY <= box.maxY && box.minZ <= box.maxZ;
}
public static IntArrayTag toNbt(BlockBox box) {
return new IntArrayTag(new int[]{box.minX, box.minY, box.minZ, box.maxX, box.maxY, box.maxZ});
public static BlockBox getBox(Chunk chunk) {
ChunkPos pos = chunk.getPos();
return BlockBox.create(new Vec3i(pos.getStartX(), chunk.getBottomY(), pos.getStartZ()), new Vec3i(pos.getEndX(), chunk.getTopY() - 1, pos.getEndZ()));
}
}

View file

@ -7,7 +7,7 @@ import org.dimdev.dimdoors.DimensionalDoorsInitializer;
import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.fluid.FluidState;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
@ -88,17 +88,17 @@ public class Location {
return DimensionalDoorsInitializer.getServer().getWorld(this.world);
}
public static CompoundTag toTag(Location location) {
CompoundTag tag = new CompoundTag();
public static NbtCompound toTag(Location location) {
NbtCompound tag = new NbtCompound();
tag.putString("world", location.world.getValue().toString());
tag.putIntArray("pos", new int[]{location.getX(), location.getY(), location.getZ()});
return tag;
}
public static Location fromTag(CompoundTag tag) {
public static Location fromTag(NbtCompound tag) {
int[] pos = tag.getIntArray("pos");
return new Location(
RegistryKey.of(Registry.DIMENSION, new Identifier(tag.getString("world"))),
RegistryKey.of(Registry.WORLD_KEY, new Identifier(tag.getString("world"))),
new BlockPos(pos[0], pos[1], pos[2])
);
}

View file

@ -1,27 +1,25 @@
package org.dimdev.dimdoors.api.util;
import com.mojang.serialization.Codec;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.nbt.NbtElement;
import net.minecraft.nbt.NbtOps;
import net.minecraft.nbt.Tag;
import net.fabricmc.fabric.api.util.NbtType;
public class NbtUtil {
public static <T> T deserialize(Tag data, Codec<T> codec) {
public static <T> T deserialize(NbtElement data, Codec<T> codec) {
return NbtOps.INSTANCE.withParser(codec).apply(data).getOrThrow(true, a -> {
});
}
public static <T> Tag serialize(T data, Codec<T> codec) {
public static <T> NbtElement serialize(T data, Codec<T> codec) {
return NbtOps.INSTANCE.withEncoder(codec).apply(data).getOrThrow(true, a -> {
});
}
public static CompoundTag asCompoundTag(Tag tag, String error) {
public static NbtCompound asCompoundTag(NbtElement tag, String error) {
if (tag == null || tag.getType() == NbtType.COMPOUND) {
return (CompoundTag) tag;
return (NbtCompound) tag;
}
throw new RuntimeException(error);

View file

@ -3,11 +3,9 @@ package org.dimdev.dimdoors.api.util;
import java.util.Iterator;
import java.util.Objects;
import java.util.function.Consumer;
import net.minecraft.nbt.NbtCompound;
import org.jetbrains.annotations.NotNull;
import net.minecraft.nbt.CompoundTag;
public final class RGBA implements Cloneable, Comparable<RGBA>, Iterable<Float> {
public static final RGBA NONE = new RGBA(0, 0, 0, 0);
@ -138,8 +136,8 @@ public final class RGBA implements Cloneable, Comparable<RGBA>, Iterable<Float>
return color;
}
public static CompoundTag toTag(RGBA rgba) {
CompoundTag tag = new CompoundTag();
public static NbtCompound toTag(RGBA rgba) {
NbtCompound tag = new NbtCompound();
tag.putFloat("red", rgba.red);
tag.putFloat("green", rgba.green);
tag.putFloat("blue", rgba.blue);
@ -147,7 +145,7 @@ public final class RGBA implements Cloneable, Comparable<RGBA>, Iterable<Float>
return tag;
}
public static RGBA fromTag(CompoundTag tag) {
public static RGBA fromTag(NbtCompound tag) {
return new RGBA(
tag.getFloat("red"),
tag.getFloat("green"),

View file

@ -1,6 +1,6 @@
package org.dimdev.dimdoors.api.util;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.registry.Registry;
@ -17,8 +17,8 @@ public class RotatedLocation extends Location {
this.pitch = pitch;
}
public static CompoundTag serialize(RotatedLocation location) {
CompoundTag tag = new CompoundTag();
public static NbtCompound serialize(RotatedLocation location) {
NbtCompound tag = new NbtCompound();
tag.putString("world", location.world.getValue().toString());
tag.putIntArray("pos", new int[]{location.getX(), location.getY(), location.getZ()});
tag.putFloat("yaw", location.pitch);
@ -26,10 +26,10 @@ public class RotatedLocation extends Location {
return tag;
}
public static RotatedLocation deserialize(CompoundTag tag) {
public static RotatedLocation deserialize(NbtCompound tag) {
int[] pos = tag.getIntArray("pos");
return new RotatedLocation(
RegistryKey.of(Registry.DIMENSION, new Identifier(tag.getString("world"))),
RegistryKey.of(Registry.WORLD_KEY, new Identifier(tag.getString("world"))),
new BlockPos(pos[0], pos[1], pos[2]),
tag.getFloat("yaw"),
tag.getFloat("pitch")

View file

@ -5,18 +5,16 @@ import java.util.Map;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.dimdev.dimdoors.api.util.math.Equation;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.Tag;
import net.fabricmc.fabric.api.util.NbtType;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.nbt.NbtElement;
import net.minecraft.nbt.NbtList;
public class TagEquations {
private static final Logger LOGGER = LogManager.getLogger();
public static CompoundTag solveCompoundTagEquations(CompoundTag tag, Map<String, Double> variableMap) {
CompoundTag solved = new CompoundTag();
public static NbtCompound solveCompoundTagEquations(NbtCompound tag, Map<String, Double> variableMap) {
NbtCompound solved = new NbtCompound();
for (String key : tag.getKeys()) {
if (tag.getType(key) == NbtType.STRING && key.startsWith("equation_")) {
try {
@ -40,7 +38,7 @@ public class TagEquations {
} else if (tag.getType(key) == NbtType.COMPOUND) {
solved.put(key, solveCompoundTagEquations(tag.getCompound(key), variableMap));
} else if (tag.getType(key) == NbtType.LIST) {
solved.put(key, solveListTagEquations((ListTag) tag.get(key), variableMap));
solved.put(key, solveListTagEquations((NbtList) tag.get(key), variableMap));
} else {
solved.put(key, tag.get(key));
}
@ -48,13 +46,13 @@ public class TagEquations {
return solved;
}
public static ListTag solveListTagEquations(ListTag listTag, Map<String, Double> variableMap) {
ListTag solved = new ListTag();
for (Tag tag : listTag) {
public static NbtList solveListTagEquations(NbtList listTag, Map<String, Double> variableMap) {
NbtList solved = new NbtList();
for (NbtElement tag : listTag) {
if (tag.getType() == NbtType.LIST) {
solved.add(solveListTagEquations((ListTag) tag, variableMap));
solved.add(solveListTagEquations((NbtList) tag, variableMap));
} else if (tag.getType() == NbtType.COMPOUND) {
solved.add(solveCompoundTagEquations((CompoundTag) tag, variableMap));
solved.add(solveCompoundTagEquations((NbtCompound) tag, variableMap));
} else {
solved.add(tag);
}

View file

@ -13,8 +13,7 @@ import org.dimdev.dimdoors.block.door.data.condition.Condition;
import org.dimdev.dimdoors.block.entity.EntranceRiftBlockEntity;
import org.dimdev.dimdoors.rift.registry.LinkProperties;
import org.dimdev.dimdoors.rift.targets.VirtualTarget;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.nbt.NbtOps;
import net.minecraft.util.Pair;
@ -59,8 +58,8 @@ public class RiftDataList {
private final Optional<LinkProperties> linkProperties;
public static OptRiftData fromJson(JsonObject json) {
Optional<VirtualTarget> destination = Optional.ofNullable(json.get("destination")).map(JsonElement::getAsJsonObject).map(j -> JsonOps.INSTANCE.convertTo(NbtOps.INSTANCE, j)).map(CompoundTag.class::cast).map(VirtualTarget::fromTag);
Optional<LinkProperties> linkProperties = Optional.ofNullable(json.get("properties")).map(JsonElement::getAsJsonObject).map(j -> JsonOps.INSTANCE.convertTo(NbtOps.INSTANCE, j)).map(CompoundTag.class::cast).map(LinkProperties::fromTag);
Optional<VirtualTarget> destination = Optional.ofNullable(json.get("destination")).map(JsonElement::getAsJsonObject).map(j -> JsonOps.INSTANCE.convertTo(NbtOps.INSTANCE, j)).map(NbtCompound.class::cast).map(VirtualTarget::fromTag);
Optional<LinkProperties> linkProperties = Optional.ofNullable(json.get("properties")).map(JsonElement::getAsJsonObject).map(j -> JsonOps.INSTANCE.convertTo(NbtOps.INSTANCE, j)).map(NbtCompound.class::cast).map(LinkProperties::fromTag);
return new OptRiftData(destination, linkProperties);
}

View file

@ -16,7 +16,7 @@ public class WorldMatchCondition implements Condition {
}
public static WorldMatchCondition fromJson(JsonObject json) {
RegistryKey<World> key = RegistryKey.of(Registry.DIMENSION, new Identifier(json.getAsJsonPrimitive("world").getAsString()));
RegistryKey<World> key = RegistryKey.of(Registry.WORLD_KEY, new Identifier(json.getAsJsonPrimitive("world").getAsString()));
return new WorldMatchCondition(key);
}

View file

@ -13,7 +13,7 @@ import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.SpawnReason;
import net.minecraft.entity.mob.EndermanEntity;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
@ -89,7 +89,7 @@ public class DetachedRiftBlockEntity extends RiftBlockEntity {
}
@Override
public CompoundTag serialize(CompoundTag tag) {
public NbtCompound serialize(NbtCompound tag) {
super.serialize(tag);
tag.putBoolean("closing", this.closing);
tag.putBoolean("stablized", this.stabilized);
@ -99,7 +99,7 @@ public class DetachedRiftBlockEntity extends RiftBlockEntity {
}
@Override
public void deserialize(CompoundTag tag) {
public void deserialize(NbtCompound tag) {
super.deserialize(tag);
this.closing = tag.getBoolean("closing");
this.stabilized = tag.getBoolean("stablized");

View file

@ -23,7 +23,7 @@ import net.minecraft.block.HorizontalFacingBlock;
import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.network.packet.s2c.play.EntityVelocityUpdateS2CPacket;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.TranslatableText;
@ -45,13 +45,13 @@ public class EntranceRiftBlockEntity extends RiftBlockEntity {
}
@Override
public void readNbt(CompoundTag nbt) {
public void readNbt(NbtCompound nbt) {
super.readNbt(nbt);
locked = nbt.getBoolean("locked");
}
@Override
public CompoundTag writeNbt(CompoundTag tag) {
public NbtCompound writeNbt(NbtCompound tag) {
tag.putBoolean("locked", locked);
return super.writeNbt(tag);
}

View file

@ -28,7 +28,7 @@ import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.entity.Entity;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.text.LiteralText;
import net.minecraft.util.math.BlockPos;
@ -51,33 +51,33 @@ public abstract class RiftBlockEntity extends BlockEntity implements BlockEntity
}
@Override
public void readNbt(CompoundTag nbt) {
public void readNbt(NbtCompound nbt) {
super.readNbt(nbt);
this.deserialize(nbt);
}
public void deserialize(CompoundTag nbt) {
public void deserialize(NbtCompound nbt) {
this.data = RiftData.fromTag(nbt.getCompound("data"));
}
@Override
public CompoundTag writeNbt(CompoundTag tag) {
public NbtCompound writeNbt(NbtCompound tag) {
super.writeNbt(tag);
return this.serialize(tag);
}
public CompoundTag serialize(CompoundTag tag) {
public NbtCompound serialize(NbtCompound tag) {
tag.put("data", RiftData.toTag(this.data));
return tag;
}
@Override
public void fromClientTag(CompoundTag tag) {
public void fromClientTag(NbtCompound tag) {
this.deserialize(tag);
}
@Override
public CompoundTag toClientTag(CompoundTag tag) {
public NbtCompound toClientTag(NbtCompound tag) {
return this.serialize(tag);
}
@ -113,7 +113,7 @@ public abstract class RiftBlockEntity extends BlockEntity implements BlockEntity
}
@Override
public CompoundTag toInitialChunkDataNbt() {
public NbtCompound toInitialChunkDataNbt() {
PlayerLookup.tracking(this).forEach(ModCriteria.RIFT_TRACKED::trigger);
return super.toInitialChunkDataNbt();
}

View file

@ -7,8 +7,7 @@ import io.github.cottonmc.cotton.gui.widget.data.Axis;
import org.dimdev.dimdoors.rift.registry.LinkProperties;
import org.dimdev.dimdoors.rift.targets.VirtualTarget;
import org.dimdev.dimdoors.api.util.RGBA;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.text.LiteralText;
public class RiftData {
@ -62,8 +61,8 @@ public class RiftData {
this.color = color;
}
public static CompoundTag toTag(RiftData data) {
CompoundTag tag = new CompoundTag();
public static NbtCompound toTag(RiftData data) {
NbtCompound tag = new NbtCompound();
if (data.destination != VirtualTarget.NoneTarget.INSTANCE) tag.put("destination", VirtualTarget.toTag(data.destination));
if (data.properties != null) tag.put("properties", LinkProperties.toTag(data.properties));
if (data.color != null) tag.put("color", RGBA.toTag(data.color));
@ -72,7 +71,7 @@ public class RiftData {
return tag;
}
public static RiftData fromTag(CompoundTag tag) {
public static RiftData fromTag(NbtCompound tag) {
RiftData data = new RiftData();
data.destination = tag.contains("destination") ? VirtualTarget.fromTag(tag.getCompound("destination")) : VirtualTarget.NoneTarget.INSTANCE;
data.properties = tag.contains("properties") ? LinkProperties.fromTag(tag.getCompound("properties")) : null;

View file

@ -2,17 +2,17 @@ package org.dimdev.dimdoors.client;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.class_5944;
import net.minecraft.client.render.Shader;
@Environment(EnvType.CLIENT)
public class ModShaders {
private static class_5944 DIMENSIONAL_PORTAL = null;
private static Shader DIMENSIONAL_PORTAL = null;
public static void setDimensionalPortal(class_5944 dimensionalPortal) {
public static void setDimensionalPortal(Shader dimensionalPortal) {
DIMENSIONAL_PORTAL = dimensionalPortal;
}
public static class_5944 getDimensionalPortal() {
public static Shader getDimensionalPortal() {
return DIMENSIONAL_PORTAL;
}
}

View file

@ -35,7 +35,7 @@ public class MyRenderLayer extends RenderLayer {
MultiPhaseParameters.builder()
.cull(DISABLE_CULLING)
.lightmap(RenderPhase.DISABLE_LIGHTMAP)
.method_34577(NO_TEXTURE)
.texture(NO_TEXTURE)
.transparency(new Transparency("crack_transparency",
() -> {
RenderSystem.enableBlend();
@ -58,7 +58,7 @@ public class MyRenderLayer extends RenderLayer {
MultiPhaseParameters.builder()
.cull(DISABLE_CULLING)
.lightmap(RenderPhase.DISABLE_LIGHTMAP)
.method_34577(new Texture(DetachedRiftBlockEntityRenderer.TESSERACT_PATH,
.texture(new Texture(DetachedRiftBlockEntityRenderer.TESSERACT_PATH,
false,
false)
)
@ -67,7 +67,7 @@ public class MyRenderLayer extends RenderLayer {
);
public static RenderLayer getMonolith(Identifier texture) {
RenderLayer.MultiPhaseParameters multiPhaseParameters = RenderLayer.MultiPhaseParameters.builder().method_34577(new RenderPhase.Texture(texture, false, false)).method_34578(new class_5942(GameRenderer::method_34508)).transparency(RenderPhase.TRANSLUCENT_TRANSPARENCY).cull(DISABLE_CULLING).lightmap(ENABLE_LIGHTMAP).depthTest(RenderPhase.ALWAYS_DEPTH_TEST).overlay(ENABLE_OVERLAY_COLOR).build(false);
RenderLayer.MultiPhaseParameters multiPhaseParameters = RenderLayer.MultiPhaseParameters.builder().texture(new RenderPhase.Texture(texture, false, false)).shader(new Shader(GameRenderer::getRenderTypeEntityTranslucentShader)).transparency(RenderPhase.TRANSLUCENT_TRANSPARENCY).cull(DISABLE_CULLING).lightmap(ENABLE_LIGHTMAP).depthTest(RenderPhase.ALWAYS_DEPTH_TEST).overlay(ENABLE_OVERLAY_COLOR).build(false);
return RenderLayerFactory.create("monolith", VertexFormats.POSITION_COLOR_TEXTURE_OVERLAY_LIGHT_NORMAL, VertexFormat.DrawMode.QUADS, 256, true, true, multiPhaseParameters);
}
}

View file

@ -24,8 +24,7 @@ import org.dimdev.dimdoors.command.arguments.PocketTemplateArgumentType;
import org.dimdev.dimdoors.pockets.PocketTemplate;
import org.dimdev.dimdoors.util.schematic.Schematic;
import org.dimdev.dimdoors.util.schematic.SchematicPlacer;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.nbt.NbtIo;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.server.network.ServerPlayerEntity;
@ -74,7 +73,7 @@ public class PocketCommand {
boolean async = DimensionalDoorsInitializer.getConfig().getPocketsConfig().asyncWorldEditPocketLoading;
Consumer<Runnable> taskAcceptor = async ? r -> source.getMinecraftServer().execute(r) : Runnable::run;
Runnable task = () -> {
CompoundTag tag = Schematic.toTag(template.getSchematic());
NbtCompound tag = Schematic.toTag(template.getSchematic());
ByteArrayOutputStream stream = new ByteArrayOutputStream();
try {
NbtIo.writeCompressed(tag, stream);

View file

@ -21,7 +21,7 @@ import net.minecraft.entity.data.TrackedData;
import net.minecraft.entity.data.TrackedDataHandlerRegistry;
import net.minecraft.entity.mob.MobEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.particle.ParticleTypes;
import net.minecraft.sound.SoundCategory;
import net.minecraft.util.math.BlockPos;
@ -262,14 +262,14 @@ public class MonolithEntity extends MobEntity {
}
@Override
public CompoundTag writeNbt(CompoundTag tag) {
public NbtCompound writeNbt(NbtCompound tag) {
super.writeNbt(tag);
tag.putInt("Aggro", this.aggro);
return tag;
}
@Override
public void readNbt(CompoundTag nbt) {
public void readNbt(NbtCompound nbt) {
super.readNbt(nbt);
this.aggro = nbt.getInt("Aggro");
}

View file

@ -61,7 +61,7 @@ public class ModFluids {
* Get the sprites from the block atlas when resources are reloaded
*/
@Override
public void apply(ResourceManager resourceManager) {
public void reload(ResourceManager resourceManager) {
final Function<Identifier, Sprite> atlas = MinecraftClient.getInstance().getSpriteAtlas(PlayerScreenHandler.BLOCK_ATLAS_TEXTURE);
fluidSprites[0] = atlas.apply(stillSpriteId);
fluidSprites[1] = atlas.apply(flowingSpriteId);

View file

@ -23,7 +23,7 @@ import net.minecraft.item.Item;
import net.minecraft.item.ItemGroup;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemUsageContext;
import net.minecraft.nbt.IntArrayTag;
import net.minecraft.nbt.NbtIntArray;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.LiteralText;
import net.minecraft.text.Text;
@ -116,18 +116,18 @@ public class RiftKeyItem extends Item {
}
public static boolean tryRemove(ItemStack stack, UUID id) {
IntArrayTag arrayTag = new IntArrayTag(DynamicSerializableUuid.toIntArray(id));
NbtIntArray arrayTag = new NbtIntArray(DynamicSerializableUuid.toIntArray(id));
return stack.getTag().getList("Ids", NbtType.INT_ARRAY).remove(arrayTag);
}
public static void add(ItemStack stack, UUID id) {
if (!has(stack, id)) {
stack.getOrCreateTag().getList("Ids", NbtType.INT_ARRAY).add(new IntArrayTag(DynamicSerializableUuid.toIntArray(id)));
stack.getOrCreateTag().getList("Ids", NbtType.INT_ARRAY).add(new NbtIntArray(DynamicSerializableUuid.toIntArray(id)));
}
}
public static boolean has(ItemStack stack, UUID id) {
return stack.getOrCreateTag().getList("Ids", NbtType.INT_ARRAY).contains(new IntArrayTag(DynamicSerializableUuid.toIntArray(id)));
return stack.getOrCreateTag().getList("Ids", NbtType.INT_ARRAY).contains(new NbtIntArray(DynamicSerializableUuid.toIntArray(id)));
}
public static boolean isEmpty(ItemStack stack) {
@ -138,8 +138,8 @@ public class RiftKeyItem extends Item {
return stack.getOrCreateTag()
.getList("Ids", NbtType.INT_ARRAY)
.stream()
.map(IntArrayTag.class::cast)
.map(IntArrayTag::getIntArray)
.map(NbtIntArray.class::cast)
.map(NbtIntArray::getIntArray)
.map(DynamicSerializableUuid::toUuid)
.collect(Collectors.toList());
}

View file

@ -17,7 +17,7 @@ import net.minecraft.item.Item;
import net.minecraft.item.ItemPlacementContext;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemUsageContext;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.sound.SoundCategory;
import net.minecraft.text.Text;
@ -106,7 +106,7 @@ public class RiftSignatureItem extends Item {
}
public static void setSource(ItemStack itemStack, RotatedLocation destination) {
if (!itemStack.hasTag()) itemStack.setTag(new CompoundTag());
if (!itemStack.hasTag()) itemStack.setTag(new NbtCompound());
itemStack.getTag().put("destination", RotatedLocation.serialize(destination));
}

View file

@ -16,7 +16,7 @@ import net.minecraft.item.Item;
import net.minecraft.item.ItemPlacementContext;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemUsageContext;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.sound.SoundCategory;
import net.minecraft.text.Text;
@ -98,7 +98,7 @@ public class StabilizedRiftSignatureItem extends Item { // TODO: common supercla
}
public static void setSource(ItemStack itemStack, RotatedLocation destination) {
if (!itemStack.hasTag()) itemStack.setTag(new CompoundTag());
if (!itemStack.hasTag()) itemStack.setTag(new NbtCompound());
itemStack.getTag().put("destination", RotatedLocation.serialize(destination));
}

View file

@ -0,0 +1,38 @@
package org.dimdev.dimdoors.mixin;
import net.minecraft.util.math.BlockBox;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.mixin.Shadow;
// TODO: DELETE WHEN MOJANK BUG FIXED
@Mixin(BlockBox.class)
public class BlockBoxMixin {
@Shadow
private int minX;
@Shadow
private int minY;
@Shadow
private int minZ;
@Shadow
private int maxX;
@Shadow
private int maxY;
@Shadow
private int maxZ;
/**
* @author CreepyCre
*/
@Overwrite
public BlockBox intersection(BlockBox box) {
this.minX = Math.max(this.minX, box.getMinX());
this.minY = Math.max(this.minY, box.getMinY());
this.minZ = Math.max(this.minZ, box.getMinZ());
this.maxX = Math.min(this.maxX, box.getMaxX());
this.maxY = Math.min(this.maxY, box.getMaxY());
this.maxZ = Math.min(this.maxZ, box.getMaxZ());
return (BlockBox) (Object) this;
}
}

View file

@ -1,17 +1,15 @@
package org.dimdev.dimdoors.mixin.accessor;
import java.util.List;
import net.minecraft.nbt.NbtElement;
import net.minecraft.nbt.NbtList;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Invoker;
import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.Tag;
@Mixin(ListTag.class)
@Mixin(NbtList.class)
public interface ListTagAccessor {
@Invoker("<init>")
static ListTag createListTag(List<Tag> list, byte type) {
static NbtList createListTag(List<NbtElement> list, byte type) {
throw new UnsupportedOperationException();
}
}

View file

@ -8,9 +8,8 @@ import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import net.minecraft.class_5944;
import net.minecraft.client.render.GameRenderer;
import net.minecraft.client.render.Shader;
import net.minecraft.client.render.VertexFormat;
import net.minecraft.client.render.VertexFormats;
import net.minecraft.resource.ResourceFactory;
@ -23,10 +22,10 @@ import net.fabricmc.api.Environment;
@Mixin(GameRenderer.class)
public abstract class GameRendererMixin {
@Shadow
protected abstract class_5944 method_34522(ResourceFactory arg, String string, VertexFormat vertexFormat) throws IOException;
protected abstract Shader loadShader(ResourceFactory arg, String string, VertexFormat vertexFormat) throws IOException;
@Inject(method = "method_34538", at = @At(value = "INVOKE", ordinal = 1, target = "Lnet/minecraft/client/render/GameRenderer;method_34522(Lnet/minecraft/resource/ResourceFactory;Ljava/lang/String;Lnet/minecraft/client/render/VertexFormat;)Lnet/minecraft/class_5944;"))
@Inject(method = "loadShaders", at = @At(value = "INVOKE", ordinal = 1, target = "Lnet/minecraft/client/render/GameRenderer;loadShader(Lnet/minecraft/resource/ResourceFactory;Ljava/lang/String;Lnet/minecraft/client/render/VertexFormat;)Lnet/minecraft/client/render/Shader;"))
public void onReload(ResourceManager resourceManager, CallbackInfo ci) throws IOException {
ModShaders.setDimensionalPortal(this.method_34522(resourceManager, "dimensional_portal", VertexFormats.POSITION));
ModShaders.setDimensionalPortal(this.loadShader(resourceManager, "dimensional_portal", VertexFormats.POSITION));
}
}

View file

@ -63,7 +63,7 @@ public class WorldRendererMixin {
RenderSystem.enableBlend();
RenderSystem.defaultBlendFunc();
RenderSystem.depthMask(false);
RenderSystem.setShader(GameRenderer::method_34543);
RenderSystem.setShader(GameRenderer::getPositionTexColorShader);
RenderSystem.setShaderColor(1, 1, 1, 1);
for(int i = 0; i < 6; ++i) {
@ -98,7 +98,7 @@ public class WorldRendererMixin {
}
float s = 30.0F;
RenderSystem.setShader(GameRenderer::method_34542);
RenderSystem.setShader(GameRenderer::getPositionTexShader);
RenderSystem.setShaderTexture(0, SUN_RENDER_PATH);
bufferBuilder.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_TEXTURE);
bufferBuilder.vertex(matrix4f, -s, 100.0F, -s).texture(0.0F, 0.0F).next();
@ -125,7 +125,7 @@ public class WorldRendererMixin {
RenderSystem.enableBlend();
RenderSystem.defaultBlendFunc();
RenderSystem.depthMask(false);
RenderSystem.setShader(GameRenderer::method_34540);
RenderSystem.setShader(GameRenderer::getPositionColorShader);
Tessellator tessellator = Tessellator.getInstance();
BufferBuilder bufferBuilder = tessellator.getBuffer();

View file

@ -38,7 +38,7 @@ public class SyncPocketAddonsS2CPacket implements SimplePacket<ClientPacketListe
@Override
public SimplePacket<ClientPacketListener> read(PacketByteBuf buf) throws IOException {
this.world = RegistryKey.of(Registry.DIMENSION, buf.readIdentifier());
this.world = RegistryKey.of(Registry.WORLD_KEY, buf.readIdentifier());
this.gridSize = buf.readInt();
this.pocketId = buf.readInt();
this.pocketRange = buf.readInt();

View file

@ -35,13 +35,13 @@ public class PocketLoader implements SimpleSynchronousResourceReloadListener {
private SimpleTree<String, VirtualPocket> pocketGroups = new SimpleTree<>(String.class);
private SimpleTree<String, VirtualPocket> virtualPockets = new SimpleTree<>(String.class);
private SimpleTree<String, PocketTemplate> templates = new SimpleTree<>(String.class);
private SimpleTree<String, Tag> dataTree = new SimpleTree<>(String.class);
private SimpleTree<String, NbtElement> dataTree = new SimpleTree<>(String.class);
private PocketLoader() {
}
@Override
public void apply(ResourceManager manager) {
public void reload(ResourceManager manager) {
pocketGenerators.clear();
pocketGroups.clear();
virtualPockets.clear();
@ -65,7 +65,7 @@ public class PocketLoader implements SimpleSynchronousResourceReloadListener {
virtualPockets.values().forEach(VirtualPocket::init);
}
private <T> CompletableFuture<SimpleTree<String, T>> loadResourcePathFromJsonToTree(ResourceManager manager, String startingPath, Function<Tag, T> reader) {
private <T> CompletableFuture<SimpleTree<String, T>> loadResourcePathFromJsonToTree(ResourceManager manager, String startingPath, Function<NbtElement, T> reader) {
int sub = startingPath.endsWith("/") ? 0 : 1;
Collection<Identifier> ids = manager.findResources(startingPath, str -> str.endsWith(".json"));
@ -85,7 +85,7 @@ public class PocketLoader implements SimpleSynchronousResourceReloadListener {
});
}
private <T> CompletableFuture<SimpleTree<String, T>> loadResourcePathFromCompressedNbtToTree(ResourceManager manager, String startingPath, String extension, BiFunction<CompoundTag, String, T> reader) {
private <T> CompletableFuture<SimpleTree<String, T>> loadResourcePathFromCompressedNbtToTree(ResourceManager manager, String startingPath, String extension, BiFunction<NbtCompound, String, T> reader) {
int sub = startingPath.endsWith("/") ? 0 : 1;
Function<Identifier, Path<String>> normalizer = id -> Path.stringPath(id.getNamespace() + ":" + id.getPath().substring(0, id.getPath().lastIndexOf(".")).substring(startingPath.length() + sub));
Collection<Identifier> ids = manager.findResources(startingPath, str -> str.endsWith(extension));
@ -125,23 +125,23 @@ public class PocketLoader implements SimpleSynchronousResourceReloadListener {
// }
// }
public Tag getDataTag(String id) {
public NbtElement getDataTag(String id) {
return this.dataTree.get(Path.stringPath(id));
}
public CompoundTag getDataCompoundTag(String id) {
public NbtCompound getDataCompoundTag(String id) {
return NbtUtil.asCompoundTag(getDataTag(id), "Could not convert Tag \"" + id + "\" to CompoundTag!");
}
private VirtualPocket loadVirtualPocket(Tag tag) {
private VirtualPocket loadVirtualPocket(NbtElement tag) {
return VirtualPocket.deserialize(tag);
}
private PocketGenerator loadPocketGenerator(Tag tag) {
private PocketGenerator loadPocketGenerator(NbtElement tag) {
return PocketGenerator.deserialize(NbtUtil.asCompoundTag(tag, "Could not load PocketGenerator since its json does not represent a CompoundTag!"));
}
private PocketTemplate loadPocketTemplate(CompoundTag tag, String id) {
private PocketTemplate loadPocketTemplate(NbtCompound tag, String id) {
try {
return new PocketTemplate(Schematic.fromTag(tag), new Identifier(id));
} catch (Exception e) {

View file

@ -29,14 +29,14 @@ import net.minecraft.inventory.Inventory;
import net.minecraft.loot.LootTable;
import net.minecraft.loot.context.LootContext;
import net.minecraft.loot.context.LootContextTypes;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.StructureWorldAccess;
public class TemplateUtils {
static void setupEntityPlaceholders(List<CompoundTag> entities, CompoundTag entityTag) {
static void setupEntityPlaceholders(List<NbtCompound> entities, NbtCompound entityTag) {
if (entityTag.contains("placeholder")) {
double x = entityTag.getDouble("x");
double y = entityTag.getDouble("y");
@ -44,13 +44,13 @@ public class TemplateUtils {
float yaw = entityTag.getFloat("yaw");
float pitch = entityTag.getFloat("pitch");
CompoundTag newTag;
NbtCompound newTag;
if ("monolith".equals(entityTag.getString("placeholder"))) {
MonolithEntity monolith = Objects.requireNonNull(ModEntityTypes.MONOLITH.create(null));
monolith.setPos(x, y, z);
monolith.yaw = yaw;
monolith.pitch = pitch;
newTag = monolith.writeNbt(new CompoundTag());
newTag = monolith.writeNbt(new NbtCompound());
} else {
throw new RuntimeException("Unknown entity placeholder: " + entityTag.getString("placeholder"));
}
@ -122,15 +122,15 @@ public class TemplateUtils {
public static void replacePlaceholders(Schematic schematic, StructureWorldAccess world) {
// Replace placeholders (some schematics will contain them)
List<CompoundTag> blockEntities = new ArrayList<>();
for (CompoundTag blockEntityTag : schematic.getBlockEntities()) {
List<NbtCompound> blockEntities = new ArrayList<>();
for (NbtCompound blockEntityTag : schematic.getBlockEntities()) {
if (blockEntityTag.contains("placeholder")) {
int x = blockEntityTag.getInt("x");
int y = blockEntityTag.getInt("y");
int z = blockEntityTag.getInt("z");
BlockPos pos = new BlockPos(x, y, z);
CompoundTag newTag = new CompoundTag();
NbtCompound newTag = new NbtCompound();
EntranceRiftBlockEntity rift = new EntranceRiftBlockEntity(pos, Schematic.getBlockSample(schematic).getBlockState(pos));
switch (blockEntityTag.getString("placeholder")) {
case "deeper_depth_door":
@ -169,8 +169,8 @@ public class TemplateUtils {
}
schematic.setBlockEntities(blockEntities);
List<CompoundTag> entities = new ArrayList<>();
for (CompoundTag entityTag : schematic.getEntities()) {
List<NbtCompound> entities = new ArrayList<>();
for (NbtCompound entityTag : schematic.getEntities()) {
TemplateUtils.setupEntityPlaceholders(entities, entityTag);
}
schematic.setEntities(entities);

View file

@ -4,7 +4,7 @@ import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.fluid.FluidState;
import net.minecraft.fluid.Fluids;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.server.world.ServerLightingProvider;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.Identifier;
@ -47,7 +47,7 @@ public class ChunkGenerator extends PocketGenerator {
}
@Override
public PocketGenerator fromTag(CompoundTag tag) {
public PocketGenerator fromTag(NbtCompound tag) {
super.fromTag(tag);
this.dimensionID = new Identifier(tag.getString("dimension_id"));
@ -60,7 +60,7 @@ public class ChunkGenerator extends PocketGenerator {
}
@Override
public CompoundTag toTag(CompoundTag tag) {
public NbtCompound toTag(NbtCompound tag) {
super.toTag(tag);
tag.putString("dimension_id", dimensionID.toString());
@ -81,7 +81,7 @@ public class ChunkGenerator extends PocketGenerator {
LOGGER.info("Generating chunk pocket at location " + pocket.getOrigin());
ServerWorld genWorld = DimensionalDoorsInitializer.getWorld(RegistryKey.of(Registry.DIMENSION, dimensionID));
ServerWorld genWorld = DimensionalDoorsInitializer.getWorld(RegistryKey.of(Registry.WORLD_KEY, dimensionID));
net.minecraft.world.gen.chunk.ChunkGenerator genWorldChunkGenerator = genWorld.getChunkManager().getChunkGenerator();
ArrayList<Chunk> protoChunks = new ArrayList<>();

View file

@ -3,8 +3,8 @@ package org.dimdev.dimdoors.pockets.generator;
import net.minecraft.block.entity.ChestBlockEntity;
import net.minecraft.block.entity.DispenserBlockEntity;
import net.minecraft.inventory.Inventory;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.nbt.NbtList;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.ServerTask;
import net.minecraft.util.math.BlockPos;
@ -43,11 +43,11 @@ public abstract class LazyPocketGenerator extends PocketGenerator {
}
@Override
public PocketGenerator fromTag(CompoundTag tag) {
public PocketGenerator fromTag(NbtCompound tag) {
super.fromTag(tag);
if (tag.contains("lazy_modifiers")) {
ListTag modifiersTag = tag.getList("lazy_modifiers", 10);
NbtList modifiersTag = tag.getList("lazy_modifiers", 10);
for (int i = 0; i < modifiersTag.size(); i++) {
lazyModifierList.add((LazyModifier) Modifier.deserialize(modifiersTag.getCompound(i)));
}
@ -57,12 +57,12 @@ public abstract class LazyPocketGenerator extends PocketGenerator {
}
@Override
public CompoundTag toTag(CompoundTag tag) {
public NbtCompound toTag(NbtCompound tag) {
super.toTag(tag);
if (lazyModifierList.size() > 0) {
List<CompoundTag> lazyModTags = lazyModifierList.stream().map(lazyModifier -> lazyModifier.toTag(new CompoundTag())).collect(Collectors.toList());
ListTag lazyModifiersTag = new ListTag();
List<NbtCompound> lazyModTags = lazyModifierList.stream().map(lazyModifier -> lazyModifier.toTag(new NbtCompound())).collect(Collectors.toList());
NbtList lazyModifiersTag = new NbtList();
lazyModifiersTag.addAll(lazyModTags);
tag.put("lazy_modifiers", lazyModifiersTag);
}

View file

@ -6,9 +6,9 @@ import net.fabricmc.fabric.api.util.NbtType;
import net.minecraft.block.entity.ChestBlockEntity;
import net.minecraft.block.entity.DispenserBlockEntity;
import net.minecraft.inventory.Inventory;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.StringTag;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.nbt.NbtList;
import net.minecraft.nbt.NbtString;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.Vec3i;
@ -41,7 +41,7 @@ public abstract class PocketGenerator implements Weighted<PocketGenerationContex
private static final int fallbackWeight = 5; // TODO: make config
protected final List<Modifier> modifierList = new ArrayList<>();
private CompoundTag builderTag;
private NbtCompound builderTag;
protected String weight = defaultWeightEquation;
protected Equation weightEquation;
protected Boolean setupLoot;
@ -55,7 +55,7 @@ public abstract class PocketGenerator implements Weighted<PocketGenerationContex
parseWeight();
}
public static PocketGenerator deserialize(CompoundTag tag) {
public static PocketGenerator deserialize(NbtCompound tag) {
Identifier id = Identifier.tryParse(tag.getString("type")); // TODO: return some NONE PocketGenerator if type cannot be found or deserialization fails.
PocketGeneratorType<? extends PocketGenerator> type = REGISTRY.get(id);
if (type == null) {
@ -65,8 +65,8 @@ public abstract class PocketGenerator implements Weighted<PocketGenerationContex
return type.fromTag(tag);
}
public static CompoundTag serialize(PocketGenerator pocketGenerator) {
return pocketGenerator.toTag(new CompoundTag());
public static NbtCompound serialize(PocketGenerator pocketGenerator) {
return pocketGenerator.toTag(new NbtCompound());
}
private void parseWeight() {
@ -83,7 +83,7 @@ public abstract class PocketGenerator implements Weighted<PocketGenerationContex
}
}
public PocketGenerator fromTag(CompoundTag tag) {
public PocketGenerator fromTag(NbtCompound tag) {
if (tag.contains("builder", NbtType.COMPOUND)) builderTag = tag.getCompound("builder");
this.weight = tag.contains("weight") ? tag.getString("weight") : defaultWeightEquation;
@ -92,14 +92,14 @@ public abstract class PocketGenerator implements Weighted<PocketGenerationContex
if (tag.contains("setup_loot")) setupLoot = tag.getBoolean("setup_loot");
if (tag.contains("modifiers")) {
ListTag modifiersTag = tag.getList("modifiers", 10);
NbtList modifiersTag = tag.getList("modifiers", 10);
for (int i = 0; i < modifiersTag.size(); i++) {
modifierList.add(Modifier.deserialize(modifiersTag.getCompound(i)));
}
}
if (tag.contains("tags")) {
ListTag listTag = tag.getList("tags", NbtType.STRING);
NbtList listTag = tag.getList("tags", NbtType.STRING);
for (int i = 0; i < listTag.size(); i++) {
tags.add(listTag.getString(i));
}
@ -107,7 +107,7 @@ public abstract class PocketGenerator implements Weighted<PocketGenerationContex
return this;
}
public CompoundTag toTag(CompoundTag tag) {
public NbtCompound toTag(NbtCompound tag) {
this.getType().toTag(tag);
if (builderTag != null) tag.put("builder", builderTag);
@ -116,16 +116,16 @@ public abstract class PocketGenerator implements Weighted<PocketGenerationContex
if (setupLoot != null) tag.putBoolean("setup_loot", setupLoot);
ListTag modifiersTag = new ListTag();
NbtList modifiersTag = new NbtList();
for (Modifier modifier : modifierList) {
modifiersTag.add(modifier.toTag(new CompoundTag()));
modifiersTag.add(modifier.toTag(new NbtCompound()));
}
if (modifiersTag.size() > 0) tag.put("modifiers", modifiersTag);
if (tags.size() > 0) {
ListTag listTag = new ListTag();
NbtList listTag = new NbtList();
for (String tagString : tags) {
listTag.add(StringTag.of(tagString));
listTag.add(NbtString.of(tagString));
}
tag.put("tags", listTag);
}
@ -225,9 +225,9 @@ public abstract class PocketGenerator implements Weighted<PocketGenerationContex
PocketGeneratorType<ChunkGenerator> CHUNK = register(new Identifier("dimdoors", ChunkGenerator.KEY), ChunkGenerator::new);
PocketGeneratorType<VoidGenerator> VOID = register(new Identifier("dimdoors", VoidGenerator.KEY), VoidGenerator::new);
PocketGenerator fromTag(CompoundTag tag);
PocketGenerator fromTag(NbtCompound tag);
CompoundTag toTag(CompoundTag tag);
NbtCompound toTag(NbtCompound tag);
static void register() {
DimensionalDoorsInitializer.apiSubscribers.forEach(d -> d.registerPocketGeneratorTypes(REGISTRY));
@ -236,12 +236,12 @@ public abstract class PocketGenerator implements Weighted<PocketGenerationContex
static <U extends PocketGenerator> PocketGeneratorType<U> register(Identifier id, Supplier<U> constructor) {
return Registry.register(REGISTRY, id, new PocketGeneratorType<U>() {
@Override
public PocketGenerator fromTag(CompoundTag tag) {
public PocketGenerator fromTag(NbtCompound tag) {
return constructor.get().fromTag(tag);
}
@Override
public CompoundTag toTag(CompoundTag tag) {
public NbtCompound toTag(NbtCompound tag) {
tag.putString("type", id.toString());
return tag;
}

View file

@ -1,7 +1,7 @@
package org.dimdev.dimdoors.pockets.generator;
import net.fabricmc.fabric.api.util.NbtType;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
@ -76,7 +76,7 @@ public class SchematicGenerator extends LazyPocketGenerator{
}
@Override
public PocketGenerator fromTag(CompoundTag tag) {
public PocketGenerator fromTag(NbtCompound tag) {
super.fromTag(tag);
this.id = tag.getString("id"); // TODO: should we force having the "dimdoors:" in the json?
@ -91,7 +91,7 @@ public class SchematicGenerator extends LazyPocketGenerator{
}
@Override
public CompoundTag toTag(CompoundTag tag) {
public NbtCompound toTag(NbtCompound tag) {
super.toTag(tag);
tag.putString("id", this.id);

View file

@ -1,6 +1,6 @@
package org.dimdev.dimdoors.pockets.generator;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3i;
import org.apache.logging.log4j.LogManager;
@ -50,7 +50,7 @@ public class VoidGenerator extends LazyPocketGenerator {
}
@Override
public PocketGenerator fromTag(CompoundTag tag) {
public PocketGenerator fromTag(NbtCompound tag) {
super.fromTag(tag);
try {
@ -69,7 +69,7 @@ public class VoidGenerator extends LazyPocketGenerator {
}
@Override
public CompoundTag toTag(CompoundTag tag) {
public NbtCompound toTag(NbtCompound tag) {
super.toTag(tag);
tag.putString("width", width);

View file

@ -2,14 +2,15 @@ package org.dimdev.dimdoors.pockets.modifier;
import net.fabricmc.fabric.api.util.NbtType;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.nbt.NbtList;
import net.minecraft.util.math.BlockBox;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.ChunkPos;
import net.minecraft.world.World;
import net.minecraft.world.chunk.Chunk;
import org.dimdev.dimdoors.DimensionalDoorsInitializer;
import org.dimdev.dimdoors.api.util.BlockBoxUtil;
import org.dimdev.dimdoors.block.entity.RiftBlockEntity;
import org.dimdev.dimdoors.pockets.PocketGenerationContext;
import org.dimdev.dimdoors.world.pocket.type.LazyGenerationPocket;
@ -22,7 +23,7 @@ public class AbsoluteRiftBlockEntityModifier implements LazyModifier {
public static final String KEY = "block_entity";
private Map<BlockPos, RiftBlockEntity> rifts;
private Map<BlockPos, CompoundTag> serializedRifts;
private Map<BlockPos, NbtCompound> serializedRifts;
public AbsoluteRiftBlockEntityModifier() {
}
@ -33,8 +34,8 @@ public class AbsoluteRiftBlockEntityModifier implements LazyModifier {
}
@Override
public Modifier fromTag(CompoundTag tag) {
serializedRifts = tag.getList("rifts", NbtType.COMPOUND).parallelStream().unordered().map(CompoundTag.class::cast)
public Modifier fromTag(NbtCompound tag) {
serializedRifts = tag.getList("rifts", NbtType.COMPOUND).parallelStream().unordered().map(NbtCompound.class::cast)
.collect(Collectors.toConcurrentMap(compound -> {
int[] ints = compound.getIntArray("Pos");
return new BlockPos(ints[0], ints[1], ints[2]);
@ -44,14 +45,14 @@ public class AbsoluteRiftBlockEntityModifier implements LazyModifier {
}
@Override
public CompoundTag toTag(CompoundTag tag) {
public NbtCompound toTag(NbtCompound tag) {
LazyModifier.super.toTag(tag);
ListTag riftsTag;
NbtList riftsTag;
if (rifts != null) {
riftsTag = rifts.values().parallelStream().unordered().map(rift -> rift.writeNbt(new CompoundTag())).collect(Collectors.toCollection(ListTag::new));
riftsTag = rifts.values().parallelStream().unordered().map(rift -> rift.writeNbt(new NbtCompound())).collect(Collectors.toCollection(NbtList::new));
} else {
riftsTag = new ListTag();
riftsTag = new NbtList();
riftsTag.addAll(serializedRifts.values());
}
tag.put("rifts", riftsTag);
@ -84,8 +85,7 @@ public class AbsoluteRiftBlockEntityModifier implements LazyModifier {
@Override
public void applyToChunk(LazyGenerationPocket pocket, Chunk chunk) {
ChunkPos chunkPos = chunk.getPos();
BlockBox chunkBox = BlockBox.create(chunkPos.getStartX(), chunk.getBottomY(), chunkPos.getStartZ(), chunkPos.getEndX(), chunk.getTopY(), chunkPos.getEndZ());
BlockBox chunkBox = BlockBoxUtil.getBox(chunk);
if (rifts != null) {
rifts.entrySet().stream().unordered().filter(entry -> chunkBox.contains(entry.getKey())).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue))

View file

@ -7,7 +7,7 @@ import net.fabricmc.fabric.api.util.NbtType;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.enums.DoubleBlockHalf;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
@ -39,7 +39,7 @@ public class DimensionalDoorModifier implements LazyCompatibleModifier {
private Direction facing;
private String doorTypeString;
private DimensionalDoorBlock doorType;
private CompoundTag doorData;
private NbtCompound doorData;
private String doorDataReference;
private String x;
@ -50,7 +50,7 @@ public class DimensionalDoorModifier implements LazyCompatibleModifier {
private Equation zEquation;
@Override
public Modifier fromTag(CompoundTag tag) {
public Modifier fromTag(NbtCompound tag) {
String facingString = tag.getString("facing");
facing = Direction.byName(tag.getString("facing"));
if (facing == null || facing.getAxis().isVertical()) {
@ -85,7 +85,7 @@ public class DimensionalDoorModifier implements LazyCompatibleModifier {
}
@Override
public CompoundTag toTag(CompoundTag tag) {
public NbtCompound toTag(NbtCompound tag) {
LazyCompatibleModifier.super.toTag(tag);
tag.putString("facing", facing.asString());
@ -139,7 +139,7 @@ public class DimensionalDoorModifier implements LazyCompatibleModifier {
if (doorData == null) {
rift.setDestination(new IdMarker(manager.nextId()));
} else {
CompoundTag solvedDoorData = TagEquations.solveCompoundTagEquations(doorData, variableMap);
NbtCompound solvedDoorData = TagEquations.solveCompoundTagEquations(doorData, variableMap);
rift.setData(RiftData.fromTag(solvedDoorData));
}

View file

@ -1,6 +1,6 @@
package org.dimdev.dimdoors.pockets.modifier;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.util.math.ChunkPos;
import net.minecraft.world.World;
import net.minecraft.world.chunk.Chunk;
@ -35,7 +35,7 @@ public interface LazyCompatibleModifier extends Modifier {
}
@Override
default CompoundTag toTag(CompoundTag tag) {
default NbtCompound toTag(NbtCompound tag) {
return Modifier.super.toTag(tag);
}
}

View file

@ -1,11 +1,11 @@
package org.dimdev.dimdoors.pockets.modifier;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.world.chunk.Chunk;
import org.dimdev.dimdoors.world.pocket.type.LazyGenerationPocket;
public interface LazyModifier extends Modifier{
default CompoundTag toTag(CompoundTag tag) {
default NbtCompound toTag(NbtCompound tag) {
return Modifier.super.toTag(tag);
}

View file

@ -2,7 +2,7 @@ package org.dimdev.dimdoors.pockets.modifier;
import com.mojang.serialization.Lifecycle;
import net.fabricmc.fabric.api.event.registry.FabricRegistryBuilder;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry;
import net.minecraft.util.registry.RegistryKey;
@ -17,19 +17,19 @@ import java.util.function.Supplier;
public interface Modifier {
Registry<ModifierType<? extends Modifier>> REGISTRY = FabricRegistryBuilder.from(new SimpleRegistry<ModifierType<? extends Modifier>>(RegistryKey.ofRegistry(new Identifier("dimdoors", "modifier_type")), Lifecycle.stable())).buildAndRegister();
static Modifier deserialize(CompoundTag tag) {
static Modifier deserialize(NbtCompound tag) {
Identifier id = Identifier.tryParse(tag.getString("type")); // TODO: return some NONE Modifier if type cannot be found or deserialization fails.
return REGISTRY.get(id).fromTag(tag);
}
static CompoundTag serialize(Modifier modifier) {
return modifier.toTag(new CompoundTag());
static NbtCompound serialize(Modifier modifier) {
return modifier.toTag(new NbtCompound());
}
Modifier fromTag(CompoundTag tag);
Modifier fromTag(NbtCompound tag);
default CompoundTag toTag(CompoundTag tag) {
default NbtCompound toTag(NbtCompound tag) {
return this.getType().toTag(tag);
}
@ -50,9 +50,9 @@ public interface Modifier {
ModifierType<OffsetModifier> OFFSET_MODIFIER_TYPE = register(new Identifier("dimdoors", OffsetModifier.KEY), OffsetModifier::new);
ModifierType<AbsoluteRiftBlockEntityModifier> ABSOLUTE_RIFT_BLOCK_ENTITY_MODIFIER_TYPE = register(new Identifier("dimdoors", AbsoluteRiftBlockEntityModifier.KEY), AbsoluteRiftBlockEntityModifier::new);
Modifier fromTag(CompoundTag tag);
Modifier fromTag(NbtCompound tag);
CompoundTag toTag(CompoundTag tag);
NbtCompound toTag(NbtCompound tag);
static void register() {
DimensionalDoorsInitializer.apiSubscribers.forEach(d -> d.registerModifierTypes(REGISTRY));
@ -61,12 +61,12 @@ public interface Modifier {
static <U extends Modifier> ModifierType<U> register(Identifier id, Supplier<U> factory) {
return Registry.register(REGISTRY, id, new ModifierType<U>() {
@Override
public Modifier fromTag(CompoundTag tag) {
public Modifier fromTag(NbtCompound tag) {
return factory.get().fromTag(tag);
}
@Override
public CompoundTag toTag(CompoundTag tag) {
public NbtCompound toTag(NbtCompound tag) {
tag.putString("type", id.toString());
return tag;
}

View file

@ -1,6 +1,6 @@
package org.dimdev.dimdoors.pockets.modifier;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.util.math.Vec3i;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@ -23,7 +23,7 @@ public class OffsetModifier implements Modifier {
private Equation offsetZEquation;
@Override
public Modifier fromTag(CompoundTag tag) {
public Modifier fromTag(NbtCompound tag) {
try {
offsetX = tag.contains("offset_x") ? tag.getString("offset_x") : "0";
@ -40,7 +40,7 @@ public class OffsetModifier implements Modifier {
}
@Override
public CompoundTag toTag(CompoundTag tag) {
public NbtCompound toTag(NbtCompound tag) {
Modifier.super.toTag(tag);
if (!offsetX.equals("0")) tag.putString("offset_x", offsetX);

View file

@ -1,8 +1,7 @@
package org.dimdev.dimdoors.pockets.modifier;
import net.minecraft.nbt.CompoundTag;
import com.google.common.base.MoreObjects;
import net.minecraft.nbt.NbtCompound;
import org.dimdev.dimdoors.rift.targets.PocketEntranceMarker;
import org.dimdev.dimdoors.rift.targets.PocketExitMarker;
import org.dimdev.dimdoors.pockets.PocketGenerationContext;
@ -22,12 +21,12 @@ public class PocketEntranceModifier implements Modifier {
}
@Override
public Modifier fromTag(CompoundTag tag) {
public Modifier fromTag(NbtCompound tag) {
return new PocketEntranceModifier(tag.getInt("id"));
}
@Override
public CompoundTag toTag(CompoundTag tag) {
public NbtCompound toTag(NbtCompound tag) {
Modifier.super.toTag(tag);
tag.putInt("id", id);

View file

@ -1,8 +1,7 @@
package org.dimdev.dimdoors.pockets.modifier;
import java.util.Optional;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.server.world.ServerWorld;
import com.google.common.base.MoreObjects;
@ -19,14 +18,14 @@ public class RelativeReferenceModifier implements Modifier {
private int point_a, point_b;
@Override
public Modifier fromTag(CompoundTag tag) {
public Modifier fromTag(NbtCompound tag) {
point_a = tag.getInt("point_a");
point_b = tag.getInt("point_b");
return this;
}
@Override
public CompoundTag toTag(CompoundTag tag) {
public NbtCompound toTag(NbtCompound tag) {
Modifier.super.toTag(tag);
tag.putInt("point_a", point_a);
tag.putInt("point_b", point_b);

View file

@ -7,11 +7,8 @@ import java.util.Map;
import java.util.function.Consumer;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import net.minecraft.nbt.CompoundTag;
import net.fabricmc.fabric.api.util.NbtType;
import net.minecraft.nbt.NbtCompound;
import com.google.common.base.MoreObjects;
import org.dimdev.dimdoors.block.entity.RiftBlockEntity;
import org.dimdev.dimdoors.block.entity.RiftData;
@ -24,12 +21,12 @@ import org.dimdev.dimdoors.world.pocket.type.Pocket;
public class RiftDataModifier implements Modifier {
public static final String KEY = "rift_data";
private CompoundTag doorData;
private NbtCompound doorData;
private String doorDataReference;
private List<Integer> ids;
@Override
public Modifier fromTag(CompoundTag tag) {
public Modifier fromTag(NbtCompound tag) {
if (tag.getType("rift_data") == NbtType.STRING) {
doorDataReference = tag.getString("rift_data");
doorData = PocketLoader.getInstance().getDataCompoundTag(doorDataReference);
@ -54,7 +51,7 @@ public class RiftDataModifier implements Modifier {
}
@Override
public CompoundTag toTag(CompoundTag tag) {
public NbtCompound toTag(NbtCompound tag) {
Modifier.super.toTag(tag);
if (doorDataReference != null) tag.putString("rift_data", doorDataReference);
@ -91,7 +88,7 @@ public class RiftDataModifier implements Modifier {
if (doorData == null) {
riftBlockEntityConsumer = rift -> rift.setDestination(VirtualTarget.NoneTarget.INSTANCE);
} else {
CompoundTag solvedDoorData = TagEquations.solveCompoundTagEquations(doorData, variableMap);
NbtCompound solvedDoorData = TagEquations.solveCompoundTagEquations(doorData, variableMap);
riftBlockEntityConsumer = rift -> rift.setData(RiftData.fromTag(solvedDoorData));
}

View file

@ -36,10 +36,10 @@ public class ShellModifier implements LazyModifier {
private BlockBox boxToDrawAround;
@Override
public CompoundTag toTag(CompoundTag tag) {
public NbtCompound toTag(NbtCompound tag) {
LazyModifier.super.toTag(tag);
ListTag layersTag = new ListTag();
NbtList layersTag = new NbtList();
for (Layer layer : layers) {
layersTag.add(layer.toTag());
}
@ -59,62 +59,74 @@ public class ShellModifier implements LazyModifier {
int thickness = layer.getThickness(pocket.toVariableMap(new HashMap<>()));
final BlockState blockState = layer.getBlockState();
ChunkPos pos = chunk.getPos();
BlockBox chunkBox = BlockBox.create(pos.getStartX(), chunk.getBottomY(), pos.getStartZ(), pos.getEndX(), chunk.getTopY(), pos.getEndZ());
BlockBox chunkBox = BlockBoxUtil.getBox(chunk);
BlockBox temp;
// x-planes
temp = BlockBox.create(boxToDrawAround.maxX + 1 + boxExpansion, boxToDrawAround.minY - thickness - boxExpansion, boxToDrawAround.minZ - thickness - boxExpansion, boxToDrawAround.maxX + thickness + boxExpansion, boxToDrawAround.maxY + thickness + boxExpansion, boxToDrawAround.maxZ + thickness + boxExpansion);
temp = BlockBoxUtil.intersection(temp, chunkBox);
if (BlockBoxUtil.isRealBox(temp)) BlockPos.stream(temp)
.forEach(blockPos -> {
if(chunk.getBlockState(blockPos).isAir()) chunk.setBlockState(blockPos, blockState, false);
});
temp = BlockBox.create(boxToDrawAround.minX - 1 - boxExpansion, boxToDrawAround.minY - thickness - boxExpansion, boxToDrawAround.minZ - thickness - boxExpansion, boxToDrawAround.minX - thickness - boxExpansion, boxToDrawAround.maxY + thickness + boxExpansion, boxToDrawAround.maxZ + thickness + boxExpansion);
temp = BlockBoxUtil.intersection(temp, chunkBox);
if (BlockBoxUtil.isRealBox(temp)) BlockPos.stream(temp)
.forEach(blockPos -> {
if(chunk.getBlockState(blockPos).isAir()) chunk.setBlockState(blockPos, blockState, false);
});
temp = BlockBox.create(new Vec3i(boxToDrawAround.getMaxX() + 1 + boxExpansion, boxToDrawAround.getMinY() - thickness - boxExpansion, boxToDrawAround.getMinZ() - thickness - boxExpansion), new Vec3i(boxToDrawAround.getMaxX() + thickness + boxExpansion, boxToDrawAround.getMaxY() + thickness + boxExpansion, boxToDrawAround.getMaxZ() + thickness + boxExpansion));
if (temp.intersects(chunkBox)) {
temp = temp.intersection(chunkBox);
BlockPos.stream(temp)
.forEach(blockPos -> {
if (chunk.getBlockState(blockPos).isAir()) chunk.setBlockState(blockPos, blockState, false);
});
}
temp = BlockBox.create(new Vec3i(boxToDrawAround.getMinX() - 1 - boxExpansion, boxToDrawAround.getMinY() - thickness - boxExpansion, boxToDrawAround.getMinZ() - thickness - boxExpansion), new Vec3i(boxToDrawAround.getMinX() - thickness - boxExpansion, boxToDrawAround.getMaxY() + thickness + boxExpansion, boxToDrawAround.getMaxZ() + thickness + boxExpansion));
if (temp.intersects(chunkBox)) {
temp = temp.intersection(chunkBox);
BlockPos.stream(temp)
.forEach(blockPos -> {
if (chunk.getBlockState(blockPos).isAir()) chunk.setBlockState(blockPos, blockState, false);
});
}
// y-planes
temp = BlockBox.create(boxToDrawAround.minX - boxExpansion, boxToDrawAround.maxY + 1 + boxExpansion, boxToDrawAround.minZ - thickness - boxExpansion, boxToDrawAround.maxX + boxExpansion, boxToDrawAround.maxY + thickness + boxExpansion, boxToDrawAround.maxZ + thickness + boxExpansion);
temp = BlockBoxUtil.intersection(temp, chunkBox);
if (BlockBoxUtil.isRealBox(temp)) BlockPos.stream(temp)
.forEach(blockPos -> {
if(chunk.getBlockState(blockPos).getBlock() instanceof AirBlock) chunk.setBlockState(blockPos, blockState, false);
});
temp = BlockBox.create(boxToDrawAround.minX - boxExpansion, boxToDrawAround.minY - 1 - boxExpansion, boxToDrawAround.minZ - thickness - boxExpansion, boxToDrawAround.maxX + boxExpansion, boxToDrawAround.minY - thickness - boxExpansion, boxToDrawAround.maxZ + thickness + boxExpansion);
temp = BlockBoxUtil.intersection(temp, chunkBox);
if (BlockBoxUtil.isRealBox(temp)) BlockPos.stream(temp)
.forEach(blockPos -> {
if(chunk.getBlockState(blockPos).isAir()) chunk.setBlockState(blockPos, blockState, false);
});
temp = BlockBox.create(new Vec3i(boxToDrawAround.getMinX() - boxExpansion, boxToDrawAround.getMaxY() + 1 + boxExpansion, boxToDrawAround.getMinZ() - thickness - boxExpansion), new Vec3i(boxToDrawAround.getMaxX() + boxExpansion, boxToDrawAround.getMaxY() + thickness + boxExpansion, boxToDrawAround.getMaxZ() + thickness + boxExpansion));
if (temp.intersects(chunkBox)) {
temp = temp.intersection(chunkBox);
BlockPos.stream(temp)
.forEach(blockPos -> {
if (chunk.getBlockState(blockPos).getBlock() instanceof AirBlock)
chunk.setBlockState(blockPos, blockState, false);
});
}
temp = BlockBox.create(new Vec3i(boxToDrawAround.getMinX() - boxExpansion, boxToDrawAround.getMinY() - 1 - boxExpansion, boxToDrawAround.getMinZ() - thickness - boxExpansion), new Vec3i(boxToDrawAround.getMaxX() + boxExpansion, boxToDrawAround.getMinY() - thickness - boxExpansion, boxToDrawAround.getMaxZ() + thickness + boxExpansion));
if (temp.intersects(chunkBox)) {
temp = temp.intersection(chunkBox);
BlockPos.stream(temp)
.forEach(blockPos -> {
if (chunk.getBlockState(blockPos).isAir()) chunk.setBlockState(blockPos, blockState, false);
});
}
// z-planes
temp = BlockBox.create(boxToDrawAround.minX - boxExpansion, boxToDrawAround.minY - boxExpansion, boxToDrawAround.minZ - 1 - boxExpansion, boxToDrawAround.maxX + boxExpansion, boxToDrawAround.maxY + boxExpansion, boxToDrawAround.minZ - thickness - boxExpansion);
temp = BlockBoxUtil.intersection(temp, chunkBox);
if (BlockBoxUtil.isRealBox(temp)) BlockPos.stream(temp)
.forEach(blockPos -> {
if(chunk.getBlockState(blockPos).isAir()) chunk.setBlockState(blockPos, blockState, false);
});
temp = BlockBox.create(boxToDrawAround.minX - boxExpansion, boxToDrawAround.minY - boxExpansion, boxToDrawAround.maxZ + 1 + boxExpansion, boxToDrawAround.maxX + boxExpansion, boxToDrawAround.maxY + boxExpansion, boxToDrawAround.maxZ + thickness + boxExpansion);
temp = BlockBoxUtil.intersection(temp, chunkBox);
if (BlockBoxUtil.isRealBox(temp)) BlockPos.stream(temp)
.forEach(blockPos -> {
if(chunk.getBlockState(blockPos).isAir()) chunk.setBlockState(blockPos, blockState, false);
});
temp = BlockBox.create(new Vec3i(boxToDrawAround.getMinX() - boxExpansion, boxToDrawAround.getMinY() - boxExpansion, boxToDrawAround.getMinZ() - 1 - boxExpansion), new Vec3i(boxToDrawAround.getMaxX() + boxExpansion, boxToDrawAround.getMaxY() + boxExpansion, boxToDrawAround.getMinZ() - thickness - boxExpansion));
if (temp.intersects(chunkBox)) {
temp = temp.intersection(chunkBox);
BlockPos.stream(temp)
.forEach(blockPos -> {
if (chunk.getBlockState(blockPos).isAir()) chunk.setBlockState(blockPos, blockState, false);
});
}
temp = BlockBox.create(new Vec3i(boxToDrawAround.getMinX() - boxExpansion, boxToDrawAround.getMinY() - boxExpansion, boxToDrawAround.getMaxZ() + 1 + boxExpansion), new Vec3i(boxToDrawAround.getMaxX() + boxExpansion, boxToDrawAround.getMaxY() + boxExpansion, boxToDrawAround.getMaxZ() + thickness + boxExpansion));
if (temp.intersects(chunkBox)) {
temp = temp.intersection(chunkBox);
BlockPos.stream(temp)
.forEach(blockPos -> {
if (chunk.getBlockState(blockPos).isAir()) chunk.setBlockState(blockPos, blockState, false);
});
}
boxExpansion += thickness;
}
}
@Override
public Modifier fromTag(CompoundTag tag) {
for (Tag layerTag : tag.getList("layers", NbtType.COMPOUND)) {
CompoundTag compoundTag = (CompoundTag) layerTag;
public Modifier fromTag(NbtCompound tag) {
for (NbtElement layerTag : tag.getList("layers", NbtType.COMPOUND)) {
NbtCompound compoundTag = (NbtCompound) layerTag;
try {
Layer layer = Layer.fromTag(compoundTag);
layers.add(layer);
@ -125,7 +137,7 @@ public class ShellModifier implements LazyModifier {
if (tag.contains("box_to_draw_around", NbtType.INT_ARRAY)) {
int[] box = tag.getIntArray("box_to_draw_around");
boxToDrawAround = BlockBox.create(box[0], box[1], box[2], box[3], box[4], box[5]);
boxToDrawAround = BlockBox.create(new Vec3i(box[0], box[1], box[2]), new Vec3i(box[3], box[4], box[5]));
}
return this;
@ -147,7 +159,7 @@ public class ShellModifier implements LazyModifier {
if (pocket instanceof LazyGenerationPocket) {
Map<String, Double> variableMap = pocket.toVariableMap(new HashMap<>());
BlockBox pocketBox = pocket.getBox();
boxToDrawAround = BlockBox.create(pocketBox.minX, pocketBox.minY, pocketBox.minZ, pocketBox.maxX, pocketBox.maxY, pocketBox.maxZ);
boxToDrawAround = BlockBox.create(new Vec3i(pocketBox.getMinX(), pocketBox.getMinY(), pocketBox.getMinZ()), new Vec3i(pocketBox.getMaxX(), pocketBox.getMaxY(), pocketBox.getMaxZ()));
layers.forEach(layer -> pocket.expand(layer.getThickness(variableMap)));
} else {
layers.forEach(layer -> drawLayer(layer, manager.getPocket(), parameters.getWorld()));
@ -170,21 +182,21 @@ public class ShellModifier implements LazyModifier {
BlockBox pocketBox = pocket.getBox();
// x-planes
BlockPos.stream(BlockBox.create(pocketBox.maxX + 1, pocketBox.minY - thickness, pocketBox.minZ - thickness, pocketBox.maxX + thickness, pocketBox.maxY + thickness, pocketBox.maxZ + thickness))
BlockPos.stream(BlockBox.create(new Vec3i(pocketBox.getMaxX() + 1, pocketBox.getMinY() - thickness, pocketBox.getMinZ() - thickness), new Vec3i(pocketBox.getMaxX() + thickness, pocketBox.getMaxY() + thickness, pocketBox.getMaxZ() + thickness)))
.forEach(blockPos -> world.setBlockState(blockPos, blockState));
BlockPos.stream(BlockBox.create(pocketBox.minX - 1, pocketBox.minY - thickness, pocketBox.minZ - thickness, pocketBox.minX - thickness, pocketBox.maxY + thickness, pocketBox.maxZ + thickness))
BlockPos.stream(BlockBox.create(new Vec3i(pocketBox.getMinX() - 1, pocketBox.getMinY() - thickness, pocketBox.getMinZ() - thickness), new Vec3i(pocketBox.getMinX() - thickness, pocketBox.getMaxY() + thickness, pocketBox.getMaxZ() + thickness)))
.forEach(blockPos -> world.setBlockState(blockPos, blockState));
// y-planes
BlockPos.stream(BlockBox.create(pocketBox.minX, pocketBox.maxY + 1, pocketBox.minZ - thickness, pocketBox.maxX, pocketBox.maxY + thickness, pocketBox.maxZ + thickness))
BlockPos.stream(BlockBox.create(new Vec3i(pocketBox.getMinX(), pocketBox.getMaxY() + 1, pocketBox.getMinZ() - thickness), new Vec3i(pocketBox.getMaxX(), pocketBox.getMaxY() + thickness, pocketBox.getMaxZ() + thickness)))
.forEach(blockPos -> world.setBlockState(blockPos, blockState));
BlockPos.stream(BlockBox.create(pocketBox.minX, pocketBox.minY - 1, pocketBox.minZ - thickness, pocketBox.maxX, pocketBox.minY - thickness, pocketBox.maxZ + thickness))
BlockPos.stream(BlockBox.create(new Vec3i(pocketBox.getMinX(), pocketBox.getMinY() - 1, pocketBox.getMinZ() - thickness), new Vec3i(pocketBox.getMaxX(), pocketBox.getMinY() - thickness, pocketBox.getMaxZ() + thickness)))
.forEach(blockPos -> world.setBlockState(blockPos, blockState));
// z-planes
BlockPos.stream(BlockBox.create(pocketBox.minX, pocketBox.minY, pocketBox.minZ - 1, pocketBox.maxX, pocketBox.maxY, pocketBox.minZ - thickness))
BlockPos.stream(BlockBox.create(new Vec3i(pocketBox.getMinX(), pocketBox.getMinY(), pocketBox.getMinZ() - 1), new Vec3i(pocketBox.getMaxX(), pocketBox.getMaxY(), pocketBox.getMinZ() - thickness)))
.forEach(blockPos -> world.setBlockState(blockPos, blockState));
BlockPos.stream(BlockBox.create(pocketBox.minX, pocketBox.minY, pocketBox.maxZ + 1, pocketBox.maxX, pocketBox.maxY, pocketBox.maxZ + thickness))
BlockPos.stream(BlockBox.create(new Vec3i(pocketBox.getMinX(), pocketBox.getMinY(), pocketBox.getMaxZ() + 1), new Vec3i(pocketBox.getMaxX(), pocketBox.getMaxY(), pocketBox.getMaxZ() + thickness)))
.forEach(blockPos -> world.setBlockState(blockPos, blockState));
pocket.expand(thickness);
@ -224,14 +236,14 @@ public class ShellModifier implements LazyModifier {
return (int) thicknessEquation.apply(variableMap);
}
public CompoundTag toTag() {
CompoundTag tag = new CompoundTag();
public NbtCompound toTag() {
NbtCompound tag = new NbtCompound();
tag.putString("block_state", blockStateString);
tag.putString("thickness", thickness);
return tag;
}
public static Layer fromTag(CompoundTag tag) throws CommandSyntaxException {
public static Layer fromTag(NbtCompound tag) throws CommandSyntaxException {
return new Layer(tag.getString("block_state"), tag.getString("thickness"));
}
}

View file

@ -2,7 +2,7 @@ package org.dimdev.dimdoors.pockets.virtual;
import com.mojang.serialization.*;
import net.fabricmc.fabric.api.event.registry.FabricRegistryBuilder;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry;
import net.minecraft.util.registry.RegistryKey;
@ -22,19 +22,19 @@ import java.util.function.Supplier;
public interface ImplementedVirtualPocket extends VirtualPocket {
Registry<VirtualPocketType<? extends ImplementedVirtualPocket>> REGISTRY = FabricRegistryBuilder.from(new SimpleRegistry<VirtualPocketType<? extends ImplementedVirtualPocket>>(RegistryKey.ofRegistry(new Identifier("dimdoors", "virtual_pocket_type")), Lifecycle.stable())).buildAndRegister();
static ImplementedVirtualPocket deserialize(CompoundTag tag) {
static ImplementedVirtualPocket deserialize(NbtCompound tag) {
Identifier id = Identifier.tryParse(tag.getString("type"));
VirtualPocketType<?> type = REGISTRY.get(id);
return type != null ? type.fromTag(tag) : VirtualPocketType.NONE.fromTag(tag);
}
static CompoundTag serialize(ImplementedVirtualPocket implementedVirtualPocket) {
return implementedVirtualPocket.toTag(new CompoundTag());
static NbtCompound serialize(ImplementedVirtualPocket implementedVirtualPocket) {
return implementedVirtualPocket.toTag(new NbtCompound());
}
ImplementedVirtualPocket fromTag(CompoundTag tag);
ImplementedVirtualPocket fromTag(NbtCompound tag);
default CompoundTag toTag(CompoundTag tag) {
default NbtCompound toTag(NbtCompound tag) {
return this.getType().toTag(tag);
}
@ -49,9 +49,9 @@ public interface ImplementedVirtualPocket extends VirtualPocket {
VirtualPocketType<ConditionalSelector> CONDITIONAL_SELECTOR = register(new Identifier("dimdoors", ConditionalSelector.KEY), ConditionalSelector::new);
VirtualPocketType<PathSelector> PATH_SELECTOR = register(new Identifier("dimdoors", PathSelector.KEY), PathSelector::new);
ImplementedVirtualPocket fromTag(CompoundTag tag);
ImplementedVirtualPocket fromTag(NbtCompound tag);
CompoundTag toTag(CompoundTag tag);
NbtCompound toTag(NbtCompound tag);
static void register() {
DimensionalDoorsInitializer.apiSubscribers.forEach(d -> d.registerVirtualSingularPocketTypes(REGISTRY));
@ -60,12 +60,12 @@ public interface ImplementedVirtualPocket extends VirtualPocket {
static <U extends ImplementedVirtualPocket> VirtualPocketType<U> register(Identifier id, Supplier<U> factory) {
return Registry.register(REGISTRY, id, new VirtualPocketType<U>() {
@Override
public ImplementedVirtualPocket fromTag(CompoundTag tag) {
public ImplementedVirtualPocket fromTag(NbtCompound tag) {
return factory.get().fromTag(tag);
}
@Override
public CompoundTag toTag(CompoundTag tag) {
public NbtCompound toTag(NbtCompound tag) {
tag.putString("type", id.toString());
return tag;
}
@ -97,7 +97,7 @@ public interface ImplementedVirtualPocket extends VirtualPocket {
}
@Override
public ImplementedVirtualPocket fromTag(CompoundTag tag) {
public ImplementedVirtualPocket fromTag(NbtCompound tag) {
return this;
}

View file

@ -1,25 +1,25 @@
package org.dimdev.dimdoors.pockets.virtual;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.Tag;
import org.dimdev.dimdoors.pockets.virtual.reference.PocketGeneratorReference;
import org.dimdev.dimdoors.pockets.PocketGenerationContext;
import org.dimdev.dimdoors.api.util.Weighted;
import org.dimdev.dimdoors.world.pocket.type.Pocket;
import net.fabricmc.fabric.api.util.NbtType;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.nbt.NbtElement;
import net.minecraft.nbt.NbtList;
public interface VirtualPocket extends Weighted<PocketGenerationContext> {
static VirtualPocket deserialize(Tag tag) {
static VirtualPocket deserialize(NbtElement tag) {
if (tag.getType() == NbtType.LIST) {
return VirtualPocketList.deserialize((ListTag) tag);
return VirtualPocketList.deserialize((NbtList) tag);
}
return ImplementedVirtualPocket.deserialize((CompoundTag) tag); // should be CompoundTag
return ImplementedVirtualPocket.deserialize((NbtCompound) tag); // should be CompoundTag
}
static Tag serialize(VirtualPocket virtualPocket) {
static NbtElement serialize(VirtualPocket virtualPocket) {
if (virtualPocket instanceof VirtualPocketList) {
return VirtualPocketList.serialize((VirtualPocketList) virtualPocket);
}

View file

@ -1,33 +1,33 @@
package org.dimdev.dimdoors.pockets.virtual;
import net.minecraft.nbt.ListTag;
import org.dimdev.dimdoors.pockets.virtual.reference.PocketGeneratorReference;
import org.dimdev.dimdoors.pockets.PocketGenerationContext;
import net.minecraft.nbt.NbtList;
import org.dimdev.dimdoors.api.util.WeightedList;
import org.dimdev.dimdoors.world.pocket.type.Pocket;
public class VirtualPocketList extends WeightedList<VirtualPocket, PocketGenerationContext> implements VirtualPocket {
public static VirtualPocketList deserialize(ListTag tag) {
public static VirtualPocketList deserialize(NbtList tag) {
return new VirtualPocketList().fromTag(tag);
}
public static ListTag serialize(VirtualPocketList virtualPocketList) {
return virtualPocketList.toTag(new ListTag());
public static NbtList serialize(VirtualPocketList virtualPocketList) {
return virtualPocketList.toTag(new NbtList());
}
public VirtualPocketList() {
super();
}
public VirtualPocketList fromTag(ListTag tag) { // Keep in mind, this would add onto the list instead of overwriting it if called multiple times.
for (net.minecraft.nbt.Tag value : tag) {
public VirtualPocketList fromTag(NbtList tag) { // Keep in mind, this would add onto the list instead of overwriting it if called multiple times.
for (net.minecraft.nbt.NbtElement value : tag) {
this.add(VirtualPocket.deserialize(value));
}
return this;
}
public ListTag toTag(ListTag tag) {
public NbtList toTag(NbtList tag) {
for(VirtualPocket virtualPocket : this) {
tag.add(VirtualPocket.serialize(virtualPocket));
}

View file

@ -1,8 +1,7 @@
package org.dimdev.dimdoors.pockets.virtual.reference;
import net.minecraft.nbt.CompoundTag;
import com.google.common.base.MoreObjects;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.util.Identifier;
import org.dimdev.dimdoors.pockets.PocketLoader;
import org.dimdev.dimdoors.pockets.generator.PocketGenerator;
@ -15,7 +14,7 @@ public class IdReference extends PocketGeneratorReference {
private Identifier id;
@Override
public ImplementedVirtualPocket fromTag(CompoundTag tag) {
public ImplementedVirtualPocket fromTag(NbtCompound tag) {
super.fromTag(tag);
// TODO: make the json need the "dimdoors:" as well and load id via Identifier#tryParse instead
@ -25,7 +24,7 @@ public class IdReference extends PocketGeneratorReference {
}
@Override
public CompoundTag toTag(CompoundTag tag) {
public NbtCompound toTag(NbtCompound tag) {
super.toTag(tag);
tag.putString("id", id.getPath());

View file

@ -7,6 +7,8 @@ import java.util.stream.Collectors;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import net.fabricmc.fabric.api.util.NbtType;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.nbt.NbtList;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.ServerTask;
import net.minecraft.util.math.BlockPos;
@ -27,9 +29,6 @@ import org.dimdev.dimdoors.api.util.math.Equation.EquationParseException;
import org.dimdev.dimdoors.world.pocket.type.LazyGenerationPocket;
import org.dimdev.dimdoors.world.pocket.type.Pocket;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag;
public abstract class PocketGeneratorReference implements ImplementedVirtualPocket {
private static final Logger LOGGER = LogManager.getLogger();
@ -37,7 +36,7 @@ public abstract class PocketGeneratorReference implements ImplementedVirtualPock
protected Equation weightEquation;
protected Boolean setupLoot;
protected final List<Modifier> modifierList = Lists.newArrayList();
protected final List<CompoundTag> addons = new ArrayList<>();
protected final List<NbtCompound> addons = new ArrayList<>();
private void parseWeight() {
try {
@ -56,7 +55,7 @@ public abstract class PocketGeneratorReference implements ImplementedVirtualPock
}
@Override
public ImplementedVirtualPocket fromTag(CompoundTag tag) {
public ImplementedVirtualPocket fromTag(NbtCompound tag) {
if (tag.contains("weight")) { // override referenced pockets weight
this.weight = tag.getString("weight");
parseWeight();
@ -65,14 +64,14 @@ public abstract class PocketGeneratorReference implements ImplementedVirtualPock
if (tag.contains("setup_loot")) setupLoot = tag.getBoolean("setup_loot");
if (tag.contains("modifiers")) {
ListTag modifiersTag = tag.getList("modifiers", 10);
NbtList modifiersTag = tag.getList("modifiers", 10);
for (int i = 0; i < modifiersTag.size(); i++) {
modifierList.add(Modifier.deserialize(modifiersTag.getCompound(i)));
}
}
if (tag.contains("addons", NbtType.LIST)) {
ListTag modifiersTag = tag.getList("addons", 10);
NbtList modifiersTag = tag.getList("addons", 10);
for (int i = 0; i < modifiersTag.size(); i++) {
addons.add(modifiersTag.getCompound(i));
}
@ -82,20 +81,20 @@ public abstract class PocketGeneratorReference implements ImplementedVirtualPock
}
@Override
public CompoundTag toTag(CompoundTag tag) {
public NbtCompound toTag(NbtCompound tag) {
ImplementedVirtualPocket.super.toTag(tag);
if (weight != null) tag.putString("weight", weight);
if (setupLoot != null) tag.putBoolean("setup_loot", setupLoot);
ListTag modifiersTag = new ListTag();
NbtList modifiersTag = new NbtList();
for (Modifier modifier : modifierList) {
modifiersTag.add(modifier.toTag(new CompoundTag()));
modifiersTag.add(modifier.toTag(new NbtCompound()));
}
if (modifiersTag.size() > 0) tag.put("modifiers", modifiersTag);
ListTag addonsTag = new ListTag();
NbtList addonsTag = new NbtList();
addonsTag.addAll(addons);
if (addonsTag.size() > 0) tag.put("addons", addonsTag);

View file

@ -1,10 +1,9 @@
package org.dimdev.dimdoors.pockets.virtual.reference;
import net.fabricmc.fabric.api.util.NbtType;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.StringTag;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.nbt.NbtList;
import net.minecraft.nbt.NbtString;
import com.google.common.base.MoreObjects;
import org.dimdev.dimdoors.pockets.PocketLoader;
import org.dimdev.dimdoors.pockets.generator.PocketGenerator;
@ -25,18 +24,18 @@ public class TagReference extends PocketGeneratorReference{
private WeightedList<PocketGenerator, PocketGenerationContext> pockets;
@Override
public ImplementedVirtualPocket fromTag(CompoundTag tag) {
public ImplementedVirtualPocket fromTag(NbtCompound tag) {
super.fromTag(tag);
if (tag.contains("required")) {
ListTag listTag = tag.getList("required", NbtType.STRING);
NbtList listTag = tag.getList("required", NbtType.STRING);
for (int i = 0; i < listTag.size(); i++) {
required.add(listTag.getString(i));
}
}
if (tag.contains("blackList")) {
ListTag listTag = tag.getList("blackList", NbtType.STRING);
NbtList listTag = tag.getList("blackList", NbtType.STRING);
for (int i = 0; i < listTag.size(); i++) {
blackList.add(listTag.getString(i));
}
@ -48,21 +47,21 @@ public class TagReference extends PocketGeneratorReference{
}
@Override
public CompoundTag toTag(CompoundTag tag) {
public NbtCompound toTag(NbtCompound tag) {
super.toTag(tag);
if (required.size() > 0) {
ListTag listTag = new ListTag();
NbtList listTag = new NbtList();
for (String tagString : required) {
listTag.add(StringTag.of(tagString));
listTag.add(NbtString.of(tagString));
}
tag.put("required", listTag);
}
if (blackList.size() > 0) {
ListTag listTag = new ListTag();
NbtList listTag = new NbtList();
for (String tagString : blackList) {
listTag.add(StringTag.of(tagString));
listTag.add(NbtString.of(tagString));
}
tag.put("blackList", listTag);
}

View file

@ -1,6 +1,6 @@
package org.dimdev.dimdoors.pockets.virtual.selection;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtCompound;
import org.dimdev.dimdoors.api.util.WeightedList;
import org.dimdev.dimdoors.pockets.PocketGenerationContext;
import org.dimdev.dimdoors.pockets.virtual.ImplementedVirtualPocket;
@ -10,7 +10,7 @@ import org.dimdev.dimdoors.world.pocket.type.Pocket;
public abstract class AbstractVirtualPocketList extends WeightedList<VirtualPocket, PocketGenerationContext> implements ImplementedVirtualPocket {
public CompoundTag toTag(CompoundTag tag) {
public NbtCompound toTag(NbtCompound tag) {
ImplementedVirtualPocket.super.toTag(tag);
return tag;

View file

@ -1,8 +1,6 @@
package org.dimdev.dimdoors.pockets.virtual.selection;
import com.google.common.collect.Maps;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.dimdev.dimdoors.pockets.virtual.ImplementedVirtualPocket;
@ -15,6 +13,8 @@ import org.dimdev.dimdoors.world.pocket.type.Pocket;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.nbt.NbtList;
public class ConditionalSelector implements ImplementedVirtualPocket {
private static final Logger LOGGER = LogManager.getLogger();
@ -35,10 +35,10 @@ public class ConditionalSelector implements ImplementedVirtualPocket {
}
@Override
public ImplementedVirtualPocket fromTag(CompoundTag tag) {
ListTag conditionalPockets = tag.getList("pockets", 10);
public ImplementedVirtualPocket fromTag(NbtCompound tag) {
NbtList conditionalPockets = tag.getList("pockets", 10);
for (int i = 0; i < conditionalPockets.size(); i++) {
CompoundTag pocket = conditionalPockets.getCompound(i);
NbtCompound pocket = conditionalPockets.getCompound(i);
String condition = pocket.getString("condition");
if (pocketMap.containsKey(condition)) continue;
try {
@ -52,12 +52,12 @@ public class ConditionalSelector implements ImplementedVirtualPocket {
}
@Override
public CompoundTag toTag(CompoundTag tag) {
public NbtCompound toTag(NbtCompound tag) {
ImplementedVirtualPocket.super.toTag(tag);
ListTag conditionalPockets = new ListTag();
NbtList conditionalPockets = new NbtList();
pocketMap.forEach((condition, pocket) -> {
CompoundTag compound = new CompoundTag();
NbtCompound compound = new NbtCompound();
compound.putString("condition", condition);
compound.put("pocket", VirtualPocket.serialize(pocket));
conditionalPockets.add(compound);

View file

@ -1,6 +1,6 @@
package org.dimdev.dimdoors.pockets.virtual.selection;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtCompound;
import org.dimdev.dimdoors.api.util.Path;
import org.dimdev.dimdoors.pockets.PocketLoader;
import org.dimdev.dimdoors.pockets.virtual.ImplementedVirtualPocket;
@ -12,14 +12,14 @@ public class PathSelector extends AbstractVirtualPocketList {
private String path;
@Override
public ImplementedVirtualPocket fromTag(CompoundTag tag) {
public ImplementedVirtualPocket fromTag(NbtCompound tag) {
this.path = tag.getString("path");
return this;
}
@Override
public CompoundTag toTag(CompoundTag tag) {
public NbtCompound toTag(NbtCompound tag) {
super.toTag(tag);
tag.putString("path", path);

View file

@ -6,11 +6,9 @@ import java.util.Collections;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;
import net.minecraft.nbt.NbtCompound;
import org.apache.commons.lang3.builder.ToStringBuilder;
import net.minecraft.nbt.CompoundTag;
public class LinkProperties {
public static final LinkProperties NONE = LinkProperties.builder().build();
@ -69,8 +67,8 @@ public class LinkProperties {
return new LinkPropertiesBuilder().floatingWeight(this.floatingWeight).entranceWeight(this.entranceWeight).groups(this.groups).linksRemaining(this.linksRemaining).oneWay(this.oneWay);
}
public static CompoundTag toTag(LinkProperties properties) {
net.minecraft.nbt.CompoundTag tag = new net.minecraft.nbt.CompoundTag();
public static NbtCompound toTag(LinkProperties properties) {
net.minecraft.nbt.NbtCompound tag = new net.minecraft.nbt.NbtCompound();
tag.putFloat("floatingWeight", properties.floatingWeight);
tag.putFloat("entranceWeight", properties.entranceWeight);
tag.putIntArray("groups", new ArrayList<>(properties.groups));
@ -79,7 +77,7 @@ public class LinkProperties {
return tag;
}
public static LinkProperties fromTag(CompoundTag tag) {
public static LinkProperties fromTag(NbtCompound tag) {
return LinkProperties.builder()
.floatingWeight(tag.getFloat("floatingWeight"))
.entranceWeight(tag.getFloat("entranceWeight"))

View file

@ -4,8 +4,7 @@ import java.util.UUID;
import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.util.dynamic.DynamicSerializableUuid;
public class PlayerRiftPointer extends RegistryVertex {
@ -35,14 +34,14 @@ public class PlayerRiftPointer extends RegistryVertex {
return "PlayerRiftPointer(player=" + this.player + ")";
}
public static CompoundTag toTag(PlayerRiftPointer vertex) {
CompoundTag tag = new CompoundTag();
public static NbtCompound toTag(PlayerRiftPointer vertex) {
NbtCompound tag = new NbtCompound();
tag.putUuid("id", vertex.id);
tag.putUuid("player", vertex.player);
return tag;
}
public static PlayerRiftPointer fromTag(CompoundTag tag) {
public static PlayerRiftPointer fromTag(NbtCompound tag) {
return new PlayerRiftPointer(tag.getUuid("id"));
}

View file

@ -1,6 +1,6 @@
package org.dimdev.dimdoors.rift.registry;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry;
import net.minecraft.util.registry.RegistryKey;
@ -26,16 +26,16 @@ public class PocketEntrancePointer extends RegistryVertex { // TODO: PocketRiftP
return "PocketEntrancePointer(pocketDim=" + this.getWorld() + ", pocketId=" + this.pocketId + ")";
}
public static CompoundTag toTag(PocketEntrancePointer vertex) {
CompoundTag tag = new CompoundTag();
public static NbtCompound toTag(PocketEntrancePointer vertex) {
NbtCompound tag = new NbtCompound();
tag.putUuid("id", vertex.id);
tag.putString("pocketDim", vertex.getWorld().getValue().toString());
tag.putInt("pocketId", vertex.pocketId);
return tag;
}
public static PocketEntrancePointer fromTag(CompoundTag tag) {
PocketEntrancePointer pointer = new PocketEntrancePointer(RegistryKey.of(Registry.DIMENSION, new Identifier(tag.getString("pocketDim"))), tag.getInt("pocketId"));
public static PocketEntrancePointer fromTag(NbtCompound tag) {
PocketEntrancePointer pointer = new PocketEntrancePointer(RegistryKey.of(Registry.WORLD_KEY, new Identifier(tag.getString("pocketDim"))), tag.getInt("pocketId"));
pointer.id = tag.getUuid("id");
return pointer;
}

View file

@ -3,8 +3,7 @@ package org.dimdev.dimdoors.rift.registry;
import java.util.Objects;
import java.util.UUID;
import java.util.function.Function;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry;
import net.minecraft.util.registry.RegistryKey;
@ -38,14 +37,14 @@ public abstract class RegistryVertex {
return "RegistryVertex(dim=" + this.world + ", id=" + this.id + ")";
}
public static RegistryVertex fromTag(CompoundTag nbt) {
public static RegistryVertex fromTag(NbtCompound nbt) {
return Objects.requireNonNull(registry.get(new Identifier(nbt.getString("type")))).fromTag(nbt);
}
public static CompoundTag toTag(RegistryVertex registryVertex) {
public static NbtCompound toTag(RegistryVertex registryVertex) {
String type = registry.getId(registryVertex.getType()).toString();
CompoundTag tag = registryVertex.getType().toTag(registryVertex);
NbtCompound tag = registryVertex.getType().toTag(registryVertex);
tag.putString("type", type);
return tag;
@ -73,19 +72,19 @@ public abstract class RegistryVertex {
RegistryVertexType<PocketEntrancePointer> ENTRANCE = register("entrance", PocketEntrancePointer::fromTag, PocketEntrancePointer::toTag);
RegistryVertexType<RiftPlaceholder> RIFT_PLACEHOLDER = register("rift_placeholder", RiftPlaceholder::fromTag, RiftPlaceholder::toTag);
T fromTag(CompoundTag tag);
T fromTag(NbtCompound tag);
CompoundTag toTag(RegistryVertex virtualType);
NbtCompound toTag(RegistryVertex virtualType);
static <T extends RegistryVertex> RegistryVertex.RegistryVertexType<T> register(String id, Function<CompoundTag, T> fromTag, Function<T, CompoundTag> toTag) {
static <T extends RegistryVertex> RegistryVertex.RegistryVertexType<T> register(String id, Function<NbtCompound, T> fromTag, Function<T, NbtCompound> toTag) {
return Registry.register(registry, id, new RegistryVertexType<T>() {
@Override
public T fromTag(CompoundTag tag) {
public T fromTag(NbtCompound tag) {
return fromTag.apply(tag);
}
@Override
public CompoundTag toTag(RegistryVertex registryVertex) {
public NbtCompound toTag(RegistryVertex registryVertex) {
return toTag.apply((T) registryVertex);
}
});

View file

@ -1,15 +1,13 @@
package org.dimdev.dimdoors.rift.registry;
import java.util.UUID;
import net.minecraft.nbt.NbtCompound;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.dimdev.dimdoors.block.entity.RiftBlockEntity;
import org.dimdev.dimdoors.api.util.Location;
import org.dimdev.dimdoors.world.level.registry.DimensionalRegistry;
import net.minecraft.nbt.CompoundTag;
public class Rift extends RegistryVertex {
private static final Logger LOGGER = LogManager.getLogger();
private Location location;
@ -73,8 +71,8 @@ public class Rift extends RegistryVertex {
return RegistryVertexType.RIFT;
}
public static CompoundTag toTag(Rift rift) {
CompoundTag tag = new CompoundTag();
public static NbtCompound toTag(Rift rift) {
NbtCompound tag = new NbtCompound();
tag.putUuid("id", rift.id);
tag.put("location", Location.toTag(rift.location));
tag.putBoolean("isDetached", rift.isDetached);
@ -82,7 +80,7 @@ public class Rift extends RegistryVertex {
return tag;
}
public static Rift fromTag(CompoundTag tag) {
public static Rift fromTag(NbtCompound tag) {
Rift rift = new Rift();
rift.id = tag.getUuid("id");
rift.location = Location.fromTag(tag.getCompound("location"));

View file

@ -1,6 +1,6 @@
package org.dimdev.dimdoors.rift.registry;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtCompound;
public class RiftPlaceholder extends Rift { // TODO: don't extend rift
@Override
@ -33,13 +33,13 @@ public class RiftPlaceholder extends Rift { // TODO: don't extend rift
return RegistryVertexType.RIFT_PLACEHOLDER;
}
public static CompoundTag toTag(RiftPlaceholder vertex) {
CompoundTag tag = new CompoundTag();
public static NbtCompound toTag(RiftPlaceholder vertex) {
NbtCompound tag = new NbtCompound();
tag.putUuid("id", vertex.id);
return tag;
}
public static RiftPlaceholder fromTag(CompoundTag tag) {
public static RiftPlaceholder fromTag(NbtCompound tag) {
RiftPlaceholder vertex = new RiftPlaceholder();
vertex.id = tag.getUuid("id");
return vertex;

View file

@ -5,6 +5,9 @@ import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;
import net.fabricmc.fabric.api.util.NbtType;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.nbt.NbtElement;
import net.minecraft.nbt.NbtList;
import net.minecraft.util.Pair;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@ -15,10 +18,6 @@ import org.dimdev.dimdoors.world.pocket.type.Pocket;
import org.dimdev.dimdoors.world.pocket.PocketDirectory;
import org.jgrapht.graph.DefaultDirectedGraph;
import org.jgrapht.graph.DefaultEdge;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.Tag;
import net.minecraft.util.registry.RegistryKey;
import net.minecraft.world.World;
@ -35,16 +34,16 @@ public class RiftRegistry {
protected Map<UUID, PlayerRiftPointer> lastPrivatePocketExits = new HashMap<>(); // Player UUID -> last rift used to enter pocket
protected Map<UUID, PlayerRiftPointer> overworldRifts = new HashMap<>(); // Player UUID -> rift used to exit the overworld
public static RiftRegistry fromTag(Map<RegistryKey<World>, PocketDirectory> pocketRegistry, CompoundTag nbt) {
public static RiftRegistry fromTag(Map<RegistryKey<World>, PocketDirectory> pocketRegistry, NbtCompound nbt) {
// Read rifts in this dimension
RiftRegistry riftRegistry = new RiftRegistry();
ListTag riftsNBT = nbt.getList("rifts", NbtType.COMPOUND);
CompletableFuture<List<Rift>> futureRifts = CompletableFuture.supplyAsync(() -> riftsNBT.parallelStream().unordered().map(CompoundTag.class::cast).map(Rift::fromTag).collect(Collectors.toList()));
NbtList riftsNBT = nbt.getList("rifts", NbtType.COMPOUND);
CompletableFuture<List<Rift>> futureRifts = CompletableFuture.supplyAsync(() -> riftsNBT.parallelStream().unordered().map(NbtCompound.class::cast).map(Rift::fromTag).collect(Collectors.toList()));
ListTag pocketsNBT = nbt.getList("pockets", NbtType.COMPOUND);
CompletableFuture<List<PocketEntrancePointer>> futurePockets = CompletableFuture.supplyAsync(() -> pocketsNBT.stream().map(CompoundTag.class::cast).map(PocketEntrancePointer::fromTag).collect(Collectors.toList()));
NbtList pocketsNBT = nbt.getList("pockets", NbtType.COMPOUND);
CompletableFuture<List<PocketEntrancePointer>> futurePockets = CompletableFuture.supplyAsync(() -> pocketsNBT.stream().map(NbtCompound.class::cast).map(PocketEntrancePointer::fromTag).collect(Collectors.toList()));
futureRifts.join().forEach(rift -> {
riftRegistry.graph.addVertex(rift);
@ -59,10 +58,10 @@ public class RiftRegistry {
});
// Read the connections between links that have a source or destination in this dimension
ListTag linksNBT = nbt.getList("links", NbtType.COMPOUND);
for (Tag linkNBT : linksNBT) {
RegistryVertex from = riftRegistry.uuidMap.get(((CompoundTag) linkNBT).getUuid("from"));
RegistryVertex to = riftRegistry.uuidMap.get(((CompoundTag) linkNBT).getUuid("to"));
NbtList linksNBT = nbt.getList("links", NbtType.COMPOUND);
for (NbtElement linkNBT : linksNBT) {
RegistryVertex from = riftRegistry.uuidMap.get(((NbtCompound) linkNBT).getUuid("from"));
RegistryVertex to = riftRegistry.uuidMap.get(((NbtCompound) linkNBT).getUuid("to"));
if (from != null && to != null) {
riftRegistry.graph.addEdge(from, to);
// We need a system for detecting links that are incomplete after processing them in the other subregistry too
@ -75,18 +74,18 @@ public class RiftRegistry {
return riftRegistry;
}
public CompoundTag toTag() {
CompoundTag tag = new CompoundTag();
public NbtCompound toTag() {
NbtCompound tag = new NbtCompound();
// Write rifts in this dimension
CompletableFuture<Pair<ListTag, ListTag>> futureRiftsAndPocketsNBT = CompletableFuture.supplyAsync(() -> {
CompletableFuture<Pair<NbtList, NbtList>> futureRiftsAndPocketsNBT = CompletableFuture.supplyAsync(() -> {
Map<Boolean, List<RegistryVertex>> vertices = this.graph.vertexSet().parallelStream().unordered().filter(vertex -> vertex instanceof Rift || vertex instanceof PocketEntrancePointer)
.collect(Collectors.partitioningBy(Rift.class::isInstance));
CompletableFuture<List<CompoundTag>> futureRiftsNBT = CompletableFuture.supplyAsync(() -> vertices.get(true).parallelStream().map(RegistryVertex::toTag).collect(Collectors.toList()));
CompletableFuture<List<CompoundTag>> futurePocketsNBT = CompletableFuture.supplyAsync(() -> vertices.get(false).parallelStream().map(RegistryVertex::toTag).collect(Collectors.toList()));
CompletableFuture<List<NbtCompound>> futureRiftsNBT = CompletableFuture.supplyAsync(() -> vertices.get(true).parallelStream().map(RegistryVertex::toTag).collect(Collectors.toList()));
CompletableFuture<List<NbtCompound>> futurePocketsNBT = CompletableFuture.supplyAsync(() -> vertices.get(false).parallelStream().map(RegistryVertex::toTag).collect(Collectors.toList()));
ListTag riftsNBT = new ListTag();
ListTag pocketsNBT = new ListTag();
NbtList riftsNBT = new NbtList();
NbtList pocketsNBT = new NbtList();
riftsNBT.addAll(futureRiftsNBT.join());
pocketsNBT.addAll(futurePocketsNBT.join());
@ -96,12 +95,12 @@ public class RiftRegistry {
// Write the connections between links that have a source or destination in this dimension
CompletableFuture<ListTag> futureLinksNBT = CompletableFuture.supplyAsync(() -> {
ListTag linksNBT = new ListTag();
CompletableFuture<NbtList> futureLinksNBT = CompletableFuture.supplyAsync(() -> {
NbtList linksNBT = new NbtList();
for (DefaultEdge edge : this.graph.edgeSet()) {
RegistryVertex from = this.graph.getEdgeSource(edge);
RegistryVertex to = this.graph.getEdgeTarget(edge);
CompoundTag linkNBT = new CompoundTag();
NbtCompound linkNBT = new NbtCompound();
linkNBT.putUuid("from", from.id);
linkNBT.putUuid("to", to.id);
linksNBT.add(linkNBT);
@ -115,7 +114,7 @@ public class RiftRegistry {
tag.put("last_private_pocket_exits", this.writePlayerRiftPointers(this.lastPrivatePocketExits));
tag.put("overworld_rifts", this.writePlayerRiftPointers(this.overworldRifts));
Pair<ListTag, ListTag> riftsAndPocketsNBT = futureRiftsAndPocketsNBT.join();
Pair<NbtList, NbtList> riftsAndPocketsNBT = futureRiftsAndPocketsNBT.join();
tag.put("rifts", riftsAndPocketsNBT.getLeft());
tag.put("pockets", riftsAndPocketsNBT.getRight());
@ -125,11 +124,11 @@ public class RiftRegistry {
}
// TODO: parallelization
private Map<UUID, PlayerRiftPointer> readPlayerRiftPointers(ListTag tag) {
private Map<UUID, PlayerRiftPointer> readPlayerRiftPointers(NbtList tag) {
Map<UUID, PlayerRiftPointer> pointerMap = new HashMap<>();
for (Tag entryNBT : tag) {
UUID player = ((CompoundTag) entryNBT).getUuid("player");
UUID rift = ((CompoundTag) entryNBT).getUuid("rift");
for (NbtElement entryNBT : tag) {
UUID player = ((NbtCompound) entryNBT).getUuid("player");
UUID rift = ((NbtCompound) entryNBT).getUuid("rift");
PlayerRiftPointer pointer = new PlayerRiftPointer(player);
pointerMap.put(player, pointer);
this.uuidMap.put(pointer.id, pointer);
@ -140,10 +139,10 @@ public class RiftRegistry {
}
// TODO: parallelization
private ListTag writePlayerRiftPointers(Map<UUID, PlayerRiftPointer> playerRiftPointerMap) {
ListTag pointers = new ListTag();
private NbtList writePlayerRiftPointers(Map<UUID, PlayerRiftPointer> playerRiftPointerMap) {
NbtList pointers = new NbtList();
for (Map.Entry<UUID, PlayerRiftPointer> entry : playerRiftPointerMap.entrySet()) {
CompoundTag entryNBT = new CompoundTag();
NbtCompound entryNBT = new NbtCompound();
entryNBT.putUuid("player", entry.getKey());
int count = 0;
for (DefaultEdge edge : this.graph.outgoingEdgesOf(entry.getValue())) {

View file

@ -13,7 +13,7 @@ import org.dimdev.dimdoors.world.level.registry.DimensionalRegistry;
import org.dimdev.dimdoors.world.pocket.VirtualLocation;
import net.minecraft.entity.Entity;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.text.TranslatableText;
import net.minecraft.util.math.BlockPos;
@ -71,13 +71,13 @@ public class EscapeTarget extends VirtualTarget implements EntityTarget { // TOD
return VirtualTargetType.ESCAPE;
}
public static CompoundTag toTag(EscapeTarget virtualTarget) {
CompoundTag tag = new CompoundTag();
public static NbtCompound toTag(EscapeTarget virtualTarget) {
NbtCompound tag = new NbtCompound();
tag.putBoolean("canEscapeLimbo", virtualTarget.canEscapeLimbo);
return tag;
}
public static EscapeTarget fromTag(CompoundTag nbt) {
public static EscapeTarget fromTag(NbtCompound nbt) {
return new EscapeTarget(nbt.getBoolean("canEscapeLimbo"));
}
}

View file

@ -1,10 +1,9 @@
package org.dimdev.dimdoors.rift.targets;
import com.mojang.serialization.Codec;
import net.minecraft.nbt.NbtCompound;
import org.dimdev.dimdoors.api.util.Location;
import net.minecraft.nbt.CompoundTag;
public class GlobalReference extends RiftReference {
public static Codec<GlobalReference> CODEC = Location.CODEC.fieldOf("location").xmap(GlobalReference::new, GlobalReference::getReferencedLocation).codec();
@ -24,13 +23,13 @@ public class GlobalReference extends RiftReference {
return VirtualTargetType.GLOBAL;
}
public static CompoundTag toTag(GlobalReference virtualTarget) {
CompoundTag tag = new CompoundTag();
public static NbtCompound toTag(GlobalReference virtualTarget) {
NbtCompound tag = new NbtCompound();
tag.put("target", Location.toTag(virtualTarget.getReferencedLocation()));
return tag;
}
public static GlobalReference fromTag(CompoundTag nbt) {
public static GlobalReference fromTag(NbtCompound nbt) {
return new GlobalReference(Location.fromTag(nbt.getCompound("target")));
}
}

View file

@ -7,7 +7,7 @@ import org.dimdev.dimdoors.api.rift.target.EntityTarget;
import org.dimdev.dimdoors.api.util.EntityUtils;
import net.minecraft.entity.Entity;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.text.Text;
public class IdMarker extends VirtualTarget implements EntityTarget {
@ -22,13 +22,13 @@ public class IdMarker extends VirtualTarget implements EntityTarget {
return VirtualTargetType.ID_MARKER;
}
public static CompoundTag toTag(IdMarker target) {
CompoundTag tag = new CompoundTag();
public static NbtCompound toTag(IdMarker target) {
NbtCompound tag = new NbtCompound();
tag.putInt("id", target.id);
return tag;
}
public static IdMarker fromTag(CompoundTag nbt) {
public static IdMarker fromTag(NbtCompound nbt) {
return new IdMarker(nbt.getInt("id"));
}

View file

@ -2,8 +2,7 @@ package org.dimdev.dimdoors.rift.targets;
import com.mojang.serialization.Codec;
import org.dimdev.dimdoors.api.util.Location;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.util.math.BlockPos;
public class LocalReference extends RiftReference {
@ -29,13 +28,13 @@ public class LocalReference extends RiftReference {
return VirtualTargetType.LOCAL;
}
public static CompoundTag toTag(LocalReference localReference) {
CompoundTag tag = new CompoundTag();
public static NbtCompound toTag(LocalReference localReference) {
NbtCompound tag = new NbtCompound();
tag.putIntArray("target", new int[]{localReference.target.getX(), localReference.target.getY(), localReference.target.getZ()});
return tag;
}
public static LocalReference fromTag(CompoundTag tag) {
public static LocalReference fromTag(NbtCompound tag) {
int[] pos = tag.getIntArray("target");
return new LocalReference(
new BlockPos(pos[0], pos[1], pos[2])

View file

@ -8,7 +8,7 @@ import org.dimdev.dimdoors.api.rift.target.EntityTarget;
import org.dimdev.dimdoors.api.util.EntityUtils;
import net.minecraft.entity.Entity;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.text.TranslatableText;
public class PocketEntranceMarker extends VirtualTarget implements EntityTarget {
@ -61,15 +61,15 @@ public class PocketEntranceMarker extends VirtualTarget implements EntityTarget
return VirtualTargetType.POCKET_ENTRANCE;
}
public static CompoundTag toTag(PocketEntranceMarker target) {
CompoundTag tag = new CompoundTag();
public static NbtCompound toTag(PocketEntranceMarker target) {
NbtCompound tag = new NbtCompound();
tag.putFloat("weight", target.weight);
tag.put("ifDestination", VirtualTarget.toTag(target.ifDestination));
tag.put("otherwiseDestination", VirtualTarget.toTag(target.otherwiseDestination));
return tag;
}
public static PocketEntranceMarker fromTag(CompoundTag tag) {
public static PocketEntranceMarker fromTag(NbtCompound tag) {
return PocketEntranceMarker.builder()
.weight(tag.getFloat("weight"))
.ifDestination(tag.contains("ifDestination") ? VirtualTarget.fromTag(tag.getCompound("ifDestination")) : NoneTarget.INSTANCE)

View file

@ -1,13 +1,12 @@
package org.dimdev.dimdoors.rift.targets;
import org.dimdev.dimdoors.pockets.PocketGenerator;
import net.minecraft.nbt.NbtCompound;
import org.dimdev.dimdoors.api.util.Location;
import org.dimdev.dimdoors.world.level.registry.DimensionalRegistry;
import org.dimdev.dimdoors.world.pocket.type.Pocket;
import org.dimdev.dimdoors.world.pocket.VirtualLocation;
import net.minecraft.nbt.CompoundTag;
public class PublicPocketTarget extends RestoringTarget {
private VirtualTarget wrappedDestination = null;
@ -44,14 +43,14 @@ public class PublicPocketTarget extends RestoringTarget {
return VirtualTargetType.PUBLIC_POCKET;
}
public static CompoundTag toTag(PublicPocketTarget target) {
CompoundTag tag = new CompoundTag();
public static NbtCompound toTag(PublicPocketTarget target) {
NbtCompound tag = new NbtCompound();
if (target.wrappedDestination != null)
tag.put("wrappedDestination", VirtualTarget.toTag(target.wrappedDestination));
return tag;
}
public static PublicPocketTarget fromTag(CompoundTag tag) {
public static PublicPocketTarget fromTag(NbtCompound tag) {
PublicPocketTarget target = new PublicPocketTarget();
if (tag.contains("wrappedDestination"))
target.wrappedDestination = VirtualTarget.fromTag(tag.getCompound("wrappedDestination"));

View file

@ -21,8 +21,7 @@ import org.dimdev.dimdoors.api.util.math.MathUtil;
import org.dimdev.dimdoors.world.level.registry.DimensionalRegistry;
import org.dimdev.dimdoors.world.pocket.type.Pocket;
import org.dimdev.dimdoors.world.pocket.VirtualLocation;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.Heightmap;
@ -227,8 +226,8 @@ public class RandomTarget extends VirtualTarget { // TODO: Split into DungeonTar
return VirtualTargetType.AVAILABLE_LINK;
}
public static CompoundTag toTag(RandomTarget target) {
CompoundTag tag = new CompoundTag();
public static NbtCompound toTag(RandomTarget target) {
NbtCompound tag = new NbtCompound();
tag.putFloat("newRiftWeight", target.newRiftWeight);
tag.putDouble("weightMaximum", target.weightMaximum);
tag.putDouble("coordFactor", target.coordFactor);
@ -241,7 +240,7 @@ public class RandomTarget extends VirtualTarget { // TODO: Split into DungeonTar
return tag;
}
public static RandomTarget fromTag(CompoundTag tag) {
public static RandomTarget fromTag(NbtCompound tag) {
return new RandomTarget(
tag.getFloat("newRiftWeight"),
tag.getDouble("weightMaximum"),

View file

@ -1,8 +1,7 @@
package org.dimdev.dimdoors.rift.targets;
import org.dimdev.dimdoors.api.util.Location;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.util.math.Vec3i;
public class RelativeReference extends RiftReference {
@ -26,13 +25,13 @@ public class RelativeReference extends RiftReference {
return VirtualTargetType.RELATIVE;
}
public static CompoundTag toTag(RelativeReference target) {
CompoundTag tag = new CompoundTag();
public static NbtCompound toTag(RelativeReference target) {
NbtCompound tag = new NbtCompound();
tag.putIntArray("offset", new int[]{target.offset.getX(), target.offset.getY(), target.offset.getZ()});
return tag;
}
public static RelativeReference fromTag(CompoundTag tag) {
public static RelativeReference fromTag(NbtCompound tag) {
int[] offset = tag.getIntArray("offset");
return new RelativeReference(new Vec3i(offset[0], offset[1], offset[2]));
}

View file

@ -10,8 +10,7 @@ import org.dimdev.dimdoors.DimensionalDoorsInitializer;
import org.dimdev.dimdoors.api.rift.target.Target;
import org.dimdev.dimdoors.api.util.Location;
import org.dimdev.dimdoors.api.util.RGBA;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry;
import net.minecraft.util.registry.RegistryKey;
@ -29,16 +28,16 @@ public abstract class VirtualTarget implements Target {
protected Location location;
public static VirtualTarget fromTag(CompoundTag nbt) {
public static VirtualTarget fromTag(NbtCompound nbt) {
Identifier id = new Identifier(nbt.getString("type"));
return Objects.requireNonNull(REGISTRY.get(id), "Unknown virtual target type " + id.toString()).fromTag(nbt);
}
public static CompoundTag toTag(VirtualTarget virtualTarget) {
public static NbtCompound toTag(VirtualTarget virtualTarget) {
Identifier id = REGISTRY.getId(virtualTarget.getType());
String type = id.toString();
CompoundTag tag = virtualTarget.getType().toTag(virtualTarget);
NbtCompound tag = virtualTarget.getType().toTag(virtualTarget);
tag.putString("type", type);
return tag;
@ -89,22 +88,22 @@ public abstract class VirtualTarget implements Target {
VirtualTargetType<RandomTarget> AVAILABLE_LINK = register("dimdoors:available_link", RandomTarget::fromTag, RandomTarget::toTag, VirtualTarget.COLOR);
VirtualTargetType<EscapeTarget> ESCAPE = register("dimdoors:escape", EscapeTarget::fromTag, EscapeTarget::toTag, VirtualTarget.COLOR);
VirtualTargetType<GlobalReference> GLOBAL = register("dimdoors:global", GlobalReference::fromTag, GlobalReference::toTag, VirtualTarget.COLOR);
VirtualTargetType<LimboTarget> LIMBO = register("dimdoors:limbo", a -> LimboTarget.INSTANCE, a -> new CompoundTag(), VirtualTarget.COLOR);
VirtualTargetType<LimboTarget> LIMBO = register("dimdoors:limbo", a -> LimboTarget.INSTANCE, a -> new NbtCompound(), VirtualTarget.COLOR);
VirtualTargetType<LocalReference> LOCAL = register("dimdoors:local", LocalReference::fromTag, LocalReference::toTag, VirtualTarget.COLOR);
VirtualTargetType<PublicPocketTarget> PUBLIC_POCKET = register("dimdoors:public_pocket", PublicPocketTarget::fromTag, PublicPocketTarget::toTag, VirtualTarget.COLOR);
VirtualTargetType<PocketEntranceMarker> POCKET_ENTRANCE = register("dimdoors:pocket_entrance", PocketEntranceMarker::fromTag, PocketEntranceMarker::toTag, VirtualTarget.COLOR);
VirtualTargetType<PocketExitMarker> POCKET_EXIT = register("dimdoors:pocket_exit", a -> new PocketExitMarker(), a -> new CompoundTag(), VirtualTarget.COLOR);
VirtualTargetType<PrivatePocketTarget> PRIVATE = register("dimdoors:private", a -> new PrivatePocketTarget(), a -> new CompoundTag(), PrivatePocketExitTarget.COLOR);
VirtualTargetType<PrivatePocketExitTarget> PRIVATE_POCKET_EXIT = register("dimdoors:private_pocket_exit", a -> new PrivatePocketExitTarget(), a -> new CompoundTag(), PrivatePocketExitTarget.COLOR);
VirtualTargetType<PocketExitMarker> POCKET_EXIT = register("dimdoors:pocket_exit", a -> new PocketExitMarker(), a -> new NbtCompound(), VirtualTarget.COLOR);
VirtualTargetType<PrivatePocketTarget> PRIVATE = register("dimdoors:private", a -> new PrivatePocketTarget(), a -> new NbtCompound(), PrivatePocketExitTarget.COLOR);
VirtualTargetType<PrivatePocketExitTarget> PRIVATE_POCKET_EXIT = register("dimdoors:private_pocket_exit", a -> new PrivatePocketExitTarget(), a -> new NbtCompound(), PrivatePocketExitTarget.COLOR);
VirtualTargetType<RelativeReference> RELATIVE = register("dimdoors:relative", RelativeReference::fromTag, RelativeReference::toTag, VirtualTarget.COLOR);
VirtualTargetType<IdMarker> ID_MARKER = register("dimdoors:id_marker", IdMarker::fromTag, IdMarker::toTag, VirtualTarget.COLOR);
VirtualTargetType<UnstableTarget> UNSTABLE = register("dimdoors:unstable", tag -> new UnstableTarget(), t -> new CompoundTag(), VirtualTarget.COLOR);
VirtualTargetType<NoneTarget> NONE = register("dimdoors:none", tag -> NoneTarget.INSTANCE, i -> new CompoundTag(), COLOR);
VirtualTargetType<UnstableTarget> UNSTABLE = register("dimdoors:unstable", tag -> new UnstableTarget(), t -> new NbtCompound(), VirtualTarget.COLOR);
VirtualTargetType<NoneTarget> NONE = register("dimdoors:none", tag -> NoneTarget.INSTANCE, i -> new NbtCompound(), COLOR);
Map<VirtualTargetType<?>, String> TRANSLATION_KEYS = new Object2ObjectArrayMap<>();
T fromTag(CompoundTag tag);
T fromTag(NbtCompound tag);
CompoundTag toTag(VirtualTarget virtualType);
NbtCompound toTag(VirtualTarget virtualType);
RGBA getColor();
@ -124,15 +123,15 @@ public abstract class VirtualTarget implements Target {
}
@SuppressWarnings("unchecked")
static <T extends VirtualTarget> VirtualTargetType<T> register(String id, Function<CompoundTag, T> fromTag, Function<T, CompoundTag> toTag, RGBA color) {
static <T extends VirtualTarget> VirtualTargetType<T> register(String id, Function<NbtCompound, T> fromTag, Function<T, NbtCompound> toTag, RGBA color) {
return Registry.register(REGISTRY, (String) id, new VirtualTargetType<T>() {
@Override
public T fromTag(CompoundTag tag) {
public T fromTag(NbtCompound tag) {
return fromTag.apply(tag);
}
@Override
public CompoundTag toTag(VirtualTarget virtualType) {
public NbtCompound toTag(VirtualTarget virtualType) {
return toTag.apply((T) virtualType);
}

View file

@ -15,10 +15,10 @@ import net.minecraft.world.dimension.DimensionType;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
public final class ModDimensions {
public static final RegistryKey<World> LIMBO = RegistryKey.of(Registry.DIMENSION, new Identifier("dimdoors:limbo"));
public static final RegistryKey<World> PERSONAL = RegistryKey.of(Registry.DIMENSION, new Identifier("dimdoors:personal_pockets"));
public static final RegistryKey<World> PUBLIC = RegistryKey.of(Registry.DIMENSION, new Identifier("dimdoors:public_pockets"));
public static final RegistryKey<World> DUNGEON = RegistryKey.of(Registry.DIMENSION, new Identifier("dimdoors:dungeon_pockets"));
public static final RegistryKey<World> LIMBO = RegistryKey.of(Registry.WORLD_KEY, new Identifier("dimdoors:limbo"));
public static final RegistryKey<World> PERSONAL = RegistryKey.of(Registry.WORLD_KEY, new Identifier("dimdoors:personal_pockets"));
public static final RegistryKey<World> PUBLIC = RegistryKey.of(Registry.WORLD_KEY, new Identifier("dimdoors:public_pockets"));
public static final RegistryKey<World> DUNGEON = RegistryKey.of(Registry.WORLD_KEY, new Identifier("dimdoors:dungeon_pockets"));
public static final RegistryKey<DimensionType> LIMBO_TYPE_KEY = RegistryKey.of(Registry.DIMENSION_TYPE_KEY, new Identifier("dimdoors:limbo"));
public static final RegistryKey<DimensionType> POCKET_TYPE_KEY = RegistryKey.of(Registry.DIMENSION_TYPE_KEY, new Identifier("dimdoors:personal_pockets"));

View file

@ -10,8 +10,6 @@ import org.dimdev.dimdoors.mixin.accessor.GenerationSettingsAccessor;
import org.dimdev.dimdoors.world.feature.decorator.EternalFluidLakeDecorator;
import org.dimdev.dimdoors.world.feature.gateway.LimboGatewayFeature;
import org.dimdev.dimdoors.world.feature.gateway.schematic.*;
import org.dimdev.dimdoors.world.feature.gateway.schematic.SchematicGateway;
import net.minecraft.structure.rule.BlockMatchRuleTest;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.BuiltinRegistries;

View file

@ -4,7 +4,7 @@ import dev.onyxstudios.cca.api.v3.component.Component;
import org.dimdev.dimdoors.world.level.DimensionalDoorsComponents;
import net.fabricmc.fabric.api.util.NbtType;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.world.chunk.Chunk;
public class ChunkLazilyGeneratedComponent implements Component {
@ -24,14 +24,14 @@ public class ChunkLazilyGeneratedComponent implements Component {
}
@Override
public void readFromNbt(CompoundTag tag) {
public void readFromNbt(NbtCompound tag) {
if (tag.contains("has_been_lazy_genned", NbtType.INT)) {
hasBeenLazyGenned = tag.getInt("has_been_lazy_genned") == 1;
}
}
@Override
public void writeToNbt(CompoundTag tag) {
public void writeToNbt(NbtCompound tag) {
if (hasBeenLazyGenned) {
tag.putInt("has_been_lazy_genned", 1);
}

View file

@ -6,9 +6,8 @@ import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.Tag;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.nbt.NbtElement;
import net.minecraft.util.Identifier;
import net.minecraft.util.Pair;
import net.minecraft.util.registry.Registry;
@ -32,7 +31,7 @@ public class DimensionalRegistry implements ComponentV3 {
private PrivateRegistry privateRegistry = new PrivateRegistry();
@Override
public void readFromNbt(CompoundTag tag) {
public void readFromNbt(NbtCompound tag) {
int riftDataVersion = tag.getInt("RiftDataVersion");
if (riftDataVersion < RIFT_DATA_VERSION) {
tag = RiftSchemas.update(riftDataVersion, tag);
@ -40,13 +39,13 @@ public class DimensionalRegistry implements ComponentV3 {
throw new UnsupportedOperationException("Downgrading is not supported!");
}
CompoundTag pocketRegistryTag = tag.getCompound("pocket_registry");
NbtCompound pocketRegistryTag = tag.getCompound("pocket_registry");
CompletableFuture<Map<RegistryKey<World>, PocketDirectory>> futurePocketRegistry = CompletableFuture.supplyAsync(() -> pocketRegistryTag.getKeys().stream().map(key -> {
CompoundTag pocketDirectoryTag = pocketRegistryTag.getCompound(key);
return CompletableFuture.supplyAsync(() -> new Pair<>(RegistryKey.of(Registry.DIMENSION, Identifier.tryParse(key)), PocketDirectory.readFromNbt(key, pocketDirectoryTag)));
NbtCompound pocketDirectoryTag = pocketRegistryTag.getCompound(key);
return CompletableFuture.supplyAsync(() -> new Pair<>(RegistryKey.of(Registry.WORLD_KEY, Identifier.tryParse(key)), PocketDirectory.readFromNbt(key, pocketDirectoryTag)));
}).parallel().map(CompletableFuture::join).collect(Collectors.toConcurrentMap(Pair::getLeft, Pair::getRight)));
CompoundTag privateRegistryTag = tag.getCompound("private_registry");
NbtCompound privateRegistryTag = tag.getCompound("private_registry");
CompletableFuture<PrivateRegistry> futurePrivateRegistry = CompletableFuture.supplyAsync(() -> {
PrivateRegistry privateRegistry = new PrivateRegistry();
privateRegistry.fromTag(privateRegistryTag);
@ -55,7 +54,7 @@ public class DimensionalRegistry implements ComponentV3 {
pocketRegistry = futurePocketRegistry.join();
CompoundTag riftRegistryTag = tag.getCompound("rift_registry");
NbtCompound riftRegistryTag = tag.getCompound("rift_registry");
CompletableFuture<RiftRegistry> futureRiftRegistry = CompletableFuture.supplyAsync(() -> RiftRegistry.fromTag(pocketRegistry, riftRegistryTag));
riftRegistry = futureRiftRegistry.join();
@ -63,17 +62,17 @@ public class DimensionalRegistry implements ComponentV3 {
}
@Override
public void writeToNbt(CompoundTag tag) {
CompletableFuture<Tag> futurePocketRegistryTag = CompletableFuture.supplyAsync(() -> {
List<CompletableFuture<Pair<String, Tag>>> futurePocketRegistryTags = new ArrayList<>();
public void writeToNbt(NbtCompound tag) {
CompletableFuture<NbtElement> futurePocketRegistryTag = CompletableFuture.supplyAsync(() -> {
List<CompletableFuture<Pair<String, NbtElement>>> futurePocketRegistryTags = new ArrayList<>();
pocketRegistry.forEach((key, value) -> futurePocketRegistryTags.add(CompletableFuture.supplyAsync(() -> new Pair<>(key.getValue().toString(), value.writeToNbt()))));
CompoundTag pocketRegistryTag = new CompoundTag();
NbtCompound pocketRegistryTag = new NbtCompound();
futurePocketRegistryTags.parallelStream().unordered().map(CompletableFuture::join).collect(Collectors.toConcurrentMap(Pair::getLeft, Pair::getRight)).forEach(pocketRegistryTag::put);
return pocketRegistryTag;
});
CompletableFuture<Tag> futureRiftRegistryTag = CompletableFuture.supplyAsync(riftRegistry::toTag);
CompletableFuture<Tag> futurePrivateRegistryTag = CompletableFuture.supplyAsync(() -> privateRegistry.toTag(new CompoundTag()));
CompletableFuture<NbtElement> futureRiftRegistryTag = CompletableFuture.supplyAsync(riftRegistry::toTag);
CompletableFuture<NbtElement> futurePrivateRegistryTag = CompletableFuture.supplyAsync(() -> privateRegistry.toTag(new NbtCompound()));
tag.put("pocket_registry", futurePocketRegistryTag.join());
tag.put("rift_registry", futureRiftRegistryTag.join());

View file

@ -8,8 +8,7 @@ import com.mojang.datafixers.DataFixerBuilder;
import com.mojang.datafixers.schemas.Schema;
import com.mojang.serialization.Dynamic;
import org.dimdev.dimdoors.world.level.registry.schema.Schema1;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.nbt.NbtOps;
import net.minecraft.util.Util;
@ -22,7 +21,7 @@ public class RiftSchemas {
// TODO: add schemas if schema changes
}).build(Runnable::run);
public static CompoundTag update(int oldVersion, CompoundTag original) {
return (CompoundTag) DATA_FIXER.update(RIFT_DATA_TYPE_REF, new Dynamic<>( NbtOps.INSTANCE, original), oldVersion, RIFT_DATA_VERSION).getValue();
public static NbtCompound update(int oldVersion, NbtCompound original) {
return (NbtCompound) DATA_FIXER.update(RIFT_DATA_TYPE_REF, new Dynamic<>( NbtOps.INSTANCE, original), oldVersion, RIFT_DATA_VERSION).getValue();
}
}

View file

@ -11,8 +11,7 @@ import net.minecraft.util.Pair;
import net.minecraft.util.math.Vec3i;
import org.dimdev.dimdoors.DimensionalDoorsInitializer;
import org.dimdev.dimdoors.api.util.math.GridUtil;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.registry.Registry;
@ -46,37 +45,37 @@ public class PocketDirectory {
this.pockets = new HashMap<>();
}
public static PocketDirectory readFromNbt(String id, CompoundTag tag) {
PocketDirectory directory = new PocketDirectory(RegistryKey.of(Registry.DIMENSION, new Identifier(id)));
public static PocketDirectory readFromNbt(String id, NbtCompound tag) {
PocketDirectory directory = new PocketDirectory(RegistryKey.of(Registry.WORLD_KEY, new Identifier(id)));
// no need to parallelize
directory.gridSize = tag.getInt("grid_size");
directory.privatePocketSize = tag.getInt("private_pocket_size");
directory.publicPocketSize = tag.getInt("public_pocket_size");
// same thing, too short anyways
CompoundTag nextIdMapTag = tag.getCompound("next_id_map");
NbtCompound nextIdMapTag = tag.getCompound("next_id_map");
directory.nextIDMap.putAll(nextIdMapTag.getKeys().stream().collect(Collectors.toMap(Integer::parseInt, nextIdMapTag::getInt)));
CompoundTag pocketsTag = tag.getCompound("pockets");
NbtCompound pocketsTag = tag.getCompound("pockets");
directory.pockets = pocketsTag.getKeys().stream().unordered().map(key -> {
CompoundTag pocketTag = pocketsTag.getCompound(key);
NbtCompound pocketTag = pocketsTag.getCompound(key);
return CompletableFuture.supplyAsync(() -> new Pair<>(Integer.parseInt(key), AbstractPocket.deserialize(pocketTag)));
}).parallel().map(CompletableFuture::join).collect(Collectors.toConcurrentMap(Pair::getLeft, Pair::getRight));
return directory;
}
public CompoundTag writeToNbt() {
CompoundTag tag = new CompoundTag();
public NbtCompound writeToNbt() {
NbtCompound tag = new NbtCompound();
tag.putInt("grid_size", this.gridSize);
tag.putInt("private_pocket_size", this.privatePocketSize);
tag.putInt("public_pocket_size", this.publicPocketSize);
CompoundTag nextIdMapTag = new CompoundTag();
NbtCompound nextIdMapTag = new NbtCompound();
this.nextIDMap.forEach((key, value) -> nextIdMapTag.putInt(key.toString(), value));
tag.put("next_id_map", nextIdMapTag);
CompoundTag pocketsTag = new CompoundTag();
this.pockets.entrySet().parallelStream().unordered().map(entry -> CompletableFuture.supplyAsync(() -> new Pair<>(entry.getKey().toString(), entry.getValue().toTag(new CompoundTag()))))
NbtCompound pocketsTag = new NbtCompound();
this.pockets.entrySet().parallelStream().unordered().map(entry -> CompletableFuture.supplyAsync(() -> new Pair<>(entry.getKey().toString(), entry.getValue().toTag(new NbtCompound()))))
.map(CompletableFuture::join).forEach(pair -> pocketsTag.put(pair.getLeft(), pair.getRight()));
tag.put("pockets", pocketsTag);

View file

@ -7,12 +7,10 @@ import java.util.stream.Collectors;
import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
import net.minecraft.nbt.Tag;
import net.minecraft.util.Pair;
import org.dimdev.dimdoors.world.level.registry.DimensionalRegistry;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.nbt.NbtElement;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry;
import net.minecraft.util.registry.RegistryKey;
@ -30,16 +28,16 @@ public class PrivateRegistry {
this.id = id;
}
public static CompoundTag toTag(PocketInfo info) {
CompoundTag tag = new CompoundTag();
public static NbtCompound toTag(PocketInfo info) {
NbtCompound tag = new NbtCompound();
tag.putString("world", info.world.getValue().toString());
tag.putInt("id", info.id);
return tag;
}
public static PocketInfo fromTag(CompoundTag tag) {
public static PocketInfo fromTag(NbtCompound tag) {
return new PocketInfo(
RegistryKey.of(Registry.DIMENSION, new Identifier(tag.getString("world"))),
RegistryKey.of(Registry.WORLD_KEY, new Identifier(tag.getString("world"))),
tag.getInt("id")
);
}
@ -52,22 +50,22 @@ public class PrivateRegistry {
public PrivateRegistry() {
}
public void fromTag(CompoundTag tag) {
public void fromTag(NbtCompound tag) {
privatePocketMap.clear();
CompoundTag privatePocketMapTag = tag.getCompound("private_pocket_map");
NbtCompound privatePocketMapTag = tag.getCompound("private_pocket_map");
CompletableFuture<Map<UUID, PocketInfo>> futurePrivatePocketMap = CompletableFuture.supplyAsync(() ->
privatePocketMapTag.getKeys().stream().unordered().map(key -> {
CompoundTag pocketInfoTag = privatePocketMapTag.getCompound(key);
NbtCompound pocketInfoTag = privatePocketMapTag.getCompound(key);
return CompletableFuture.supplyAsync(() -> new Pair<>(UUID.fromString(key), PocketInfo.fromTag(pocketInfoTag)));
}).parallel().map(CompletableFuture::join).collect(Collectors.toConcurrentMap(Pair::getLeft, Pair::getRight)));
futurePrivatePocketMap.join().forEach(this.privatePocketMap::put);
}
public CompoundTag toTag(CompoundTag tag) {
CompletableFuture<CompoundTag> futurePrivatePocketMapTag = CompletableFuture.supplyAsync(() -> {
Map<String, Tag> privatePocketTagMap = this.privatePocketMap.entrySet().parallelStream().unordered().collect(Collectors.toConcurrentMap(entry -> entry.getKey().toString(), entry -> PocketInfo.toTag(entry.getValue())));
CompoundTag privatePocketMapTag = new CompoundTag();
public NbtCompound toTag(NbtCompound tag) {
CompletableFuture<NbtCompound> futurePrivatePocketMapTag = CompletableFuture.supplyAsync(() -> {
Map<String, NbtElement> privatePocketTagMap = this.privatePocketMap.entrySet().parallelStream().unordered().collect(Collectors.toConcurrentMap(entry -> entry.getKey().toString(), entry -> PocketInfo.toTag(entry.getValue())));
NbtCompound privatePocketMapTag = new NbtCompound();
privatePocketTagMap.forEach(privatePocketMapTag::put);
return privatePocketMapTag;
});

View file

@ -7,8 +7,7 @@ import org.dimdev.dimdoors.DimensionalDoorsInitializer;
import org.dimdev.dimdoors.world.level.registry.DimensionalRegistry;
import org.dimdev.dimdoors.api.util.Location;
import org.dimdev.dimdoors.world.ModDimensions;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
@ -42,8 +41,8 @@ public class VirtualLocation {
this.depth = depth;
}
public static CompoundTag toTag(VirtualLocation virtualLocation) {
CompoundTag tag = new CompoundTag();
public static NbtCompound toTag(VirtualLocation virtualLocation) {
NbtCompound tag = new NbtCompound();
tag.putString("world", virtualLocation.world.getValue().toString());
tag.putInt("x", virtualLocation.x);
tag.putInt("z", virtualLocation.z);
@ -51,9 +50,9 @@ public class VirtualLocation {
return tag;
}
public static VirtualLocation fromTag(CompoundTag tag) {
public static VirtualLocation fromTag(NbtCompound tag) {
return new VirtualLocation(
RegistryKey.of(Registry.DIMENSION, new Identifier(tag.getString("world"))),
RegistryKey.of(Registry.WORLD_KEY, new Identifier(tag.getString("world"))),
tag.getInt("x"),
tag.getInt("z"),
tag.getInt("depth")

View file

@ -4,7 +4,7 @@ import com.mojang.serialization.Lifecycle;
import org.dimdev.dimdoors.DimensionalDoorsInitializer;
import net.fabricmc.fabric.api.event.registry.FabricRegistryBuilder;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.Vec3i;
import net.minecraft.util.registry.Registry;
@ -34,28 +34,28 @@ public abstract class AbstractPocket<V extends AbstractPocket<?>> {
return id;
}
public static AbstractPocket<? extends AbstractPocket<?>> deserialize(CompoundTag tag) {
public static AbstractPocket<? extends AbstractPocket<?>> deserialize(NbtCompound tag) {
Identifier id = Identifier.tryParse(tag.getString("type"));
return REGISTRY.get(id).fromTag(tag);
}
public static AbstractPocketBuilder<?, ?> deserializeBuilder(CompoundTag tag) {
public static AbstractPocketBuilder<?, ?> deserializeBuilder(NbtCompound tag) {
Identifier id = Identifier.tryParse(tag.getString("type"));
return REGISTRY.get(id).builder().fromTag(tag);
}
public static CompoundTag serialize(AbstractPocket<?> pocket) {
return pocket.toTag(new CompoundTag());
public static NbtCompound serialize(AbstractPocket<?> pocket) {
return pocket.toTag(new NbtCompound());
}
public V fromTag(CompoundTag tag) {
public V fromTag(NbtCompound tag) {
this.id = tag.getInt("id");
this.world = RegistryKey.of(Registry.DIMENSION, new Identifier(tag.getString("world")));
this.world = RegistryKey.of(Registry.WORLD_KEY, new Identifier(tag.getString("world")));
return (V) this;
}
public CompoundTag toTag(CompoundTag tag) {
public NbtCompound toTag(NbtCompound tag) {
tag.putInt("id", id);
tag.putString("world", world.getValue().toString());
@ -90,9 +90,9 @@ public abstract class AbstractPocket<V extends AbstractPocket<?>> {
AbstractPocketType<LazyGenerationPocket> LAZY_GENERATION_POCKET = register(new Identifier("dimdoors", LazyGenerationPocket.KEY), LazyGenerationPocket::new, LazyGenerationPocket::builderLazyGenerationPocket);
T fromTag(CompoundTag tag);
T fromTag(NbtCompound tag);
CompoundTag toTag(CompoundTag tag);
NbtCompound toTag(NbtCompound tag);
T instance();
@ -105,12 +105,12 @@ public abstract class AbstractPocket<V extends AbstractPocket<?>> {
static <U extends AbstractPocket<P>, P extends AbstractPocket<P>> AbstractPocketType<U> register(Identifier id, Supplier<U> supplier, Supplier<? extends AbstractPocketBuilder<?, U>> factorySupplier) {
return Registry.register(REGISTRY, id, new AbstractPocketType<U>() {
@Override
public U fromTag(CompoundTag tag) {
public U fromTag(NbtCompound tag) {
return (U) supplier.get().fromTag(tag);
}
@Override
public CompoundTag toTag(CompoundTag tag) {
public NbtCompound toTag(NbtCompound tag) {
tag.putString("type", id.toString());
return tag;
}
@ -165,9 +165,9 @@ public abstract class AbstractPocket<V extends AbstractPocket<?>> {
return (P) this;
}
abstract public P fromTag(CompoundTag tag);
abstract public P fromTag(NbtCompound tag);
abstract public CompoundTag toTag(CompoundTag tag);
abstract public NbtCompound toTag(NbtCompound tag);
/*
public P fromTag(CompoundTag tag) {

View file

@ -1,7 +1,7 @@
package org.dimdev.dimdoors.world.pocket.type;
import net.fabricmc.fabric.api.util.NbtType;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtCompound;
import org.dimdev.dimdoors.world.level.registry.DimensionalRegistry;
import org.dimdev.dimdoors.world.pocket.PocketDirectory;
@ -11,7 +11,7 @@ public class IdReferencePocket extends AbstractPocket<IdReferencePocket> {
protected int referencedId;
@Override
public IdReferencePocket fromTag(CompoundTag tag) {
public IdReferencePocket fromTag(NbtCompound tag) {
super.fromTag(tag);
this.referencedId = tag.getInt("referenced_id");
@ -20,7 +20,7 @@ public class IdReferencePocket extends AbstractPocket<IdReferencePocket> {
}
@Override
public CompoundTag toTag(CompoundTag tag) {
public NbtCompound toTag(NbtCompound tag) {
tag = super.toTag(tag);
tag.putInt("referenced_id", referencedId);
@ -62,13 +62,13 @@ public class IdReferencePocket extends AbstractPocket<IdReferencePocket> {
}
@Override
public IdReferencePocketBuilder fromTag(CompoundTag tag) {
public IdReferencePocketBuilder fromTag(NbtCompound tag) {
if (tag.contains("referenced_id", NbtType.INT)) referencedId = tag.getInt("referenced_id");
return this;
}
@Override
public CompoundTag toTag(CompoundTag tag) {
public NbtCompound toTag(NbtCompound tag) {
if (referencedId != Integer.MIN_VALUE) tag.putInt("referenced_id", referencedId);
return tag;
}

View file

@ -2,11 +2,12 @@ package org.dimdev.dimdoors.world.pocket.type;
import net.fabricmc.fabric.api.util.NbtType;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.util.math.BlockBox;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.ChunkPos;
import net.minecraft.world.chunk.Chunk;
import org.dimdev.dimdoors.api.util.BlockBoxUtil;
import org.dimdev.dimdoors.pockets.generator.LazyPocketGenerator;
import org.dimdev.dimdoors.pockets.generator.PocketGenerator;
import org.dimdev.dimdoors.world.level.component.ChunkLazilyGeneratedComponent;
@ -25,8 +26,7 @@ public class LazyGenerationPocket extends Pocket {
ChunkLazilyGeneratedComponent lazyGenned = ChunkLazilyGeneratedComponent.get(chunk);
if (lazyGenned.hasBeenLazyGenned()) return;
ChunkPos pos = chunk.getPos();
BlockBox chunkBox = BlockBox.create(pos.getStartX(), chunk.getBottomY(), pos.getStartZ(), pos.getEndX(), chunk.getTopY(), pos.getEndZ());
BlockBox chunkBox = BlockBoxUtil.getBox(chunk);
if (!chunkBox.intersects(getBox())) return;
generator.generateChunk(this, chunk);
@ -49,14 +49,14 @@ public class LazyGenerationPocket extends Pocket {
public void init() {
BlockBox box = getBox();
toBeGennedChunkCount = (Math.floorDiv(box.maxX, 16) - Math.floorDiv(box.minX, 16) + 1) * (Math.floorDiv(box.maxZ, 16) - Math.floorDiv(box.minZ, 16) + 1);
toBeGennedChunkCount = (Math.floorDiv(box.getMaxX(), 16) - Math.floorDiv(box.getMinX(), 16) + 1) * (Math.floorDiv(box.getMaxZ(), 16) - Math.floorDiv(box.getMinZ(), 16) + 1);
}
@Override
public CompoundTag toTag(CompoundTag tag) {
public NbtCompound toTag(NbtCompound tag) {
super.toTag(tag);
if (generator != null) tag.put("generator", generator.toTag(new CompoundTag()));
if (generator != null) tag.put("generator", generator.toTag(new NbtCompound()));
if (toBeGennedChunkCount > 0) tag.putInt("to_be_genned_chunks", toBeGennedChunkCount);
return tag;
@ -72,7 +72,7 @@ public class LazyGenerationPocket extends Pocket {
}
@Override
public Pocket fromTag(CompoundTag tag) {
public Pocket fromTag(NbtCompound tag) {
super.fromTag(tag);
if (tag.contains("generator", NbtType.COMPOUND)) generator = (LazyPocketGenerator) PocketGenerator.deserialize(tag.getCompound("generator"));

View file

@ -7,14 +7,14 @@ import java.util.stream.Collectors;
import java.util.stream.IntStream;
import net.fabricmc.fabric.api.util.NbtType;
import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.Tag;
import net.minecraft.util.Identifier;
import org.dimdev.dimdoors.DimensionalDoorsInitializer;
import org.dimdev.dimdoors.world.level.registry.DimensionalRegistry;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.nbt.NbtElement;
import net.minecraft.nbt.NbtList;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.math.BlockBox;
import net.minecraft.util.math.BlockPos;
@ -37,7 +37,7 @@ public class Pocket extends AbstractPocket<Pocket> implements AddonProvider {
public Pocket(int id, RegistryKey<World> world, int x, int z) {
super(id, world);
int gridSize = DimensionalRegistry.getPocketDirectory(world).getGridSize() * 16;
this.box = BlockBox.create(x * gridSize, 0, z * gridSize, (x + 1) * gridSize, 0, (z + 1) * gridSize);
this.box = BlockBox.create(new Vec3i(x * gridSize, 0, z * gridSize), new Vec3i((x + 1) * gridSize, 0, (z + 1) * gridSize));
this.virtualLocation = new VirtualLocation(world, x, z, 0);
}
@ -72,15 +72,15 @@ public class Pocket extends AbstractPocket<Pocket> implements AddonProvider {
}
public BlockPos getOrigin() {
return new BlockPos(this.box.minX, this.box.minY, this.box.minZ);
return new BlockPos(this.box.getMinX(), this.box.getMinY(), this.box.getMinZ());
}
public void offsetOrigin(Vec3i vec) {
offsetOrigin(vec.getX(), vec.getY(), vec.getZ());
this.box.move(vec);
}
public void offsetOrigin(int x, int y, int z) {
this.box = box.offset(x, y, z);
this.box.move(x, y, z);
}
public void setSize(Vec3i size) {
@ -88,7 +88,7 @@ public class Pocket extends AbstractPocket<Pocket> implements AddonProvider {
}
public void setSize(int x, int y, int z) {
this.box = BlockBox.create(this.box.minX, this.box.minY, this.box.minZ, this.box.minX + x - 1, this.box.minY + y - 1, this.box.minZ + z - 1);
this.box = BlockBox.create(new Vec3i(this.box.getMinX(), this.box.getMinY(), this.box.getMinZ()), new Vec3i(this.box.getMinX() + x - 1, this.box.getMinY() + y - 1, this.box.getMinZ() + z - 1));
}
public void setRange(int range) {
@ -105,15 +105,15 @@ public class Pocket extends AbstractPocket<Pocket> implements AddonProvider {
return this.box.getDimensions();
}
public CompoundTag toTag(CompoundTag tag) {
public NbtCompound toTag(NbtCompound tag) {
super.toTag(tag);
tag.putInt("range", range);
tag.putIntArray("box", IntStream.of(this.box.minX, this.box.minY, this.box.minZ, this.box.maxX, this.box.maxY, this.box.maxZ).toArray());
tag.putIntArray("box", IntStream.of(this.box.getMinX(), this.box.getMinY(), this.box.getMinZ(), this.box.getMaxX(), this.box.getMaxY(), this.box.getMaxZ()).toArray());
tag.put("virtualLocation", VirtualLocation.toTag(this.virtualLocation));
ListTag addonsTag = new ListTag();
addonsTag.addAll(addons.values().stream().map(addon -> addon.toTag(new CompoundTag())).collect(Collectors.toList()));
NbtList addonsTag = new NbtList();
addonsTag.addAll(addons.values().stream().map(addon -> addon.toTag(new NbtCompound())).collect(Collectors.toList()));
if (addonsTag.size() > 0) tag.put("addons", addonsTag);
return tag;
@ -124,17 +124,17 @@ public class Pocket extends AbstractPocket<Pocket> implements AddonProvider {
return AbstractPocketType.POCKET;
}
public Pocket fromTag(CompoundTag tag) {
public Pocket fromTag(NbtCompound tag) {
super.fromTag(tag);
this.range = tag.getInt("range");
int[] box = tag.getIntArray("box");
this.box = BlockBox.create(box[0], box[1], box[2], box[3], box[4], box[5]);
this.box = BlockBox.create(new Vec3i(box[0], box[1], box[2]), new Vec3i(box[3], box[4], box[5]));
this.virtualLocation = VirtualLocation.fromTag(tag.getCompound("virtualLocation"));
if (tag.contains("addons", NbtType.LIST)) {
for (Tag addonTag : tag.getList("addons", NbtType.COMPOUND)) {
PocketAddon addon = PocketAddon.deserialize((CompoundTag) addonTag);
for (NbtElement addonTag : tag.getList("addons", NbtType.COMPOUND)) {
PocketAddon addon = PocketAddon.deserialize((NbtCompound) addonTag);
addons.put(addon.getId(), addon);
}
}
@ -145,7 +145,7 @@ public class Pocket extends AbstractPocket<Pocket> implements AddonProvider {
public Map<BlockPos, BlockEntity> getBlockEntities() {
ServerWorld serverWorld = DimensionalDoorsInitializer.getWorld(this.getWorld());
Map<BlockPos, BlockEntity> blockEntities = new HashMap<>();
ChunkPos.stream(new ChunkPos(new BlockPos(box.minX, box.minY, box.minZ)), new ChunkPos(new BlockPos(box.maxX, box.maxY, box.maxZ))).forEach(chunkPos -> serverWorld.getChunk(chunkPos.x, chunkPos.z).getBlockEntities().forEach((blockPos, blockEntity) -> {
ChunkPos.stream(new ChunkPos(new BlockPos(box.getMinX(), box.getMinY(), box.getMinZ())), new ChunkPos(new BlockPos(box.getMaxX(), box.getMaxY(), box.getMaxZ()))).forEach(chunkPos -> serverWorld.getChunk(chunkPos.x, chunkPos.z).getBlockEntities().forEach((blockPos, blockEntity) -> {
if (this.box.contains(blockPos)) blockEntities.put(blockPos, blockEntity);
}));
return blockEntities;
@ -157,9 +157,9 @@ public class Pocket extends AbstractPocket<Pocket> implements AddonProvider {
public Map<String, Double> toVariableMap(Map<String, Double> variableMap) {
variableMap = super.toVariableMap(variableMap);
variableMap.put("originX", (double) this.box.minX);
variableMap.put("originY", (double) this.box.minY);
variableMap.put("originZ", (double) this.box.minZ);
variableMap.put("originX", (double) this.box.getMinX());
variableMap.put("originY", (double) this.box.getMinY());
variableMap.put("originZ", (double) this.box.getMinZ());
variableMap.put("width", (double) this.box.getDimensions().getX());
variableMap.put("height", (double) this.box.getDimensions().getY());
variableMap.put("length", (double) this.box.getDimensions().getZ());
@ -173,8 +173,7 @@ public class Pocket extends AbstractPocket<Pocket> implements AddonProvider {
}
public void expand(int amount) {
if (amount == 0) return;
this.box = BlockBox.create(box.minX - amount, box.minY - amount, box.minZ - amount, box.maxX + amount, box.maxY + amount, box.maxZ + amount);
this.box.expand(amount);
}
public static PocketBuilder<?, Pocket> builder() {
@ -205,10 +204,10 @@ public class Pocket extends AbstractPocket<Pocket> implements AddonProvider {
}
// TODO: actually utilize fromTag/ toTag methods + implement them
public P fromTag(CompoundTag tag) {
public P fromTag(NbtCompound tag) {
if (tag.contains("addons", NbtType.LIST)) {
for (Tag addonTag : tag.getList("addons", NbtType.COMPOUND)) {
PocketAddon.PocketBuilderAddon<?> addon = PocketAddon.deserializeBuilder((CompoundTag) addonTag);
for (NbtElement addonTag : tag.getList("addons", NbtType.COMPOUND)) {
PocketAddon.PocketBuilderAddon<?> addon = PocketAddon.deserializeBuilder((NbtCompound) addonTag);
addons.put(addon.getId(), addon);
}
}
@ -216,9 +215,9 @@ public class Pocket extends AbstractPocket<Pocket> implements AddonProvider {
return getSelf();
}
public CompoundTag toTag(CompoundTag tag) {
ListTag addonsTag = new ListTag();
addonsTag.addAll(addons.values().stream().map(addon -> addon.toTag(new CompoundTag())).collect(Collectors.toList()));
public NbtCompound toTag(NbtCompound tag) {
NbtList addonsTag = new NbtList();
addonsTag.addAll(addons.values().stream().map(addon -> addon.toTag(new NbtCompound())).collect(Collectors.toList()));
if (addonsTag.size() > 0) tag.put("addons", addonsTag);
return tag;
@ -251,7 +250,7 @@ public class Pocket extends AbstractPocket<Pocket> implements AddonProvider {
T instance = super.build();
instance.setRange(range);
instance.setBox(BlockBox.create(origin.getX(), origin.getY(), origin.getZ(), origin.getX() + size.getX(), origin.getY() + size.getY(), origin.getZ() + size.getZ()));
instance.setBox(BlockBox.create(new Vec3i(origin.getX(), origin.getY(), origin.getZ()), new Vec3i(origin.getX() + size.getX(), origin.getY() + size.getY(), origin.getZ() + size.getZ())));
instance.virtualLocation = virtualLocation;
addons.values().forEach(addon -> addon.apply(instance));

View file

@ -1,9 +1,9 @@
package org.dimdev.dimdoors.world.pocket.type.addon;
import net.fabricmc.fabric.api.util.NbtType;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.Tag;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.nbt.NbtElement;
import net.minecraft.nbt.NbtList;
import net.minecraft.util.Identifier;
import java.util.ArrayList;
@ -30,12 +30,12 @@ public abstract class AddonContainer<T extends ContainedAddon> implements Pocket
}
@Override
public PocketAddon fromTag(CompoundTag tag) {
public PocketAddon fromTag(NbtCompound tag) {
this.id = Identifier.tryParse(tag.getString("id"));
if (tag.contains("addons", NbtType.LIST)) {
for (Tag addonTag : tag.getList("addons", NbtType.COMPOUND)) {
addons.add((T) PocketAddon.deserialize((CompoundTag) addonTag));
for (NbtElement addonTag : tag.getList("addons", NbtType.COMPOUND)) {
addons.add((T) PocketAddon.deserialize((NbtCompound) addonTag));
}
}
@ -43,12 +43,12 @@ public abstract class AddonContainer<T extends ContainedAddon> implements Pocket
}
@Override
public CompoundTag toTag(CompoundTag tag) {
public NbtCompound toTag(NbtCompound tag) {
PocketAddon.super.toTag(tag);
ListTag addonsTag = new ListTag();
NbtList addonsTag = new NbtList();
for(T addon : addons) {
addonsTag.add(addon.toTag(new CompoundTag()));
addonsTag.add(addon.toTag(new NbtCompound()));
}
tag.put("addons", addonsTag);

View file

@ -2,7 +2,7 @@ package org.dimdev.dimdoors.world.pocket.type.addon;
import net.minecraft.block.BlockState;
import net.minecraft.entity.Entity;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.text.TranslatableText;
import net.minecraft.util.DyeColor;
@ -27,8 +27,8 @@ public class DyeableAddon implements PocketAddon {
private int count = 0;
private static int amountOfDyeRequiredToColor(Pocket pocket) {
int outerVolume = pocket.getBox().getBlockCountX() * pocket.getBox().getBlockCountY() * pocket.getBox().getBlockCountZ();
int innerVolume = (pocket.getBox().getBlockCountX() - 5) * (pocket.getBox().getBlockCountY() - 5) * (pocket.getBox().getBlockCountZ() - 5);
int outerVolume = pocket.getBox().getBlockCountY() * pocket.getBox().getBlockCountZ() * pocket.getBox().getBlockCountZ();
int innerVolume = (pocket.getBox().getBlockCountY() - 5) * (pocket.getBox().getBlockCountZ() - 5) * (pocket.getBox().getBlockCountZ() - 5);
return Math.max((outerVolume - innerVolume) / BLOCKS_PAINTED_PER_DYE, 1);
}
@ -82,7 +82,7 @@ public class DyeableAddon implements PocketAddon {
}
@Override
public PocketAddon fromTag(CompoundTag tag) {
public PocketAddon fromTag(NbtCompound tag) {
this.dyeColor = PocketColor.from(tag.getInt("dyeColor"));
this.nextDyeColor = PocketColor.from(tag.getInt("nextDyeColor"));
@ -92,7 +92,7 @@ public class DyeableAddon implements PocketAddon {
}
@Override
public CompoundTag toTag(CompoundTag tag) {
public NbtCompound toTag(NbtCompound tag) {
PocketAddon.super.toTag(tag);
tag.putInt("dyeColor", this.dyeColor.getId());
@ -139,14 +139,14 @@ public class DyeableAddon implements PocketAddon {
}
@Override
public PocketBuilderAddon<DyeableAddon> fromTag(CompoundTag tag) {
public PocketBuilderAddon<DyeableAddon> fromTag(NbtCompound tag) {
this.dyeColor = PocketColor.from(tag.getInt("dye_color"));
return this;
}
@Override
public CompoundTag toTag(CompoundTag tag) {
public NbtCompound toTag(NbtCompound tag) {
PocketBuilderAddon.super.toTag(tag);
tag.putInt("dye_color", dyeColor.getId());

View file

@ -2,7 +2,7 @@ package org.dimdev.dimdoors.world.pocket.type.addon;
import com.mojang.serialization.Lifecycle;
import net.fabricmc.fabric.api.event.registry.FabricRegistryBuilder;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry;
import net.minecraft.util.registry.RegistryKey;
@ -18,18 +18,18 @@ import java.util.function.Supplier;
public interface PocketAddon {
Registry<PocketAddonType<? extends PocketAddon>> REGISTRY = FabricRegistryBuilder.from(new SimpleRegistry<PocketAddonType<? extends PocketAddon>>(RegistryKey.ofRegistry(new Identifier("dimdoors", "pocket_applicable_addon_type")), Lifecycle.stable())).buildAndRegister();
static PocketAddon deserialize(CompoundTag tag) {
static PocketAddon deserialize(NbtCompound tag) {
Identifier id = Identifier.tryParse(tag.getString("type")); // TODO: NONE PocketAddon type;
return REGISTRY.get(id).fromTag(tag);
}
static PocketBuilderAddon<?> deserializeBuilder(CompoundTag tag) {
static PocketBuilderAddon<?> deserializeBuilder(NbtCompound tag) {
Identifier id = Identifier.tryParse(tag.getString("type")); // TODO: NONE PocketAddon type;
return REGISTRY.get(id).builderAddonInstance().fromTag(tag);
}
static CompoundTag serialize(PocketAddon addon) {
return addon.toTag(new CompoundTag());
static NbtCompound serialize(PocketAddon addon) {
return addon.toTag(new NbtCompound());
}
@ -37,9 +37,9 @@ public interface PocketAddon {
return true;
}
PocketAddon fromTag(CompoundTag tag);
PocketAddon fromTag(NbtCompound tag);
default CompoundTag toTag(CompoundTag tag) {
default NbtCompound toTag(NbtCompound tag) {
return this.getType().toTag(tag);
}
@ -71,9 +71,9 @@ public interface PocketAddon {
Identifier getId();
PocketBuilderAddon<T> fromTag(CompoundTag tag);
PocketBuilderAddon<T> fromTag(NbtCompound tag);
default CompoundTag toTag(CompoundTag tag) {
default NbtCompound toTag(NbtCompound tag) {
return this.getType().toTag(tag);
}
@ -85,9 +85,9 @@ public interface PocketAddon {
PocketAddonType<PreventBlockModificationAddon> PREVENT_BLOCK_MODIFICATION_ADDON = register(PreventBlockModificationAddon.ID, PreventBlockModificationAddon::new, PreventBlockModificationAddon.PreventBlockModificationBuilderAddon::new);
PocketAddonType<BlockBreakContainer> BLOCK_BREAK_CONTAINER = register(BlockBreakContainer.ID, BlockBreakContainer::new, null);
T fromTag(CompoundTag tag);
T fromTag(NbtCompound tag);
CompoundTag toTag(CompoundTag tag);
NbtCompound toTag(NbtCompound tag);
T instance();
@ -102,12 +102,12 @@ public interface PocketAddon {
static <U extends PocketAddon> PocketAddonType<U> register(Identifier id, Supplier<U> factory, Supplier<PocketBuilderAddon<U>> addonSupplier) {
return Registry.register(REGISTRY, id, new PocketAddonType<U>() {
@Override
public U fromTag(CompoundTag tag) {
public U fromTag(NbtCompound tag) {
return (U) factory.get().fromTag(tag);
}
@Override
public CompoundTag toTag(CompoundTag tag) {
public NbtCompound toTag(NbtCompound tag) {
tag.putString("type", id.toString());
return tag;
}

View file

@ -7,7 +7,7 @@ import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.BlockItem;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
@ -62,7 +62,7 @@ public class PreventBlockModificationAddon implements AutoSyncedAddon, AttackBlo
}
@Override
public PocketAddon fromTag(CompoundTag tag) {
public PocketAddon fromTag(NbtCompound tag) {
return this;
}
@ -89,7 +89,7 @@ public class PreventBlockModificationAddon implements AutoSyncedAddon, AttackBlo
}
@Override
public PocketBuilderAddon<PreventBlockModificationAddon> fromTag(CompoundTag tag) {
public PocketBuilderAddon<PreventBlockModificationAddon> fromTag(NbtCompound tag) {
return this;
}

View file

@ -1,6 +1,6 @@
package org.dimdev.dimdoors.world.pocket.type.addon.blockbreak;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.util.Identifier;
import org.dimdev.dimdoors.world.pocket.type.addon.AutoSyncedAddon;
@ -13,13 +13,13 @@ import java.io.IOException;
public class BlockBreakRegexBlacklistAddon implements AutoSyncedAddon, ContainedAddon { //TODO
@Override
public AutoSyncedAddon read(PacketByteBuf buf) throws IOException {
this.fromTag(buf.readCompoundTag());
this.fromTag(buf.readNbt());
return this;
}
@Override
public PacketByteBuf write(PacketByteBuf buf) throws IOException {
buf.writeCompoundTag(this.toTag(new CompoundTag()));
buf.writeNbt(this.toTag(new NbtCompound()));
return buf;
}
@ -29,7 +29,7 @@ public class BlockBreakRegexBlacklistAddon implements AutoSyncedAddon, Contained
}
@Override
public PocketAddon fromTag(CompoundTag tag) {
public PocketAddon fromTag(NbtCompound tag) {
return null;
}

View file

@ -14,6 +14,7 @@
"aquifers_enabled": false,
"disable_mob_generation": false,
"sea_level": 32,
"min_surface_level": 16,
"structures": {
"structures": {}
},

View file

@ -3,6 +3,7 @@
"package": "org.dimdev.dimdoors.mixin",
"compatibilityLevel": "JAVA_8",
"mixins": [
"BlockBoxMixin",
"BlockMixin",
"DefaultBiomeFeaturesMixin",
"ExtendedServerPlayNetworkhandlerMixin",

View file

@ -12,6 +12,8 @@ import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.math.*;
import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.chunk.ChunkSection;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.dimdev.dimdoors.block.entity.RiftBlockEntity;
import org.dimdev.dimdoors.api.util.BlockBoxUtil;
import org.dimdev.dimdoors.api.util.BlockPlacementType;
@ -21,8 +23,8 @@ import net.minecraft.block.entity.BlockEntity;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.fluid.FluidState;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.nbt.NbtList;
import net.minecraft.nbt.NbtOps;
import net.minecraft.world.BlockView;
import net.minecraft.world.ModifiableWorld;
@ -39,8 +41,8 @@ public class RelativeBlockSample implements BlockView, ModifiableWorld {
private final BiMap<Biome, Integer> biomePalette;
private final Map<BlockPos, BlockState> blockContainer;
private final Map<BlockPos, Biome> biomeContainer;
private final Map<BlockPos, CompoundTag> blockEntityContainer;
private final BiMap<CompoundTag, Vec3d> entityContainer;
private final Map<BlockPos, NbtCompound> blockEntityContainer;
private final BiMap<NbtCompound, Vec3d> entityContainer;
public RelativeBlockSample(Schematic schematic) {
this.schematic = schematic;
@ -68,15 +70,15 @@ public class RelativeBlockSample implements BlockView, ModifiableWorld {
}
}
}
for (CompoundTag blockEntityTag : schematic.getBlockEntities()) {
for (NbtCompound blockEntityTag : schematic.getBlockEntities()) {
int[] arr = blockEntityTag.getIntArray("Pos");
BlockPos position = new BlockPos(arr[0], arr[1], arr[2]);
this.blockEntityContainer.put(position, blockEntityTag);
}
this.entityContainer = HashBiMap.create();
for (CompoundTag entityTag : schematic.getEntities()) {
ListTag doubles = entityTag.getList("Pos", NbtType.DOUBLE);
for (NbtCompound entityTag : schematic.getEntities()) {
NbtList doubles = entityTag.getList("Pos", NbtType.DOUBLE);
this.entityContainer.put(entityTag, new Vec3d(doubles.getDouble(0), doubles.getDouble(1), doubles.getDouble(2)));
}
}
@ -109,11 +111,11 @@ public class RelativeBlockSample implements BlockView, ModifiableWorld {
world.setBlockState(actualPos, state, 0, 0);
if (placementType.shouldMarkForUpdate()) ((ServerWorld) world).getChunkManager().markForUpdate(actualPos);
});
for (Map.Entry<BlockPos, CompoundTag> entry : this.blockEntityContainer.entrySet()) {
for (Map.Entry<BlockPos, NbtCompound> entry : this.blockEntityContainer.entrySet()) {
BlockPos pos = entry.getKey();
BlockPos actualPos = origin.add(entry.getKey());
CompoundTag tag = entry.getValue();
NbtCompound tag = entry.getValue();
if(tag.contains("Id")) {
tag.put("id", tag.get("Id")); // boogers
tag.remove("Id");
@ -124,9 +126,9 @@ public class RelativeBlockSample implements BlockView, ModifiableWorld {
world.toServerWorld().addBlockEntity(blockEntity);
}
}
for (Map.Entry<CompoundTag, Vec3d> entry : this.entityContainer.entrySet()) {
CompoundTag tag = entry.getKey();
ListTag doubles = tag.getList("Pos", NbtType.DOUBLE);
for (Map.Entry<NbtCompound, Vec3d> entry : this.entityContainer.entrySet()) {
NbtCompound tag = entry.getKey();
NbtList doubles = tag.getList("Pos", NbtType.DOUBLE);
Vec3d vec = entry.getValue().add(origin.getX(), origin.getY(), origin.getZ());
doubles.set(0, NbtOps.INSTANCE.createDouble(vec.x));
doubles.set(1, NbtOps.INSTANCE.createDouble(vec.y));
@ -139,10 +141,12 @@ public class RelativeBlockSample implements BlockView, ModifiableWorld {
public void place(BlockPos origin, ServerWorld world, Chunk chunk, BlockPlacementType placementType, boolean biomes) {
ChunkPos pos = chunk.getPos();
BlockBox chunkBox = BlockBox.create(pos.getStartX(), chunk.getBottomY(), pos.getStartZ(), pos.getEndX(), chunk.getTopY(), pos.getEndZ());
BlockBox schemBox = BlockBox.create(origin.getX(), origin.getY(), origin.getZ(), origin.getX() + schematic.getWidth() - 1, origin.getY() + schematic.getHeight() - 1, origin.getZ() + schematic.getLength() - 1);
BlockBox intersection = BlockBoxUtil.intersection(chunkBox, schemBox);
if (!BlockBoxUtil.isRealBox(intersection)) return;
BlockBox chunkBox = BlockBoxUtil.getBox(chunk);
Vec3i schemDimensions = new Vec3i(schematic.getWidth(), schematic.getHeight(), schematic.getLength());
BlockBox intersection = BlockBox.create(origin, origin.add(schemDimensions).add(-1, -1, -1));
if (!intersection.intersects(chunkBox)) return;
intersection.intersection(chunkBox);
ServerChunkManager serverChunkManager = world.getChunkManager();
@ -200,7 +204,7 @@ public class RelativeBlockSample implements BlockView, ModifiableWorld {
// TODO: is it ok if this is not executed with MinecraftServer#send?
this.entityContainer.forEach(((tag, vec3d) -> {
ListTag doubles = tag.getList("Pos", NbtType.DOUBLE);
NbtList doubles = tag.getList("Pos", NbtType.DOUBLE);
Vec3d vec = vec3d.add(origin.getX(), origin.getY(), origin.getZ());
if (intersection.contains(new Vec3i(vec.x, vec.y, vec.z))) {
doubles.set(0, NbtOps.INSTANCE.createDouble(vec.x));
@ -244,7 +248,7 @@ public class RelativeBlockSample implements BlockView, ModifiableWorld {
return this.blockContainer;
}
public Map<BlockPos, CompoundTag> getBlockEntityContainer() {
public Map<BlockPos, NbtCompound> getBlockEntityContainer() {
return this.blockEntityContainer;
}

View file

@ -23,7 +23,7 @@ import com.mojang.serialization.codecs.RecordCodecBuilder;
import net.minecraft.SharedConstants;
import net.minecraft.block.BlockState;
import net.minecraft.entity.Entity;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.nbt.NbtOps;
import net.minecraft.util.math.Vec3i;
import net.minecraft.util.registry.BuiltinRegistries;
@ -42,8 +42,8 @@ public class Schematic {
Codec.INT.fieldOf("PaletteMax").forGetter(Schematic::getPaletteMax),
SchematicBlockPalette.CODEC.fieldOf("Palette").forGetter(Schematic::getBlockPalette),
Codec.BYTE_BUFFER.fieldOf("BlockData").forGetter(Schematic::getBlockData),
Codec.list(CompoundTag.CODEC).optionalFieldOf("BlockEntities", ImmutableList.of()).forGetter(Schematic::getBlockEntities),
Codec.list(CompoundTag.CODEC).optionalFieldOf("Entities", ImmutableList.of()).forGetter(Schematic::getEntities),
Codec.list(NbtCompound.CODEC).optionalFieldOf("BlockEntities", ImmutableList.of()).forGetter(Schematic::getBlockEntities),
Codec.list(NbtCompound.CODEC).optionalFieldOf("Entities", ImmutableList.of()).forGetter(Schematic::getEntities),
Codec.unboundedMap(BuiltinRegistries.BIOME, Codec.INT).optionalFieldOf("BiomePalette", Collections.emptyMap()).forGetter(Schematic::getBiomePalette),
Codec.BYTE_BUFFER.optionalFieldOf("BiomeData", ByteBuffer.wrap(new byte[0])).forGetter(Schematic::getBlockData)
).apply(instance, Schematic::new));
@ -58,13 +58,13 @@ public class Schematic {
private final int paletteMax;
private final BiMap<BlockState, Integer> blockPalette;
private final ByteBuffer blockData;
private List<CompoundTag> blockEntities;
private List<CompoundTag> entities;
private List<NbtCompound> blockEntities;
private List<NbtCompound> entities;
private final BiMap<Biome, Integer> biomePalette;
private final ByteBuffer biomeData;
private RelativeBlockSample cachedBlockSample = null;
public Schematic(int version, int dataVersion, SchematicMetadata metadata, short width, short height, short length, Vec3i offset, int paletteMax, Map<BlockState, Integer> blockPalette, ByteBuffer blockData, List<CompoundTag> blockEntities, List<CompoundTag> entities, Map<Biome, Integer> biomePalette, ByteBuffer biomeData) {
public Schematic(int version, int dataVersion, SchematicMetadata metadata, short width, short height, short length, Vec3i offset, int paletteMax, Map<BlockState, Integer> blockPalette, ByteBuffer blockData, List<NbtCompound> blockEntities, List<NbtCompound> entities, Map<Biome, Integer> biomePalette, ByteBuffer biomeData) {
this.version = version;
this.dataVersion = dataVersion;
this.metadata = metadata;
@ -121,7 +121,7 @@ public class Schematic {
return this.blockData;
}
public List<CompoundTag> getBlockEntities() {
public List<NbtCompound> getBlockEntities() {
return this.blockEntities;
}
@ -133,23 +133,23 @@ public class Schematic {
return this.biomeData;
}
public void setBlockEntities(List<CompoundTag> blockEntities) {
public void setBlockEntities(List<NbtCompound> blockEntities) {
this.blockEntities = blockEntities.stream().map(SchematicPlacer::fixEntityId).collect(Collectors.toList());
}
public void setEntities(Collection<? extends Entity> entities) {
this.setEntities(entities.stream().map((e) -> {
CompoundTag tag = new CompoundTag();
e.saveSelfToTag(tag);
NbtCompound tag = new NbtCompound();
e.saveSelfNbt(tag);
return tag;
}).collect(Collectors.toList()));
}
public List<CompoundTag> getEntities() {
public List<NbtCompound> getEntities() {
return this.entities;
}
public void setEntities(List<CompoundTag> entities) {
public void setEntities(List<NbtCompound> entities) {
this.entities = entities;
}
@ -160,12 +160,12 @@ public class Schematic {
return schem.cachedBlockSample;
}
public static Schematic fromTag(CompoundTag tag) {
public static Schematic fromTag(NbtCompound tag) {
return CODEC.decode(NbtOps.INSTANCE, tag).getOrThrow(false, PRINT_TO_STDERR).getFirst();
}
public static CompoundTag toTag(Schematic schem) {
return (CompoundTag) CODEC.encodeStart(NbtOps.INSTANCE, schem).getOrThrow(false, PRINT_TO_STDERR);
public static NbtCompound toTag(Schematic schem) {
return (NbtCompound) CODEC.encodeStart(NbtOps.INSTANCE, schem).getOrThrow(false, PRINT_TO_STDERR);
}
public static Schematic fromJson(JsonObject json) {

View file

@ -12,9 +12,9 @@ import org.apache.logging.log4j.Logger;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.DoubleTag;
import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.nbt.NbtDouble;
import net.minecraft.nbt.NbtList;
import net.minecraft.nbt.NbtOps;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.StructureWorldAccess;
@ -89,9 +89,9 @@ public final class SchematicPlacer {
}
private static void placeEntities(int originX, int originY, int originZ, Schematic schematic, StructureWorldAccess world) {
List<CompoundTag> entityTags = schematic.getEntities();
for (CompoundTag tag : entityTags) {
ListTag listTag = Objects.requireNonNull(tag.getList("Pos", 6), "Entity in schematic \"" + schematic.getMetadata().getName() + "\" did not have a Pos tag!");
List<NbtCompound> entityTags = schematic.getEntities();
for (NbtCompound tag : entityTags) {
NbtList listTag = Objects.requireNonNull(tag.getList("Pos", 6), "Entity in schematic \"" + schematic.getMetadata().getName() + "\" did not have a Pos tag!");
SchematicPlacer.processPos(listTag, originX, originY, originZ, tag);
EntityType<?> entityType = EntityType.fromNbt(tag).orElseThrow(AssertionError::new);
@ -104,7 +104,7 @@ public final class SchematicPlacer {
}
}
public static CompoundTag fixEntityId(CompoundTag tag) {
public static NbtCompound fixEntityId(NbtCompound tag) {
if (!tag.contains("Id") && tag.contains("id")) {
tag.putString("Id", tag.getString("id"));
} else if (tag.contains("Id") && !tag.contains("id")) {
@ -118,13 +118,13 @@ public final class SchematicPlacer {
return tag;
}
private static void processPos(ListTag listTag, int originX, int originY, int originZ, CompoundTag tag) {
private static void processPos(NbtList listTag, int originX, int originY, int originZ, NbtCompound tag) {
double x = listTag.getDouble(0);
double y = listTag.getDouble(1);
double z = listTag.getDouble(2);
tag.remove("Pos");
tag.put("Pos", NbtOps.INSTANCE.createList(Stream.of(DoubleTag.of(x + originX),
DoubleTag.of(y + originY),
DoubleTag.of(z + originZ))));
tag.put("Pos", NbtOps.INSTANCE.createList(Stream.of(NbtDouble.of(x + originX),
NbtDouble.of(y + originY),
NbtDouble.of(z + originZ))));
}
}

View file

@ -1,7 +1,10 @@
package org.dimdev.dimdoors.util.schematic;
import java.util.Optional;
import java.util.function.Predicate;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.world.Heightmap;
import org.dimdev.dimdoors.api.util.BlockPlacementType;
import org.jetbrains.annotations.Nullable;
@ -33,6 +36,11 @@ public class WorldlyBlockSample implements BlockView, ModifiableTestableWorld {
return this.relativeBlockSample.getBlockEntity(pos);
}
@Override
public <T extends BlockEntity> Optional<T> getBlockEntity(BlockPos pos, BlockEntityType<T> type) {
return Optional.ofNullable(type.get(this, pos));
}
@Override
public BlockState getBlockState(BlockPos pos) {
return this.relativeBlockSample.getBlockState(pos);
@ -63,6 +71,16 @@ public class WorldlyBlockSample implements BlockView, ModifiableTestableWorld {
return state.test(this.getBlockState(pos));
}
@Override
public boolean testFluidState(BlockPos pos, Predicate<FluidState> state) {
throw new RuntimeException("Method Implementation missing!"); // FIXME
}
@Override
public BlockPos getTopPosition(Heightmap.Type type, BlockPos blockPos) {
throw new RuntimeException("Method Implementation missing!"); // FIXME
}
@Override
public int getHeight() {
return this.relativeBlockSample.getHeight();