From 77b544ce4f93f1e77e55dff02b9e2fe3710c0e70 Mon Sep 17 00:00:00 2001 From: yueh Date: Mon, 29 Jun 2020 11:45:25 +0200 Subject: [PATCH] Refactored drive state sync Removed blinking state for now --- .../appeng/api/storage/cells/CellState.java | 2 +- .../appeng/block/storage/DriveSlotState.java | 6 ++- .../tesr/DriveLedTileEntityRenderer.java | 3 +- .../appeng/tile/storage/ChestTileEntity.java | 40 +++++++++--------- .../appeng/tile/storage/DriveTileEntity.java | 35 +++++++++------ .../blockstates/chest.json | 10 ++++- .../block/chest/cell_state_not_empty.json | 31 ++++++++++++++ .../block/chest/cell_state_not_empty.png | Bin 0 -> 146 bytes 8 files changed, 89 insertions(+), 38 deletions(-) create mode 100644 src/main/resources/assets/appliedenergistics2/models/block/chest/cell_state_not_empty.json create mode 100644 src/main/resources/assets/appliedenergistics2/textures/block/chest/cell_state_not_empty.png diff --git a/src/api/java/appeng/api/storage/cells/CellState.java b/src/api/java/appeng/api/storage/cells/CellState.java index c8dfe2299..65af69101 100644 --- a/src/api/java/appeng/api/storage/cells/CellState.java +++ b/src/api/java/appeng/api/storage/cells/CellState.java @@ -50,5 +50,5 @@ public enum CellState { /** * Full cell, technically could have free types */ - FULL, + FULL; } \ No newline at end of file diff --git a/src/main/java/appeng/block/storage/DriveSlotState.java b/src/main/java/appeng/block/storage/DriveSlotState.java index 4cd8306ba..51d00f8ea 100644 --- a/src/main/java/appeng/block/storage/DriveSlotState.java +++ b/src/main/java/appeng/block/storage/DriveSlotState.java @@ -37,6 +37,9 @@ public enum DriveSlotState implements IStringSerializable { // Online and free space ONLINE("online"), + // Online and not space + NOT_EMPTY("not_empty"), + // Types full, space left TYPES_FULL("types_full"), @@ -60,8 +63,9 @@ public enum DriveSlotState implements IStringSerializable { case ABSENT: return DriveSlotState.EMPTY; case EMPTY: - case NOT_EMPTY: return DriveSlotState.ONLINE; + case NOT_EMPTY: + return DriveSlotState.NOT_EMPTY; case TYPES_FULL: return DriveSlotState.TYPES_FULL; case FULL: diff --git a/src/main/java/appeng/client/render/tesr/DriveLedTileEntityRenderer.java b/src/main/java/appeng/client/render/tesr/DriveLedTileEntityRenderer.java index 8969a7b51..9a1164235 100644 --- a/src/main/java/appeng/client/render/tesr/DriveLedTileEntityRenderer.java +++ b/src/main/java/appeng/client/render/tesr/DriveLedTileEntityRenderer.java @@ -43,7 +43,8 @@ public class DriveLedTileEntityRenderer extends TileEntityRenderer(DriveSlotState.class); STATE_COLORS.put(DriveSlotState.OFFLINE, new Vector3f(0, 0, 0)); STATE_COLORS.put(DriveSlotState.ONLINE, new Vector3f(0, 1, 0)); - STATE_COLORS.put(DriveSlotState.TYPES_FULL, new Vector3f(0, 0.667f, 0)); + STATE_COLORS.put(DriveSlotState.NOT_EMPTY, new Vector3f(0f, 0.667f, 1)); + STATE_COLORS.put(DriveSlotState.TYPES_FULL, new Vector3f(1, 0.667f, 0)); STATE_COLORS.put(DriveSlotState.FULL, new Vector3f(1, 0, 0)); } diff --git a/src/main/java/appeng/tile/storage/ChestTileEntity.java b/src/main/java/appeng/tile/storage/ChestTileEntity.java index 57db14c31..7e521b998 100644 --- a/src/main/java/appeng/tile/storage/ChestTileEntity.java +++ b/src/main/java/appeng/tile/storage/ChestTileEntity.java @@ -110,6 +110,13 @@ import appeng.util.item.AEItemStack; public class ChestTileEntity extends AENetworkPowerTileEntity implements IMEChest, ITerminalHost, IPriorityHost, IConfigManagerHost, IColorableTile, ITickableTileEntity { + + private static final int BIT_POWER_MASK = Byte.MIN_VALUE; + private static final int BIT_STATE_MASK = 0b111; + + private static final int BIT_CELL_STATE_MASK = 0b111; + private static final int BIT_CELL_STATE_BITS = 3; + private final AppEngInternalInventory inputInventory = new AppEngInternalInventory(this, 1); private final AppEngInternalInventory cellInventory = new AppEngInternalInventory(this, 1); private final IItemHandler internalInventory = new WrapperChainedItemHandler(this.inputInventory, @@ -163,13 +170,13 @@ public class ChestTileEntity extends AENetworkPowerTileEntity final int oldState = this.state; for (int x = 0; x < this.getCellCount(); x++) { - this.state |= (this.getCellStatus(x).ordinal() << (3 * x)); + this.state |= (this.getCellStatus(x).ordinal() << (BIT_CELL_STATE_BITS * x)); } if (this.isPowered()) { - this.state |= 0x40; + this.state |= BIT_POWER_MASK; } else { - this.state &= ~0x40; + this.state &= ~BIT_POWER_MASK; } final boolean currentActive = this.getProxy().isActive(); @@ -245,7 +252,7 @@ public class ChestTileEntity extends AENetworkPowerTileEntity @Override public CellState getCellStatus(final int slot) { if (isRemote()) { - return CellState.values()[(this.state >> (slot * 3)) & 3]; + return CellState.values()[(this.state >> (slot * BIT_CELL_STATE_BITS)) & BIT_CELL_STATE_MASK]; } this.updateHandler(); @@ -273,7 +280,7 @@ public class ChestTileEntity extends AENetworkPowerTileEntity @Override public boolean isPowered() { if (isRemote()) { - return (this.state & 0x40) == 0x40; + return (this.state & BIT_POWER_MASK) == BIT_POWER_MASK; } boolean gridPowered = this.getAECurrentPower() > 64; @@ -290,12 +297,7 @@ public class ChestTileEntity extends AENetworkPowerTileEntity @Override public boolean isCellBlinking(final int slot) { - final long now = this.world.getGameTime(); - if (now - this.lastStateChange > 8) { - return false; - } - - return ((this.state >> (slot * 3 + 2)) & 0x01) == 0x01; + return false; } @Override @@ -327,14 +329,14 @@ public class ChestTileEntity extends AENetworkPowerTileEntity try { if (!this.getProxy().getEnergy().isNetworkPowered()) { final double powerUsed = this.extractAEPower(idleUsage, Actionable.MODULATE, PowerMultiplier.CONFIG); // drain - if (powerUsed + 0.1 >= idleUsage != (this.state & 0x40) > 0) { + if (powerUsed + 0.1 >= idleUsage != (this.state & BIT_POWER_MASK) > 0) { this.recalculateDisplay(); } } } catch (final GridAccessException e) { final double powerUsed = this.extractAEPower(this.getProxy().getIdlePowerUsage(), Actionable.MODULATE, PowerMultiplier.CONFIG); // drain - if (powerUsed + 0.1 >= idleUsage != (this.state & 0x40) > 0) { + if (powerUsed + 0.1 >= idleUsage != (this.state & BIT_POWER_MASK) > 0) { this.recalculateDisplay(); } } @@ -348,20 +350,16 @@ public class ChestTileEntity extends AENetworkPowerTileEntity protected void writeToStream(final PacketBuffer data) throws IOException { super.writeToStream(data); - if (this.world.getGameTime() - this.lastStateChange > 8) { - this.state = 0; - } else { - this.state &= 0x24924924; // just keep the blinks... - } + this.state = 0; for (int x = 0; x < this.getCellCount(); x++) { this.state |= (this.getCellStatus(x).ordinal() << (3 * x)); } if (this.isPowered()) { - this.state |= 0x40; + this.state |= BIT_POWER_MASK; } else { - this.state &= ~0x40; + this.state &= ~BIT_POWER_MASK; } data.writeByte(this.state); @@ -519,7 +517,7 @@ public class ChestTileEntity extends AENetworkPowerTileEntity } this.lastStateChange = now; - this.state |= 1 << (slot * 3 + 2); + this.state |= 1 << (slot * BIT_CELL_STATE_BITS + 2); this.recalculateDisplay(); } diff --git a/src/main/java/appeng/tile/storage/DriveTileEntity.java b/src/main/java/appeng/tile/storage/DriveTileEntity.java index 044e37357..bfb169725 100644 --- a/src/main/java/appeng/tile/storage/DriveTileEntity.java +++ b/src/main/java/appeng/tile/storage/DriveTileEntity.java @@ -77,9 +77,11 @@ import appeng.util.inv.filter.IAEItemFilter; public class DriveTileEntity extends AENetworkInvTileEntity implements IChestOrDrive, IPriorityHost { - private static final int BIT_POWER_MASK = 0x80000000; - private static final int BIT_BLINK_MASK = 0x24924924; - private static final int BIT_STATE_MASK = 0xDB6DB6DB; + private static final int BIT_POWER_MASK = Integer.MIN_VALUE; + private static final int BIT_STATE_MASK = 0b111111111111111111111111111111; + + private static final int BIT_CELL_STATE_MASK = 0b111; + private static final int BIT_CELL_STATE_BITS = 3; private final AppEngCellInventory inv = new AppEngCellInventory(this, 10); private final ICellHandler[] handlersBySlot = new ICellHandler[10]; @@ -95,13 +97,18 @@ public class DriveTileEntity extends AENetworkInvTileEntity implements IChestOrD /** * The state of all cells inside a drive as bitset, using the following format. * - * Bit 31: power state. 0 = off, 1 = on. Bit 30: undefined Bit 29-0: 3 bits as - * state of each cell with the cell in slot 0 located in the 3 least significant - * bits. + * - Bit 31: power state. 0 = off, 1 = on. + * + * - Bit 30: reserved + * + * - Bit 29-0: 3 bits for the state of each cell * - * Cell states: Bit 2: blink. 0 = off, 1 = on. Bit 1-0: cell status + * Cell states: + * + * - Bit 2-0: {@link CellState} ordinal * * + * */ private int state = 0; @@ -128,8 +135,11 @@ public class DriveTileEntity extends AENetworkInvTileEntity implements IChestOrD newState |= BIT_POWER_MASK; } for (int x = 0; x < this.getCellCount(); x++) { - newState |= (this.getCellStatus(x).ordinal() << (3 * x)); + final int o = this.getCellStatus(x).ordinal(); + final int i = (o << (BIT_CELL_STATE_BITS * x)); + newState |= i; } + data.writeInt(newState); writeCellItemIds(data); @@ -224,7 +234,8 @@ public class DriveTileEntity extends AENetworkInvTileEntity implements IChestOrD @Override public CellState getCellStatus(final int slot) { if (Platform.isClient()) { - return CellState.values()[(this.state >> (slot * 3)) & 3]; + final int cellState = ((this.state >> (slot * BIT_CELL_STATE_BITS)) & BIT_CELL_STATE_MASK); + return CellState.values()[cellState]; } final DriveWatcher handler = this.invBySlot[slot]; @@ -246,7 +257,7 @@ public class DriveTileEntity extends AENetworkInvTileEntity implements IChestOrD @Override public boolean isCellBlinking(final int slot) { - return ((this.state >> (slot * 3 + 2)) & 0x01) == 0x01; + return false; } @Override @@ -286,7 +297,7 @@ public class DriveTileEntity extends AENetworkInvTileEntity implements IChestOrD } for (int x = 0; x < this.getCellCount(); x++) { - newState |= (this.getCellStatus(x).ordinal() << (3 * x)); + newState |= (this.getCellStatus(x).ordinal() << (BIT_CELL_STATE_BITS * x)); } if (newState != this.state) { @@ -416,8 +427,6 @@ public class DriveTileEntity extends AENetworkInvTileEntity implements IChestOrD @Override public void blinkCell(final int slot) { - this.state |= 1 << (slot * 3 + 2); - this.recalculateDisplay(); } diff --git a/src/main/resources/assets/appliedenergistics2/blockstates/chest.json b/src/main/resources/assets/appliedenergistics2/blockstates/chest.json index 2a3496fb1..b5a8459ea 100644 --- a/src/main/resources/assets/appliedenergistics2/blockstates/chest.json +++ b/src/main/resources/assets/appliedenergistics2/blockstates/chest.json @@ -15,7 +15,7 @@ }, { "when": { - "slot_state": "online|types_full|full" + "slot_state": "online|not_empty|types_full|full" }, "apply": { "model": "appliedenergistics2:block/chest/lights_on" @@ -45,6 +45,14 @@ "model": "appliedenergistics2:block/chest/cell_state_online" } }, + { + "when": { + "slot_state": "not_empty" + }, + "apply": { + "model": "appliedenergistics2:block/chest/cell_state_not_empty" + } + }, { "when": { "slot_state": "types_full" diff --git a/src/main/resources/assets/appliedenergistics2/models/block/chest/cell_state_not_empty.json b/src/main/resources/assets/appliedenergistics2/models/block/chest/cell_state_not_empty.json new file mode 100644 index 000000000..cb3dcba8f --- /dev/null +++ b/src/main/resources/assets/appliedenergistics2/models/block/chest/cell_state_not_empty.json @@ -0,0 +1,31 @@ +{ + "loader": "appliedenergistics2:uvlightmap", + "textures": { + "backdrop": "appliedenergistics2:block/chest/cell_state_backdrop", + "state": "appliedenergistics2:block/chest/cell_state_not_empty" + }, + "elements": [ + { + "from": [0, 0, 0], + "to": [16, 16, 16], + "faces": { + "north": { + "texture": "#backdrop" + } + } + }, + { + "from": [0, 0, 0], + "to": [16, 16, 16], + "faces": { + "north": { + "texture": "#state", + "uvlightmap": { + "block": 0.007, + "sky": 0.007 + } + } + } + } + ] +} diff --git a/src/main/resources/assets/appliedenergistics2/textures/block/chest/cell_state_not_empty.png b/src/main/resources/assets/appliedenergistics2/textures/block/chest/cell_state_not_empty.png new file mode 100644 index 0000000000000000000000000000000000000000..79541fdc18801a5ecc75dd18aaf2e49a70d50c2b GIT binary patch literal 146 zcmeAS@N?(olHy`uVBq!ia0y~yU=RRd4mJh`2Kmqb6B!s77>k44ofy`glX=O&z`&C3 z=