mirror of
https://github.com/GTNewHorizons/Postea.git
synced 2026-11-11 16:07:36 +00:00
Attach absent tile entity and entity lists to the chunk tag
This commit is contained in:
3 files changed
+61
-6
No files matched your search
@@ -1,7 +1,5 @@
|
||||
package com.gtnewhorizons.postea.api;
|
||||
|
||||
import static net.minecraftforge.common.util.Constants.NBT.TAG_COMPOUND;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
@@ -13,14 +11,15 @@ import net.minecraft.world.chunk.storage.ExtendedBlockStorage;
|
||||
import com.gtnewhorizons.postea.compat.Compat;
|
||||
import com.gtnewhorizons.postea.compat.SubChunkAccess;
|
||||
import com.gtnewhorizons.postea.utility.NbtItemStacks;
|
||||
import com.gtnewhorizons.postea.utility.NbtLists;
|
||||
import com.gtnewhorizons.postea.utility.VersionStamps;
|
||||
|
||||
/**
|
||||
* A chunk as handed to {@link IVersionedTransformer#transformChunk}: its block storage and the raw {@code Level}
|
||||
* tag as read from disk, before tile entities and entities are parsed. Coordinates are chunk-local
|
||||
* ({@code 0..15}, {@code y 0..255}); block ids and metadata are the world's numeric values at full EndlessIDs
|
||||
* width. The world is not loaded yet: block access through {@link #world()} is not possible. Changing a block id
|
||||
* does not recompute lighting or the height map; Postea flags the chunk for a relight when an id changed.
|
||||
* width. The world is not loaded yet: block access through {@link #world()} is not possible. When a transformer
|
||||
* changed a block id, Postea recomputes the height map and flags the chunk for a relight once all transformers ran.
|
||||
*/
|
||||
public final class ChunkTransformContext {
|
||||
|
||||
@@ -68,11 +67,11 @@ public final class ChunkTransformContext {
|
||||
}
|
||||
|
||||
public NBTTagList tileEntityTags() {
|
||||
return levelTag.getTagList("TileEntities", TAG_COMPOUND);
|
||||
return NbtLists.compoundList(levelTag, "TileEntities");
|
||||
}
|
||||
|
||||
public NBTTagList entityTags() {
|
||||
return levelTag.getTagList("Entities", TAG_COMPOUND);
|
||||
return NbtLists.compoundList(levelTag, "Entities");
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.gtnewhorizons.postea.utility;
|
||||
|
||||
import static net.minecraftforge.common.util.Constants.NBT.TAG_COMPOUND;
|
||||
import static net.minecraftforge.common.util.Constants.NBT.TAG_LIST;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
|
||||
public final class NbtLists {
|
||||
|
||||
private NbtLists() {}
|
||||
|
||||
/**
|
||||
* The list of compounds stored under {@code key}, attached to {@code parent} first when absent so that tags
|
||||
* appended to it are part of {@code parent}.
|
||||
*/
|
||||
public static NBTTagList compoundList(NBTTagCompound parent, String key) {
|
||||
if (!parent.hasKey(key, TAG_LIST)) parent.setTag(key, new NBTTagList());
|
||||
return parent.getTagList(key, TAG_COMPOUND);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.gtnewhorizons.postea.utility;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class NbtListsTest {
|
||||
|
||||
@Test
|
||||
void anAbsentListIsCreatedAndAttachedSoAppendedTagsAreKept() {
|
||||
NBTTagCompound level = new NBTTagCompound();
|
||||
|
||||
NbtLists.compoundList(level, "TileEntities")
|
||||
.appendTag(new NBTTagCompound());
|
||||
|
||||
assertEquals(
|
||||
1,
|
||||
level.getTagList("TileEntities", 10)
|
||||
.tagCount());
|
||||
}
|
||||
|
||||
@Test
|
||||
void anExistingListIsReturnedAsIs() {
|
||||
NBTTagCompound level = new NBTTagCompound();
|
||||
NBTTagList existing = new NBTTagList();
|
||||
existing.appendTag(new NBTTagCompound());
|
||||
level.setTag("Entities", existing);
|
||||
|
||||
assertSame(existing, NbtLists.compoundList(level, "Entities"));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user