Refactored drive state sync
Removed blinking state for now
This commit is contained in:
@@ -50,5 +50,5 @@ public enum CellState {
|
|||||||
/**
|
/**
|
||||||
* Full cell, technically could have free types
|
* Full cell, technically could have free types
|
||||||
*/
|
*/
|
||||||
FULL,
|
FULL;
|
||||||
}
|
}
|
||||||
@@ -37,6 +37,9 @@ public enum DriveSlotState implements IStringSerializable {
|
|||||||
// Online and free space
|
// Online and free space
|
||||||
ONLINE("online"),
|
ONLINE("online"),
|
||||||
|
|
||||||
|
// Online and not space
|
||||||
|
NOT_EMPTY("not_empty"),
|
||||||
|
|
||||||
// Types full, space left
|
// Types full, space left
|
||||||
TYPES_FULL("types_full"),
|
TYPES_FULL("types_full"),
|
||||||
|
|
||||||
@@ -60,8 +63,9 @@ public enum DriveSlotState implements IStringSerializable {
|
|||||||
case ABSENT:
|
case ABSENT:
|
||||||
return DriveSlotState.EMPTY;
|
return DriveSlotState.EMPTY;
|
||||||
case EMPTY:
|
case EMPTY:
|
||||||
case NOT_EMPTY:
|
|
||||||
return DriveSlotState.ONLINE;
|
return DriveSlotState.ONLINE;
|
||||||
|
case NOT_EMPTY:
|
||||||
|
return DriveSlotState.NOT_EMPTY;
|
||||||
case TYPES_FULL:
|
case TYPES_FULL:
|
||||||
return DriveSlotState.TYPES_FULL;
|
return DriveSlotState.TYPES_FULL;
|
||||||
case FULL:
|
case FULL:
|
||||||
|
|||||||
@@ -43,7 +43,8 @@ public class DriveLedTileEntityRenderer extends TileEntityRenderer<DriveTileEnti
|
|||||||
STATE_COLORS = new EnumMap<>(DriveSlotState.class);
|
STATE_COLORS = new EnumMap<>(DriveSlotState.class);
|
||||||
STATE_COLORS.put(DriveSlotState.OFFLINE, new Vector3f(0, 0, 0));
|
STATE_COLORS.put(DriveSlotState.OFFLINE, new Vector3f(0, 0, 0));
|
||||||
STATE_COLORS.put(DriveSlotState.ONLINE, new Vector3f(0, 1, 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));
|
STATE_COLORS.put(DriveSlotState.FULL, new Vector3f(1, 0, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -110,6 +110,13 @@ import appeng.util.item.AEItemStack;
|
|||||||
|
|
||||||
public class ChestTileEntity extends AENetworkPowerTileEntity
|
public class ChestTileEntity extends AENetworkPowerTileEntity
|
||||||
implements IMEChest, ITerminalHost, IPriorityHost, IConfigManagerHost, IColorableTile, ITickableTileEntity {
|
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 inputInventory = new AppEngInternalInventory(this, 1);
|
||||||
private final AppEngInternalInventory cellInventory = new AppEngInternalInventory(this, 1);
|
private final AppEngInternalInventory cellInventory = new AppEngInternalInventory(this, 1);
|
||||||
private final IItemHandler internalInventory = new WrapperChainedItemHandler(this.inputInventory,
|
private final IItemHandler internalInventory = new WrapperChainedItemHandler(this.inputInventory,
|
||||||
@@ -163,13 +170,13 @@ public class ChestTileEntity extends AENetworkPowerTileEntity
|
|||||||
final int oldState = this.state;
|
final int oldState = this.state;
|
||||||
|
|
||||||
for (int x = 0; x < this.getCellCount(); x++) {
|
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()) {
|
if (this.isPowered()) {
|
||||||
this.state |= 0x40;
|
this.state |= BIT_POWER_MASK;
|
||||||
} else {
|
} else {
|
||||||
this.state &= ~0x40;
|
this.state &= ~BIT_POWER_MASK;
|
||||||
}
|
}
|
||||||
|
|
||||||
final boolean currentActive = this.getProxy().isActive();
|
final boolean currentActive = this.getProxy().isActive();
|
||||||
@@ -245,7 +252,7 @@ public class ChestTileEntity extends AENetworkPowerTileEntity
|
|||||||
@Override
|
@Override
|
||||||
public CellState getCellStatus(final int slot) {
|
public CellState getCellStatus(final int slot) {
|
||||||
if (isRemote()) {
|
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();
|
this.updateHandler();
|
||||||
@@ -273,7 +280,7 @@ public class ChestTileEntity extends AENetworkPowerTileEntity
|
|||||||
@Override
|
@Override
|
||||||
public boolean isPowered() {
|
public boolean isPowered() {
|
||||||
if (isRemote()) {
|
if (isRemote()) {
|
||||||
return (this.state & 0x40) == 0x40;
|
return (this.state & BIT_POWER_MASK) == BIT_POWER_MASK;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean gridPowered = this.getAECurrentPower() > 64;
|
boolean gridPowered = this.getAECurrentPower() > 64;
|
||||||
@@ -290,12 +297,7 @@ public class ChestTileEntity extends AENetworkPowerTileEntity
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isCellBlinking(final int slot) {
|
public boolean isCellBlinking(final int slot) {
|
||||||
final long now = this.world.getGameTime();
|
return false;
|
||||||
if (now - this.lastStateChange > 8) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return ((this.state >> (slot * 3 + 2)) & 0x01) == 0x01;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -327,14 +329,14 @@ public class ChestTileEntity extends AENetworkPowerTileEntity
|
|||||||
try {
|
try {
|
||||||
if (!this.getProxy().getEnergy().isNetworkPowered()) {
|
if (!this.getProxy().getEnergy().isNetworkPowered()) {
|
||||||
final double powerUsed = this.extractAEPower(idleUsage, Actionable.MODULATE, PowerMultiplier.CONFIG); // drain
|
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();
|
this.recalculateDisplay();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (final GridAccessException e) {
|
} catch (final GridAccessException e) {
|
||||||
final double powerUsed = this.extractAEPower(this.getProxy().getIdlePowerUsage(), Actionable.MODULATE,
|
final double powerUsed = this.extractAEPower(this.getProxy().getIdlePowerUsage(), Actionable.MODULATE,
|
||||||
PowerMultiplier.CONFIG); // drain
|
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();
|
this.recalculateDisplay();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -348,20 +350,16 @@ public class ChestTileEntity extends AENetworkPowerTileEntity
|
|||||||
protected void writeToStream(final PacketBuffer data) throws IOException {
|
protected void writeToStream(final PacketBuffer data) throws IOException {
|
||||||
super.writeToStream(data);
|
super.writeToStream(data);
|
||||||
|
|
||||||
if (this.world.getGameTime() - this.lastStateChange > 8) {
|
this.state = 0;
|
||||||
this.state = 0;
|
|
||||||
} else {
|
|
||||||
this.state &= 0x24924924; // just keep the blinks...
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int x = 0; x < this.getCellCount(); x++) {
|
for (int x = 0; x < this.getCellCount(); x++) {
|
||||||
this.state |= (this.getCellStatus(x).ordinal() << (3 * x));
|
this.state |= (this.getCellStatus(x).ordinal() << (3 * x));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.isPowered()) {
|
if (this.isPowered()) {
|
||||||
this.state |= 0x40;
|
this.state |= BIT_POWER_MASK;
|
||||||
} else {
|
} else {
|
||||||
this.state &= ~0x40;
|
this.state &= ~BIT_POWER_MASK;
|
||||||
}
|
}
|
||||||
|
|
||||||
data.writeByte(this.state);
|
data.writeByte(this.state);
|
||||||
@@ -519,7 +517,7 @@ public class ChestTileEntity extends AENetworkPowerTileEntity
|
|||||||
}
|
}
|
||||||
this.lastStateChange = now;
|
this.lastStateChange = now;
|
||||||
|
|
||||||
this.state |= 1 << (slot * 3 + 2);
|
this.state |= 1 << (slot * BIT_CELL_STATE_BITS + 2);
|
||||||
|
|
||||||
this.recalculateDisplay();
|
this.recalculateDisplay();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -77,9 +77,11 @@ import appeng.util.inv.filter.IAEItemFilter;
|
|||||||
|
|
||||||
public class DriveTileEntity extends AENetworkInvTileEntity implements IChestOrDrive, IPriorityHost {
|
public class DriveTileEntity extends AENetworkInvTileEntity implements IChestOrDrive, IPriorityHost {
|
||||||
|
|
||||||
private static final int BIT_POWER_MASK = 0x80000000;
|
private static final int BIT_POWER_MASK = Integer.MIN_VALUE;
|
||||||
private static final int BIT_BLINK_MASK = 0x24924924;
|
private static final int BIT_STATE_MASK = 0b111111111111111111111111111111;
|
||||||
private static final int BIT_STATE_MASK = 0xDB6DB6DB;
|
|
||||||
|
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 AppEngCellInventory inv = new AppEngCellInventory(this, 10);
|
||||||
private final ICellHandler[] handlersBySlot = new ICellHandler[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.
|
* 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
|
* - Bit 31: power state. 0 = off, 1 = on.
|
||||||
* state of each cell with the cell in slot 0 located in the 3 least significant
|
*
|
||||||
* bits.
|
* - 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;
|
private int state = 0;
|
||||||
|
|
||||||
@@ -128,8 +135,11 @@ public class DriveTileEntity extends AENetworkInvTileEntity implements IChestOrD
|
|||||||
newState |= BIT_POWER_MASK;
|
newState |= BIT_POWER_MASK;
|
||||||
}
|
}
|
||||||
for (int x = 0; x < this.getCellCount(); x++) {
|
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);
|
data.writeInt(newState);
|
||||||
|
|
||||||
writeCellItemIds(data);
|
writeCellItemIds(data);
|
||||||
@@ -224,7 +234,8 @@ public class DriveTileEntity extends AENetworkInvTileEntity implements IChestOrD
|
|||||||
@Override
|
@Override
|
||||||
public CellState getCellStatus(final int slot) {
|
public CellState getCellStatus(final int slot) {
|
||||||
if (Platform.isClient()) {
|
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];
|
final DriveWatcher handler = this.invBySlot[slot];
|
||||||
@@ -246,7 +257,7 @@ public class DriveTileEntity extends AENetworkInvTileEntity implements IChestOrD
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isCellBlinking(final int slot) {
|
public boolean isCellBlinking(final int slot) {
|
||||||
return ((this.state >> (slot * 3 + 2)) & 0x01) == 0x01;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -286,7 +297,7 @@ public class DriveTileEntity extends AENetworkInvTileEntity implements IChestOrD
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (int x = 0; x < this.getCellCount(); x++) {
|
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) {
|
if (newState != this.state) {
|
||||||
@@ -416,8 +427,6 @@ public class DriveTileEntity extends AENetworkInvTileEntity implements IChestOrD
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void blinkCell(final int slot) {
|
public void blinkCell(final int slot) {
|
||||||
this.state |= 1 << (slot * 3 + 2);
|
|
||||||
|
|
||||||
this.recalculateDisplay();
|
this.recalculateDisplay();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"when": {
|
"when": {
|
||||||
"slot_state": "online|types_full|full"
|
"slot_state": "online|not_empty|types_full|full"
|
||||||
},
|
},
|
||||||
"apply": {
|
"apply": {
|
||||||
"model": "appliedenergistics2:block/chest/lights_on"
|
"model": "appliedenergistics2:block/chest/lights_on"
|
||||||
@@ -45,6 +45,14 @@
|
|||||||
"model": "appliedenergistics2:block/chest/cell_state_online"
|
"model": "appliedenergistics2:block/chest/cell_state_online"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"when": {
|
||||||
|
"slot_state": "not_empty"
|
||||||
|
},
|
||||||
|
"apply": {
|
||||||
|
"model": "appliedenergistics2:block/chest/cell_state_not_empty"
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"when": {
|
"when": {
|
||||||
"slot_state": "types_full"
|
"slot_state": "types_full"
|
||||||
|
|||||||
+31
@@ -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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
BIN
Binary file not shown.
|
After Width: | Height: | Size: 146 B |
Reference in New Issue
Block a user