| 1 | package net.minecraft.util.datafix.fixes;
|
| 2 |
|
| 3 | import com.google.common.collect.Lists;
|
| 4 | import com.google.common.collect.Maps;
|
| 5 | import com.google.common.collect.Sets;
|
| 6 | import com.mojang.datafixers.DataFix;
|
| 7 | import com.mojang.datafixers.DataFixUtils;
|
| 8 | import com.mojang.datafixers.TypeRewriteRule;
|
| 9 | import com.mojang.datafixers.schemas.Schema;
|
| 10 | import com.mojang.datafixers.types.Type;
|
| 11 | import com.mojang.logging.LogUtils;
|
| 12 | import com.mojang.serialization.Dynamic;
|
| 13 | import it.unimi.dsi.fastutil.ints.Int2ObjectLinkedOpenHashMap;
|
| 14 | import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
| 15 | import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
| 16 | import it.unimi.dsi.fastutil.ints.IntArrayList;
|
| 17 | import it.unimi.dsi.fastutil.ints.IntList;
|
| 18 | import it.unimi.dsi.fastutil.ints.Int2ObjectMap.Entry;
|
| 19 | import java.nio.ByteBuffer;
|
| 20 | import java.util.Arrays;
|
| 21 | import java.util.BitSet;
|
| 22 | import java.util.List;
|
| 23 | import java.util.Map;
|
| 24 | import java.util.Objects;
|
| 25 | import java.util.Optional;
|
| 26 | import java.util.Set;
|
| 27 | import java.util.stream.Collectors;
|
| 28 | import net.minecraft.nbt.CompoundTag;
|
| 29 | import net.minecraft.nbt.NbtOps;
|
| 30 | import net.minecraft.nbt.Tag;
|
| 31 | import net.minecraft.util.CrudeIncrementalIntIdentityHashBiMap;
|
| 32 | import net.minecraft.util.datafix.PackedBitStorage;
|
| 33 | import org.jspecify.annotations.Nullable;
|
| 34 | import org.slf4j.Logger;
|
| 35 |
|
| 36 | public class ChunkPalettedStorageFix extends DataFix {
|
| 37 | private static final int NORTH_WEST_MASK = 128;
|
| 38 | private static final int WEST_MASK = 64;
|
| 39 | private static final int SOUTH_WEST_MASK = 32;
|
| 40 | private static final int SOUTH_MASK = 16;
|
| 41 | private static final int SOUTH_EAST_MASK = 8;
|
| 42 | private static final int EAST_MASK = 4;
|
| 43 | private static final int NORTH_EAST_MASK = 2;
|
| 44 | private static final int NORTH_MASK = 1;
|
| 45 | private static final Logger LOGGER = LogUtils.getLogger();
|
| 46 | private static final int SIZE = 4096;
|
| 47 |
|
| 48 | public ChunkPalettedStorageFix(final Schema outputSchema, final boolean changesType) {
|
| 49 | super(outputSchema, changesType);
|
| 50 | }
|
| 51 |
|
| 52 | private static Dynamic<?> legacyBlockState(final String id, final Map<String, String> properties) {
|
| 53 | Dynamic<Tag> dynamic = new Dynamic<>(NbtOps.INSTANCE, new CompoundTag());
|
| 54 | Dynamic<Tag> blockState = dynamic.set("Name", dynamic.createString(id));
|
| 55 | if (!properties.isEmpty()) {
|
| 56 | blockState = blockState.set(
|
| 57 | "Properties",
|
| 58 | dynamic.createMap(
|
| 59 | properties.entrySet().stream().collect(Collectors.toMap(entry -> dynamic.createString(entry.getKey()), entry -> dynamic.createString(entry.getValue())))
|
| 60 | )
|
| 61 | );
|
| 62 | }
|
| 63 |
|
| 64 | return blockState;
|
| 65 | }
|
| 66 |
|
| 67 | private static Dynamic<?> legacyBlockState(final String id) {
|
| 68 | return legacyBlockState(id, Map.of());
|
| 69 | }
|
| 70 |
|
| 71 | public static String getName(final Dynamic<?> state) {
|
| 72 | return state.get("Name").asString("");
|
| 73 | }
|
| 74 |
|
| 75 | public static String getProperty(final Dynamic<?> state, final String property) {
|
| 76 | return state.get("Properties").get(property).asString("");
|
| 77 | }
|
| 78 |
|
| 79 | public static int idFor(final CrudeIncrementalIntIdentityHashBiMap<Dynamic<?>> states, final Dynamic<?> state) {
|
| 80 | int id = states.getId(state);
|
| 81 | if (id == -1) {
|
| 82 | id = states.add(state);
|
| 83 | }
|
| 84 |
|
| 85 | return id;
|
| 86 | }
|
| 87 |
|
| 88 | private Dynamic<?> fix(final Dynamic<?> input) {
|
| 89 | Optional<? extends Dynamic<?>> level = input.get("Level").result();
|
| 90 | return level.isPresent() && level.get().get("Sections").asStreamOpt().result().isPresent()
|
| 91 | ? input.set("Level", new ChunkPalettedStorageFix.UpgradeChunk((Dynamic<?>)level.get()).write())
|
| 92 | : input;
|
| 93 | }
|
| 94 |
|
| 95 | @Override
|
| 96 | public TypeRewriteRule makeRule() {
|
| 97 | Type<?> oldType = this.getInputSchema().getType(References.CHUNK);
|
| 98 | Type<?> newType = this.getOutputSchema().getType(References.CHUNK);
|
| 99 | return this.writeFixAndRead("ChunkPalettedStorageFix", oldType, newType, this::fix);
|
| 100 | }
|
| 101 |
|
| 102 | public static int getSideMask(final boolean west, final boolean east, final boolean north, final boolean south) {
|
| 103 | int s = 0;
|
| 104 | if (north) {
|
| 105 | if (east) {
|
| 106 | s |= 2;
|
| 107 | } else if (west) {
|
| 108 | s |= 128;
|
| 109 | } else {
|
| 110 | s |= 1;
|
| 111 | }
|
| 112 | } else if (south) {
|
| 113 | if (west) {
|
| 114 | s |= 32;
|
| 115 | } else if (east) {
|
| 116 | s |= 8;
|
| 117 | } else {
|
| 118 | s |= 16;
|
| 119 | }
|
| 120 | } else if (east) {
|
| 121 | s |= 4;
|
| 122 | } else if (west) {
|
| 123 | s |= 64;
|
| 124 | }
|
| 125 |
|
| 126 | return s;
|
| 127 | }
|
| 128 |
|
| 129 | private static class DataLayer {
|
| 130 | private static final int SIZE = 2048;
|
| 131 | private static final int NIBBLE_SIZE = 4;
|
| 132 | private final byte[] data;
|
| 133 |
|
| 134 | public DataLayer() {
|
| 135 | this.data = new byte[2048];
|
| 136 | }
|
| 137 |
|
| 138 | public DataLayer(final byte[] data) {
|
| 139 | this.data = data;
|
| 140 | if (data.length != 2048) {
|
| 141 | throw new IllegalArgumentException("ChunkNibbleArrays should be 2048 bytes not: " + data.length);
|
| 142 | }
|
| 143 | }
|
| 144 |
|
| 145 | public int get(final int x, final int y, final int z) {
|
| 146 | int position = this.getPosition(y << 8 | z << 4 | x);
|
| 147 | return this.isFirst(y << 8 | z << 4 | x) ? this.data[position] & 15 : this.data[position] >> 4 & 15;
|
| 148 | }
|
| 149 |
|
| 150 | private boolean isFirst(final int position) {
|
| 151 | return (position & 1) == 0;
|
| 152 | }
|
| 153 |
|
| 154 | private int getPosition(final int position) {
|
| 155 | return position >> 1;
|
| 156 | }
|
| 157 | }
|
| 158 |
|
| 159 | public enum Direction {
|
| 160 | DOWN(ChunkPalettedStorageFix.Direction.AxisDirection.NEGATIVE, ChunkPalettedStorageFix.Direction.Axis.Y),
|
| 161 | UP(ChunkPalettedStorageFix.Direction.AxisDirection.POSITIVE, ChunkPalettedStorageFix.Direction.Axis.Y),
|
| 162 | NORTH(ChunkPalettedStorageFix.Direction.AxisDirection.NEGATIVE, ChunkPalettedStorageFix.Direction.Axis.Z),
|
| 163 | SOUTH(ChunkPalettedStorageFix.Direction.AxisDirection.POSITIVE, ChunkPalettedStorageFix.Direction.Axis.Z),
|
| 164 | WEST(ChunkPalettedStorageFix.Direction.AxisDirection.NEGATIVE, ChunkPalettedStorageFix.Direction.Axis.X),
|
| 165 | EAST(ChunkPalettedStorageFix.Direction.AxisDirection.POSITIVE, ChunkPalettedStorageFix.Direction.Axis.X);
|
| 166 |
|
| 167 | private final ChunkPalettedStorageFix.Direction.Axis axis;
|
| 168 | private final ChunkPalettedStorageFix.Direction.AxisDirection axisDirection;
|
| 169 |
|
| 170 | Direction(final ChunkPalettedStorageFix.Direction.AxisDirection axisDirection, final ChunkPalettedStorageFix.Direction.Axis axis) {
|
| 171 | this.axis = axis;
|
| 172 | this.axisDirection = axisDirection;
|
| 173 | }
|
| 174 |
|
| 175 | public ChunkPalettedStorageFix.Direction.AxisDirection getAxisDirection() {
|
| 176 | return this.axisDirection;
|
| 177 | }
|
| 178 |
|
| 179 | public ChunkPalettedStorageFix.Direction.Axis getAxis() {
|
| 180 | return this.axis;
|
| 181 | }
|
| 182 |
|
| 183 | public enum Axis {
|
| 184 | X,
|
| 185 | Y,
|
| 186 | Z;
|
| 187 | }
|
| 188 |
|
| 189 | public enum AxisDirection {
|
| 190 | POSITIVE(1),
|
| 191 | NEGATIVE(-1);
|
| 192 |
|
| 193 | private final int step;
|
| 194 |
|
| 195 | AxisDirection(final int step) {
|
| 196 | this.step = step;
|
| 197 | }
|
| 198 |
|
| 199 | public int getStep() {
|
| 200 | return this.step;
|
| 201 | }
|
| 202 | }
|
| 203 | }
|
| 204 |
|
| 205 | private static class MappingConstants {
|
| 206 | private static final BitSet VIRTUAL = new BitSet(256);
|
| 207 | private static final BitSet FIX = new BitSet(256);
|
| 208 | private static final Dynamic<?> PUMPKIN = ChunkPalettedStorageFix.legacyBlockState("minecraft:pumpkin");
|
| 209 | private static final Dynamic<?> SNOWY_PODZOL = ChunkPalettedStorageFix.legacyBlockState("minecraft:podzol", Map.of("snowy", "true"));
|
| 210 | private static final Dynamic<?> SNOWY_GRASS = ChunkPalettedStorageFix.legacyBlockState("minecraft:grass_block", Map.of("snowy", "true"));
|
| 211 | private static final Dynamic<?> SNOWY_MYCELIUM = ChunkPalettedStorageFix.legacyBlockState("minecraft:mycelium", Map.of("snowy", "true"));
|
| 212 | private static final Dynamic<?> UPPER_SUNFLOWER = ChunkPalettedStorageFix.legacyBlockState("minecraft:sunflower", Map.of("half", "upper"));
|
| 213 | private static final Dynamic<?> UPPER_LILAC = ChunkPalettedStorageFix.legacyBlockState("minecraft:lilac", Map.of("half", "upper"));
|
| 214 | private static final Dynamic<?> UPPER_TALL_GRASS = ChunkPalettedStorageFix.legacyBlockState("minecraft:tall_grass", Map.of("half", "upper"));
|
| 215 | private static final Dynamic<?> UPPER_LARGE_FERN = ChunkPalettedStorageFix.legacyBlockState("minecraft:large_fern", Map.of("half", "upper"));
|
| 216 | private static final Dynamic<?> UPPER_ROSE_BUSH = ChunkPalettedStorageFix.legacyBlockState("minecraft:rose_bush", Map.of("half", "upper"));
|
| 217 | private static final Dynamic<?> UPPER_PEONY = ChunkPalettedStorageFix.legacyBlockState("minecraft:peony", Map.of("half", "upper"));
|
| 218 | private static final Map<String, Dynamic<?>> FLOWER_POT_MAP = DataFixUtils.make(Maps.newHashMap(), map -> {
|
| 219 | map.put("minecraft:air0", ChunkPalettedStorageFix.legacyBlockState("minecraft:flower_pot"));
|
| 220 | map.put("minecraft:red_flower0", ChunkPalettedStorageFix.legacyBlockState("minecraft:potted_poppy"));
|
| 221 | map.put("minecraft:red_flower1", ChunkPalettedStorageFix.legacyBlockState("minecraft:potted_blue_orchid"));
|
| 222 | map.put("minecraft:red_flower2", ChunkPalettedStorageFix.legacyBlockState("minecraft:potted_allium"));
|
| 223 | map.put("minecraft:red_flower3", ChunkPalettedStorageFix.legacyBlockState("minecraft:potted_azure_bluet"));
|
| 224 | map.put("minecraft:red_flower4", ChunkPalettedStorageFix.legacyBlockState("minecraft:potted_red_tulip"));
|
| 225 | map.put("minecraft:red_flower5", ChunkPalettedStorageFix.legacyBlockState("minecraft:potted_orange_tulip"));
|
| 226 | map.put("minecraft:red_flower6", ChunkPalettedStorageFix.legacyBlockState("minecraft:potted_white_tulip"));
|
| 227 | map.put("minecraft:red_flower7", ChunkPalettedStorageFix.legacyBlockState("minecraft:potted_pink_tulip"));
|
| 228 | map.put("minecraft:red_flower8", ChunkPalettedStorageFix.legacyBlockState("minecraft:potted_oxeye_daisy"));
|
| 229 | map.put("minecraft:yellow_flower0", ChunkPalettedStorageFix.legacyBlockState("minecraft:potted_dandelion"));
|
| 230 | map.put("minecraft:sapling0", ChunkPalettedStorageFix.legacyBlockState("minecraft:potted_oak_sapling"));
|
| 231 | map.put("minecraft:sapling1", ChunkPalettedStorageFix.legacyBlockState("minecraft:potted_spruce_sapling"));
|
| 232 | map.put("minecraft:sapling2", ChunkPalettedStorageFix.legacyBlockState("minecraft:potted_birch_sapling"));
|
| 233 | map.put("minecraft:sapling3", ChunkPalettedStorageFix.legacyBlockState("minecraft:potted_jungle_sapling"));
|
| 234 | map.put("minecraft:sapling4", ChunkPalettedStorageFix.legacyBlockState("minecraft:potted_acacia_sapling"));
|
| 235 | map.put("minecraft:sapling5", ChunkPalettedStorageFix.legacyBlockState("minecraft:potted_dark_oak_sapling"));
|
| 236 | map.put("minecraft:red_mushroom0", ChunkPalettedStorageFix.legacyBlockState("minecraft:potted_red_mushroom"));
|
| 237 | map.put("minecraft:brown_mushroom0", ChunkPalettedStorageFix.legacyBlockState("minecraft:potted_brown_mushroom"));
|
| 238 | map.put("minecraft:deadbush0", ChunkPalettedStorageFix.legacyBlockState("minecraft:potted_dead_bush"));
|
| 239 | map.put("minecraft:tallgrass2", ChunkPalettedStorageFix.legacyBlockState("minecraft:potted_fern"));
|
| 240 | map.put("minecraft:cactus0", ChunkPalettedStorageFix.legacyBlockState("minecraft:potted_cactus"));
|
| 241 | });
|
| 242 | private static final Map<String, Dynamic<?>> SKULL_MAP = DataFixUtils.make(Maps.newHashMap(), map -> {
|
| 243 | mapSkull(map, 0, "skeleton", "skull");
|
| 244 | mapSkull(map, 1, "wither_skeleton", "skull");
|
| 245 | mapSkull(map, 2, "zombie", "head");
|
| 246 | mapSkull(map, 3, "player", "head");
|
| 247 | mapSkull(map, 4, "creeper", "head");
|
| 248 | mapSkull(map, 5, "dragon", "head");
|
| 249 | });
|
| 250 | private static final Map<String, Dynamic<?>> DOOR_MAP = DataFixUtils.make(Maps.newHashMap(), map -> {
|
| 251 | mapDoor(map, "oak_door");
|
| 252 | mapDoor(map, "iron_door");
|
| 253 | mapDoor(map, "spruce_door");
|
| 254 | mapDoor(map, "birch_door");
|
| 255 | mapDoor(map, "jungle_door");
|
| 256 | mapDoor(map, "acacia_door");
|
| 257 | mapDoor(map, "dark_oak_door");
|
| 258 | });
|
| 259 | private static final Map<String, Dynamic<?>> NOTE_BLOCK_MAP = DataFixUtils.make(Maps.newHashMap(), map -> {
|
| 260 | for (int i = 0; i < 26; i++) {
|
| 261 | map.put("true" + i, ChunkPalettedStorageFix.legacyBlockState("minecraft:note_block", Map.of("powered", "true", "note", String.valueOf(i))));
|
| 262 | map.put("false" + i, ChunkPalettedStorageFix.legacyBlockState("minecraft:note_block", Map.of("powered", "false", "note", String.valueOf(i))));
|
| 263 | }
|
| 264 | });
|
| 265 | private static final Int2ObjectMap<String> DYE_COLOR_MAP = DataFixUtils.make(new Int2ObjectOpenHashMap<>(), map -> {
|
| 266 | map.put(0, "white");
|
| 267 | map.put(1, "orange");
|
| 268 | map.put(2, "magenta");
|
| 269 | map.put(3, "light_blue");
|
| 270 | map.put(4, "yellow");
|
| 271 | map.put(5, "lime");
|
| 272 | map.put(6, "pink");
|
| 273 | map.put(7, "gray");
|
| 274 | map.put(8, "light_gray");
|
| 275 | map.put(9, "cyan");
|
| 276 | map.put(10, "purple");
|
| 277 | map.put(11, "blue");
|
| 278 | map.put(12, "brown");
|
| 279 | map.put(13, "green");
|
| 280 | map.put(14, "red");
|
| 281 | map.put(15, "black");
|
| 282 | });
|
| 283 | private static final Map<String, Dynamic<?>> BED_BLOCK_MAP = DataFixUtils.make(Maps.newHashMap(), map -> {
|
| 284 | for (Entry<String> entry : DYE_COLOR_MAP.int2ObjectEntrySet()) {
|
| 285 | if (!Objects.equals(entry.getValue(), "red")) {
|
| 286 | addBeds(map, entry.getIntKey(), entry.getValue());
|
| 287 | }
|
| 288 | }
|
| 289 | });
|
| 290 | private static final Map<String, Dynamic<?>> BANNER_BLOCK_MAP = DataFixUtils.make(Maps.newHashMap(), map -> {
|
| 291 | for (Entry<String> entry : DYE_COLOR_MAP.int2ObjectEntrySet()) {
|
| 292 | if (!Objects.equals(entry.getValue(), "white")) {
|
| 293 | addBanners(map, 15 - entry.getIntKey(), entry.getValue());
|
| 294 | }
|
| 295 | }
|
| 296 | });
|
| 297 | private static final Dynamic<?> AIR = ChunkPalettedStorageFix.legacyBlockState("minecraft:air");
|
| 298 |
|
| 299 | private static void mapSkull(final Map<String, Dynamic<?>> map, final int i, final String name, final String type) {
|
| 300 | map.put(i + "north", ChunkPalettedStorageFix.legacyBlockState("minecraft:" + name + "_wall_" + type, Map.of("facing", "north")));
|
| 301 | map.put(i + "east", ChunkPalettedStorageFix.legacyBlockState("minecraft:" + name + "_wall_" + type, Map.of("facing", "east")));
|
| 302 | map.put(i + "south", ChunkPalettedStorageFix.legacyBlockState("minecraft:" + name + "_wall_" + type, Map.of("facing", "south")));
|
| 303 | map.put(i + "west", ChunkPalettedStorageFix.legacyBlockState("minecraft:" + name + "_wall_" + type, Map.of("facing", "west")));
|
| 304 |
|
| 305 | for (int rot = 0; rot < 16; rot++) {
|
| 306 | map.put("" + i + rot, ChunkPalettedStorageFix.legacyBlockState("minecraft:" + name + "_" + type, Map.of("rotation", String.valueOf(rot))));
|
| 307 | }
|
| 308 | }
|
| 309 |
|
| 310 | private static void mapDoor(final Map<String, Dynamic<?>> map, final String type) {
|
| 311 | String id = "minecraft:" + type;
|
| 312 | map.put(
|
| 313 | "minecraft:" + type + "eastlowerleftfalsefalse",
|
| 314 | ChunkPalettedStorageFix.legacyBlockState(id, Map.of("facing", "east", "half", "lower", "hinge", "left", "open", "false", "powered", "false"))
|
| 315 | );
|
| 316 | map.put(
|
| 317 | "minecraft:" + type + "eastlowerleftfalsetrue",
|
| 318 | ChunkPalettedStorageFix.legacyBlockState(id, Map.of("facing", "east", "half", "lower", "hinge", "left", "open", "false", "powered", "true"))
|
| 319 | );
|
| 320 | map.put(
|
| 321 | "minecraft:" + type + "eastlowerlefttruefalse",
|
| 322 | ChunkPalettedStorageFix.legacyBlockState(id, Map.of("facing", "east", "half", "lower", "hinge", "left", "open", "true", "powered", "false"))
|
| 323 | );
|
| 324 | map.put(
|
| 325 | "minecraft:" + type + "eastlowerlefttruetrue",
|
| 326 | ChunkPalettedStorageFix.legacyBlockState(id, Map.of("facing", "east", "half", "lower", "hinge", "left", "open", "true", "powered", "true"))
|
| 327 | );
|
| 328 | map.put(
|
| 329 | "minecraft:" + type + "eastlowerrightfalsefalse",
|
| 330 | ChunkPalettedStorageFix.legacyBlockState(id, Map.of("facing", "east", "half", "lower", "hinge", "right", "open", "false", "powered", "false"))
|
| 331 | );
|
| 332 | map.put(
|
| 333 | "minecraft:" + type + "eastlowerrightfalsetrue",
|
| 334 | ChunkPalettedStorageFix.legacyBlockState(id, Map.of("facing", "east", "half", "lower", "hinge", "right", "open", "false", "powered", "true"))
|
| 335 | );
|
| 336 | map.put(
|
| 337 | "minecraft:" + type + "eastlowerrighttruefalse",
|
| 338 | ChunkPalettedStorageFix.legacyBlockState(id, Map.of("facing", "east", "half", "lower", "hinge", "right", "open", "true", "powered", "false"))
|
| 339 | );
|
| 340 | map.put(
|
| 341 | "minecraft:" + type + "eastlowerrighttruetrue",
|
| 342 | ChunkPalettedStorageFix.legacyBlockState(id, Map.of("facing", "east", "half", "lower", "hinge", "right", "open", "true", "powered", "true"))
|
| 343 | );
|
| 344 | map.put(
|
| 345 | "minecraft:" + type + "eastupperleftfalsefalse",
|
| 346 | ChunkPalettedStorageFix.legacyBlockState(id, Map.of("facing", "east", "half", "upper", "hinge", "left", "open", "false", "powered", "false"))
|
| 347 | );
|
| 348 | map.put(
|
| 349 | "minecraft:" + type + "eastupperleftfalsetrue",
|
| 350 | ChunkPalettedStorageFix.legacyBlockState(id, Map.of("facing", "east", "half", "upper", "hinge", "left", "open", "false", "powered", "true"))
|
| 351 | );
|
| 352 | map.put(
|
| 353 | "minecraft:" + type + "eastupperlefttruefalse",
|
| 354 | ChunkPalettedStorageFix.legacyBlockState(id, Map.of("facing", "east", "half", "upper", "hinge", "left", "open", "true", "powered", "false"))
|
| 355 | );
|
| 356 | map.put(
|
| 357 | "minecraft:" + type + "eastupperlefttruetrue",
|
| 358 | ChunkPalettedStorageFix.legacyBlockState(id, Map.of("facing", "east", "half", "upper", "hinge", "left", "open", "true", "powered", "true"))
|
| 359 | );
|
| 360 | map.put(
|
| 361 | "minecraft:" + type + "eastupperrightfalsefalse",
|
| 362 | ChunkPalettedStorageFix.legacyBlockState(id, Map.of("facing", "east", "half", "upper", "hinge", "right", "open", "false", "powered", "false"))
|
| 363 | );
|
| 364 | map.put(
|
| 365 | "minecraft:" + type + "eastupperrightfalsetrue",
|
| 366 | ChunkPalettedStorageFix.legacyBlockState(id, Map.of("facing", "east", "half", "upper", "hinge", "right", "open", "false", "powered", "true"))
|
| 367 | );
|
| 368 | map.put(
|
| 369 | "minecraft:" + type + "eastupperrighttruefalse",
|
| 370 | ChunkPalettedStorageFix.legacyBlockState(id, Map.of("facing", "east", "half", "upper", "hinge", "right", "open", "true", "powered", "false"))
|
| 371 | );
|
| 372 | map.put(
|
| 373 | "minecraft:" + type + "eastupperrighttruetrue",
|
| 374 | ChunkPalettedStorageFix.legacyBlockState(id, Map.of("facing", "east", "half", "upper", "hinge", "right", "open", "true", "powered", "true"))
|
| 375 | );
|
| 376 | map.put(
|
| 377 | "minecraft:" + type + "northlowerleftfalsefalse",
|
| 378 | ChunkPalettedStorageFix.legacyBlockState(id, Map.of("facing", "north", "half", "lower", "hinge", "left", "open", "false", "powered", "false"))
|
| 379 | );
|
| 380 | map.put(
|
| 381 | "minecraft:" + type + "northlowerleftfalsetrue",
|
| 382 | ChunkPalettedStorageFix.legacyBlockState(id, Map.of("facing", "north", "half", "lower", "hinge", "left", "open", "false", "powered", "true"))
|
| 383 | );
|
| 384 | map.put(
|
| 385 | "minecraft:" + type + "northlowerlefttruefalse",
|
| 386 | ChunkPalettedStorageFix.legacyBlockState(id, Map.of("facing", "north", "half", "lower", "hinge", "left", "open", "true", "powered", "false"))
|
| 387 | );
|
| 388 | map.put(
|
| 389 | "minecraft:" + type + "northlowerlefttruetrue",
|
| 390 | ChunkPalettedStorageFix.legacyBlockState(id, Map.of("facing", "north", "half", "lower", "hinge", "left", "open", "true", "powered", "true"))
|
| 391 | );
|
| 392 | map.put(
|
| 393 | "minecraft:" + type + "northlowerrightfalsefalse",
|
| 394 | ChunkPalettedStorageFix.legacyBlockState(id, Map.of("facing", "north", "half", "lower", "hinge", "right", "open", "false", "powered", "false"))
|
| 395 | );
|
| 396 | map.put(
|
| 397 | "minecraft:" + type + "northlowerrightfalsetrue",
|
| 398 | ChunkPalettedStorageFix.legacyBlockState(id, Map.of("facing", "north", "half", "lower", "hinge", "right", "open", "false", "powered", "true"))
|
| 399 | );
|
| 400 | map.put(
|
| 401 | "minecraft:" + type + "northlowerrighttruefalse",
|
| 402 | ChunkPalettedStorageFix.legacyBlockState(id, Map.of("facing", "north", "half", "lower", "hinge", "right", "open", "true", "powered", "false"))
|
| 403 | );
|
| 404 | map.put(
|
| 405 | "minecraft:" + type + "northlowerrighttruetrue",
|
| 406 | ChunkPalettedStorageFix.legacyBlockState(id, Map.of("facing", "north", "half", "lower", "hinge", "right", "open", "true", "powered", "true"))
|
| 407 | );
|
| 408 | map.put(
|
| 409 | "minecraft:" + type + "northupperleftfalsefalse",
|
| 410 | ChunkPalettedStorageFix.legacyBlockState(id, Map.of("facing", "north", "half", "upper", "hinge", "left", "open", "false", "powered", "false"))
|
| 411 | );
|
| 412 | map.put(
|
| 413 | "minecraft:" + type + "northupperleftfalsetrue",
|
| 414 | ChunkPalettedStorageFix.legacyBlockState(id, Map.of("facing", "north", "half", "upper", "hinge", "left", "open", "false", "powered", "true"))
|
| 415 | );
|
| 416 | map.put(
|
| 417 | "minecraft:" + type + "northupperlefttruefalse",
|
| 418 | ChunkPalettedStorageFix.legacyBlockState(id, Map.of("facing", "north", "half", "upper", "hinge", "left", "open", "true", "powered", "false"))
|
| 419 | );
|
| 420 | map.put(
|
| 421 | "minecraft:" + type + "northupperlefttruetrue",
|
| 422 | ChunkPalettedStorageFix.legacyBlockState(id, Map.of("facing", "north", "half", "upper", "hinge", "left", "open", "true", "powered", "true"))
|
| 423 | );
|
| 424 | map.put(
|
| 425 | "minecraft:" + type + "northupperrightfalsefalse",
|
| 426 | ChunkPalettedStorageFix.legacyBlockState(id, Map.of("facing", "north", "half", "upper", "hinge", "right", "open", "false", "powered", "false"))
|
| 427 | );
|
| 428 | map.put(
|
| 429 | "minecraft:" + type + "northupperrightfalsetrue",
|
| 430 | ChunkPalettedStorageFix.legacyBlockState(id, Map.of("facing", "north", "half", "upper", "hinge", "right", "open", "false", "powered", "true"))
|
| 431 | );
|
| 432 | map.put(
|
| 433 | "minecraft:" + type + "northupperrighttruefalse",
|
| 434 | ChunkPalettedStorageFix.legacyBlockState(id, Map.of("facing", "north", "half", "upper", "hinge", "right", "open", "true", "powered", "false"))
|
| 435 | );
|
| 436 | map.put(
|
| 437 | "minecraft:" + type + "northupperrighttruetrue",
|
| 438 | ChunkPalettedStorageFix.legacyBlockState(id, Map.of("facing", "north", "half", "upper", "hinge", "right", "open", "true", "powered", "true"))
|
| 439 | );
|
| 440 | map.put(
|
| 441 | "minecraft:" + type + "southlowerleftfalsefalse",
|
| 442 | ChunkPalettedStorageFix.legacyBlockState(id, Map.of("facing", "south", "half", "lower", "hinge", "left", "open", "false", "powered", "false"))
|
| 443 | );
|
| 444 | map.put(
|
| 445 | "minecraft:" + type + "southlowerleftfalsetrue",
|
| 446 | ChunkPalettedStorageFix.legacyBlockState(id, Map.of("facing", "south", "half", "lower", "hinge", "left", "open", "false", "powered", "true"))
|
| 447 | );
|
| 448 | map.put(
|
| 449 | "minecraft:" + type + "southlowerlefttruefalse",
|
| 450 | ChunkPalettedStorageFix.legacyBlockState(id, Map.of("facing", "south", "half", "lower", "hinge", "left", "open", "true", "powered", "false"))
|
| 451 | );
|
| 452 | map.put(
|
| 453 | "minecraft:" + type + "southlowerlefttruetrue",
|
| 454 | ChunkPalettedStorageFix.legacyBlockState(id, Map.of("facing", "south", "half", "lower", "hinge", "left", "open", "true", "powered", "true"))
|
| 455 | );
|
| 456 | map.put(
|
| 457 | "minecraft:" + type + "southlowerrightfalsefalse",
|
| 458 | ChunkPalettedStorageFix.legacyBlockState(id, Map.of("facing", "south", "half", "lower", "hinge", "right", "open", "false", "powered", "false"))
|
| 459 | );
|
| 460 | map.put(
|
| 461 | "minecraft:" + type + "southlowerrightfalsetrue",
|
| 462 | ChunkPalettedStorageFix.legacyBlockState(id, Map.of("facing", "south", "half", "lower", "hinge", "right", "open", "false", "powered", "true"))
|
| 463 | );
|
| 464 | map.put(
|
| 465 | "minecraft:" + type + "southlowerrighttruefalse",
|
| 466 | ChunkPalettedStorageFix.legacyBlockState(id, Map.of("facing", "south", "half", "lower", "hinge", "right", "open", "true", "powered", "false"))
|
| 467 | );
|
| 468 | map.put(
|
| 469 | "minecraft:" + type + "southlowerrighttruetrue",
|
| 470 | ChunkPalettedStorageFix.legacyBlockState(id, Map.of("facing", "south", "half", "lower", "hinge", "right", "open", "true", "powered", "true"))
|
| 471 | );
|
| 472 | map.put(
|
| 473 | "minecraft:" + type + "southupperleftfalsefalse",
|
| 474 | ChunkPalettedStorageFix.legacyBlockState(id, Map.of("facing", "south", "half", "upper", "hinge", "left", "open", "false", "powered", "false"))
|
| 475 | );
|
| 476 | map.put(
|
| 477 | "minecraft:" + type + "southupperleftfalsetrue",
|
| 478 | ChunkPalettedStorageFix.legacyBlockState(id, Map.of("facing", "south", "half", "upper", "hinge", "left", "open", "false", "powered", "true"))
|
| 479 | );
|
| 480 | map.put(
|
| 481 | "minecraft:" + type + "southupperlefttruefalse",
|
| 482 | ChunkPalettedStorageFix.legacyBlockState(id, Map.of("facing", "south", "half", "upper", "hinge", "left", "open", "true", "powered", "false"))
|
| 483 | );
|
| 484 | map.put(
|
| 485 | "minecraft:" + type + "southupperlefttruetrue",
|
| 486 | ChunkPalettedStorageFix.legacyBlockState(id, Map.of("facing", "south", "half", "upper", "hinge", "left", "open", "true", "powered", "true"))
|
| 487 | );
|
| 488 | map.put(
|
| 489 | "minecraft:" + type + "southupperrightfalsefalse",
|
| 490 | ChunkPalettedStorageFix.legacyBlockState(id, Map.of("facing", "south", "half", "upper", "hinge", "right", "open", "false", "powered", "false"))
|
| 491 | );
|
| 492 | map.put(
|
| 493 | "minecraft:" + type + "southupperrightfalsetrue",
|
| 494 | ChunkPalettedStorageFix.legacyBlockState(id, Map.of("facing", "south", "half", "upper", "hinge", "right", "open", "false", "powered", "true"))
|
| 495 | );
|
| 496 | map.put(
|
| 497 | "minecraft:" + type + "southupperrighttruefalse",
|
| 498 | ChunkPalettedStorageFix.legacyBlockState(id, Map.of("facing", "south", "half", "upper", "hinge", "right", "open", "true", "powered", "false"))
|
| 499 | );
|
| 500 | map.put(
|
| 501 | "minecraft:" + type + "southupperrighttruetrue",
|
| 502 | ChunkPalettedStorageFix.legacyBlockState(id, Map.of("facing", "south", "half", "upper", "hinge", "right", "open", "true", "powered", "true"))
|
| 503 | );
|
| 504 | map.put(
|
| 505 | "minecraft:" + type + "westlowerleftfalsefalse",
|
| 506 | ChunkPalettedStorageFix.legacyBlockState(id, Map.of("facing", "west", "half", "lower", "hinge", "left", "open", "false", "powered", "false"))
|
| 507 | );
|
| 508 | map.put(
|
| 509 | "minecraft:" + type + "westlowerleftfalsetrue",
|
| 510 | ChunkPalettedStorageFix.legacyBlockState(id, Map.of("facing", "west", "half", "lower", "hinge", "left", "open", "false", "powered", "true"))
|
| 511 | );
|
| 512 | map.put(
|
| 513 | "minecraft:" + type + "westlowerlefttruefalse",
|
| 514 | ChunkPalettedStorageFix.legacyBlockState(id, Map.of("facing", "west", "half", "lower", "hinge", "left", "open", "true", "powered", "false"))
|
| 515 | );
|
| 516 | map.put(
|
| 517 | "minecraft:" + type + "westlowerlefttruetrue",
|
| 518 | ChunkPalettedStorageFix.legacyBlockState(id, Map.of("facing", "west", "half", "lower", "hinge", "left", "open", "true", "powered", "true"))
|
| 519 | );
|
| 520 | map.put(
|
| 521 | "minecraft:" + type + "westlowerrightfalsefalse",
|
| 522 | ChunkPalettedStorageFix.legacyBlockState(id, Map.of("facing", "west", "half", "lower", "hinge", "right", "open", "false", "powered", "false"))
|
| 523 | );
|
| 524 | map.put(
|
| 525 | "minecraft:" + type + "westlowerrightfalsetrue",
|
| 526 | ChunkPalettedStorageFix.legacyBlockState(id, Map.of("facing", "west", "half", "lower", "hinge", "right", "open", "false", "powered", "true"))
|
| 527 | );
|
| 528 | map.put(
|
| 529 | "minecraft:" + type + "westlowerrighttruefalse",
|
| 530 | ChunkPalettedStorageFix.legacyBlockState(id, Map.of("facing", "west", "half", "lower", "hinge", "right", "open", "true", "powered", "false"))
|
| 531 | );
|
| 532 | map.put(
|
| 533 | "minecraft:" + type + "westlowerrighttruetrue",
|
| 534 | ChunkPalettedStorageFix.legacyBlockState(id, Map.of("facing", "west", "half", "lower", "hinge", "right", "open", "true", "powered", "true"))
|
| 535 | );
|
| 536 | map.put(
|
| 537 | "minecraft:" + type + "westupperleftfalsefalse",
|
| 538 | ChunkPalettedStorageFix.legacyBlockState(id, Map.of("facing", "west", "half", "upper", "hinge", "left", "open", "false", "powered", "false"))
|
| 539 | );
|
| 540 | map.put(
|
| 541 | "minecraft:" + type + "westupperleftfalsetrue",
|
| 542 | ChunkPalettedStorageFix.legacyBlockState(id, Map.of("facing", "west", "half", "upper", "hinge", "left", "open", "false", "powered", "true"))
|
| 543 | );
|
| 544 | map.put(
|
| 545 | "minecraft:" + type + "westupperlefttruefalse",
|
| 546 | ChunkPalettedStorageFix.legacyBlockState(id, Map.of("facing", "west", "half", "upper", "hinge", "left", "open", "true", "powered", "false"))
|
| 547 | );
|
| 548 | map.put(
|
| 549 | "minecraft:" + type + "westupperlefttruetrue",
|
| 550 | ChunkPalettedStorageFix.legacyBlockState(id, Map.of("facing", "west", "half", "upper", "hinge", "left", "open", "true", "powered", "true"))
|
| 551 | );
|
| 552 | map.put(
|
| 553 | "minecraft:" + type + "westupperrightfalsefalse",
|
| 554 | ChunkPalettedStorageFix.legacyBlockState(id, Map.of("facing", "west", "half", "upper", "hinge", "right", "open", "false", "powered", "false"))
|
| 555 | );
|
| 556 | map.put(
|
| 557 | "minecraft:" + type + "westupperrightfalsetrue",
|
| 558 | ChunkPalettedStorageFix.legacyBlockState(id, Map.of("facing", "west", "half", "upper", "hinge", "right", "open", "false", "powered", "true"))
|
| 559 | );
|
| 560 | map.put(
|
| 561 | "minecraft:" + type + "westupperrighttruefalse",
|
| 562 | ChunkPalettedStorageFix.legacyBlockState(id, Map.of("facing", "west", "half", "upper", "hinge", "right", "open", "true", "powered", "false"))
|
| 563 | );
|
| 564 | map.put(
|
| 565 | "minecraft:" + type + "westupperrighttruetrue",
|
| 566 | ChunkPalettedStorageFix.legacyBlockState(id, Map.of("facing", "west", "half", "upper", "hinge", "right", "open", "true", "powered", "true"))
|
| 567 | );
|
| 568 | }
|
| 569 |
|
| 570 | private static void addBeds(final Map<String, Dynamic<?>> map, final int colorId, final String color) {
|
| 571 | map.put(
|
| 572 | "southfalsefoot" + colorId,
|
| 573 | ChunkPalettedStorageFix.legacyBlockState("minecraft:" + color + "_bed", Map.of("facing", "south", "occupied", "false", "part", "foot"))
|
| 574 | );
|
| 575 | map.put(
|
| 576 | "westfalsefoot" + colorId,
|
| 577 | ChunkPalettedStorageFix.legacyBlockState("minecraft:" + color + "_bed", Map.of("facing", "west", "occupied", "false", "part", "foot"))
|
| 578 | );
|
| 579 | map.put(
|
| 580 | "northfalsefoot" + colorId,
|
| 581 | ChunkPalettedStorageFix.legacyBlockState("minecraft:" + color + "_bed", Map.of("facing", "north", "occupied", "false", "part", "foot"))
|
| 582 | );
|
| 583 | map.put(
|
| 584 | "eastfalsefoot" + colorId,
|
| 585 | ChunkPalettedStorageFix.legacyBlockState("minecraft:" + color + "_bed", Map.of("facing", "east", "occupied", "false", "part", "foot"))
|
| 586 | );
|
| 587 | map.put(
|
| 588 | "southfalsehead" + colorId,
|
| 589 | ChunkPalettedStorageFix.legacyBlockState("minecraft:" + color + "_bed", Map.of("facing", "south", "occupied", "false", "part", "head"))
|
| 590 | );
|
| 591 | map.put(
|
| 592 | "westfalsehead" + colorId,
|
| 593 | ChunkPalettedStorageFix.legacyBlockState("minecraft:" + color + "_bed", Map.of("facing", "west", "occupied", "false", "part", "head"))
|
| 594 | );
|
| 595 | map.put(
|
| 596 | "northfalsehead" + colorId,
|
| 597 | ChunkPalettedStorageFix.legacyBlockState("minecraft:" + color + "_bed", Map.of("facing", "north", "occupied", "false", "part", "head"))
|
| 598 | );
|
| 599 | map.put(
|
| 600 | "eastfalsehead" + colorId,
|
| 601 | ChunkPalettedStorageFix.legacyBlockState("minecraft:" + color + "_bed", Map.of("facing", "east", "occupied", "false", "part", "head"))
|
| 602 | );
|
| 603 | map.put(
|
| 604 | "southtruehead" + colorId,
|
| 605 | ChunkPalettedStorageFix.legacyBlockState("minecraft:" + color + "_bed", Map.of("facing", "south", "occupied", "true", "part", "head"))
|
| 606 | );
|
| 607 | map.put(
|
| 608 | "westtruehead" + colorId,
|
| 609 | ChunkPalettedStorageFix.legacyBlockState("minecraft:" + color + "_bed", Map.of("facing", "west", "occupied", "true", "part", "head"))
|
| 610 | );
|
| 611 | map.put(
|
| 612 | "northtruehead" + colorId,
|
| 613 | ChunkPalettedStorageFix.legacyBlockState("minecraft:" + color + "_bed", Map.of("facing", "north", "occupied", "true", "part", "head"))
|
| 614 | );
|
| 615 | map.put(
|
| 616 | "easttruehead" + colorId,
|
| 617 | ChunkPalettedStorageFix.legacyBlockState("minecraft:" + color + "_bed", Map.of("facing", "east", "occupied", "true", "part", "head"))
|
| 618 | );
|
| 619 | }
|
| 620 |
|
| 621 | private static void addBanners(final Map<String, Dynamic<?>> map, final int colorId, final String color) {
|
| 622 | for (int i = 0; i < 16; i++) {
|
| 623 | map.put(i + "_" + colorId, ChunkPalettedStorageFix.legacyBlockState("minecraft:" + color + "_banner", Map.of("rotation", String.valueOf(i))));
|
| 624 | }
|
| 625 |
|
| 626 | map.put("north_" + colorId, ChunkPalettedStorageFix.legacyBlockState("minecraft:" + color + "_wall_banner", Map.of("facing", "north")));
|
| 627 | map.put("south_" + colorId, ChunkPalettedStorageFix.legacyBlockState("minecraft:" + color + "_wall_banner", Map.of("facing", "south")));
|
| 628 | map.put("west_" + colorId, ChunkPalettedStorageFix.legacyBlockState("minecraft:" + color + "_wall_banner", Map.of("facing", "west")));
|
| 629 | map.put("east_" + colorId, ChunkPalettedStorageFix.legacyBlockState("minecraft:" + color + "_wall_banner", Map.of("facing", "east")));
|
| 630 | }
|
| 631 |
|
| 632 | static {
|
| 633 | FIX.set(2);
|
| 634 | FIX.set(3);
|
| 635 | FIX.set(110);
|
| 636 | FIX.set(140);
|
| 637 | FIX.set(144);
|
| 638 | FIX.set(25);
|
| 639 | FIX.set(86);
|
| 640 | FIX.set(26);
|
| 641 | FIX.set(176);
|
| 642 | FIX.set(177);
|
| 643 | FIX.set(175);
|
| 644 | FIX.set(64);
|
| 645 | FIX.set(71);
|
| 646 | FIX.set(193);
|
| 647 | FIX.set(194);
|
| 648 | FIX.set(195);
|
| 649 | FIX.set(196);
|
| 650 | FIX.set(197);
|
| 651 | VIRTUAL.set(54);
|
| 652 | VIRTUAL.set(146);
|
| 653 | VIRTUAL.set(25);
|
| 654 | VIRTUAL.set(26);
|
| 655 | VIRTUAL.set(51);
|
| 656 | VIRTUAL.set(53);
|
| 657 | VIRTUAL.set(67);
|
| 658 | VIRTUAL.set(108);
|
| 659 | VIRTUAL.set(109);
|
| 660 | VIRTUAL.set(114);
|
| 661 | VIRTUAL.set(128);
|
| 662 | VIRTUAL.set(134);
|
| 663 | VIRTUAL.set(135);
|
| 664 | VIRTUAL.set(136);
|
| 665 | VIRTUAL.set(156);
|
| 666 | VIRTUAL.set(163);
|
| 667 | VIRTUAL.set(164);
|
| 668 | VIRTUAL.set(180);
|
| 669 | VIRTUAL.set(203);
|
| 670 | VIRTUAL.set(55);
|
| 671 | VIRTUAL.set(85);
|
| 672 | VIRTUAL.set(113);
|
| 673 | VIRTUAL.set(188);
|
| 674 | VIRTUAL.set(189);
|
| 675 | VIRTUAL.set(190);
|
| 676 | VIRTUAL.set(191);
|
| 677 | VIRTUAL.set(192);
|
| 678 | VIRTUAL.set(93);
|
| 679 | VIRTUAL.set(94);
|
| 680 | VIRTUAL.set(101);
|
| 681 | VIRTUAL.set(102);
|
| 682 | VIRTUAL.set(160);
|
| 683 | VIRTUAL.set(106);
|
| 684 | VIRTUAL.set(107);
|
| 685 | VIRTUAL.set(183);
|
| 686 | VIRTUAL.set(184);
|
| 687 | VIRTUAL.set(185);
|
| 688 | VIRTUAL.set(186);
|
| 689 | VIRTUAL.set(187);
|
| 690 | VIRTUAL.set(132);
|
| 691 | VIRTUAL.set(139);
|
| 692 | VIRTUAL.set(199);
|
| 693 | }
|
| 694 | }
|
| 695 |
|
| 696 | private static class Section {
|
| 697 | private final CrudeIncrementalIntIdentityHashBiMap<Dynamic<?>> palette = CrudeIncrementalIntIdentityHashBiMap.create(32);
|
| 698 | private final List<Dynamic<?>> listTag;
|
| 699 | private final Dynamic<?> section;
|
| 700 | private final boolean hasData;
|
| 701 | private final Int2ObjectMap<IntList> toFix = new Int2ObjectLinkedOpenHashMap<>();
|
| 702 | private final IntList update = new IntArrayList();
|
| 703 | public final int y;
|
| 704 | private final Set<Dynamic<?>> seen = Sets.newIdentityHashSet();
|
| 705 | private final int[] buffer = new int[4096];
|
| 706 |
|
| 707 | public Section(final Dynamic<?> section) {
|
| 708 | this.listTag = Lists.newArrayList();
|
| 709 | this.section = section;
|
| 710 | this.y = section.get("Y").asInt(0);
|
| 711 | this.hasData = section.get("Blocks").result().isPresent();
|
| 712 | }
|
| 713 |
|
| 714 | public Dynamic<?> getBlock(final int pos) {
|
| 715 | if (pos >= 0 && pos <= 4095) {
|
| 716 | Dynamic<?> tag = this.palette.byId(this.buffer[pos]);
|
| 717 | return tag == null ? ChunkPalettedStorageFix.MappingConstants.AIR : tag;
|
| 718 | } else {
|
| 719 | return ChunkPalettedStorageFix.MappingConstants.AIR;
|
| 720 | }
|
| 721 | }
|
| 722 |
|
| 723 | public void setBlock(final int idx, final Dynamic<?> blockState) {
|
| 724 | if (this.seen.add(blockState)) {
|
| 725 | this.listTag.add("%%FILTER_ME%%".equals(ChunkPalettedStorageFix.getName(blockState)) ? ChunkPalettedStorageFix.MappingConstants.AIR : blockState);
|
| 726 | }
|
| 727 |
|
| 728 | this.buffer[idx] = ChunkPalettedStorageFix.idFor(this.palette, blockState);
|
| 729 | }
|
| 730 |
|
| 731 | public int upgrade(int sides) {
|
| 732 | if (!this.hasData) {
|
| 733 | return sides;
|
| 734 | }
|
| 735 |
|
| 736 | ByteBuffer blocks = this.section.get("Blocks").asByteBufferOpt().result().get();
|
| 737 | ChunkPalettedStorageFix.DataLayer data = this.section
|
| 738 | .get("Data")
|
| 739 | .asByteBufferOpt()
|
| 740 | .map(buffer -> new ChunkPalettedStorageFix.DataLayer(DataFixUtils.toArray(buffer)))
|
| 741 | .result()
|
| 742 | .orElseGet(ChunkPalettedStorageFix.DataLayer::new);
|
| 743 | ChunkPalettedStorageFix.DataLayer addBlocks = this.section
|
| 744 | .get("Add")
|
| 745 | .asByteBufferOpt()
|
| 746 | .map(buffer -> new ChunkPalettedStorageFix.DataLayer(DataFixUtils.toArray(buffer)))
|
| 747 | .result()
|
| 748 | .orElseGet(ChunkPalettedStorageFix.DataLayer::new);
|
| 749 | this.seen.add(ChunkPalettedStorageFix.MappingConstants.AIR);
|
| 750 | ChunkPalettedStorageFix.idFor(this.palette, ChunkPalettedStorageFix.MappingConstants.AIR);
|
| 751 | this.listTag.add(ChunkPalettedStorageFix.MappingConstants.AIR);
|
| 752 |
|
| 753 | for (int idx = 0; idx < 4096; idx++) {
|
| 754 | int xx = idx & 15;
|
| 755 | int yy = idx >> 8 & 15;
|
| 756 | int zz = idx >> 4 & 15;
|
| 757 | int id = addBlocks.get(xx, yy, zz) << 12 | (blocks.get(idx) & 255) << 4 | data.get(xx, yy, zz);
|
| 758 | if (ChunkPalettedStorageFix.MappingConstants.FIX.get(id >> 4)) {
|
| 759 | this.addFix(id >> 4, idx);
|
| 760 | }
|
| 761 |
|
| 762 | if (ChunkPalettedStorageFix.MappingConstants.VIRTUAL.get(id >> 4)) {
|
| 763 | int s = ChunkPalettedStorageFix.getSideMask(xx == 0, xx == 15, zz == 0, zz == 15);
|
| 764 | if (s == 0) {
|
| 765 | this.update.add(idx);
|
| 766 | } else {
|
| 767 | sides |= s;
|
| 768 | }
|
| 769 | }
|
| 770 |
|
| 771 | this.setBlock(idx, BlockStateData.getTag(id));
|
| 772 | }
|
| 773 |
|
| 774 | return sides;
|
| 775 | }
|
| 776 |
|
| 777 | private void addFix(final int id, final int position) {
|
| 778 | IntList list = this.toFix.get(id);
|
| 779 | if (list == null) {
|
| 780 | list = new IntArrayList();
|
| 781 | this.toFix.put(id, list);
|
| 782 | }
|
| 783 |
|
| 784 | list.add(position);
|
| 785 | }
|
| 786 |
|
| 787 | public Dynamic<?> write() {
|
| 788 | Dynamic<?> section = this.section;
|
| 789 | if (!this.hasData) {
|
| 790 | return section;
|
| 791 | }
|
| 792 |
|
| 793 | section = section.set("Palette", section.createList(this.listTag.stream()));
|
| 794 | int size = Math.max(4, DataFixUtils.ceillog2(this.seen.size()));
|
| 795 | PackedBitStorage storage = new PackedBitStorage(size, 4096);
|
| 796 |
|
| 797 | for (int j = 0; j < this.buffer.length; j++) {
|
| 798 | storage.set(j, this.buffer[j]);
|
| 799 | }
|
| 800 |
|
| 801 | section = section.set("BlockStates", section.createLongList(Arrays.stream(storage.getRaw())));
|
| 802 | section = section.remove("Blocks");
|
| 803 | section = section.remove("Data");
|
| 804 | return section.remove("Add");
|
| 805 | }
|
| 806 | }
|
| 807 |
|
| 808 | private static final class UpgradeChunk {
|
| 809 | private int sides;
|
| 810 | private final ChunkPalettedStorageFix.@Nullable Section[] sections = new ChunkPalettedStorageFix.Section[16];
|
| 811 | private final Dynamic<?> level;
|
| 812 | private final int x;
|
| 813 | private final int z;
|
| 814 | private final Int2ObjectMap<Dynamic<?>> blockEntities = new Int2ObjectLinkedOpenHashMap<>(16);
|
| 815 |
|
| 816 | public UpgradeChunk(final Dynamic<?> level) {
|
| 817 | this.level = level;
|
| 818 | this.x = level.get("xPos").asInt(0) << 4;
|
| 819 | this.z = level.get("zPos").asInt(0) << 4;
|
| 820 | level.get("TileEntities").asStreamOpt().ifSuccess(s -> s.forEach(entity -> {
|
| 821 | int x = entity.get("x").asInt(0) - this.x & 15;
|
| 822 | int y = entity.get("y").asInt(0);
|
| 823 | int z = entity.get("z").asInt(0) - this.z & 15;
|
| 824 | int key = y << 8 | z << 4 | x;
|
| 825 | if (this.blockEntities.put(key, (Dynamic<?>)entity) != null) {
|
| 826 | ChunkPalettedStorageFix.LOGGER.warn("In chunk: {}x{} found a duplicate block entity at position: [{}, {}, {}]", this.x, this.z, x, y, z);
|
| 827 | }
|
| 828 | }));
|
| 829 | boolean convertedFromAlphaFormat = level.get("convertedFromAlphaFormat").asBoolean(false);
|
| 830 | level.get("Sections").asStreamOpt().ifSuccess(s -> s.forEach(sec -> {
|
| 831 | ChunkPalettedStorageFix.Section sectionx = new ChunkPalettedStorageFix.Section((Dynamic<?>)sec);
|
| 832 | this.sides = sectionx.upgrade(this.sides);
|
| 833 | this.sections[sectionx.y] = sectionx;
|
| 834 | }));
|
| 835 |
|
| 836 | for (ChunkPalettedStorageFix.Section section : this.sections) {
|
| 837 | if (section != null) {
|
| 838 | for (Entry<IntList> entry : section.toFix.int2ObjectEntrySet()) {
|
| 839 | int dy = section.y << 12;
|
| 840 | switch (entry.getIntKey()) {
|
| 841 | case 2:
|
| 842 | for (int pos : entry.getValue()) {
|
| 843 | pos |= dy;
|
| 844 | Dynamic<?> state = this.getBlock(pos);
|
| 845 | if ("minecraft:grass_block".equals(ChunkPalettedStorageFix.getName(state))) {
|
| 846 | String name = ChunkPalettedStorageFix.getName(this.getBlock(relative(pos, ChunkPalettedStorageFix.Direction.UP)));
|
| 847 | if ("minecraft:snow".equals(name) || "minecraft:snow_layer".equals(name)) {
|
| 848 | this.setBlock(pos, ChunkPalettedStorageFix.MappingConstants.SNOWY_GRASS);
|
| 849 | }
|
| 850 | }
|
| 851 | }
|
| 852 | break;
|
| 853 | case 3:
|
| 854 | for (int pos : entry.getValue()) {
|
| 855 | pos |= dy;
|
| 856 | Dynamic<?> state = this.getBlock(pos);
|
| 857 | if ("minecraft:podzol".equals(ChunkPalettedStorageFix.getName(state))) {
|
| 858 | String name = ChunkPalettedStorageFix.getName(this.getBlock(relative(pos, ChunkPalettedStorageFix.Direction.UP)));
|
| 859 | if ("minecraft:snow".equals(name) || "minecraft:snow_layer".equals(name)) {
|
| 860 | this.setBlock(pos, ChunkPalettedStorageFix.MappingConstants.SNOWY_PODZOL);
|
| 861 | }
|
| 862 | }
|
| 863 | }
|
| 864 | break;
|
| 865 | case 25:
|
| 866 | for (int pos : entry.getValue()) {
|
| 867 | pos |= dy;
|
| 868 | Dynamic<?> entity = this.removeBlockEntity(pos);
|
| 869 | if (entity != null) {
|
| 870 | String key = Boolean.toString(entity.get("powered").asBoolean(false)) + (byte)Math.min(Math.max(entity.get("note").asInt(0), 0), 24);
|
| 871 | this.setBlock(
|
| 872 | pos,
|
| 873 | ChunkPalettedStorageFix.MappingConstants.NOTE_BLOCK_MAP.getOrDefault(key, ChunkPalettedStorageFix.MappingConstants.NOTE_BLOCK_MAP.get("false0"))
|
| 874 | );
|
| 875 | }
|
| 876 | }
|
| 877 | break;
|
| 878 | case 26:
|
| 879 | for (int pos : entry.getValue()) {
|
| 880 | pos |= dy;
|
| 881 | Dynamic<?> entity = this.getBlockEntity(pos);
|
| 882 | Dynamic<?> state = this.getBlock(pos);
|
| 883 | if (entity != null) {
|
| 884 | int color = entity.get("color").asInt(0);
|
| 885 | if (color != 14 && color >= 0 && color < 16) {
|
| 886 | String key = ChunkPalettedStorageFix.getProperty(state, "facing")
|
| 887 | + ChunkPalettedStorageFix.getProperty(state, "occupied")
|
| 888 | + ChunkPalettedStorageFix.getProperty(state, "part")
|
| 889 | + color;
|
| 890 | if (ChunkPalettedStorageFix.MappingConstants.BED_BLOCK_MAP.containsKey(key)) {
|
| 891 | this.setBlock(pos, ChunkPalettedStorageFix.MappingConstants.BED_BLOCK_MAP.get(key));
|
| 892 | }
|
| 893 | }
|
| 894 | }
|
| 895 | }
|
| 896 | break;
|
| 897 | case 64:
|
| 898 | case 71:
|
| 899 | case 193:
|
| 900 | case 194:
|
| 901 | case 195:
|
| 902 | case 196:
|
| 903 | case 197:
|
| 904 | for (int pos : entry.getValue()) {
|
| 905 | pos |= dy;
|
| 906 | Dynamic<?> state = this.getBlock(pos);
|
| 907 | if (ChunkPalettedStorageFix.getName(state).endsWith("_door")) {
|
| 908 | Dynamic<?> lower = this.getBlock(pos);
|
| 909 | if ("lower".equals(ChunkPalettedStorageFix.getProperty(lower, "half"))) {
|
| 910 | int abovePos = relative(pos, ChunkPalettedStorageFix.Direction.UP);
|
| 911 | Dynamic<?> upper = this.getBlock(abovePos);
|
| 912 | String name = ChunkPalettedStorageFix.getName(lower);
|
| 913 | if (name.equals(ChunkPalettedStorageFix.getName(upper))) {
|
| 914 | String facing = ChunkPalettedStorageFix.getProperty(lower, "facing");
|
| 915 | String open = ChunkPalettedStorageFix.getProperty(lower, "open");
|
| 916 | String hinge = convertedFromAlphaFormat ? "left" : ChunkPalettedStorageFix.getProperty(upper, "hinge");
|
| 917 | String powered = convertedFromAlphaFormat ? "false" : ChunkPalettedStorageFix.getProperty(upper, "powered");
|
| 918 | this.setBlock(pos, ChunkPalettedStorageFix.MappingConstants.DOOR_MAP.get(name + facing + "lower" + hinge + open + powered));
|
| 919 | this.setBlock(abovePos, ChunkPalettedStorageFix.MappingConstants.DOOR_MAP.get(name + facing + "upper" + hinge + open + powered));
|
| 920 | }
|
| 921 | }
|
| 922 | }
|
| 923 | }
|
| 924 | break;
|
| 925 | case 86:
|
| 926 | for (int pos : entry.getValue()) {
|
| 927 | pos |= dy;
|
| 928 | Dynamic<?> state = this.getBlock(pos);
|
| 929 | if ("minecraft:carved_pumpkin".equals(ChunkPalettedStorageFix.getName(state))) {
|
| 930 | String name = ChunkPalettedStorageFix.getName(this.getBlock(relative(pos, ChunkPalettedStorageFix.Direction.DOWN)));
|
| 931 | if ("minecraft:grass_block".equals(name) || "minecraft:dirt".equals(name)) {
|
| 932 | this.setBlock(pos, ChunkPalettedStorageFix.MappingConstants.PUMPKIN);
|
| 933 | }
|
| 934 | }
|
| 935 | }
|
| 936 | break;
|
| 937 | case 110:
|
| 938 | for (int pos : entry.getValue()) {
|
| 939 | pos |= dy;
|
| 940 | Dynamic<?> state = this.getBlock(pos);
|
| 941 | if ("minecraft:mycelium".equals(ChunkPalettedStorageFix.getName(state))) {
|
| 942 | String name = ChunkPalettedStorageFix.getName(this.getBlock(relative(pos, ChunkPalettedStorageFix.Direction.UP)));
|
| 943 | if ("minecraft:snow".equals(name) || "minecraft:snow_layer".equals(name)) {
|
| 944 | this.setBlock(pos, ChunkPalettedStorageFix.MappingConstants.SNOWY_MYCELIUM);
|
| 945 | }
|
| 946 | }
|
| 947 | }
|
| 948 | break;
|
| 949 | case 140:
|
| 950 | for (int pos : entry.getValue()) {
|
| 951 | pos |= dy;
|
| 952 | Dynamic<?> entity = this.removeBlockEntity(pos);
|
| 953 | if (entity != null) {
|
| 954 | String key = entity.get("Item").asString("") + entity.get("Data").asInt(0);
|
| 955 | this.setBlock(
|
| 956 | pos,
|
| 957 | ChunkPalettedStorageFix.MappingConstants.FLOWER_POT_MAP
|
| 958 | .getOrDefault(key, ChunkPalettedStorageFix.MappingConstants.FLOWER_POT_MAP.get("minecraft:air0"))
|
| 959 | );
|
| 960 | }
|
| 961 | }
|
| 962 | break;
|
| 963 | case 144:
|
| 964 | for (int pos : entry.getValue()) {
|
| 965 | pos |= dy;
|
| 966 | Dynamic<?> entity = this.getBlockEntity(pos);
|
| 967 | if (entity != null) {
|
| 968 | String type = String.valueOf(entity.get("SkullType").asInt(0));
|
| 969 | String facing = ChunkPalettedStorageFix.getProperty(this.getBlock(pos), "facing");
|
| 970 | String key;
|
| 971 | if (!"up".equals(facing) && !"down".equals(facing)) {
|
| 972 | key = type + facing;
|
| 973 | } else {
|
| 974 | key = type + entity.get("Rot").asInt(0);
|
| 975 | }
|
| 976 |
|
| 977 | entity.remove("SkullType");
|
| 978 | entity.remove("facing");
|
| 979 | entity.remove("Rot");
|
| 980 | this.setBlock(
|
| 981 | pos, ChunkPalettedStorageFix.MappingConstants.SKULL_MAP.getOrDefault(key, ChunkPalettedStorageFix.MappingConstants.SKULL_MAP.get("0north"))
|
| 982 | );
|
| 983 | }
|
| 984 | }
|
| 985 | break;
|
| 986 | case 175:
|
| 987 | for (int pos : entry.getValue()) {
|
| 988 | pos |= dy;
|
| 989 | Dynamic<?> block = this.getBlock(pos);
|
| 990 | if ("upper".equals(ChunkPalettedStorageFix.getProperty(block, "half"))) {
|
| 991 | Dynamic<?> below = this.getBlock(relative(pos, ChunkPalettedStorageFix.Direction.DOWN));
|
| 992 | String variant = ChunkPalettedStorageFix.getName(below);
|
| 993 | switch (variant) {
|
| 994 | case "minecraft:sunflower":
|
| 995 | this.setBlock(pos, ChunkPalettedStorageFix.MappingConstants.UPPER_SUNFLOWER);
|
| 996 | break;
|
| 997 | case "minecraft:lilac":
|
| 998 | this.setBlock(pos, ChunkPalettedStorageFix.MappingConstants.UPPER_LILAC);
|
| 999 | break;
|
| 1000 | case "minecraft:tall_grass":
|
| 1001 | this.setBlock(pos, ChunkPalettedStorageFix.MappingConstants.UPPER_TALL_GRASS);
|
| 1002 | break;
|
| 1003 | case "minecraft:large_fern":
|
| 1004 | this.setBlock(pos, ChunkPalettedStorageFix.MappingConstants.UPPER_LARGE_FERN);
|
| 1005 | break;
|
| 1006 | case "minecraft:rose_bush":
|
| 1007 | this.setBlock(pos, ChunkPalettedStorageFix.MappingConstants.UPPER_ROSE_BUSH);
|
| 1008 | break;
|
| 1009 | case "minecraft:peony":
|
| 1010 | this.setBlock(pos, ChunkPalettedStorageFix.MappingConstants.UPPER_PEONY);
|
| 1011 | }
|
| 1012 | }
|
| 1013 | }
|
| 1014 | break;
|
| 1015 | case 176:
|
| 1016 | case 177:
|
| 1017 | for (int pos : entry.getValue()) {
|
| 1018 | pos |= dy;
|
| 1019 | Dynamic<?> entity = this.getBlockEntity(pos);
|
| 1020 | Dynamic<?> state = this.getBlock(pos);
|
| 1021 | if (entity != null) {
|
| 1022 | int color = entity.get("Base").asInt(0);
|
| 1023 | if (color != 15 && color >= 0 && color < 16) {
|
| 1024 | String key = ChunkPalettedStorageFix.getProperty(state, entry.getIntKey() == 176 ? "rotation" : "facing") + "_" + color;
|
| 1025 | if (ChunkPalettedStorageFix.MappingConstants.BANNER_BLOCK_MAP.containsKey(key)) {
|
| 1026 | this.setBlock(pos, ChunkPalettedStorageFix.MappingConstants.BANNER_BLOCK_MAP.get(key));
|
| 1027 | }
|
| 1028 | }
|
| 1029 | }
|
| 1030 | }
|
| 1031 | }
|
| 1032 | }
|
| 1033 | }
|
| 1034 | }
|
| 1035 | }
|
| 1036 |
|
| 1037 | private @Nullable Dynamic<?> getBlockEntity(final int pos) {
|
| 1038 | return this.blockEntities.get(pos);
|
| 1039 | }
|
| 1040 |
|
| 1041 | private @Nullable Dynamic<?> removeBlockEntity(final int pos) {
|
| 1042 | return this.blockEntities.remove(pos);
|
| 1043 | }
|
| 1044 |
|
| 1045 | public static int relative(final int pos, final ChunkPalettedStorageFix.Direction direction) {
|
| 1046 | return switch (direction.getAxis()) {
|
| 1047 | case X -> {
|
| 1048 | int x = (pos & 15) + direction.getAxisDirection().getStep();
|
| 1049 | yield x >= 0 && x <= 15 ? pos & -16 | x : -1;
|
| 1050 | }
|
| 1051 | case Y -> {
|
| 1052 | int y = (pos >> 8) + direction.getAxisDirection().getStep();
|
| 1053 | yield y >= 0 && y <= 255 ? pos & 0xFF | y << 8 : -1;
|
| 1054 | }
|
| 1055 | case Z -> {
|
| 1056 | int z = (pos >> 4 & 15) + direction.getAxisDirection().getStep();
|
| 1057 | yield z >= 0 && z <= 15 ? pos & -241 | z << 4 : -1;
|
| 1058 | }
|
| 1059 | };
|
| 1060 | }
|
| 1061 |
|
| 1062 | private void setBlock(final int pos, final Dynamic<?> block) {
|
| 1063 | if (pos >= 0 && pos <= 65535) {
|
| 1064 | ChunkPalettedStorageFix.Section section = this.getSection(pos);
|
| 1065 | if (section != null) {
|
| 1066 | section.setBlock(pos & 4095, block);
|
| 1067 | }
|
| 1068 | }
|
| 1069 | }
|
| 1070 |
|
| 1071 | private ChunkPalettedStorageFix.@Nullable Section getSection(final int pos) {
|
| 1072 | int sectionY = pos >> 12;
|
| 1073 | return sectionY < this.sections.length ? this.sections[sectionY] : null;
|
| 1074 | }
|
| 1075 |
|
| 1076 | public Dynamic<?> getBlock(final int pos) {
|
| 1077 | if (pos >= 0 && pos <= 65535) {
|
| 1078 | ChunkPalettedStorageFix.Section section = this.getSection(pos);
|
| 1079 | return section == null ? ChunkPalettedStorageFix.MappingConstants.AIR : section.getBlock(pos & 4095);
|
| 1080 | } else {
|
| 1081 | return ChunkPalettedStorageFix.MappingConstants.AIR;
|
| 1082 | }
|
| 1083 | }
|
| 1084 |
|
| 1085 | public Dynamic<?> write() {
|
| 1086 | Dynamic<?> level = this.level;
|
| 1087 | if (this.blockEntities.isEmpty()) {
|
| 1088 | level = level.remove("TileEntities");
|
| 1089 | } else {
|
| 1090 | level = level.set("TileEntities", level.createList(this.blockEntities.values().stream()));
|
| 1091 | }
|
| 1092 |
|
| 1093 | Dynamic<?> indices = level.emptyMap();
|
| 1094 | List<Dynamic<?>> sections = Lists.newArrayList();
|
| 1095 |
|
| 1096 | for (ChunkPalettedStorageFix.Section section : this.sections) {
|
| 1097 | if (section != null) {
|
| 1098 | sections.add(section.write());
|
| 1099 | indices = indices.set(String.valueOf(section.y), indices.createIntList(Arrays.stream(section.update.toIntArray())));
|
| 1100 | }
|
| 1101 | }
|
| 1102 |
|
| 1103 | Dynamic<?> tag = level.emptyMap();
|
| 1104 | tag = tag.set("Sides", tag.createByte((byte)this.sides));
|
| 1105 | tag = tag.set("Indices", indices);
|
| 1106 | return level.set("UpgradeData", tag).set("Sections", tag.createList(sections.stream()));
|
| 1107 | }
|
| 1108 | }
|
| 1109 | }
|
| 1110 |
|