mirror of
https://github.com/Thorfusion/Mekanism-Community-Edition.git
synced 2026-11-19 11:49:27 +00:00
6 files changed
+236
-63
No files matched your search
@@ -7,7 +7,7 @@ import mekanism.client.gui.element.GuiRateBar.IRateInfoHandler;
|
||||
import mekanism.client.gui.element.gauge.GuiEnergyGauge;
|
||||
import mekanism.client.gui.element.tab.GuiMatrixTab;
|
||||
import mekanism.client.gui.element.tab.GuiMatrixTab.MatrixTab;
|
||||
import mekanism.common.inventory.container.ContainerNull;
|
||||
import mekanism.common.inventory.container.ContainerInductionMatrixStats;
|
||||
import mekanism.common.tile.TileEntityInductionCasing;
|
||||
import mekanism.common.util.LangUtils;
|
||||
import mekanism.common.util.MekanismUtils;
|
||||
@@ -21,7 +21,7 @@ import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
public class GuiMatrixStats extends GuiMekanismTile<TileEntityInductionCasing> {
|
||||
|
||||
public GuiMatrixStats(InventoryPlayer inventory, TileEntityInductionCasing tile) {
|
||||
super(tile, new ContainerNull(inventory.player, tile));
|
||||
super(tile, new ContainerInductionMatrixStats(inventory, tile));
|
||||
ResourceLocation resource = getGuiLocation();
|
||||
addGuiElement(new GuiMatrixTab(this, tileEntity, MatrixTab.MAIN, resource));
|
||||
addGuiElement(new GuiEnergyGauge(() -> tileEntity, GuiEnergyGauge.Type.STANDARD, this, resource, 6, 13));
|
||||
@@ -77,4 +77,4 @@ public class GuiMatrixStats extends GuiMekanismTile<TileEntityInductionCasing> {
|
||||
protected ResourceLocation getGuiLocation() {
|
||||
return MekanismUtils.getResource(ResourceType.GUI, "GuiNull.png");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -35,6 +35,7 @@ import mekanism.common.inventory.container.ContainerFormulaicAssemblicator;
|
||||
import mekanism.common.inventory.container.ContainerFuelwoodHeater;
|
||||
import mekanism.common.inventory.container.ContainerGasTank;
|
||||
import mekanism.common.inventory.container.ContainerInductionMatrix;
|
||||
import mekanism.common.inventory.container.ContainerInductionMatrixStats;
|
||||
import mekanism.common.inventory.container.ContainerLaserAmplifier;
|
||||
import mekanism.common.inventory.container.ContainerLaserTractorBeam;
|
||||
import mekanism.common.inventory.container.ContainerMetallurgicInfuser;
|
||||
@@ -371,7 +372,7 @@ public class CommonProxy implements IGuiProvider {
|
||||
case 49:
|
||||
return new ContainerInductionMatrix(player.inventory, (TileEntityInductionCasing) tileEntity);
|
||||
case 50:
|
||||
return new ContainerNull(player, (TileEntityContainerBlock) tileEntity);
|
||||
return new ContainerInductionMatrixStats(player.inventory, (TileEntityInductionCasing) tileEntity);
|
||||
case 51:
|
||||
return new ContainerNull(player, (TileEntityContainerBlock) tileEntity);
|
||||
case 52:
|
||||
@@ -470,4 +471,4 @@ public class CommonProxy implements IGuiProvider {
|
||||
public void throwApiPresentException() {
|
||||
throw new RuntimeException(String.join(" ", API_PRESENT_MESSAGE));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,8 @@
|
||||
package mekanism.common.content.matrix;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import mekanism.api.Coord4D;
|
||||
import mekanism.api.TileNetworkList;
|
||||
import mekanism.common.multiblock.SynchronizedData;
|
||||
import mekanism.common.tile.TileEntityInductionCell;
|
||||
import mekanism.common.tile.TileEntityInductionProvider;
|
||||
@@ -201,37 +199,6 @@ public class SynchronizedMatrixData extends SynchronizedData<SynchronizedMatrixD
|
||||
}
|
||||
}
|
||||
|
||||
public TileNetworkList addStructureData(TileNetworkList data) {
|
||||
data.add(cachedTotal);
|
||||
data.add(storageCap);
|
||||
data.add(transferCap);
|
||||
data.add(lastInput);
|
||||
data.add(lastOutput);
|
||||
|
||||
data.add(volWidth);
|
||||
data.add(volHeight);
|
||||
data.add(volLength);
|
||||
|
||||
data.add(cells.size());
|
||||
data.add(providers.size());
|
||||
return data;
|
||||
}
|
||||
|
||||
public void readStructureData(ByteBuf dataStream) {
|
||||
cachedTotal = dataStream.readDouble();
|
||||
storageCap = dataStream.readDouble();
|
||||
transferCap = dataStream.readDouble();
|
||||
lastInput = dataStream.readDouble();
|
||||
lastOutput = dataStream.readDouble();
|
||||
|
||||
volWidth = dataStream.readInt();
|
||||
volHeight = dataStream.readInt();
|
||||
volLength = dataStream.readInt();
|
||||
|
||||
clientCells = dataStream.readInt();
|
||||
clientProviders = dataStream.readInt();
|
||||
}
|
||||
|
||||
public double getStorageCap() {
|
||||
return storageCap;
|
||||
}
|
||||
@@ -267,4 +234,53 @@ public class SynchronizedMatrixData extends SynchronizedData<SynchronizedMatrixD
|
||||
public int getProviderCount() {
|
||||
return providers.isEmpty() ? clientProviders : providers.size();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Only call this from the client when synchronizing container data.
|
||||
*/
|
||||
public void setCachedTotal(double cachedTotal) {
|
||||
this.cachedTotal = cachedTotal;
|
||||
}
|
||||
|
||||
/**
|
||||
* Only call this from the client when synchronizing container data.
|
||||
*/
|
||||
public void setStorageCap(double storageCap) {
|
||||
this.storageCap = storageCap;
|
||||
}
|
||||
|
||||
/**
|
||||
* Only call this from the client when synchronizing container data.
|
||||
*/
|
||||
public void setTransferCap(double transferCap) {
|
||||
this.transferCap = transferCap;
|
||||
}
|
||||
|
||||
/**
|
||||
* Only call this from the client when synchronizing container data.
|
||||
*/
|
||||
public void setLastInput(double lastInput) {
|
||||
this.lastInput = lastInput;
|
||||
}
|
||||
|
||||
/**
|
||||
* Only call this from the client when synchronizing container data.
|
||||
*/
|
||||
public void setLastOutput(double lastOutput) {
|
||||
this.lastOutput = lastOutput;
|
||||
}
|
||||
|
||||
/**
|
||||
* Only call this from the client when synchronizing container data.
|
||||
*/
|
||||
public void setClientCells(int clientCells) {
|
||||
this.clientCells = clientCells;
|
||||
}
|
||||
|
||||
/**
|
||||
* Only call this from the client when synchronizing container data.
|
||||
*/
|
||||
public void setClientProviders(int clientProviders) {
|
||||
this.clientProviders = clientProviders;
|
||||
}
|
||||
}
|
||||
@@ -1,19 +1,169 @@
|
||||
package mekanism.common.inventory.container;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import mekanism.common.content.matrix.SynchronizedMatrixData;
|
||||
import mekanism.common.inventory.slot.SlotEnergy.SlotCharge;
|
||||
import mekanism.common.inventory.slot.SlotEnergy.SlotDischarge;
|
||||
import mekanism.common.tile.TileEntityInductionCasing;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.inventory.IContainerListener;
|
||||
|
||||
public class ContainerInductionMatrix extends ContainerEnergyStorage<TileEntityInductionCasing> {
|
||||
|
||||
private static final int DOUBLE_PARTS = 4;
|
||||
private static final int DOUBLE_PROPERTIES = 5;
|
||||
private static final int FIRST_INT_PROPERTY = DOUBLE_PARTS * DOUBLE_PROPERTIES;
|
||||
|
||||
private final long[] lastDoubleValues = new long[DOUBLE_PROPERTIES];
|
||||
private final int[] lastIntValues = new int[5];
|
||||
|
||||
public ContainerInductionMatrix(InventoryPlayer inventory, TileEntityInductionCasing tile) {
|
||||
super(tile, inventory);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addListener(@Nonnull IContainerListener listener) {
|
||||
super.addListener(listener);
|
||||
sendAllMatrixData(listener);
|
||||
cacheMatrixData();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void detectAndSendChanges() {
|
||||
super.detectAndSendChanges();
|
||||
long[] doubleValues = getDoubleValues();
|
||||
int[] intValues = getIntValues();
|
||||
for (IContainerListener listener : listeners) {
|
||||
for (int valueIndex = 0; valueIndex < doubleValues.length; valueIndex++) {
|
||||
if (doubleValues[valueIndex] != lastDoubleValues[valueIndex]) {
|
||||
sendDouble(listener, valueIndex, doubleValues[valueIndex]);
|
||||
}
|
||||
}
|
||||
for (int valueIndex = 0; valueIndex < intValues.length; valueIndex++) {
|
||||
if (intValues[valueIndex] != lastIntValues[valueIndex]) {
|
||||
listener.sendWindowProperty(this, FIRST_INT_PROPERTY + valueIndex, intValues[valueIndex]);
|
||||
}
|
||||
}
|
||||
}
|
||||
System.arraycopy(doubleValues, 0, lastDoubleValues, 0, doubleValues.length);
|
||||
System.arraycopy(intValues, 0, lastIntValues, 0, intValues.length);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateProgressBar(int property, int value) {
|
||||
SynchronizedMatrixData structure = getOrCreateClientStructure();
|
||||
if (property < FIRST_INT_PROPERTY) {
|
||||
int valueIndex = property / DOUBLE_PARTS;
|
||||
int part = property % DOUBLE_PARTS;
|
||||
long oldBits = getDoubleValues()[valueIndex];
|
||||
int shift = part * Short.SIZE;
|
||||
long mask = 0xFFFFL << shift;
|
||||
long newBits = (oldBits & ~mask) | (((long) value & 0xFFFFL) << shift);
|
||||
setDoubleValue(structure, valueIndex, Double.longBitsToDouble(newBits));
|
||||
} else {
|
||||
setIntValue(structure, property - FIRST_INT_PROPERTY, value);
|
||||
}
|
||||
}
|
||||
|
||||
private void sendAllMatrixData(IContainerListener listener) {
|
||||
long[] doubleValues = getDoubleValues();
|
||||
for (int valueIndex = 0; valueIndex < doubleValues.length; valueIndex++) {
|
||||
sendDouble(listener, valueIndex, doubleValues[valueIndex]);
|
||||
}
|
||||
int[] intValues = getIntValues();
|
||||
for (int valueIndex = 0; valueIndex < intValues.length; valueIndex++) {
|
||||
listener.sendWindowProperty(this, FIRST_INT_PROPERTY + valueIndex, intValues[valueIndex]);
|
||||
}
|
||||
}
|
||||
|
||||
private void sendDouble(IContainerListener listener, int valueIndex, long value) {
|
||||
int firstProperty = valueIndex * DOUBLE_PARTS;
|
||||
for (int part = 0; part < DOUBLE_PARTS; part++) {
|
||||
listener.sendWindowProperty(this, firstProperty + part, (int) (value >>> (part * Short.SIZE) & 0xFFFFL));
|
||||
}
|
||||
}
|
||||
|
||||
private void cacheMatrixData() {
|
||||
long[] doubleValues = getDoubleValues();
|
||||
int[] intValues = getIntValues();
|
||||
System.arraycopy(doubleValues, 0, lastDoubleValues, 0, doubleValues.length);
|
||||
System.arraycopy(intValues, 0, lastIntValues, 0, intValues.length);
|
||||
}
|
||||
|
||||
private long[] getDoubleValues() {
|
||||
SynchronizedMatrixData structure = tileEntity.structure;
|
||||
return new long[]{
|
||||
Double.doubleToRawLongBits(structure == null ? 0 : structure.getEnergy()),
|
||||
Double.doubleToRawLongBits(structure == null ? 0 : structure.getStorageCap()),
|
||||
Double.doubleToRawLongBits(structure == null ? 0 : structure.getTransferCap()),
|
||||
Double.doubleToRawLongBits(structure == null ? 0 : structure.getLastInput()),
|
||||
Double.doubleToRawLongBits(structure == null ? 0 : structure.getLastOutput())
|
||||
};
|
||||
}
|
||||
|
||||
private int[] getIntValues() {
|
||||
SynchronizedMatrixData structure = tileEntity.structure;
|
||||
return new int[]{
|
||||
structure == null ? 0 : structure.volWidth,
|
||||
structure == null ? 0 : structure.volHeight,
|
||||
structure == null ? 0 : structure.volLength,
|
||||
structure == null ? 0 : structure.getCellCount(),
|
||||
structure == null ? 0 : structure.getProviderCount()
|
||||
};
|
||||
}
|
||||
|
||||
private SynchronizedMatrixData getOrCreateClientStructure() {
|
||||
if (tileEntity.structure == null) {
|
||||
tileEntity.structure = new SynchronizedMatrixData();
|
||||
}
|
||||
return tileEntity.structure;
|
||||
}
|
||||
|
||||
private void setDoubleValue(SynchronizedMatrixData structure, int valueIndex, double value) {
|
||||
switch (valueIndex) {
|
||||
case 0:
|
||||
structure.setCachedTotal(value);
|
||||
break;
|
||||
case 1:
|
||||
structure.setStorageCap(value);
|
||||
break;
|
||||
case 2:
|
||||
structure.setTransferCap(value);
|
||||
break;
|
||||
case 3:
|
||||
structure.setLastInput(value);
|
||||
break;
|
||||
case 4:
|
||||
structure.setLastOutput(value);
|
||||
break;
|
||||
default:
|
||||
}
|
||||
}
|
||||
|
||||
private void setIntValue(SynchronizedMatrixData structure, int valueIndex, int value) {
|
||||
switch (valueIndex) {
|
||||
case 0:
|
||||
structure.volWidth = value;
|
||||
break;
|
||||
case 1:
|
||||
structure.volHeight = value;
|
||||
break;
|
||||
case 2:
|
||||
structure.volLength = value;
|
||||
break;
|
||||
case 3:
|
||||
structure.setClientCells(value);
|
||||
break;
|
||||
case 4:
|
||||
structure.setClientProviders(value);
|
||||
break;
|
||||
default:
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addSlots() {
|
||||
addSlotToContainer(new SlotCharge(tileEntity, 0, 146, 20));
|
||||
addSlotToContainer(new SlotDischarge(tileEntity, 1, 146, 51));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package mekanism.common.inventory.container;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import mekanism.common.tile.TileEntityInductionCasing;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public class ContainerInductionMatrixStats extends ContainerInductionMatrix {
|
||||
|
||||
public ContainerInductionMatrixStats(InventoryPlayer inventory, TileEntityInductionCasing tile) {
|
||||
super(inventory, tile);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addSlots() {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addInventorySlots(InventoryPlayer inventory) {
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ItemStack transferStackInSlot(EntityPlayer player, int slotID) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,6 @@
|
||||
package mekanism.common.tile;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import javax.annotation.Nonnull;
|
||||
import mekanism.api.TileNetworkList;
|
||||
import mekanism.api.energy.IStrictEnergyStorage;
|
||||
import mekanism.common.Mekanism;
|
||||
import mekanism.common.capabilities.Capabilities;
|
||||
@@ -20,7 +18,6 @@ import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
import net.minecraftforge.fml.common.FMLCommonHandler;
|
||||
import net.minecraftforge.items.CapabilityItemHandler;
|
||||
|
||||
public class TileEntityInductionCasing extends TileEntityMultiblock<SynchronizedMatrixData> implements IStrictEnergyStorage, IComputerIntegration {
|
||||
@@ -61,25 +58,6 @@ public class TileEntityInductionCasing extends TileEntityMultiblock<Synchronized
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileNetworkList getNetworkedData(TileNetworkList data) {
|
||||
super.getNetworkedData(data);
|
||||
if (structure != null) {
|
||||
structure.addStructureData(data);
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handlePacketData(ByteBuf dataStream) {
|
||||
super.handlePacketData(dataStream);
|
||||
if (FMLCommonHandler.instance().getEffectiveSide().isClient()) {
|
||||
if (clientHasStructure) {
|
||||
structure.readStructureData(dataStream);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SynchronizedMatrixData getNewStructure() {
|
||||
return new SynchronizedMatrixData();
|
||||
@@ -208,4 +186,4 @@ public class TileEntityInductionCasing extends TileEntityMultiblock<Synchronized
|
||||
}
|
||||
return super.isCapabilityDisabled(capability, side);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user