mirror of
https://github.com/GTNewHorizons/Applied-Energistics-2-Unofficial.git
synced 2026-10-25 20:22:23 +00:00
Cell Restriction rework (#1265)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
This commit is contained in:
1 parent
528620fa9a
commit
03c28f0fb8
18 files changed
+351
-279
No files matched your search
@@ -128,4 +128,8 @@ public interface IStorageCell extends ICellWorkbenchItem {
|
||||
default IAEStackType<?> getStackType() {
|
||||
return ITEM_STACK_TYPE;
|
||||
}
|
||||
|
||||
default int getTypeWeight() {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
@@ -1,122 +1,129 @@
|
||||
package appeng.client.gui.implementations;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
|
||||
import org.lwjgl.input.Keyboard;
|
||||
|
||||
import com.gtnewhorizon.gtnhlib.util.numberformatting.NumberFormatUtil;
|
||||
|
||||
import appeng.client.gui.GuiSub;
|
||||
import appeng.client.gui.widgets.GuiAeButton;
|
||||
import appeng.client.gui.widgets.MEGuiTextField;
|
||||
import appeng.container.implementations.ContainerCellRestriction;
|
||||
import appeng.container.implementations.ContainerCellRestriction.CellData;
|
||||
import appeng.core.AELog;
|
||||
import appeng.core.localization.GuiColors;
|
||||
import appeng.core.localization.GuiText;
|
||||
import appeng.core.sync.network.NetworkHandler;
|
||||
import appeng.core.sync.packets.PacketSwitchGuis;
|
||||
import appeng.core.sync.packets.PacketValueConfig;
|
||||
import appeng.helpers.ICellRestriction;
|
||||
import appeng.helpers.ICellRestriction.CellData;
|
||||
import appeng.helpers.ICellRestriction.CellRestrictionData;
|
||||
import appeng.util.calculators.ArithHelper;
|
||||
import appeng.util.calculators.Calculator;
|
||||
|
||||
public class GuiCellRestriction extends GuiSub {
|
||||
|
||||
private MEGuiTextField amountField;
|
||||
private MEGuiTextField typesField;
|
||||
private CellData cellData;
|
||||
private final MEGuiTextField amountField;
|
||||
private final MEGuiTextField typesField;
|
||||
private final ContainerCellRestriction cellRestriction;
|
||||
private final GuiAeButton reset;
|
||||
|
||||
private CellData cellData = new CellData(0, 0, 0, 0);
|
||||
private CellRestrictionData cellRestrictionData = new CellRestrictionData((byte) 0, 0);
|
||||
|
||||
private static final int BASE_LINE_X = 48;
|
||||
|
||||
public GuiCellRestriction(InventoryPlayer ip, ICellRestriction obj) {
|
||||
super(new ContainerCellRestriction(ip, obj));
|
||||
this.xSize = 204;
|
||||
this.xSize = 213;
|
||||
|
||||
this.amountField = new MEGuiTextField(85, 12);
|
||||
this.cellRestriction = (ContainerCellRestriction) this.inventorySlots;
|
||||
this.amountField = new MEGuiTextField(95, 12);
|
||||
this.typesField = new MEGuiTextField(30, 12);
|
||||
this.cellData = new CellData();
|
||||
this.typesField.setMaxStringLength(3);
|
||||
|
||||
this.reset = new GuiAeButton(
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
12,
|
||||
12,
|
||||
GuiText.ResetRestriction.getLocal(),
|
||||
GuiText.ResetRestrictionHint.getLocal());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGui() {
|
||||
super.initGui();
|
||||
|
||||
this.amountField.x = this.guiLeft + 64;
|
||||
this.amountField.x = this.guiLeft + 62;
|
||||
this.typesField.x = this.guiLeft + 170;
|
||||
|
||||
this.amountField.y = this.guiTop + 32;
|
||||
this.typesField.y = this.amountField.y;
|
||||
|
||||
this.typesField.x = this.guiLeft + 162;
|
||||
this.typesField.y = this.guiTop + 32;
|
||||
this.reset.xPosition = this.guiLeft + BASE_LINE_X;
|
||||
this.reset.yPosition = this.amountField.y;
|
||||
|
||||
if (this.inventorySlots instanceof ContainerCellRestriction ccr) {
|
||||
ccr.setAmountField(this.amountField);
|
||||
ccr.setTypesField(this.typesField);
|
||||
ccr.setCellData(cellData);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGuiClosed() {
|
||||
super.onGuiClosed();
|
||||
}
|
||||
|
||||
public String filterCellRestriction() {
|
||||
|
||||
String types = this.typesField.getText();
|
||||
long amount = getAmount();
|
||||
|
||||
int restrictionTypes = 0;
|
||||
long restrictionAmount = 0;
|
||||
|
||||
try {
|
||||
restrictionTypes = Math.min(Integer.parseInt(types), cellData.getTotalTypes());
|
||||
} catch (Exception ignored) {
|
||||
//
|
||||
}
|
||||
try {
|
||||
restrictionAmount = Math
|
||||
.min(amount, (cellData.getTotalBytes() - cellData.getPerType()) * cellData.getPerByte());
|
||||
} catch (Exception ignored) {
|
||||
//
|
||||
}
|
||||
return restrictionTypes + "," + restrictionAmount;
|
||||
this.buttonList.add(this.reset);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawFG(int offsetX, int offsetY, int mouseX, int mouseY) {
|
||||
this.fontRendererObj.drawString(GuiText.CellRestriction.getLocal(), 58, 6, GuiColors.DefaultBlack.getColor());
|
||||
String type = cellData.getCellType();
|
||||
switch (type) {
|
||||
case "item":
|
||||
this.fontRendererObj
|
||||
.drawString(GuiText.NumberOfItems.getLocal(), 64, 23, GuiColors.DefaultBlack.getColor());
|
||||
break;
|
||||
case "fluid":
|
||||
this.fontRendererObj
|
||||
.drawString(GuiText.NumberOfFluids.getLocal(), 64, 23, GuiColors.DefaultBlack.getColor());
|
||||
break;
|
||||
if (this.cellRestriction.updated) {
|
||||
this.cellData = this.cellRestriction.cellDataSync.get();
|
||||
this.cellRestrictionData = this.cellRestriction.cellRestrictionDataSync.get();
|
||||
this.typesField.setText(String.valueOf(this.cellRestrictionData.restrictionTypes));
|
||||
this.amountField.setText(String.valueOf(this.cellRestrictionData.restrictionAmount));
|
||||
|
||||
this.cellRestriction.updated = false;
|
||||
}
|
||||
this.fontRendererObj.drawString(GuiText.Types.getLocal(), 162, 23, GuiColors.DefaultBlack.getColor());
|
||||
|
||||
this.fontRendererObj
|
||||
.drawString(GuiText.CellRestrictionTips.getLocal(), 64, 50, GuiColors.DefaultBlack.getColor());
|
||||
switch (type) {
|
||||
case "item":
|
||||
this.fontRendererObj.drawString(
|
||||
GuiText.ItemsPerByte.getLocal() + " " + cellData.getPerByte(),
|
||||
64,
|
||||
60,
|
||||
GuiColors.DefaultBlack.getColor());
|
||||
break;
|
||||
case "fluid":
|
||||
this.fontRendererObj.drawString(
|
||||
GuiText.FluidsPerByte.getLocal() + " " + cellData.getPerByte() + " mB",
|
||||
64,
|
||||
60,
|
||||
GuiColors.DefaultBlack.getColor());
|
||||
break;
|
||||
}
|
||||
.drawString(GuiText.CellRestriction.getLocal(), BASE_LINE_X, 6, GuiColors.DefaultBlack.getColor());
|
||||
|
||||
this.fontRendererObj
|
||||
.drawString(GuiText.ResourceAmount.getLocal(), BASE_LINE_X, 22, GuiColors.DefaultBlack.getColor());
|
||||
|
||||
this.fontRendererObj
|
||||
.drawString(GuiText.Types.getLocal(), BASE_LINE_X + 122, 22, GuiColors.DefaultBlack.getColor());
|
||||
|
||||
int cellDataLine = 37;
|
||||
final int types = this.getTypes();
|
||||
final long bytesAllocated = this.getBytesAllocated(types);
|
||||
this.fontRendererObj.drawString(
|
||||
GuiText.BytesPerType.getLocal() + " " + cellData.getPerType(),
|
||||
64,
|
||||
70,
|
||||
GuiText.MaximumOfResource.getLocal(fmt(this.getMaxAmount(types))),
|
||||
BASE_LINE_X,
|
||||
cellDataLine += 10,
|
||||
GuiColors.DefaultBlack.getColor());
|
||||
this.fontRendererObj.drawString(
|
||||
GuiText.BytesTotal.getLocal(fmt(this.cellData.totalBytes)),
|
||||
BASE_LINE_X,
|
||||
cellDataLine += 10,
|
||||
GuiColors.DefaultBlack.getColor());
|
||||
|
||||
this.fontRendererObj.drawString(
|
||||
GuiText.BytesAllocated.getLocal(fmt(bytesAllocated)),
|
||||
BASE_LINE_X,
|
||||
cellDataLine += 10,
|
||||
GuiColors.DefaultBlack.getColor());
|
||||
|
||||
this.fontRendererObj.drawString(
|
||||
GuiText.BytesFree.getLocal(fmt(this.getFreeBytes(bytesAllocated))),
|
||||
BASE_LINE_X,
|
||||
cellDataLine += 10,
|
||||
GuiColors.DefaultBlack.getColor());
|
||||
|
||||
this.fontRendererObj.drawString(
|
||||
GuiText.ResourcesPerByte.getLocal(fmt(this.cellData.perByte)),
|
||||
BASE_LINE_X,
|
||||
cellDataLine += 10,
|
||||
GuiColors.DefaultBlack.getColor());
|
||||
|
||||
this.fontRendererObj.drawString(
|
||||
GuiText.BytesPerType.getLocal(fmt(this.cellData.perType)),
|
||||
BASE_LINE_X,
|
||||
cellDataLine += 10,
|
||||
GuiColors.DefaultBlack.getColor());
|
||||
}
|
||||
|
||||
@@ -136,28 +143,68 @@ public class GuiCellRestriction extends GuiSub {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void keyTyped(final char character, final int key) {
|
||||
if (key == Keyboard.KEY_RETURN || key == Keyboard.KEY_NUMPADENTER) {
|
||||
try {
|
||||
NetworkHandler.instance.sendToServer(new PacketValueConfig("cellRestriction", filterCellRestriction()));
|
||||
} catch (IOException e) {
|
||||
AELog.debug(e);
|
||||
}
|
||||
NetworkHandler.instance.sendToServer(new PacketSwitchGuis());
|
||||
} else if (!(this.amountField.textboxKeyTyped(character, key)
|
||||
|| this.typesField.textboxKeyTyped(character, key))) {
|
||||
super.keyTyped(character, key);
|
||||
}
|
||||
protected void actionPerformed(GuiButton btn) {
|
||||
if (btn == this.reset) {
|
||||
this.cellRestriction.cellRestrictionDataSync.set(new CellRestrictionData((byte) 0, 0));
|
||||
this.cellRestriction.updated = true;
|
||||
} else super.actionPerformed(btn);
|
||||
}
|
||||
|
||||
private long getAmount() {
|
||||
String out = this.amountField.getText();
|
||||
double resultD = Calculator.conversion(out);
|
||||
@Override
|
||||
protected void keyTyped(final char character, final int key) {
|
||||
if (key == Keyboard.KEY_RETURN || key == Keyboard.KEY_NUMPADENTER) {
|
||||
this.cellRestriction.cellRestrictionDataSync.set(filterCellRestriction());
|
||||
this.cellRestriction.tickClientSync();
|
||||
NetworkHandler.instance.sendToServer(new PacketSwitchGuis());
|
||||
} else
|
||||
if (!(this.amountField.textboxKeyTyped(character, key) || this.typesField.textboxKeyTyped(character, key)))
|
||||
super.keyTyped(character, key);
|
||||
}
|
||||
|
||||
if (resultD <= 0 || Double.isNaN(resultD)) {
|
||||
private static String fmt(double v) {
|
||||
return NumberFormatUtil.formatNumber(v);
|
||||
}
|
||||
|
||||
private CellRestrictionData filterCellRestriction() {
|
||||
final byte types = (byte) this.getTypes();
|
||||
return new CellRestrictionData(types, this.getAmount(types));
|
||||
}
|
||||
|
||||
private long getFreeBytes(final long bytesAllocated) {
|
||||
return this.cellData.totalBytes - bytesAllocated;
|
||||
}
|
||||
|
||||
private long getBytesAllocated(final int types) {
|
||||
final int nTypes = types == 0 ? this.cellData.totalTypes : types;
|
||||
return (long) this.cellData.perType * nTypes
|
||||
+ (long) Math.ceil((double) this.getAmount(types) / this.cellData.perByte);
|
||||
}
|
||||
|
||||
private long getMaxAmount(final int types) {
|
||||
final int nTypes = types == 0 ? this.cellData.totalTypes : types;
|
||||
return (this.cellData.totalBytes - (long) this.cellData.perType * nTypes) * this.cellData.perByte;
|
||||
}
|
||||
|
||||
private long getAmount(final int types) {
|
||||
try {
|
||||
final double resultD = Calculator.conversion(this.amountField.getText());
|
||||
|
||||
if (resultD <= 0 || Double.isNaN(resultD)) return 0;
|
||||
else return (long) Math.min(ArithHelper.round(resultD, 0), this.getMaxAmount(types));
|
||||
} catch (Exception ignored) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
private int getTypes() {
|
||||
try {
|
||||
return Math.max(
|
||||
0,
|
||||
Math.min(
|
||||
Integer.parseInt(this.typesField.getText()),
|
||||
this.cellRestriction.cellDataSync.get().totalTypes));
|
||||
} catch (Exception ignored) {
|
||||
return 0;
|
||||
} else {
|
||||
return (long) ArithHelper.round(resultD, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,127 +1,52 @@
|
||||
package appeng.container.implementations;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
|
||||
import appeng.client.gui.widgets.MEGuiTextField;
|
||||
import appeng.container.ContainerSubGui;
|
||||
import appeng.container.guisync.GuiSync;
|
||||
import appeng.container.sync.SyncCodecs;
|
||||
import appeng.container.sync.SyncRegistrar;
|
||||
import appeng.container.sync.handlers.ObjectSyncHandler;
|
||||
import appeng.helpers.ICellRestriction;
|
||||
import appeng.helpers.ICellRestriction.CellData;
|
||||
import appeng.helpers.ICellRestriction.CellRestrictionData;
|
||||
import appeng.util.Platform;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
public class ContainerCellRestriction extends ContainerSubGui {
|
||||
|
||||
public static class CellData {
|
||||
|
||||
private Long totalBytes;
|
||||
private Integer totalTypes;
|
||||
private Integer perType;
|
||||
private Integer perByte;
|
||||
private String cellType;
|
||||
|
||||
public void setPerType(Integer perType) {
|
||||
this.perType = perType;
|
||||
}
|
||||
|
||||
public void setTotalBytes(Long totalBytes) {
|
||||
this.totalBytes = totalBytes;
|
||||
}
|
||||
|
||||
public void setTotalTypes(Integer totalTypes) {
|
||||
this.totalTypes = totalTypes;
|
||||
}
|
||||
|
||||
public void setPerByte(Integer perByte) {
|
||||
this.perByte = perByte;
|
||||
}
|
||||
|
||||
public void setCellType(String cellType) {
|
||||
this.cellType = cellType;
|
||||
}
|
||||
|
||||
public Integer getPerType() {
|
||||
return perType;
|
||||
}
|
||||
|
||||
public Integer getTotalTypes() {
|
||||
return totalTypes;
|
||||
}
|
||||
|
||||
public Long getTotalBytes() {
|
||||
return totalBytes;
|
||||
}
|
||||
|
||||
public Integer getPerByte() {
|
||||
return perByte;
|
||||
}
|
||||
|
||||
public String getCellType() {
|
||||
return cellType;
|
||||
}
|
||||
}
|
||||
|
||||
private final ICellRestriction Host;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
private MEGuiTextField typesField;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
private MEGuiTextField amountField;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
private CellData cellData;
|
||||
|
||||
@GuiSync(69)
|
||||
public String cellRestriction;
|
||||
public final ObjectSyncHandler<CellData> cellDataSync;
|
||||
public final ObjectSyncHandler<CellRestrictionData> cellRestrictionDataSync;
|
||||
public boolean updated = false;
|
||||
|
||||
public ContainerCellRestriction(final InventoryPlayer ip, final ICellRestriction te) {
|
||||
super(ip, te);
|
||||
this.Host = te;
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void setAmountField(final MEGuiTextField f) {
|
||||
this.amountField = f;
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void setTypesField(final MEGuiTextField f) {
|
||||
this.typesField = f;
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void setCellData(CellData newCellData) {
|
||||
this.cellData = newCellData;
|
||||
}
|
||||
|
||||
public void setCellRestriction(String data) {
|
||||
this.Host.setCellRestriction(null, data);
|
||||
this.cellRestriction = data;
|
||||
final SyncRegistrar sync = this.syncRegistrar();
|
||||
this.cellDataSync = sync.object(
|
||||
"cellData",
|
||||
SyncCodecs.packetWritable(CellData.class, CellData::new, CellData::copy, Objects::equals),
|
||||
this.Host.getCellData(null)).onClientChange((oldValue, newValue) -> { this.updated = true; });
|
||||
this.cellRestrictionDataSync = sync
|
||||
.object(
|
||||
"cellRestrictionData",
|
||||
SyncCodecs.packetWritable(
|
||||
CellRestrictionData.class,
|
||||
CellRestrictionData::new,
|
||||
CellRestrictionData::copy,
|
||||
Objects::equals),
|
||||
this.Host.getCellRestrictionData(null))
|
||||
.onServerChange((oldValue, newValue) -> { this.Host.setCellRestriction(null, newValue); })
|
||||
.onClientChange((oldValue, newValue) -> { this.updated = true; });
|
||||
}
|
||||
|
||||
@Override
|
||||
public void detectAndSendChanges() {
|
||||
if (Platform.isServer()) this.cellRestriction = this.Host.getCellData(null);
|
||||
if (Platform.isServer()) {
|
||||
this.cellDataSync.set(this.Host.getCellData(null));
|
||||
this.cellRestrictionDataSync.set(this.Host.getCellRestrictionData(null));
|
||||
}
|
||||
super.detectAndSendChanges();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpdate(final String field, final Object oldValue, final Object newValue) {
|
||||
if (field.equals("cellRestriction") && (this.amountField != null && this.typesField != null)) {
|
||||
String[] newData = cellRestriction.split(",", 7);
|
||||
this.cellData.setTotalBytes(Long.parseLong(newData[0]));
|
||||
this.cellData.setTotalTypes(Integer.parseInt(newData[1]));
|
||||
this.cellData.setPerType(Integer.parseInt(newData[2]));
|
||||
this.cellData.setPerByte(Integer.parseInt(newData[3]));
|
||||
this.cellData.setCellType(newData[6]);
|
||||
this.typesField.setMaxStringLength(cellData.getTotalTypes().toString().length());
|
||||
this.amountField.setMaxStringLength(
|
||||
String.valueOf((cellData.getTotalBytes() - cellData.getPerType()) * cellData.getPerByte())
|
||||
.length());
|
||||
this.typesField.setText(newData[4]);
|
||||
this.amountField.setText(newData[5]);
|
||||
}
|
||||
super.onUpdate(field, oldValue, newValue);
|
||||
}
|
||||
}
|
||||
@@ -278,16 +278,20 @@ public enum GuiText implements Localization {
|
||||
ToFollow,
|
||||
ToUnfollow,
|
||||
CellRestriction,
|
||||
CellRestrictionTips,
|
||||
Restricted,
|
||||
MaxItems,
|
||||
MaxFluid,
|
||||
MaxTypes,
|
||||
NumberOfItems,
|
||||
NumberOfFluids,
|
||||
ItemsPerByte,
|
||||
FluidsPerByte,
|
||||
|
||||
ResourceAmount,
|
||||
MaximumOfResource,
|
||||
BytesTotal,
|
||||
BytesFree,
|
||||
BytesAllocated,
|
||||
ResourcesPerByte,
|
||||
BytesPerType,
|
||||
ResetRestriction,
|
||||
ResetRestrictionHint,
|
||||
|
||||
ControlButtonValuesDesc1,
|
||||
ControlButtonValuesDesc2,
|
||||
|
||||
|
||||
@@ -26,7 +26,6 @@ import appeng.api.util.IConfigManager;
|
||||
import appeng.api.util.IConfigurableObject;
|
||||
import appeng.container.AEBaseContainer;
|
||||
import appeng.container.PrimaryGui;
|
||||
import appeng.container.implementations.ContainerCellRestriction;
|
||||
import appeng.container.implementations.ContainerCellWorkbench;
|
||||
import appeng.container.implementations.ContainerCraftConfirm;
|
||||
import appeng.container.implementations.ContainerCraftingCPU;
|
||||
@@ -173,8 +172,6 @@ public class PacketValueConfig extends AppEngPacket {
|
||||
} else if (this.Name.equals("CellWorkbench.Fuzzy")) {
|
||||
ccw.setFuzzy(FuzzyMode.valueOf(this.Value));
|
||||
}
|
||||
} else if (this.Name.equals("cellRestriction") && c instanceof final ContainerCellRestriction ccr) {
|
||||
ccr.setCellRestriction(this.Value);
|
||||
} else if (c instanceof ContainerNetworkTool) {
|
||||
if (this.Name.equals("NetworkTool") && this.Value.equals("Toggle")) {
|
||||
((ContainerNetworkTool) c).toggleFacadeMode();
|
||||
|
||||
@@ -2,9 +2,96 @@ package appeng.helpers;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import appeng.container.guisync.IGuiPacketWritable;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
public interface ICellRestriction {
|
||||
|
||||
String getCellData(ItemStack is);
|
||||
class CellData implements IGuiPacketWritable {
|
||||
|
||||
void setCellRestriction(ItemStack is, String newData);
|
||||
public final long totalBytes;
|
||||
public final int totalTypes;
|
||||
public final int perType;
|
||||
public final int perByte;
|
||||
|
||||
public CellData(final long totalBytes, final int totalTypes, final int perType, final int perByte) {
|
||||
this.totalBytes = totalBytes;
|
||||
this.totalTypes = totalTypes;
|
||||
this.perType = perType;
|
||||
this.perByte = perByte;
|
||||
}
|
||||
|
||||
public CellData(ByteBuf buf) {
|
||||
this.totalBytes = buf.readLong();
|
||||
this.totalTypes = buf.readInt();
|
||||
this.perType = buf.readInt();
|
||||
this.perByte = buf.readInt();
|
||||
}
|
||||
|
||||
public CellData copy() {
|
||||
return new CellData(this.totalBytes, this.totalTypes, this.perType, this.perByte);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToPacket(ByteBuf buf) {
|
||||
buf.writeLong(this.totalBytes);
|
||||
buf.writeInt(this.totalTypes);
|
||||
buf.writeInt(this.perType);
|
||||
buf.writeInt(this.perByte);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof CellData cd) {
|
||||
return cd.totalBytes == this.totalBytes && cd.totalTypes == this.totalTypes
|
||||
&& cd.perType == this.perType
|
||||
&& cd.perByte == this.perByte;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
class CellRestrictionData implements IGuiPacketWritable {
|
||||
|
||||
public final byte restrictionTypes;
|
||||
public final long restrictionAmount;
|
||||
|
||||
public CellRestrictionData(final byte restrictionTypes, final long restrictionAmount) {
|
||||
this.restrictionTypes = restrictionTypes;
|
||||
this.restrictionAmount = restrictionAmount;
|
||||
}
|
||||
|
||||
public CellRestrictionData(ByteBuf buf) {
|
||||
this.restrictionTypes = buf.readByte();
|
||||
this.restrictionAmount = buf.readLong();
|
||||
}
|
||||
|
||||
public CellRestrictionData copy() {
|
||||
return new CellRestrictionData(this.restrictionTypes, this.restrictionAmount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToPacket(ByteBuf buf) {
|
||||
buf.writeByte(this.restrictionTypes);
|
||||
buf.writeLong(this.restrictionAmount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof CellRestrictionData crd) {
|
||||
return crd.restrictionTypes == this.restrictionTypes && crd.restrictionAmount == this.restrictionAmount;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isReset() {
|
||||
return this.restrictionTypes == 0 && this.restrictionAmount == 0;
|
||||
}
|
||||
}
|
||||
|
||||
CellData getCellData(ItemStack is);
|
||||
|
||||
CellRestrictionData getCellRestrictionData(ItemStack is);
|
||||
|
||||
void setCellRestriction(ItemStack is, CellRestrictionData newRestriction);
|
||||
}
|
||||
@@ -4,7 +4,6 @@ import static appeng.util.item.AEItemStackType.ITEM_STACK_TYPE;
|
||||
|
||||
import java.text.NumberFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
@@ -208,14 +207,15 @@ public abstract class AEBaseCell extends AEBaseItem implements IStorageCell, IIt
|
||||
lines.add(GuiText.Sticky.getLocal());
|
||||
}
|
||||
}
|
||||
List<Object> restricted = handler.getRestricted();
|
||||
if (restricted != null && ((long) restricted.get(0) != 0 || (byte) restricted.get(1) != 0)) {
|
||||
final CellRestrictionData cellRestrictionData = this.getCellRestrictionData(stack);
|
||||
if (cellRestrictionData.restrictionTypes != 0 || cellRestrictionData.restrictionAmount != 0) {
|
||||
lines.add(GuiText.Restricted.getLocal());
|
||||
if (GuiScreen.isShiftKeyDown()) {
|
||||
NumberFormat nf = NumberFormat.getNumberInstance();
|
||||
if ((long) restricted.get(0) != 0)
|
||||
lines.add(GuiText.MaxItems.getLocal() + " " + nf.format((long) restricted.get(0)));
|
||||
if ((byte) restricted.get(1) != 0) lines.add(GuiText.MaxTypes.getLocal() + " " + restricted.get(1));
|
||||
final NumberFormat nf = NumberFormat.getNumberInstance();
|
||||
if (cellRestrictionData.restrictionTypes != 0)
|
||||
lines.add(GuiText.MaxTypes.getLocal(cellRestrictionData.restrictionTypes));
|
||||
if (cellRestrictionData.restrictionAmount != 0)
|
||||
lines.add(GuiText.MaxItems.getLocal(nf.format(cellRestrictionData.restrictionAmount)));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -391,29 +391,32 @@ public abstract class AEBaseCell extends AEBaseItem implements IStorageCell, IIt
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCellData(ItemStack is) {
|
||||
return totalBytes + ","
|
||||
+ this.getTotalTypes(null)
|
||||
+ ","
|
||||
+ perType
|
||||
+ ","
|
||||
+ 8
|
||||
+ ","
|
||||
+ ItemStackNBT.getByte(is, "cellRestrictionTypes")
|
||||
+ ","
|
||||
+ ItemStackNBT.getLong(is, "cellRestrictionAmount")
|
||||
+ ","
|
||||
+ "item";
|
||||
public CellData getCellData(ItemStack is) {
|
||||
return new CellData(this.totalBytes, this.totalTypes, this.perType, 8);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCellRestriction(ItemStack is, String newData) {
|
||||
List<String> data = Arrays.asList(newData.split(",", 2));
|
||||
ItemStackNBT.setByte(is, "cellRestrictionTypes", Byte.parseByte(data.get(0)));
|
||||
ItemStackNBT.setLong(is, "cellRestrictionAmount", Long.parseLong(data.get(1)));
|
||||
public CellRestrictionData getCellRestrictionData(ItemStack is) {
|
||||
return new CellRestrictionData(
|
||||
ItemStackNBT.getByte(is, "cellRestrictionTypes"),
|
||||
ItemStackNBT.getLong(is, "cellRestrictionAmount"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCellRestriction(ItemStack is, CellRestrictionData newRestriction) {
|
||||
if (newRestriction.isReset()) {
|
||||
ItemStackNBT.removeTag(is, "cellRestrictionTypes");
|
||||
ItemStackNBT.removeTag(is, "cellRestrictionAmount");
|
||||
} else {
|
||||
ItemStackNBT.setByte(is, "cellRestrictionTypes", newRestriction.restrictionTypes);
|
||||
ItemStackNBT.setLong(is, "cellRestrictionAmount", newRestriction.restrictionAmount);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public abstract IAEStackType<?> getStackType();
|
||||
|
||||
@Override
|
||||
public abstract int getTypeWeight();
|
||||
}
|
||||
@@ -179,4 +179,9 @@ public abstract class AEBasePortableCell extends AEBasePoweredItem implements IS
|
||||
public void setOreFilter(ItemStack is, String filter) {
|
||||
ItemStackNBT.setString(is, "OreFilter", filter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTypeWeight() {
|
||||
return 8;
|
||||
}
|
||||
}
|
||||
@@ -35,4 +35,9 @@ public class ItemBasicStorageCell extends AEBaseCell {
|
||||
public IAEStackType<?> getStackType() {
|
||||
return ITEM_STACK_TYPE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTypeWeight() {
|
||||
return 8;
|
||||
}
|
||||
}
|
||||
@@ -668,4 +668,9 @@ public class ToolColorApplicator extends AEBasePoweredItem
|
||||
public void setOreFilter(ItemStack is, String filter) {
|
||||
ItemStackNBT.setString(is, "OreFilter", filter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTypeWeight() {
|
||||
return 8;
|
||||
}
|
||||
}
|
||||
@@ -518,4 +518,9 @@ public class ToolMassCannon extends AEBasePoweredItem implements IStorageCell {
|
||||
public void setOreFilter(ItemStack is, String filter) {
|
||||
ItemStackNBT.setString(is, "OreFilter", filter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTypeWeight() {
|
||||
return 8;
|
||||
}
|
||||
}
|
||||
@@ -13,9 +13,6 @@ package appeng.me.storage;
|
||||
import static appeng.util.item.AEFluidStackType.FLUID_STACK_TYPE;
|
||||
import static appeng.util.item.AEItemStackType.ITEM_STACK_TYPE;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import net.minecraft.inventory.IInventory;
|
||||
@@ -59,7 +56,7 @@ public abstract class CellInventory<StackType extends IAEStack<StackType>> imple
|
||||
private boolean cardDistribution = false;
|
||||
private byte restrictionTypes = 0;
|
||||
private long restrictionLong = 0;
|
||||
private int typeWeight = 8;
|
||||
private int typeWeight = 1;
|
||||
private final int distTypesCount;
|
||||
|
||||
protected CellInventory(final ItemStack o, final ISaveProvider container) throws AppEngException {
|
||||
@@ -72,6 +69,7 @@ public abstract class CellInventory<StackType extends IAEStack<StackType>> imple
|
||||
if (this.cellItem.getItem() instanceof IStorageCell type) {
|
||||
this.cellType = type;
|
||||
this.maxTypes = this.cellType.getTotalTypes(this.cellItem);
|
||||
this.typeWeight = type.getTypeWeight();
|
||||
} else this.cellType = null;
|
||||
|
||||
if (this.cellType == null) {
|
||||
@@ -593,14 +591,6 @@ public abstract class CellInventory<StackType extends IAEStack<StackType>> imple
|
||||
return 4;
|
||||
}
|
||||
|
||||
public List<Object> getRestriction() {
|
||||
return Arrays.asList(restrictionLong, restrictionTypes);
|
||||
}
|
||||
|
||||
protected void setTypeWeight(int typeWeight) {
|
||||
this.typeWeight = typeWeight;
|
||||
}
|
||||
|
||||
@Override
|
||||
public StorageChannel getChannel() {
|
||||
IAEStackType<?> type = this.getStackType();
|
||||
|
||||
@@ -10,8 +10,6 @@
|
||||
|
||||
package appeng.me.storage;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
@@ -160,13 +158,4 @@ public abstract class CellInventoryHandler<StackType extends IAEStack<StackType>
|
||||
public TYPE getCellType() {
|
||||
return this.getStorageChannel() == StorageChannel.FLUIDS ? TYPE.FLUID : TYPE.ITEM;
|
||||
}
|
||||
|
||||
public List<Object> getRestricted() {
|
||||
ICellInventory<?> cellInventory = this.getCellInv();
|
||||
if (cellInventory instanceof CellInventory<?>ci) {
|
||||
return ci.getRestriction();
|
||||
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -12,8 +12,6 @@ public class FluidCellInventory extends CellInventory<IAEFluidStack> {
|
||||
|
||||
public FluidCellInventory(ItemStack o, ISaveProvider container2) throws AppEngException {
|
||||
super(o, container2);
|
||||
|
||||
this.setTypeWeight(256 * 8);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -12,8 +12,6 @@ public class ItemCellInventory extends CellInventory<IAEItemStack> {
|
||||
|
||||
public ItemCellInventory(ItemStack o, ISaveProvider container2) throws AppEngException {
|
||||
super(o, container2);
|
||||
|
||||
this.setTypeWeight(8);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -146,7 +146,7 @@ public class TileCellWorkbench extends AEBaseTile implements ICellWorkbench, IPr
|
||||
ItemStack is = this.cell.getStackInSlot(0);
|
||||
if (this.manager.getSetting(Settings.COPY_MODE) == CopyMode.KEEP_ON_REMOVE) {
|
||||
if (is != null && is.getItem() instanceof ICellRestriction icr)
|
||||
icr.setCellRestriction(is, cellRestrictTypes + "," + cellRestrictAmount);
|
||||
icr.setCellRestriction(is, new CellRestrictionData(cellRestrictTypes, cellRestrictAmount));
|
||||
}
|
||||
|
||||
if (is != null && is.getItem() instanceof ICellWorkbenchItem wi) {
|
||||
@@ -251,22 +251,28 @@ public class TileCellWorkbench extends AEBaseTile implements ICellWorkbench, IPr
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCellData(ItemStack n) {
|
||||
public CellData getCellData(ItemStack n) {
|
||||
ItemStack is = this.cell.getStackInSlot(0);
|
||||
if (is != null && is.getItem() instanceof ICellRestriction icr) return icr.getCellData(is);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCellRestriction(ItemStack n, String newData) {
|
||||
public CellRestrictionData getCellRestrictionData(ItemStack n) {
|
||||
ItemStack is = this.cell.getStackInSlot(0);
|
||||
if (is != null && is.getItem() instanceof ICellRestriction icr) return icr.getCellRestrictionData(is);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCellRestriction(ItemStack n, CellRestrictionData newRestriction) {
|
||||
if (this.manager.getSetting(Settings.COPY_MODE) == CopyMode.KEEP_ON_REMOVE) {
|
||||
String[] s = newData.split(",", 2);
|
||||
cellRestrictTypes = Byte.parseByte(s[0]);
|
||||
cellRestrictAmount = Long.parseLong(s[1]);
|
||||
this.cellRestrictTypes = newRestriction.restrictionTypes;
|
||||
this.cellRestrictAmount = newRestriction.restrictionAmount;
|
||||
}
|
||||
|
||||
ItemStack is = this.cell.getStackInSlot(0);
|
||||
if (is != null && is.getItem() instanceof ICellRestriction icr) icr.setCellRestriction(is, newData);
|
||||
if (is != null && is.getItem() instanceof ICellRestriction icr) icr.setCellRestriction(is, newRestriction);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -452,15 +452,19 @@ gui.appliedenergistics2.ToFollow=Follow
|
||||
gui.appliedenergistics2.ToUnfollow=Unfollow
|
||||
gui.appliedenergistics2.CellRestriction=Cell Restriction
|
||||
gui.appliedenergistics2.Restricted=Restricted
|
||||
gui.appliedenergistics2.CellRestrictionTips=0 for default
|
||||
gui.appliedenergistics2.MaxItems=Max Items:
|
||||
gui.appliedenergistics2.MaxFluid=Max Fluids:
|
||||
gui.appliedenergistics2.MaxTypes=Max Types:
|
||||
gui.appliedenergistics2.NumberOfItems=Number of items
|
||||
gui.appliedenergistics2.NumberOfFluids=Number of fluids
|
||||
gui.appliedenergistics2.ItemsPerByte=Items per byte:
|
||||
gui.appliedenergistics2.FluidsPerByte=Fluids per byte:
|
||||
gui.appliedenergistics2.BytesPerType=Bytes per type:
|
||||
gui.appliedenergistics2.MaxItems=Max Resources: %s
|
||||
gui.appliedenergistics2.MaxTypes=Max Types: %s
|
||||
|
||||
gui.appliedenergistics2.ResourceAmount=Resource amount
|
||||
gui.appliedenergistics2.MaximumOfResource=Max: §6%s
|
||||
gui.appliedenergistics2.BytesAllocated=Allocated bytes: §c%s
|
||||
gui.appliedenergistics2.BytesTotal=Total bytes: §5%s
|
||||
gui.appliedenergistics2.BytesFree=Free bytes: §2%s
|
||||
gui.appliedenergistics2.ResourcesPerByte=Resources per byte: §6%s
|
||||
gui.appliedenergistics2.BytesPerType=Byte per type: §6%s
|
||||
gui.appliedenergistics2.ResetRestriction=R
|
||||
gui.appliedenergistics2.ResetRestrictionHint=Reset restriction
|
||||
|
||||
gui.appliedenergistics2.ControlButtonValuesDesc1=Set custom amount step values
|
||||
gui.appliedenergistics2.ControlButtonValuesDesc2=Negative buttons are mirrored
|
||||
gui.appliedenergistics2.SelectColor=Select a Color
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 906 B After Width: | Height: | Size: 649 B |
Reference in new issue
Block a user