From ab3970981d28201b018163a9ba6edb68f751bbb4 Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Sat, 16 May 2026 13:46:42 +0200 Subject: [PATCH] Remove more reflection --- .../src/de/steamwar/techhider/BlockIds.java | 31 +++++++------------ 1 file changed, 11 insertions(+), 20 deletions(-) diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/techhider/BlockIds.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/techhider/BlockIds.java index b5cc352c..93ac2bda 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/techhider/BlockIds.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/techhider/BlockIds.java @@ -19,9 +19,10 @@ package de.steamwar.techhider; -import com.google.common.collect.ImmutableList; import de.steamwar.Reflection; import net.minecraft.core.IdMapper; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.StateDefinition; import net.minecraft.world.level.material.FlowingFluid; import net.minecraft.world.level.material.FluidState; @@ -35,31 +36,21 @@ import java.util.Set; public class BlockIds { public static final BlockIds impl = new BlockIds(); - Reflection.Method getCombinedId = Reflection.getTypedMethod(TechHider.block, null, int.class, TechHider.iBlockData); - - private static final Class blockStateList = StateDefinition.class; - private static final Class fluidTypeFlowing = FlowingFluid.class; - private static final Class fluid = FluidState.class; - - private static final Reflection.Method getBlockData = Reflection.getTypedMethod(TechHider.block, null, TechHider.iBlockData); public int materialToId(Material material) { - return getCombinedId(getBlockData.invoke(getBlock(material))); + return getCombinedId(getBlock(material).defaultBlockState()); } - private static final Reflection.Method getStates = Reflection.getTypedMethod(TechHider.block, null, blockStateList); - private static final Reflection.Method getStateList = Reflection.getTypedMethod(blockStateList, null, ImmutableList.class); - private static final Object water = Reflection.getTypedMethod(fluidTypeFlowing, null, fluid, boolean.class).invoke(Reflection.getField(Fluids.class, fluidTypeFlowing, 1).get(null), false); - private static final Iterable registryBlockId = (Iterable) Reflection.getField(TechHider.block, IdMapper.class, 0).get(null); - private static final Reflection.Method getFluid = Reflection.getTypedMethod(TechHider.iBlockData, null, fluid); + private static final FluidState water = Fluids.WATER.getSource(false); + private static final Iterable registryBlockId = (Iterable) Reflection.getField(TechHider.block, IdMapper.class, 0).get(null); public Set materialToAllIds(Material material) { Set ids = new HashSet<>(); - for(Object data : (ImmutableList) getStateList.invoke(getStates.invoke(getBlock(material)))) { + for(BlockState data : getBlock(material).getStateDefinition().getPossibleStates()) { ids.add(getCombinedId(data)); } if(material == Material.WATER) { - for(Object data : registryBlockId) { - if(getFluid.invoke(data) == water) { + for(BlockState data : registryBlockId) { + if (data.getFluidState() == water) { ids.add(getCombinedId(data)); } } @@ -68,11 +59,11 @@ public class BlockIds { return ids; } - private Object getBlock(Material material) { + private Block getBlock(Material material) { return CraftMagicNumbers.getBlock(material); } - public int getCombinedId(Object blockData) { - return (int) getCombinedId.invoke(null, blockData); + public int getCombinedId(BlockState blockData) { + return Block.getId(blockData); } }