Unify constants for directions that were redefined all over the place.
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package li.cil.oc2.client.model;
|
||||
|
||||
import li.cil.oc2.common.Constants;
|
||||
import li.cil.oc2.common.block.BusCableBlock;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.client.renderer.model.BakedQuad;
|
||||
@@ -21,8 +22,6 @@ import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
public final class BusCableBakedModel implements IDynamicBakedModel {
|
||||
private static final Direction[] DIRECTIONS = Direction.values();
|
||||
private static final Direction.Axis[] AXES = Direction.Axis.values();
|
||||
|
||||
private final IBakedModel proxy;
|
||||
private final IBakedModel[] straightModelByAxis;
|
||||
@@ -40,8 +39,8 @@ public final class BusCableBakedModel implements IDynamicBakedModel {
|
||||
return proxy.getQuads(null, side, rand, extraData);
|
||||
}
|
||||
|
||||
for (int i = 0; i < AXES.length; i++) {
|
||||
final Direction.Axis axis = AXES[i];
|
||||
for (int i = 0; i < Constants.AXES.length; i++) {
|
||||
final Direction.Axis axis = Constants.AXES[i];
|
||||
if (isStraightAlongAxis(state, axis)) {
|
||||
return straightModelByAxis[i].getQuads(state, side, rand, extraData);
|
||||
}
|
||||
@@ -94,7 +93,7 @@ public final class BusCableBakedModel implements IDynamicBakedModel {
|
||||
|
||||
public static IModelData getBusCableSupportSideData(final IBlockDisplayReader world, final BlockPos pos, final BlockState state, final IModelData tileData) {
|
||||
Direction supportSide = null;
|
||||
for (final Direction direction : DIRECTIONS) {
|
||||
for (final Direction direction : Constants.DIRECTIONS) {
|
||||
if (isNeighborInDirectionSolid(world, pos, direction)) {
|
||||
final EnumProperty<BusCableBlock.ConnectionType> property = BusCableBlock.FACING_TO_CONNECTION_MAP.get(direction);
|
||||
if (state.hasProperty(property) && state.get(property) == BusCableBlock.ConnectionType.PLUG) {
|
||||
@@ -124,7 +123,7 @@ public final class BusCableBakedModel implements IDynamicBakedModel {
|
||||
}
|
||||
|
||||
private static boolean isStraightAlongAxis(final BlockState state, final Direction.Axis axis) {
|
||||
for (final Direction direction : DIRECTIONS) {
|
||||
for (final Direction direction : Constants.DIRECTIONS) {
|
||||
final EnumProperty<BusCableBlock.ConnectionType> property = BusCableBlock.FACING_TO_CONNECTION_MAP.get(direction);
|
||||
if (axis.test(direction)) {
|
||||
if (state.get(property) != BusCableBlock.ConnectionType.LINK) {
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package li.cil.oc2.common;
|
||||
|
||||
import net.minecraft.util.Direction;
|
||||
|
||||
public final class Constants {
|
||||
public static final int KILOBYTE = 1024;
|
||||
public static final int MEGABYTE = 1024 * KILOBYTE;
|
||||
@@ -7,6 +9,10 @@ public final class Constants {
|
||||
|
||||
public static final int TICK_SECONDS = 20;
|
||||
|
||||
public static final Direction[] DIRECTIONS = Direction.values();
|
||||
public static final Direction.Axis[] AXES = Direction.Axis.values();
|
||||
public static final int BLOCK_FACE_COUNT = DIRECTIONS.length;
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
public static final String BLOCK_ENTITY_TAG_NAME_IN_ITEM = "BlockEntityTag";
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package li.cil.oc2.common.block;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import li.cil.oc2.common.Constants;
|
||||
import li.cil.oc2.common.integration.Wrenches;
|
||||
import li.cil.oc2.common.item.Items;
|
||||
import li.cil.oc2.common.tileentity.BusCableTileEntity;
|
||||
@@ -58,8 +59,6 @@ public final class BusCableBlock extends Block {
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
private static final Direction[] FACING_VALUES = Direction.values();
|
||||
|
||||
public static final EnumProperty<ConnectionType> CONNECTION_NORTH = EnumProperty.create("connection_north", ConnectionType.class);
|
||||
public static final EnumProperty<ConnectionType> CONNECTION_EAST = EnumProperty.create("connection_east", ConnectionType.class);
|
||||
public static final EnumProperty<ConnectionType> CONNECTION_SOUTH = EnumProperty.create("connection_south", ConnectionType.class);
|
||||
@@ -158,7 +157,7 @@ public final class BusCableBlock extends Block {
|
||||
final List<ItemStack> drops = new ArrayList<>(super.getDrops(state, builder));
|
||||
|
||||
int plugCount = 0;
|
||||
for (final Direction side : FACING_VALUES) {
|
||||
for (final Direction side : Constants.DIRECTIONS) {
|
||||
final ConnectionType connectionType = state.get(FACING_TO_CONNECTION_MAP.get(side));
|
||||
if (connectionType == ConnectionType.PLUG) {
|
||||
plugCount++;
|
||||
@@ -220,9 +219,9 @@ public final class BusCableBlock extends Block {
|
||||
|
||||
private VoxelShape[] makeShapes() {
|
||||
final VoxelShape coreShape = Block.makeCuboidShape(5, 5, 5, 11, 11, 11);
|
||||
final VoxelShape[] connectionShapes = new VoxelShape[FACING_VALUES.length];
|
||||
for (int i = 0; i < FACING_VALUES.length; i++) {
|
||||
final Direction direction = FACING_VALUES[i];
|
||||
final VoxelShape[] connectionShapes = new VoxelShape[Constants.DIRECTIONS.length];
|
||||
for (int i = 0; i < Constants.DIRECTIONS.length; i++) {
|
||||
final Direction direction = Constants.DIRECTIONS[i];
|
||||
connectionShapes[i] = VoxelShapes.create(
|
||||
0.5 + Math.min((-2.0 / (16 - 6)), direction.getXOffset() * 0.5),
|
||||
0.5 + Math.min((-2.0 / (16 - 6)), direction.getYOffset() * 0.5),
|
||||
@@ -236,7 +235,7 @@ public final class BusCableBlock extends Block {
|
||||
for (int i = 0; i < result.length; i++) {
|
||||
VoxelShape shape = coreShape;
|
||||
|
||||
for (int j = 0; j < FACING_VALUES.length; j++) {
|
||||
for (int j = 0; j < Constants.DIRECTIONS.length; j++) {
|
||||
if ((i & (1 << j)) != 0) {
|
||||
shape = VoxelShapes.or(shape, connectionShapes[j]);
|
||||
}
|
||||
@@ -251,8 +250,8 @@ public final class BusCableBlock extends Block {
|
||||
private int getShapeIndex(final BlockState state) {
|
||||
int index = 0;
|
||||
|
||||
for (int i = 0; i < FACING_VALUES.length; i++) {
|
||||
if (state.get(FACING_TO_CONNECTION_MAP.get(FACING_VALUES[i])) != ConnectionType.NONE) {
|
||||
for (int i = 0; i < Constants.DIRECTIONS.length; i++) {
|
||||
if (state.get(FACING_TO_CONNECTION_MAP.get(Constants.DIRECTIONS[i])) != ConnectionType.NONE) {
|
||||
index |= 1 << i;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import li.cil.oc2.api.bus.BlockDeviceBusElement;
|
||||
import li.cil.oc2.api.bus.DeviceBus;
|
||||
import li.cil.oc2.api.bus.DeviceBusElement;
|
||||
import li.cil.oc2.api.bus.device.rpc.RPCDevice;
|
||||
import li.cil.oc2.common.Constants;
|
||||
import li.cil.oc2.common.bus.device.rpc.TypeNameRPCDevice;
|
||||
import li.cil.oc2.common.bus.device.util.BlockDeviceInfo;
|
||||
import li.cil.oc2.common.bus.device.util.Devices;
|
||||
@@ -26,17 +27,12 @@ import java.util.Optional;
|
||||
import static java.util.Objects.requireNonNull;
|
||||
|
||||
public class TileEntityDeviceBusElement extends AbstractGroupingBlockDeviceBusElement implements BlockDeviceBusElement {
|
||||
private static final int NEIGHBOR_COUNT = 6;
|
||||
final Direction[] NEIGHBOR_DIRECTIONS = Direction.values();
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
private final TileEntity tileEntity;
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
public TileEntityDeviceBusElement(final TileEntity tileEntity) {
|
||||
super(NEIGHBOR_COUNT);
|
||||
super(Constants.BLOCK_FACE_COUNT);
|
||||
this.tileEntity = tileEntity;
|
||||
}
|
||||
|
||||
@@ -55,7 +51,7 @@ public class TileEntityDeviceBusElement extends AbstractGroupingBlockDeviceBusEl
|
||||
}
|
||||
|
||||
final ArrayList<LazyOptional<DeviceBusElement>> neighbors = new ArrayList<>();
|
||||
for (final Direction neighborDirection : NEIGHBOR_DIRECTIONS) {
|
||||
for (final Direction neighborDirection : Constants.DIRECTIONS) {
|
||||
if (!canScanContinueTowards(neighborDirection)) {
|
||||
continue;
|
||||
}
|
||||
@@ -133,7 +129,7 @@ public class TileEntityDeviceBusElement extends AbstractGroupingBlockDeviceBusEl
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
private void scanNeighborsForDevices() {
|
||||
for (final Direction direction : Direction.values()) {
|
||||
for (final Direction direction : Constants.DIRECTIONS) {
|
||||
handleNeighborChanged(tileEntity.getPos().offset(direction));
|
||||
}
|
||||
}
|
||||
@@ -141,7 +137,7 @@ public class TileEntityDeviceBusElement extends AbstractGroupingBlockDeviceBusEl
|
||||
private void scheduleBusScanInAdjacentBusElements() {
|
||||
final World world = requireNonNull(tileEntity.getWorld());
|
||||
final BlockPos pos = tileEntity.getPos();
|
||||
for (final Direction direction : Direction.values()) {
|
||||
for (final Direction direction : Constants.DIRECTIONS) {
|
||||
final BlockPos neighborPos = pos.offset(direction);
|
||||
final TileEntity tileEntity = WorldUtils.getTileEntityIfChunkExists(world, neighborPos);
|
||||
if (tileEntity == null) {
|
||||
|
||||
@@ -8,6 +8,7 @@ import li.cil.oc2.api.bus.device.object.Parameter;
|
||||
import li.cil.oc2.api.bus.device.rpc.RPCDevice;
|
||||
import li.cil.oc2.api.bus.device.rpc.RPCMethod;
|
||||
import li.cil.oc2.api.capabilities.RedstoneEmitter;
|
||||
import li.cil.oc2.common.Constants;
|
||||
import li.cil.oc2.common.bus.device.util.IdentityProxy;
|
||||
import li.cil.oc2.common.capabilities.Capabilities;
|
||||
import li.cil.oc2.common.util.HorizontalBlockUtils;
|
||||
@@ -28,7 +29,6 @@ import javax.annotation.Nullable;
|
||||
import java.util.List;
|
||||
|
||||
public final class RedstoneInterfaceCardItemDevice extends IdentityProxy<ItemStack> implements RPCDevice, DocumentedDevice, ItemDevice, ICapabilityProvider {
|
||||
private static final int FACE_COUNT = Direction.values().length;
|
||||
|
||||
private static final String OUTPUT_TAG_NAME = "output";
|
||||
|
||||
@@ -43,7 +43,7 @@ public final class RedstoneInterfaceCardItemDevice extends IdentityProxy<ItemSta
|
||||
private final TileEntity tileEntity;
|
||||
private final ObjectDevice device;
|
||||
private final RedstoneEmitter[] capabilities;
|
||||
private final byte[] output = new byte[FACE_COUNT];
|
||||
private final byte[] output = new byte[Constants.BLOCK_FACE_COUNT];
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -52,8 +52,8 @@ public final class RedstoneInterfaceCardItemDevice extends IdentityProxy<ItemSta
|
||||
this.tileEntity = tileEntity;
|
||||
this.device = new ObjectDevice(this, "redstone");
|
||||
|
||||
capabilities = new RedstoneEmitter[FACE_COUNT];
|
||||
for (int i = 0; i < FACE_COUNT; i++) {
|
||||
capabilities = new RedstoneEmitter[Constants.BLOCK_FACE_COUNT];
|
||||
for (int i = 0; i < Constants.BLOCK_FACE_COUNT; i++) {
|
||||
final int indexForClosure = i;
|
||||
capabilities[i] = () -> output[indexForClosure];
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import li.cil.oc2.api.bus.device.object.Callback;
|
||||
import li.cil.oc2.api.bus.device.object.DocumentedDevice;
|
||||
import li.cil.oc2.api.bus.device.object.NamedDevice;
|
||||
import li.cil.oc2.api.bus.device.object.Parameter;
|
||||
import li.cil.oc2.common.Constants;
|
||||
import li.cil.oc2.common.util.HorizontalBlockUtils;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
@@ -19,9 +20,7 @@ import java.util.Collection;
|
||||
import static java.util.Collections.singletonList;
|
||||
|
||||
public final class RedstoneInterfaceTileEntity extends TileEntity implements NamedDevice, DocumentedDevice {
|
||||
private static final int FACE_COUNT = Direction.values().length;
|
||||
|
||||
private static final String OUTPUT_NBT_TAG_NAME = "output";
|
||||
private static final String OUTPUT_TAG_NAME = "output";
|
||||
|
||||
private static final String GET_REDSTONE_INPUT = "getRedstoneInput";
|
||||
private static final String GET_REDSTONE_OUTPUT = "getRedstoneOutput";
|
||||
@@ -31,7 +30,7 @@ public final class RedstoneInterfaceTileEntity extends TileEntity implements Nam
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
private final byte[] output = new byte[FACE_COUNT];
|
||||
private final byte[] output = new byte[Constants.BLOCK_FACE_COUNT];
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -44,14 +43,14 @@ public final class RedstoneInterfaceTileEntity extends TileEntity implements Nam
|
||||
@Override
|
||||
public CompoundNBT write(CompoundNBT compound) {
|
||||
compound = super.write(compound);
|
||||
compound.putByteArray(OUTPUT_NBT_TAG_NAME, output);
|
||||
compound.putByteArray(OUTPUT_TAG_NAME, output);
|
||||
return compound;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(final BlockState state, final CompoundNBT compound) {
|
||||
super.read(state, compound);
|
||||
final byte[] serializedOutput = compound.getByteArray(OUTPUT_NBT_TAG_NAME);
|
||||
final byte[] serializedOutput = compound.getByteArray(OUTPUT_TAG_NAME);
|
||||
System.arraycopy(serializedOutput, 0, output, 0, Math.min(serializedOutput.length, output.length));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user