mirror of https://github.com/cabaletta/baritone
Remove normalizations from BlockOptionalMeta
This commit is contained in:
parent
f3d860e8fa
commit
e3d3407de5
|
@ -42,7 +42,6 @@ public final class BlockOptionalMeta {
|
|||
private final ImmutableSet<Integer> stateHashes;
|
||||
private final ImmutableSet<Integer> stackHashes;
|
||||
private static final Pattern pattern = Pattern.compile("^(.+?)(?::(\\d+))?$");
|
||||
private static final Map<Object, Object> normalizations;
|
||||
|
||||
public BlockOptionalMeta(@Nonnull Block block) {
|
||||
this.block = block;
|
||||
|
@ -72,162 +71,6 @@ public final class BlockOptionalMeta {
|
|||
stackHashes = getStackHashes(blockstates);
|
||||
}
|
||||
|
||||
static {
|
||||
Map<Object, Object> _normalizations = new HashMap<>();
|
||||
Consumer<Enum> put = instance -> _normalizations.put(instance.getClass(), instance);
|
||||
put.accept(EnumFacing.NORTH);
|
||||
put.accept(EnumFacing.Axis.Y);
|
||||
put.accept(Half.BOTTOM);
|
||||
put.accept(StairsShape.STRAIGHT);
|
||||
put.accept(AttachFace.FLOOR);
|
||||
put.accept(DoubleBlockHalf.UPPER);
|
||||
put.accept(SlabType.BOTTOM);
|
||||
put.accept(DoorHingeSide.LEFT);
|
||||
put.accept(BedPart.HEAD);
|
||||
put.accept(RailShape.NORTH_SOUTH);
|
||||
_normalizations.put(BlockBanner.ROTATION, 0);
|
||||
_normalizations.put(BlockBed.OCCUPIED, false);
|
||||
_normalizations.put(BlockBrewingStand.HAS_BOTTLE[0], false);
|
||||
_normalizations.put(BlockBrewingStand.HAS_BOTTLE[1], false);
|
||||
_normalizations.put(BlockBrewingStand.HAS_BOTTLE[2], false);
|
||||
_normalizations.put(BlockButton.POWERED, false);
|
||||
// _normalizations.put(BlockCactus.AGE, 0);
|
||||
// _normalizations.put(BlockCauldron.LEVEL, 0);
|
||||
// _normalizations.put(BlockChorusFlower.AGE, 0);
|
||||
_normalizations.put(BlockChorusPlant.NORTH, false);
|
||||
_normalizations.put(BlockChorusPlant.EAST, false);
|
||||
_normalizations.put(BlockChorusPlant.SOUTH, false);
|
||||
_normalizations.put(BlockChorusPlant.WEST, false);
|
||||
_normalizations.put(BlockChorusPlant.UP, false);
|
||||
_normalizations.put(BlockChorusPlant.DOWN, false);
|
||||
// _normalizations.put(BlockCocoa.AGE, 0);
|
||||
// _normalizations.put(BlockCrops.AGE, 0);
|
||||
_normalizations.put(BlockDirtSnowy.SNOWY, false);
|
||||
_normalizations.put(BlockDoor.OPEN, false);
|
||||
_normalizations.put(BlockDoor.POWERED, false);
|
||||
// _normalizations.put(BlockFarmland.MOISTURE, 0);
|
||||
_normalizations.put(BlockFence.NORTH, false);
|
||||
_normalizations.put(BlockFence.EAST, false);
|
||||
_normalizations.put(BlockFence.WEST, false);
|
||||
_normalizations.put(BlockFence.SOUTH, false);
|
||||
// _normalizations.put(BlockFenceGate.POWERED, false);
|
||||
// _normalizations.put(BlockFenceGate.IN_WALL, false);
|
||||
_normalizations.put(BlockFire.AGE, 0);
|
||||
_normalizations.put(BlockFire.NORTH, false);
|
||||
_normalizations.put(BlockFire.EAST, false);
|
||||
_normalizations.put(BlockFire.SOUTH, false);
|
||||
_normalizations.put(BlockFire.WEST, false);
|
||||
_normalizations.put(BlockFire.UP, false);
|
||||
// _normalizations.put(BlockFrostedIce.AGE, 0);
|
||||
_normalizations.put(BlockGrass.SNOWY, false);
|
||||
// _normalizations.put(BlockHopper.ENABLED, true);
|
||||
// _normalizations.put(BlockLever.POWERED, false);
|
||||
// _normalizations.put(BlockLiquid.LEVEL, 0);
|
||||
// _normalizations.put(BlockMycelium.SNOWY, false);
|
||||
// _normalizations.put(BlockNetherWart.AGE, false);
|
||||
_normalizations.put(BlockLeaves.DISTANCE, false);
|
||||
// _normalizations.put(BlockLeaves.DECAYABLE, false);
|
||||
// _normalizations.put(BlockObserver.POWERED, false);
|
||||
_normalizations.put(BlockPane.NORTH, false);
|
||||
_normalizations.put(BlockPane.EAST, false);
|
||||
_normalizations.put(BlockPane.WEST, false);
|
||||
_normalizations.put(BlockPane.SOUTH, false);
|
||||
// _normalizations.put(BlockPistonBase.EXTENDED, false);
|
||||
// _normalizations.put(BlockPressurePlate.POWERED, false);
|
||||
// _normalizations.put(BlockPressurePlateWeighted.POWER, false);
|
||||
// _normalizations.put(BlockRailDetector.POWERED, false);
|
||||
// _normalizations.put(BlockRailPowered.POWERED, false);
|
||||
_normalizations.put(BlockRedstoneWire.NORTH, false);
|
||||
_normalizations.put(BlockRedstoneWire.EAST, false);
|
||||
_normalizations.put(BlockRedstoneWire.SOUTH, false);
|
||||
_normalizations.put(BlockRedstoneWire.WEST, false);
|
||||
// _normalizations.put(BlockReed.AGE, false);
|
||||
_normalizations.put(BlockSapling.STAGE, 0);
|
||||
_normalizations.put(BlockStandingSign.ROTATION, 0);
|
||||
_normalizations.put(BlockStem.AGE, 0);
|
||||
_normalizations.put(BlockTripWire.NORTH, false);
|
||||
_normalizations.put(BlockTripWire.EAST, false);
|
||||
_normalizations.put(BlockTripWire.WEST, false);
|
||||
_normalizations.put(BlockTripWire.SOUTH, false);
|
||||
_normalizations.put(BlockVine.NORTH, false);
|
||||
_normalizations.put(BlockVine.EAST, false);
|
||||
_normalizations.put(BlockVine.SOUTH, false);
|
||||
_normalizations.put(BlockVine.WEST, false);
|
||||
_normalizations.put(BlockVine.UP, false);
|
||||
_normalizations.put(BlockWall.UP, false);
|
||||
_normalizations.put(BlockWall.NORTH, false);
|
||||
_normalizations.put(BlockWall.EAST, false);
|
||||
_normalizations.put(BlockWall.WEST, false);
|
||||
_normalizations.put(BlockWall.SOUTH, false);
|
||||
normalizations = Collections.unmodifiableMap(_normalizations);
|
||||
}
|
||||
|
||||
public static <C extends Comparable<C>, P extends IProperty<C>> P castToIProperty(Object value) {
|
||||
//noinspection unchecked
|
||||
return (P) value;
|
||||
}
|
||||
|
||||
public static <C extends Comparable<C>, P extends IProperty<C>> C castToIPropertyValue(P iproperty, Object value) {
|
||||
//noinspection unchecked
|
||||
return (C) value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalizes the specified blockstate by setting meta-affecting properties which
|
||||
* are not being targeted by the meta parameter to their default values.
|
||||
* <p>
|
||||
* For example, block variant/color is the primary target for the meta value, so properties
|
||||
* such as rotation/facing direction will be set to default values in order to nullify
|
||||
* the effect that they have on the state's meta value.
|
||||
*
|
||||
* @param state The state to normalize
|
||||
* @return The normalized block state
|
||||
*/
|
||||
public static IBlockState normalize(IBlockState state) {
|
||||
IBlockState newState = state;
|
||||
|
||||
for (IProperty<?> property : state.getProperties()) {
|
||||
Class<?> valueClass = property.getValueClass();
|
||||
if (normalizations.containsKey(property)) {
|
||||
try {
|
||||
newState = newState.with(
|
||||
castToIProperty(property),
|
||||
castToIPropertyValue(property, normalizations.get(property))
|
||||
);
|
||||
} catch (IllegalArgumentException ignored) {}
|
||||
} else if (normalizations.containsKey(state.get(property))) {
|
||||
try {
|
||||
newState = newState.with(
|
||||
castToIProperty(property),
|
||||
castToIPropertyValue(property, normalizations.get(state.get(property)))
|
||||
);
|
||||
} catch (IllegalArgumentException ignored) {}
|
||||
} else if (normalizations.containsKey(valueClass)) {
|
||||
try {
|
||||
newState = newState.with(
|
||||
castToIProperty(property),
|
||||
castToIPropertyValue(property, normalizations.get(valueClass))
|
||||
);
|
||||
} catch (IllegalArgumentException ignored) {}
|
||||
}
|
||||
}
|
||||
|
||||
return newState;
|
||||
}
|
||||
|
||||
/**
|
||||
* Evaluate the target meta value for the specified state. The target meta value is
|
||||
* most often that which is influenced by the variant/color property of the block state.
|
||||
*
|
||||
* @see #normalize(IBlockState)
|
||||
*
|
||||
* @param state The state to check
|
||||
* @return The target meta of the state
|
||||
*/
|
||||
public static int stateMeta(IBlockState state) {
|
||||
return state.hashCode();
|
||||
}
|
||||
|
||||
private static Set<IBlockState> getStates(@Nonnull Block block) {
|
||||
return new HashSet<>(block.getStateContainer().getValidStates());
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue