From fb457d1b37477d567373d646891e07cde57afa5a Mon Sep 17 00:00:00 2001 From: quat1024 Date: Thu, 15 Jun 2023 01:53:46 -0400 Subject: [PATCH] where we're going we don't need backwards compat --- .../block/entity/TemplateEntity.java | 5 +- .../templates/util/BlockStateUtil.java | 48 ------------------- 2 files changed, 1 insertion(+), 52 deletions(-) delete mode 100644 src/main/java/io/github/cottonmc/templates/util/BlockStateUtil.java diff --git a/src/main/java/io/github/cottonmc/templates/block/entity/TemplateEntity.java b/src/main/java/io/github/cottonmc/templates/block/entity/TemplateEntity.java index 07badad..818b838 100644 --- a/src/main/java/io/github/cottonmc/templates/block/entity/TemplateEntity.java +++ b/src/main/java/io/github/cottonmc/templates/block/entity/TemplateEntity.java @@ -1,10 +1,8 @@ package io.github.cottonmc.templates.block.entity; -import io.github.cottonmc.templates.util.BlockStateUtil; import net.fabricmc.fabric.api.block.entity.BlockEntityClientSerializable; import net.fabricmc.fabric.api.rendering.data.v1.RenderAttachmentBlockEntity; import net.fabricmc.fabric.api.server.PlayerStream; -import net.fabricmc.fabric.api.util.NbtType; import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; @@ -39,8 +37,7 @@ public abstract class TemplateEntity extends BlockEntity implements BlockEntityC @Override public void fromTag(CompoundTag tag) { super.fromTag(tag); - if (tag.contains("BlockState", NbtType.COMPOUND)) renderedState = NbtHelper.toBlockState(tag.getCompound("BlockState")); - else renderedState = BlockStateUtil.fromTag(tag); + renderedState = NbtHelper.toBlockState(tag.getCompound("BlockState")); glowstone = tag.getBoolean("Glowstone"); redstone = tag.getBoolean("Redstone"); if (world != null && world.isClient) { diff --git a/src/main/java/io/github/cottonmc/templates/util/BlockStateUtil.java b/src/main/java/io/github/cottonmc/templates/util/BlockStateUtil.java deleted file mode 100644 index c884bbc..0000000 --- a/src/main/java/io/github/cottonmc/templates/util/BlockStateUtil.java +++ /dev/null @@ -1,48 +0,0 @@ -package io.github.cottonmc.templates.util; - -import net.minecraft.block.Block; -import net.minecraft.block.BlockState; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.state.StateManager; -import net.minecraft.state.property.Property; -import net.minecraft.util.Identifier; -import net.minecraft.util.registry.Registry; - -import java.util.Optional; - -/** - * use {@link net.minecraft.nbt.NbtHelper}, which I should have been using from the start oops - */ -@Deprecated -public class BlockStateUtil { - public static BlockState fromTag(CompoundTag tag) { - Block block = Registry.BLOCK.get(new Identifier(tag.getString("Block"))); - CompoundTag properties = tag.getCompound("Properties"); - StateManager factory = block.getStateManager(); - BlockState state = factory.getDefaultState(); - for (String key : properties.getKeys()) { - Property prop = factory.getProperty(key); - if (prop != null) state = parseProperty(state, prop, properties.getString(key)); - } - return state; - } - - public static CompoundTag toTag(CompoundTag tag, BlockState state) { - tag.putString("Block", Registry.BLOCK.getId(state.getBlock()).toString()); - CompoundTag properties = new CompoundTag(); - for (Property prop : state.getProperties()) { - String value = state.get(prop).toString(); - properties.putString(prop.getName(), value); - } - tag.put("Properties", properties); - return tag; - } - - public static > BlockState parseProperty(BlockState state, Property property, String value) { - Optional optional = property.parse(value); - if (optional.isPresent()) { - state = state.with(property, optional.get()); - } - return state; - } -}