Make 1.18 to be effectively in a usable state (#1452)

* Update swathes of easy-to-update-sort-of-code.
 - Untested
 - Should compile but NMF broken something
 - Several todos:
  - biome history//better support (move to biome sections in core)
  - regen (haha lol no thanks, someone else can do that)
  - probably actually do the palette stuff that probably won't work in PaperweightPlatformAdapter

* ci: Provide basic Jenkinsfile for ghprb pipeline

* build: Update paperweight

* upstream: Update Upstream

de6fa17 Add getBrush helper for use with instanceof pattern matching (1926)

* FAWE will now load on startup

* it....works?

* Begin to allow biome edits (and fix biomes reverting to plains upon editing blocks)

* Add new blocks/block properties

* Only create biome palette if supplies is null

* Fix biome operations

* Finally get removing BlockID done (major version change allows it)

* refactor!: Drop PlotSquared v4

Fawe 2.0.0 and newer requires Java 17, PlotSquared v4 supports 1.13 and 1.14, Fawe wont work on these versions nevertheless and refuses to load due Java version incompatiblities with older versions. Newer versions can use PlotSquared v6.

* docs: Update readme

* Added and removed some comments

* Added and removed some comments

* refactor: Rename worldedit configuration

* build: Re-add 1.17 module

This the a very nasty commit

* chore: Implement missing methods

* build: Update paperweight

* upstream: Update upstream

6df194e Remove finalize, use a Cleaner instead (1943)
9843a4f Fix snapshots in 1.18 (1959)

* ci: Escape workflows

* build: Update paperweight to 1.18.1

* build: Update Paster

* Fix compilation

* Bump to 1.18.1

* Do both 1.18 and 1.18.1

Co-authored-by: Alex <mc.cache@web.de>

* Fix single-block lookups

* Reserve ordinals 0 through 3 for air/"reserved"

* Create block palette data with values

* Fix classpath for testing for starlight

* Correctly use block rather than sky light layer [not used in paper]

Co-authored-by: NotMyFault <mc.cache@web.de>
Co-authored-by: Matt <4009945+MattBDev@users.noreply.github.com>
This commit is contained in:
Jordan
2021-12-20 21:12:04 +00:00
committed by GitHub
parent c697eb8d41
commit d6e3c331d4
76 changed files with 2447 additions and 3052 deletions

View File

@ -121,12 +121,12 @@ public final class BlockTypes {
@Nullable
public static final BlockType BEDROCK = init();
@Nullable
public static final BlockType BEE_NEST = init();
@Nullable
public static final BlockType BEEHIVE = init();
@Nullable
public static final BlockType BEETROOTS = init();
@Nullable
public static final BlockType BEE_NEST = init();
@Nullable
public static final BlockType BELL = init();
@Nullable
public static final BlockType BIG_DRIPLEAF = init();
@ -163,6 +163,14 @@ public final class BlockTypes {
@Nullable
public static final BlockType BIRCH_WOOD = init();
@Nullable
public static final BlockType BLACKSTONE = init();
@Nullable
public static final BlockType BLACKSTONE_SLAB = init();
@Nullable
public static final BlockType BLACKSTONE_STAIRS = init();
@Nullable
public static final BlockType BLACKSTONE_WALL = init();
@Nullable
public static final BlockType BLACK_BANNER = init();
@Nullable
public static final BlockType BLACK_BED = init();
@ -191,14 +199,6 @@ public final class BlockTypes {
@Nullable
public static final BlockType BLACK_WOOL = init();
@Nullable
public static final BlockType BLACKSTONE = init();
@Nullable
public static final BlockType BLACKSTONE_SLAB = init();
@Nullable
public static final BlockType BLACKSTONE_STAIRS = init();
@Nullable
public static final BlockType BLACKSTONE_WALL = init();
@Nullable
public static final BlockType BLAST_FURNACE = init();
@Nullable
public static final BlockType BLUE_BANNER = init();
@ -247,14 +247,14 @@ public final class BlockTypes {
@Nullable
public static final BlockType BREWING_STAND = init();
@Nullable
public static final BlockType BRICKS = init();
@Nullable
public static final BlockType BRICK_SLAB = init();
@Nullable
public static final BlockType BRICK_STAIRS = init();
@Nullable
public static final BlockType BRICK_WALL = init();
@Nullable
public static final BlockType BRICKS = init();
@Nullable
public static final BlockType BROWN_BANNER = init();
@Nullable
public static final BlockType BROWN_BED = init();
@ -389,8 +389,6 @@ public final class BlockTypes {
@Nullable
public static final BlockType COPPER_BLOCK = init();
@Nullable
public static final BlockType COPPER_ORE = init();
@Nullable
public static final BlockType CORNFLOWER = init();
@Nullable
public static final BlockType CRACKED_DEEPSLATE_BRICKS = init();
@ -571,14 +569,14 @@ public final class BlockTypes {
@Nullable
public static final BlockType DEEPSLATE = init();
@Nullable
public static final BlockType DEEPSLATE_BRICKS = init();
@Nullable
public static final BlockType DEEPSLATE_BRICK_SLAB = init();
@Nullable
public static final BlockType DEEPSLATE_BRICK_STAIRS = init();
@Nullable
public static final BlockType DEEPSLATE_BRICK_WALL = init();
@Nullable
public static final BlockType DEEPSLATE_BRICKS = init();
@Nullable
public static final BlockType DEEPSLATE_COAL_ORE = init();
@Nullable
public static final BlockType DEEPSLATE_COPPER_ORE = init();
@ -595,14 +593,14 @@ public final class BlockTypes {
@Nullable
public static final BlockType DEEPSLATE_REDSTONE_ORE = init();
@Nullable
public static final BlockType DEEPSLATE_TILES = init();
@Nullable
public static final BlockType DEEPSLATE_TILE_SLAB = init();
@Nullable
public static final BlockType DEEPSLATE_TILE_STAIRS = init();
@Nullable
public static final BlockType DEEPSLATE_TILE_WALL = init();
@Nullable
public static final BlockType DEEPSLATE_TILES = init();
@Nullable
public static final BlockType DETECTOR_RAIL = init();
@Nullable
public static final BlockType DIAMOND_BLOCK = init();
@ -641,6 +639,8 @@ public final class BlockTypes {
@Nullable
public static final BlockType ENCHANTING_TABLE = init();
@Nullable
public static final BlockType ENDER_CHEST = init();
@Nullable
public static final BlockType END_GATEWAY = init();
@Nullable
public static final BlockType END_PORTAL = init();
@ -651,18 +651,16 @@ public final class BlockTypes {
@Nullable
public static final BlockType END_STONE = init();
@Nullable
public static final BlockType END_STONE_BRICKS = init();
@Nullable
public static final BlockType END_STONE_BRICK_SLAB = init();
@Nullable
public static final BlockType END_STONE_BRICK_STAIRS = init();
@Nullable
public static final BlockType END_STONE_BRICK_WALL = init();
@Nullable
public static final BlockType END_STONE_BRICKS = init();
@Nullable
public static final BlockType EXPOSED_COPPER = init();
@Nullable
public static final BlockType ENDER_CHEST = init();
@Nullable
public static final BlockType EXPOSED_CUT_COPPER = init();
@Nullable
public static final BlockType EXPOSED_CUT_COPPER_SLAB = init();
@ -685,12 +683,12 @@ public final class BlockTypes {
@Nullable
public static final BlockType FLETCHING_TABLE = init();
@Nullable
public static final BlockType FLOWER_POT = init();
@Nullable
public static final BlockType FLOWERING_AZALEA = init();
@Nullable
public static final BlockType FLOWERING_AZALEA_LEAVES = init();
@Nullable
public static final BlockType FLOWER_POT = init();
@Nullable
public static final BlockType FROSTED_ICE = init();
@Nullable
public static final BlockType FURNACE = init();
@ -701,10 +699,10 @@ public final class BlockTypes {
@Nullable
public static final BlockType GLASS_PANE = init();
@Nullable
public static final BlockType GLOW_LICHEN = init();
@Nullable
public static final BlockType GLOWSTONE = init();
@Nullable
public static final BlockType GLOW_LICHEN = init();
@Nullable
public static final BlockType GOLD_BLOCK = init();
@Nullable
public static final BlockType GOLD_ORE = init();
@ -720,9 +718,6 @@ public final class BlockTypes {
public static final BlockType GRASS = init();
@Nullable
public static final BlockType GRASS_BLOCK = init();
@Deprecated
@Nullable
public static final BlockType GRASS_PATH = init();
@Nullable
public static final BlockType GRAVEL = init();
@Nullable
@ -790,10 +785,10 @@ public final class BlockTypes {
@Nullable
public static final BlockType HEAVY_WEIGHTED_PRESSURE_PLATE = init();
@Nullable
public static final BlockType HONEY_BLOCK = init();
@Nullable
public static final BlockType HONEYCOMB_BLOCK = init();
@Nullable
public static final BlockType HONEY_BLOCK = init();
@Nullable
public static final BlockType HOPPER = init();
@Nullable
public static final BlockType HORN_CORAL = init();
@ -892,6 +887,8 @@ public final class BlockTypes {
@Nullable
public static final BlockType LIGHT = init();
@Nullable
public static final BlockType LIGHTNING_ROD = init();
@Nullable
public static final BlockType LIGHT_BLUE_BANNER = init();
@Nullable
public static final BlockType LIGHT_BLUE_BED = init();
@ -950,8 +947,6 @@ public final class BlockTypes {
@Nullable
public static final BlockType LIGHT_WEIGHTED_PRESSURE_PLATE = init();
@Nullable
public static final BlockType LIGHTNING_ROD = init();
@Nullable
public static final BlockType LILAC = init();
@Nullable
public static final BlockType LILY_OF_THE_VALLEY = init();
@ -1026,10 +1021,6 @@ public final class BlockTypes {
@Nullable
public static final BlockType MELON_STEM = init();
@Nullable
public static final BlockType MOSS_BLOCK = init();
@Nullable
public static final BlockType MOSS_CARPET = init();
@Nullable
public static final BlockType MOSSY_COBBLESTONE = init();
@Nullable
public static final BlockType MOSSY_COBBLESTONE_SLAB = init();
@ -1038,13 +1029,17 @@ public final class BlockTypes {
@Nullable
public static final BlockType MOSSY_COBBLESTONE_WALL = init();
@Nullable
public static final BlockType MOSSY_STONE_BRICKS = init();
@Nullable
public static final BlockType MOSSY_STONE_BRICK_SLAB = init();
@Nullable
public static final BlockType MOSSY_STONE_BRICK_STAIRS = init();
@Nullable
public static final BlockType MOSSY_STONE_BRICK_WALL = init();
@Nullable
public static final BlockType MOSSY_STONE_BRICKS = init();
public static final BlockType MOSS_BLOCK = init();
@Nullable
public static final BlockType MOSS_CARPET = init();
@Nullable
public static final BlockType MOVING_PISTON = init();
@Nullable
@ -1052,6 +1047,12 @@ public final class BlockTypes {
@Nullable
public static final BlockType MYCELIUM = init();
@Nullable
public static final BlockType NETHERITE_BLOCK = init();
@Nullable
public static final BlockType NETHERRACK = init();
@Nullable
public static final BlockType NETHER_BRICKS = init();
@Nullable
public static final BlockType NETHER_BRICK_FENCE = init();
@Nullable
public static final BlockType NETHER_BRICK_SLAB = init();
@ -1060,8 +1061,6 @@ public final class BlockTypes {
@Nullable
public static final BlockType NETHER_BRICK_WALL = init();
@Nullable
public static final BlockType NETHER_BRICKS = init();
@Nullable
public static final BlockType NETHER_GOLD_ORE = init();
@Nullable
public static final BlockType NETHER_PORTAL = init();
@ -1074,10 +1073,6 @@ public final class BlockTypes {
@Nullable
public static final BlockType NETHER_WART_BLOCK = init();
@Nullable
public static final BlockType NETHERITE_BLOCK = init();
@Nullable
public static final BlockType NETHERRACK = init();
@Nullable
public static final BlockType NOTE_BLOCK = init();
@Nullable
public static final BlockType OAK_BUTTON = init();
@ -1212,14 +1207,14 @@ public final class BlockTypes {
@Nullable
public static final BlockType POLISHED_BLACKSTONE = init();
@Nullable
public static final BlockType POLISHED_BLACKSTONE_BRICKS = init();
@Nullable
public static final BlockType POLISHED_BLACKSTONE_BRICK_SLAB = init();
@Nullable
public static final BlockType POLISHED_BLACKSTONE_BRICK_STAIRS = init();
@Nullable
public static final BlockType POLISHED_BLACKSTONE_BRICK_WALL = init();
@Nullable
public static final BlockType POLISHED_BLACKSTONE_BRICKS = init();
@Nullable
public static final BlockType POLISHED_BLACKSTONE_BUTTON = init();
@Nullable
public static final BlockType POLISHED_BLACKSTONE_PRESSURE_PLATE = init();
@ -1257,9 +1252,12 @@ public final class BlockTypes {
public static final BlockType POTTED_ACACIA_SAPLING = init();
@Nullable
public static final BlockType POTTED_ALLIUM = init();
@Deprecated //No longer has "bush"
@Nullable
public static final BlockType POTTED_AZALEA_BUSH = init();
@Nullable
public static final BlockType POTTED_AZALEA = init();
@Nullable
public static final BlockType POTTED_AZURE_BLUET = init();
@Nullable
public static final BlockType POTTED_BAMBOO = init();
@ -1285,9 +1283,12 @@ public final class BlockTypes {
public static final BlockType POTTED_DEAD_BUSH = init();
@Nullable
public static final BlockType POTTED_FERN = init();
@Deprecated //No longer has "bush"
@Nullable
public static final BlockType POTTED_FLOWERING_AZALEA_BUSH = init();
@Nullable
public static final BlockType POTTED_FLOWERING_AZALEA = init();
@Nullable
public static final BlockType POTTED_JUNGLE_SAPLING = init();
@Nullable
public static final BlockType POTTED_LILY_OF_THE_VALLEY = init();
@ -1324,12 +1325,12 @@ public final class BlockTypes {
@Nullable
public static final BlockType PRISMARINE = init();
@Nullable
public static final BlockType PRISMARINE_BRICKS = init();
@Nullable
public static final BlockType PRISMARINE_BRICK_SLAB = init();
@Nullable
public static final BlockType PRISMARINE_BRICK_STAIRS = init();
@Nullable
public static final BlockType PRISMARINE_BRICKS = init();
@Nullable
public static final BlockType PRISMARINE_SLAB = init();
@Nullable
public static final BlockType PRISMARINE_STAIRS = init();
@ -1394,6 +1395,18 @@ public final class BlockTypes {
@Nullable
public static final BlockType RAW_IRON_BLOCK = init();
@Nullable
public static final BlockType REDSTONE_BLOCK = init();
@Nullable
public static final BlockType REDSTONE_LAMP = init();
@Nullable
public static final BlockType REDSTONE_ORE = init();
@Nullable
public static final BlockType REDSTONE_TORCH = init();
@Nullable
public static final BlockType REDSTONE_WALL_TORCH = init();
@Nullable
public static final BlockType REDSTONE_WIRE = init();
@Nullable
public static final BlockType RED_BANNER = init();
@Nullable
public static final BlockType RED_BED = init();
@ -1414,14 +1427,14 @@ public final class BlockTypes {
@Nullable
public static final BlockType RED_MUSHROOM_BLOCK = init();
@Nullable
public static final BlockType RED_NETHER_BRICKS = init();
@Nullable
public static final BlockType RED_NETHER_BRICK_SLAB = init();
@Nullable
public static final BlockType RED_NETHER_BRICK_STAIRS = init();
@Nullable
public static final BlockType RED_NETHER_BRICK_WALL = init();
@Nullable
public static final BlockType RED_NETHER_BRICKS = init();
@Nullable
public static final BlockType RED_SAND = init();
@Nullable
public static final BlockType RED_SANDSTONE = init();
@ -1446,18 +1459,6 @@ public final class BlockTypes {
@Nullable
public static final BlockType RED_WOOL = init();
@Nullable
public static final BlockType REDSTONE_BLOCK = init();
@Nullable
public static final BlockType REDSTONE_LAMP = init();
@Nullable
public static final BlockType REDSTONE_ORE = init();
@Nullable
public static final BlockType REDSTONE_TORCH = init();
@Nullable
public static final BlockType REDSTONE_WALL_TORCH = init();
@Nullable
public static final BlockType REDSTONE_WIRE = init();
@Nullable
public static final BlockType REPEATER = init();
@Nullable
public static final BlockType REPEATING_COMMAND_BLOCK = init();
@ -1482,12 +1483,12 @@ public final class BlockTypes {
@Nullable
public static final BlockType SCULK_SENSOR = init();
@Nullable
public static final BlockType SEAGRASS = init();
@Nullable
public static final BlockType SEA_LANTERN = init();
@Nullable
public static final BlockType SEA_PICKLE = init();
@Nullable
public static final BlockType SEAGRASS = init();
@Nullable
public static final BlockType SHROOMLIGHT = init();
@Nullable
public static final BlockType SHULKER_BOX = init();
@ -1591,14 +1592,16 @@ public final class BlockTypes {
@Nullable
public static final BlockType STONE = init();
@Nullable
public static final BlockType STONECUTTER = init();
@Nullable
public static final BlockType STONE_BRICKS = init();
@Nullable
public static final BlockType STONE_BRICK_SLAB = init();
@Nullable
public static final BlockType STONE_BRICK_STAIRS = init();
@Nullable
public static final BlockType STONE_BRICK_WALL = init();
@Nullable
public static final BlockType STONE_BRICKS = init();
@Nullable
public static final BlockType STONE_BUTTON = init();
@Nullable
public static final BlockType STONE_PRESSURE_PLATE = init();
@ -1607,8 +1610,6 @@ public final class BlockTypes {
@Nullable
public static final BlockType STONE_STAIRS = init();
@Nullable
public static final BlockType STONECUTTER = init();
@Nullable
public static final BlockType STRIPPED_ACACIA_LOG = init();
@Nullable
public static final BlockType STRIPPED_ACACIA_WOOD = init();
@ -1772,10 +1773,10 @@ public final class BlockTypes {
@Nullable
public static final BlockType WEATHERED_CUT_COPPER_SLAB = init();
@Nullable
public static final BlockType WEEPING_VINES = init();
@Nullable
public static final BlockType WEATHERED_CUT_COPPER_STAIRS = init();
@Nullable
public static final BlockType WEEPING_VINES = init();
@Nullable
public static final BlockType WEEPING_VINES_PLANT = init();
@Nullable
public static final BlockType WET_SPONGE = init();

View File

@ -2,7 +2,6 @@ package com.sk89q.worldedit.world.block;
import com.fastasyncworldedit.core.registry.state.PropertyKey;
import com.fastasyncworldedit.core.util.MathMan;
import com.fastasyncworldedit.core.world.block.BlockID;
import com.google.common.primitives.Booleans;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.WorldEdit;
@ -14,7 +13,6 @@ import com.sk89q.worldedit.world.registry.BlockMaterial;
import com.sk89q.worldedit.world.registry.BlockRegistry;
import com.sk89q.worldedit.world.registry.Registries;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
@ -218,14 +216,15 @@ public class BlockTypesCache {
: item, item -> item));
int size = blockMap.size() + 1;
Field[] idFields = BlockID.class.getDeclaredFields();
for (Field field : idFields) {
size = Math.max(field.getInt(null) + 1, size);
}
BIT_OFFSET = MathMan.log2nlz(size);
BIT_MASK = ((1 << BIT_OFFSET) - 1);
values = new BlockType[size];
/*Field[] idFields = BlockID.class.getDeclaredFields();
for (Field field : idFields) {
size = Math.max(field.getInt(null) + 1, size);
}
// Register the statically declared ones first
for (Field field : idFields) {
if (field.getType() == int.class) {
@ -245,9 +244,30 @@ public class BlockTypesCache {
// Note: Throws IndexOutOfBoundsError if nothing is registered and blocksMap is empty
values[internalId] = type;
}
}*/
// Register "Reserved". Ensure air/reserved and 0/1/2/3
{
int internalId = 0;
for (String id : new String[]{"minecraft:__reserved__", "minecraft:air", "minecraft:cave_air",
"minecraft:void_air"}) {
String defaultState = blockMap.remove(id);
if (defaultState == null) {
defaultState = id;
}
if (values[internalId] != null) {
throw new IllegalStateException(
"Invalid duplicate id for __reserved__! Something has gone very wrong. Are " +
"any plugins shading FAWE?!");
}
BlockType type = register(defaultState, internalId, stateList, tickList);
// Note: Throws IndexOutOfBoundsError if nothing is registered and blocksMap is empty
values[internalId] = type;
internalId++;
}
}
{ // Register new blocks
{ // Register real blocks
int internalId = 1;
for (Map.Entry<String, String> entry : blockMap.entrySet()) {
String defaultState = entry.getValue();

View File

@ -26,7 +26,7 @@ import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.storage.InvalidFormatException;
/**
* The chunk format for Minecraft 1.16 and newer
* The chunk format for Minecraft 1.16 and 1.17
*/
public class AnvilChunk16 extends AnvilChunk15 {

View File

@ -0,0 +1,218 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.world.chunk;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.jnbt.IntTag;
import com.sk89q.jnbt.ListTag;
import com.sk89q.jnbt.LongArrayTag;
import com.sk89q.jnbt.NBTUtils;
import com.sk89q.jnbt.Tag;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.registry.state.Property;
import com.sk89q.worldedit.world.DataException;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockType;
import com.sk89q.worldedit.world.block.BlockTypes;
import com.sk89q.worldedit.world.storage.InvalidFormatException;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import javax.annotation.Nullable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* The chunk format for Minecraft 1.18 and newer
*/
public class AnvilChunk18 implements Chunk {
private final CompoundTag rootTag;
private final Int2ObjectOpenHashMap<BlockState[]> blocks;
private final int rootX;
private final int rootZ;
private Map<BlockVector3, Map<String, Tag>> tileEntities;
/**
* Construct the chunk with a compound tag.
*
* @param tag the tag to read
* @throws DataException on a data error
*/
public AnvilChunk18(CompoundTag tag) throws DataException {
rootTag = tag;
rootX = NBTUtils.getChildTag(rootTag.getValue(), "xPos", IntTag.class).getValue();
rootZ = NBTUtils.getChildTag(rootTag.getValue(), "zPos", IntTag.class).getValue();
List<Tag> sections = NBTUtils.getChildTag(rootTag.getValue(), "sections", ListTag.class).getValue();
blocks = new Int2ObjectOpenHashMap<>(sections.size());
for (Tag rawSectionTag : sections) {
if (!(rawSectionTag instanceof CompoundTag sectionTag)) {
continue;
}
Object yValue = sectionTag.getValue().get("Y").getValue(); // sometimes a byte, sometimes an int
if (!(yValue instanceof Number)) {
throw new InvalidFormatException("Y is not numeric: " + yValue);
}
int y = ((Number) yValue).intValue();
Tag rawBlockStatesTag = sectionTag.getValue().get("block_states"); // null for sections outside of the world limits
if (rawBlockStatesTag instanceof CompoundTag blockStatesTag) {
// parse palette
List<CompoundTag> paletteEntries = blockStatesTag.getList("palette", CompoundTag.class);
int paletteSize = paletteEntries.size();
if (paletteSize == 0) {
continue;
}
BlockState[] palette = new BlockState[paletteSize];
for (int paletteEntryId = 0; paletteEntryId < paletteSize; paletteEntryId++) {
CompoundTag paletteEntry = paletteEntries.get(paletteEntryId);
BlockType type = BlockTypes.get(paletteEntry.getString("Name"));
if (type == null) {
throw new InvalidFormatException("Invalid block type: " + paletteEntry.getString("Name"));
}
BlockState blockState = type.getDefaultState();
if (paletteEntry.containsKey("Properties")) {
CompoundTag properties = NBTUtils.getChildTag(paletteEntry.getValue(), "Properties", CompoundTag.class);
for (Property<?> property : blockState.getStates().keySet()) {
if (properties.containsKey(property.getName())) {
String value = properties.getString(property.getName());
try {
blockState = getBlockStateWith(blockState, property, value);
} catch (IllegalArgumentException e) {
throw new InvalidFormatException("Invalid block state for " + blockState.getBlockType().getId() + ", " + property.getName() + ": " + value);
}
}
}
}
palette[paletteEntryId] = blockState;
}
if (paletteSize == 1) {
// the same block everywhere
blocks.put(y, palette);
continue;
}
// parse block states
long[] blockStatesSerialized = NBTUtils.getChildTag(blockStatesTag.getValue(), "data", LongArrayTag.class).getValue();
BlockState[] chunkSectionBlocks = new BlockState[16 * 16 * 16];
blocks.put(y, chunkSectionBlocks);
readBlockStates(palette, blockStatesSerialized, chunkSectionBlocks);
}
}
}
protected void readBlockStates(BlockState[] palette, long[] blockStatesSerialized, BlockState[] chunkSectionBlocks) throws InvalidFormatException {
PackedIntArrayReader reader = new PackedIntArrayReader(blockStatesSerialized);
for (int blockPos = 0; blockPos < chunkSectionBlocks.length; blockPos++) {
int index = reader.get(blockPos);
if (index >= palette.length) {
throw new InvalidFormatException("Invalid block state table entry: " + index);
}
chunkSectionBlocks[blockPos] = palette[index];
}
}
private <T> BlockState getBlockStateWith(BlockState source, Property<T> property, String value) {
return source.with(property, property.getValueFor(value));
}
/**
* Used to load the tile entities.
*/
private void populateTileEntities() throws DataException {
tileEntities = new HashMap<>();
if (!rootTag.getValue().containsKey("block_entities")) {
return;
}
List<Tag> tags = NBTUtils.getChildTag(rootTag.getValue(),
"block_entities", ListTag.class).getValue();
for (Tag tag : tags) {
if (!(tag instanceof CompoundTag t)) {
throw new InvalidFormatException("CompoundTag expected in block_entities");
}
Map<String, Tag> values = new HashMap<>(t.getValue());
int x = ((IntTag) values.get("x")).getValue();
int y = ((IntTag) values.get("y")).getValue();
int z = ((IntTag) values.get("z")).getValue();
BlockVector3 vec = BlockVector3.at(x, y, z);
tileEntities.put(vec, values);
}
}
/**
* Get the map of tags keyed to strings for a block's tile entity data. May
* return null if there is no tile entity data. Not public yet because
* what this function returns isn't ideal for usage.
*
* @param position the position
* @return the compound tag for that position, which may be null
* @throws DataException thrown if there is a data error
*/
@Nullable
private CompoundTag getBlockTileEntity(BlockVector3 position) throws DataException {
if (tileEntities == null) {
populateTileEntities();
}
Map<String, Tag> values = tileEntities.get(position);
if (values == null) {
return null;
}
return new CompoundTag(values);
}
@Override
public BaseBlock getBlock(BlockVector3 position) throws DataException {
int x = position.getX() - rootX * 16;
int y = position.getY();
int z = position.getZ() - rootZ * 16;
int section = y >> 4;
int yIndex = y & 0x0F;
BlockState[] sectionBlocks = blocks.get(section);
if (sectionBlocks == null) {
return BlockTypes.AIR.getDefaultState().toBaseBlock();
}
BlockState state = sectionBlocks[sectionBlocks.length == 1 ? 0 : ((yIndex << 8) | (z << 4) | x)];
CompoundTag tileEntity = getBlockTileEntity(position);
if (tileEntity != null) {
return state.toBaseBlock(tileEntity);
}
return state.toBaseBlock();
}
}

View File

@ -34,6 +34,7 @@ import com.sk89q.worldedit.world.chunk.AnvilChunk13;
import com.sk89q.worldedit.world.chunk.AnvilChunk15;
import com.sk89q.worldedit.world.chunk.AnvilChunk16;
import com.sk89q.worldedit.world.chunk.AnvilChunk17;
import com.sk89q.worldedit.world.chunk.AnvilChunk18;
import com.sk89q.worldedit.world.chunk.Chunk;
import com.sk89q.worldedit.world.chunk.OldChunk;
@ -72,8 +73,28 @@ public class ChunkStoreHelper {
* @throws DataException if the rootTag is not valid chunk data
*/
public static Chunk getChunk(CompoundTag rootTag) throws DataException {
int dataVersion = rootTag.getInt("DataVersion");
if (dataVersion == 0) {
dataVersion = -1;
}
final Platform platform = WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.WORLD_EDITING);
final int currentDataVersion = platform.getDataVersion();
if ((dataVersion > 0 || hasLevelSections(rootTag)) && dataVersion < currentDataVersion) { // only fix up MCA format, DFU doesn't support MCR chunks
final DataFixer dataFixer = platform.getDataFixer();
if (dataFixer != null) {
rootTag = (CompoundTag) AdventureNBTConverter.fromAdventure(dataFixer.fixUp(DataFixer.FixTypes.CHUNK,
rootTag.asBinaryTag(), dataVersion));
dataVersion = currentDataVersion;
}
}
if (dataVersion >= Constants.DATA_VERSION_MC_1_18) {
return new AnvilChunk18(rootTag);
}
//FAWE start - biome and entity restore
return getChunk(rootTag, () -> null);
//FAWE end
}
/**
@ -113,21 +134,6 @@ public class ChunkStoreHelper {
if (dataVersion == 0) {
dataVersion = -1;
}
final Platform platform = WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.WORLD_EDITING);
final int currentDataVersion = platform.getDataVersion();
if (tag
.getValue()
.containsKey("Sections") && dataVersion < currentDataVersion) { // only fix up MCA format, DFU doesn't support MCR chunks
final DataFixer dataFixer = platform.getDataFixer();
if (dataFixer != null) {
//FAWE start - BinaryTag
tag = (CompoundTag) AdventureNBTConverter.fromAdventure(dataFixer
.fixUp(DataFixer.FixTypes.CHUNK, rootTag.asBinaryTag(), dataVersion)
.get("Level"));
//FAWE end
dataVersion = currentDataVersion;
}
}
//FAWE start - biome and entity restore
if (dataVersion >= Constants.DATA_VERSION_MC_1_17) {
return new AnvilChunk17(tag, entitiesTag);
@ -153,6 +159,15 @@ public class ChunkStoreHelper {
return new OldChunk(tag);
}
private static boolean hasLevelSections(CompoundTag rootTag) {
Map<String, Tag> children = rootTag.getValue();
Tag levelTag = children.get("Level");
if (levelTag instanceof CompoundTag) {
return ((CompoundTag) levelTag).getValue().containsKey("Sections");
}
return false;
}
private ChunkStoreHelper() {
}

View File

@ -105,7 +105,7 @@ public class TrueZipMcRegionChunkStore extends McRegionChunkStore {
endIndex = entryName.lastIndexOf('\\');
}
folder = entryName.substring(0, endIndex);
if (folder.endsWith("poi")) {
if (folder.endsWith("poi") || folder.endsWith("entities")) {
continue;
}
name = folder + "/" + name;

View File

@ -101,9 +101,7 @@ public class ZippedMcRegionChunkStore extends McRegionChunkStore {
endIndex = entryName.lastIndexOf('\\');
}
folder = entryName.substring(0, endIndex);
//FAWE start - biome and entity restore
if (folder.endsWith("poi") || folder.endsWith("entities")) {
//FAWE end
continue;
}
name = folder + "/" + name;