Skip to content

Commit

Permalink
refactor: use hardcoded versions for StateUpdaters
Browse files Browse the repository at this point in the history
  • Loading branch information
IWareQ committed Feb 13, 2025
1 parent 680c465 commit f7fcf6d
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.allaymc.api.registry.Registries;
import org.allaymc.api.utils.HashUtils;
import org.allaymc.api.utils.Identifier;
import org.allaymc.updater.block.BlockStateUpdater_1_21_40;
import org.allaymc.updater.block.BlockStateUpdaters;
import org.cloudburstmc.nbt.NbtMap;
import org.cloudburstmc.nbt.NbtMapBuilder;
Expand Down Expand Up @@ -134,7 +135,7 @@ public BlockState blockState() {
}

// Get block type
var updatedNbt = BlockStateUpdaters.updateBlockState(nbtBuilder.build(), BlockStateUpdaters.LATEST_VERSION);
var updatedNbt = BlockStateUpdaters.updateBlockState(nbtBuilder.build(), BlockStateUpdater_1_21_40.INSTANCE.getVersion());
var blockType = Registries.BLOCKS.get(new Identifier(updatedNbt.getString("name")));
if (blockType == null) {
throw new IllegalArgumentException("Unknown block type " + updatedNbt.getString("name"));
Expand Down
3 changes: 2 additions & 1 deletion api/src/main/java/org/allaymc/api/item/ItemHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.allaymc.api.item.type.ItemType;
import org.allaymc.api.registry.Registries;
import org.allaymc.api.utils.Identifier;
import org.allaymc.updater.item.ItemStateUpdater_1_21_50;
import org.allaymc.updater.item.ItemStateUpdaters;
import org.cloudburstmc.nbt.NbtMap;

Expand All @@ -35,7 +36,7 @@ public final class ItemHelper {
*/
public static ItemStack fromNBT(NbtMap nbt) {
try {
nbt = ItemStateUpdaters.updateItemState(nbt, ItemStateUpdaters.LATEST_VERSION);
nbt = ItemStateUpdaters.updateItemState(nbt, ItemStateUpdater_1_21_50.INSTANCE.getVersion());
int count = nbt.getByte("Count", (byte) 1);
int meta = nbt.getShort("Damage");
var name = nbt.getString("Name");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import lombok.experimental.UtilityClass;
import org.allaymc.api.registry.Registries;
import org.allaymc.api.utils.Identifier;
import org.allaymc.updater.item.ItemStateUpdater_1_21_50;
import org.allaymc.updater.item.ItemStateUpdaters;
import org.cloudburstmc.nbt.NbtMap;
import org.cloudburstmc.nbt.NbtMapBuilder;
Expand Down Expand Up @@ -71,7 +72,7 @@ public Getter meta(int meta) {
* @return The item type.
*/
public ItemType<?> itemType() {
var updatedNbt = ItemStateUpdaters.updateItemState(nbtMapBuilder.build(), ItemStateUpdaters.LATEST_VERSION);
var updatedNbt = ItemStateUpdaters.updateItemState(nbtMapBuilder.build(), ItemStateUpdater_1_21_50.INSTANCE.getVersion());
var itemType = Registries.ITEMS.get(new Identifier(updatedNbt.getString("Name")));
if (itemType == null) {
throw new IllegalArgumentException("Unknown item type " + updatedNbt.getString("Name"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.allaymc.server.world.AllayWorldData;
import org.allaymc.server.world.chunk.*;
import org.allaymc.server.world.gamerule.AllayGameRules;
import org.allaymc.updater.block.BlockStateUpdater_1_21_40;
import org.allaymc.updater.block.BlockStateUpdaters;
import org.cloudburstmc.nbt.*;
import org.cloudburstmc.nbt.util.stream.LittleEndianDataInputStream;
Expand Down Expand Up @@ -433,7 +434,7 @@ private static BlockState fastBlockStateDeserializer(ByteBuf buffer) {
blockStateHash = PaletteUtils.fastReadBlockStateHash(input, buffer);
if (blockStateHash == PaletteUtils.HASH_NOT_LATEST) {
var oldNbtMap = (NbtMap) nbtInputStream.readTag();
var newNbtMap = BlockStateUpdaters.updateBlockState(oldNbtMap, BlockStateUpdaters.LATEST_VERSION);
var newNbtMap = BlockStateUpdaters.updateBlockState(oldNbtMap, BlockStateUpdater_1_21_40.INSTANCE.getVersion());
// Make sure that tree map is used
// If the map inside states nbt is not tree map
// the block state hash will be wrong!
Expand Down

0 comments on commit f7fcf6d

Please sign in to comment.