forked from SteamWar/SteamWar
Remove more reflection
This commit is contained in:
@@ -19,9 +19,10 @@
|
|||||||
|
|
||||||
package de.steamwar.techhider;
|
package de.steamwar.techhider;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableList;
|
|
||||||
import de.steamwar.Reflection;
|
import de.steamwar.Reflection;
|
||||||
import net.minecraft.core.IdMapper;
|
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.block.state.StateDefinition;
|
||||||
import net.minecraft.world.level.material.FlowingFluid;
|
import net.minecraft.world.level.material.FlowingFluid;
|
||||||
import net.minecraft.world.level.material.FluidState;
|
import net.minecraft.world.level.material.FluidState;
|
||||||
@@ -35,31 +36,21 @@ import java.util.Set;
|
|||||||
public class BlockIds {
|
public class BlockIds {
|
||||||
public static final BlockIds impl = new 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) {
|
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 FluidState water = Fluids.WATER.getSource(false);
|
||||||
private static final Reflection.Method getStateList = Reflection.getTypedMethod(blockStateList, null, ImmutableList.class);
|
private static final Iterable<BlockState> registryBlockId = (Iterable<BlockState>) Reflection.getField(TechHider.block, IdMapper.class, 0).get(null);
|
||||||
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);
|
|
||||||
public Set<Integer> materialToAllIds(Material material) {
|
public Set<Integer> materialToAllIds(Material material) {
|
||||||
Set<Integer> ids = new HashSet<>();
|
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));
|
ids.add(getCombinedId(data));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(material == Material.WATER) {
|
if(material == Material.WATER) {
|
||||||
for(Object data : registryBlockId) {
|
for(BlockState data : registryBlockId) {
|
||||||
if(getFluid.invoke(data) == water) {
|
if (data.getFluidState() == water) {
|
||||||
ids.add(getCombinedId(data));
|
ids.add(getCombinedId(data));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -68,11 +59,11 @@ public class BlockIds {
|
|||||||
return ids;
|
return ids;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Object getBlock(Material material) {
|
private Block getBlock(Material material) {
|
||||||
return CraftMagicNumbers.getBlock(material);
|
return CraftMagicNumbers.getBlock(material);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getCombinedId(Object blockData) {
|
public int getCombinedId(BlockState blockData) {
|
||||||
return (int) getCombinedId.invoke(null, blockData);
|
return Block.getId(blockData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user