Remove more reflection

This commit is contained in:
2026-05-16 13:46:42 +02:00
parent 9e4c9ce04a
commit ab3970981d
@@ -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<BlockState> registryBlockId = (Iterable<BlockState>) Reflection.getField(TechHider.block, IdMapper.class, 0).get(null);
public Set<Integer> materialToAllIds(Material material) {
Set<Integer> 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);
}
}