Merge remote-tracking branch 'origin/8.0.x-1.16.1'
This commit is contained in:
@@ -13,8 +13,6 @@ import appeng.client.gui.implementations.NumberEntryWidget;
|
||||
import appeng.client.gui.implementations.UpgradeableScreen;
|
||||
import appeng.client.gui.widgets.ServerSettingToggleButton;
|
||||
import appeng.core.localization.GuiText;
|
||||
import appeng.core.sync.network.NetworkHandler;
|
||||
import appeng.core.sync.packets.ConfigValuePacket;
|
||||
import appeng.fluids.client.gui.widgets.FluidSlotWidget;
|
||||
import appeng.fluids.container.FluidLevelEmitterContainer;
|
||||
|
||||
@@ -31,17 +29,24 @@ public class FluidLevelEmitterScreen extends UpgradeableScreen<FluidLevelEmitter
|
||||
public void init() {
|
||||
super.init();
|
||||
|
||||
this.level = new NumberEntryWidget(this, 20, 17, 138, 62, NumberEntryType.LEVEL_FLUID_VOLUME,
|
||||
this::onLevelChange);
|
||||
this.level = new NumberEntryWidget(this, 20, 17, 138, 62, NumberEntryType.LEVEL_FLUID_VOLUME);
|
||||
this.level.setTextFieldBounds(25, 44, 75);
|
||||
container.setTextField(this.level);
|
||||
this.level.addButtons(children::add, this::addButton);
|
||||
this.level.setValue(container.getReportingValue());
|
||||
this.level.setOnChange(this::saveReportingValue);
|
||||
this.level.setOnConfirm(this::closeScreen);
|
||||
|
||||
this.changeFocus(true);
|
||||
|
||||
final int y = 40;
|
||||
final int x = 80 + 57;
|
||||
this.guiSlots.add(new FluidSlotWidget(this.container.getFluidConfigInventory(), 0, 0, x, y));
|
||||
}
|
||||
|
||||
private void saveReportingValue() {
|
||||
this.level.getLongValue().ifPresent(container::setReportingValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addButtons() {
|
||||
this.redstoneMode = new ServerSettingToggleButton<>(this.guiLeft - 18, this.guiTop + 28,
|
||||
@@ -82,8 +87,4 @@ public class FluidLevelEmitterScreen extends UpgradeableScreen<FluidLevelEmitter
|
||||
protected void handleButtonVisibility() {
|
||||
}
|
||||
|
||||
private void onLevelChange(long level) {
|
||||
NetworkHandler.instance().sendToServer(new ConfigValuePacket("FluidLevelEmitter.Value", String.valueOf(level)));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -71,7 +71,7 @@ public abstract class FluidConfigurableContainer extends UpgradeableContainer im
|
||||
|
||||
@Override
|
||||
protected void standardDetectAndSendChanges() {
|
||||
if (Platform.isServer()) {
|
||||
if (isServer()) {
|
||||
this.getSyncHelper().sendDiff(this.listeners);
|
||||
|
||||
// clear out config items that are no longer valid (eg capacity upgrade removed)
|
||||
|
||||
@@ -81,7 +81,7 @@ public class FluidInterfaceContainer extends FluidConfigurableContainer {
|
||||
public void detectAndSendChanges() {
|
||||
this.verifyPermissions(SecurityPermissions.BUILD, false);
|
||||
|
||||
if (Platform.isServer()) {
|
||||
if (isServer()) {
|
||||
this.tankSync.sendDiff(this.listeners);
|
||||
}
|
||||
|
||||
|
||||
@@ -4,16 +4,14 @@ import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.inventory.container.ContainerType;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
|
||||
import appeng.api.config.RedstoneMode;
|
||||
import appeng.api.config.SecurityPermissions;
|
||||
import appeng.api.config.Settings;
|
||||
import appeng.client.gui.implementations.NumberEntryWidget;
|
||||
import appeng.container.ContainerLocator;
|
||||
import appeng.container.guisync.GuiSync;
|
||||
import appeng.container.implementations.ContainerHelper;
|
||||
import appeng.core.sync.network.NetworkHandler;
|
||||
import appeng.core.sync.packets.ConfigValuePacket;
|
||||
import appeng.fluids.parts.FluidLevelEmitterPart;
|
||||
import appeng.fluids.util.IAEFluidTank;
|
||||
import appeng.util.Platform;
|
||||
@@ -25,34 +23,41 @@ public class FluidLevelEmitterContainer extends FluidConfigurableContainer {
|
||||
FluidLevelEmitterContainer::new, FluidLevelEmitterPart.class, SecurityPermissions.BUILD);
|
||||
|
||||
public static FluidLevelEmitterContainer fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) {
|
||||
return helper.fromNetwork(windowId, inv, buf);
|
||||
return helper.fromNetwork(windowId, inv, buf, (host, container, buffer) -> {
|
||||
container.reportingValue = buffer.readVarLong();
|
||||
});
|
||||
}
|
||||
|
||||
public static boolean open(PlayerEntity player, ContainerLocator locator) {
|
||||
return helper.open(player, locator);
|
||||
return helper.open(player, locator, (host, buffer) -> {
|
||||
buffer.writeVarLong(host.getReportingValue());
|
||||
});
|
||||
}
|
||||
|
||||
private final FluidLevelEmitterPart lvlEmitter;
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
private NumberEntryWidget textField;
|
||||
@GuiSync(3)
|
||||
public long EmitterValue = -1;
|
||||
// Only synced once on container-open, and only used on client
|
||||
private long reportingValue;
|
||||
|
||||
public FluidLevelEmitterContainer(int id, final PlayerInventory ip, final FluidLevelEmitterPart te) {
|
||||
super(TYPE, id, ip, te);
|
||||
this.lvlEmitter = te;
|
||||
}
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public void setTextField(final NumberEntryWidget level) {
|
||||
this.textField = level;
|
||||
this.textField.setValue(this.EmitterValue);
|
||||
public long getReportingValue() {
|
||||
return reportingValue;
|
||||
}
|
||||
|
||||
public void setLevel(final long l, final PlayerEntity player) {
|
||||
this.lvlEmitter.setReportingValue(l);
|
||||
this.EmitterValue = l;
|
||||
public void setReportingValue(long reportingValue) {
|
||||
if (isClient()) {
|
||||
if (reportingValue != this.reportingValue) {
|
||||
this.reportingValue = reportingValue;
|
||||
NetworkHandler.instance()
|
||||
.sendToServer(new ConfigValuePacket("FluidLevelEmitter.Value", String.valueOf(reportingValue)));
|
||||
}
|
||||
} else {
|
||||
this.lvlEmitter.setReportingValue(reportingValue);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -74,8 +79,7 @@ public class FluidLevelEmitterContainer extends FluidConfigurableContainer {
|
||||
public void detectAndSendChanges() {
|
||||
this.verifyPermissions(SecurityPermissions.BUILD, false);
|
||||
|
||||
if (Platform.isServer()) {
|
||||
this.EmitterValue = this.lvlEmitter.getReportingValue();
|
||||
if (isServer()) {
|
||||
this.setRedStoneMode(
|
||||
(RedstoneMode) this.getUpgradeable().getConfigManager().getSetting(Settings.REDSTONE_EMITTER));
|
||||
}
|
||||
@@ -83,15 +87,6 @@ public class FluidLevelEmitterContainer extends FluidConfigurableContainer {
|
||||
this.standardDetectAndSendChanges();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpdate(final String field, final Object oldValue, final Object newValue) {
|
||||
if (field.equals("EmitterValue")) {
|
||||
if (this.textField != null) {
|
||||
this.textField.setValue(this.EmitterValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAEFluidTank getFluidConfigInventory() {
|
||||
return this.lvlEmitter.getConfig();
|
||||
|
||||
@@ -128,7 +128,7 @@ public class FluidStorageBusContainer extends FluidConfigurableContainer {
|
||||
public void detectAndSendChanges() {
|
||||
this.verifyPermissions(SecurityPermissions.BUILD, false);
|
||||
|
||||
if (Platform.isServer()) {
|
||||
if (isServer()) {
|
||||
this.setFuzzyMode((FuzzyMode) this.getUpgradeable().getConfigManager().getSetting(Settings.FUZZY_MODE));
|
||||
this.setReadWriteMode(
|
||||
(AccessRestriction) this.getUpgradeable().getConfigManager().getSetting(Settings.ACCESS));
|
||||
|
||||
@@ -119,7 +119,7 @@ public class FluidTerminalContainer extends AEBaseContainer
|
||||
this.clientCM.registerSetting(Settings.SORT_BY, SortOrder.NAME);
|
||||
this.clientCM.registerSetting(Settings.SORT_DIRECTION, SortDir.ASCENDING);
|
||||
this.clientCM.registerSetting(Settings.VIEW_MODE, ViewItems.ALL);
|
||||
if (Platform.isServer()) {
|
||||
if (isServer()) {
|
||||
this.serverCM = terminal.getConfigManager();
|
||||
this.monitor = terminal
|
||||
.getInventory(Api.instance().storage().getStorageChannel(IFluidStorageChannel.class));
|
||||
@@ -191,7 +191,7 @@ public class FluidTerminalContainer extends AEBaseContainer
|
||||
}
|
||||
|
||||
private void queueInventory(final IContainerListener c) {
|
||||
if (Platform.isServer() && c instanceof PlayerEntity && this.monitor != null) {
|
||||
if (isServer() && c instanceof PlayerEntity && this.monitor != null) {
|
||||
try {
|
||||
MEFluidInventoryUpdatePacket piu = new MEFluidInventoryUpdatePacket();
|
||||
final IItemList<IAEFluidStack> monitorCache = this.monitor.getStorageList();
|
||||
@@ -216,14 +216,14 @@ public class FluidTerminalContainer extends AEBaseContainer
|
||||
|
||||
@Override
|
||||
public IConfigManager getConfigManager() {
|
||||
if (Platform.isServer()) {
|
||||
if (isServer()) {
|
||||
return this.serverCM;
|
||||
}
|
||||
return this.clientCM;
|
||||
}
|
||||
|
||||
public void setTargetStack(final IAEFluidStack stack) {
|
||||
if (Platform.isClient()) {
|
||||
if (isClient()) {
|
||||
if (stack == null && this.clientRequestedTargetFluid == null) {
|
||||
return;
|
||||
}
|
||||
@@ -246,7 +246,7 @@ public class FluidTerminalContainer extends AEBaseContainer
|
||||
|
||||
@Override
|
||||
public void detectAndSendChanges() {
|
||||
if (Platform.isServer()) {
|
||||
if (isServer()) {
|
||||
if (this.monitor != this.terminal
|
||||
.getInventory(Api.instance().storage().getStorageChannel(IFluidStorageChannel.class))) {
|
||||
this.setValidContainer(false);
|
||||
|
||||
@@ -13,6 +13,14 @@ import appeng.core.AELog;
|
||||
import appeng.util.Platform;
|
||||
|
||||
public class AEFluidInventory implements IAEFluidTank {
|
||||
|
||||
/**
|
||||
* While this may seem redundant, it helps since this class heavily mixes AE
|
||||
* fluids stacks, which use null to represent "nothing", and Minecraft's
|
||||
* FluidStack, which uses #isEmpty() to represent nothing.
|
||||
*/
|
||||
private static final IAEFluidStack EMPTY_AE_FLUIDSTACK = null;
|
||||
|
||||
private final IAEFluidStack[] fluids;
|
||||
private final IAEFluidInventory handler;
|
||||
private final int capacity;
|
||||
@@ -31,13 +39,13 @@ public class AEFluidInventory implements IAEFluidTank {
|
||||
public void setFluidInSlot(final int slot, final IAEFluidStack fluid) {
|
||||
if (slot >= 0 && slot < this.getSlots()) {
|
||||
if (Objects.equals(this.fluids[slot], fluid)) {
|
||||
if (fluid != null && fluid.getStackSize() != this.fluids[slot].getStackSize()) {
|
||||
if (fluid != EMPTY_AE_FLUIDSTACK && fluid.getStackSize() != this.fluids[slot].getStackSize()) {
|
||||
this.fluids[slot].setStackSize(Math.min(fluid.getStackSize(), this.capacity));
|
||||
this.onContentChanged(slot);
|
||||
}
|
||||
} else {
|
||||
if (fluid == null) {
|
||||
this.fluids[slot] = null;
|
||||
if (fluid == EMPTY_AE_FLUIDSTACK) {
|
||||
this.fluids[slot] = EMPTY_AE_FLUIDSTACK;
|
||||
} else {
|
||||
this.fluids[slot] = fluid.copy();
|
||||
this.fluids[slot].setStackSize(Math.min(fluid.getStackSize(), this.capacity));
|
||||
@@ -59,7 +67,7 @@ public class AEFluidInventory implements IAEFluidTank {
|
||||
if (slot >= 0 && slot < this.getSlots()) {
|
||||
return this.fluids[slot];
|
||||
}
|
||||
return null;
|
||||
return EMPTY_AE_FLUIDSTACK;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -78,12 +86,12 @@ public class AEFluidInventory implements IAEFluidTank {
|
||||
if (tank < 0 || tank >= fluids.length) {
|
||||
return FluidStack.EMPTY;
|
||||
}
|
||||
return fluids[tank] == null ? FluidStack.EMPTY : fluids[tank].getFluidStack();
|
||||
return fluids[tank] == EMPTY_AE_FLUIDSTACK ? FluidStack.EMPTY : fluids[tank].getFluidStack();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTankCapacity(int tank) {
|
||||
return Math.min(this.capacity, Integer.MAX_VALUE);
|
||||
return this.capacity;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -98,20 +106,20 @@ public class AEFluidInventory implements IAEFluidTank {
|
||||
|
||||
final IAEFluidStack fluid = this.fluids[slot];
|
||||
|
||||
if (fluid != null && !fluid.getFluidStack().equals(resource)) {
|
||||
if (fluid != EMPTY_AE_FLUIDSTACK && !fluid.getFluidStack().equals(resource)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int amountToStore = this.capacity;
|
||||
|
||||
if (fluid != null) {
|
||||
if (fluid != EMPTY_AE_FLUIDSTACK) {
|
||||
amountToStore -= fluid.getStackSize();
|
||||
}
|
||||
|
||||
amountToStore = Math.min(amountToStore, resource.getAmount());
|
||||
|
||||
if (doFill) {
|
||||
if (fluid == null) {
|
||||
if (fluid == EMPTY_AE_FLUIDSTACK) {
|
||||
this.setFluidInSlot(slot, AEFluidStack.fromFluidStack(resource));
|
||||
} else {
|
||||
fluid.setStackSize(fluid.getStackSize() + amountToStore);
|
||||
@@ -141,14 +149,14 @@ public class AEFluidInventory implements IAEFluidTank {
|
||||
|
||||
int amountToStore = this.capacity;
|
||||
|
||||
if (fluid != null) {
|
||||
if (fluid != EMPTY_AE_FLUIDSTACK) {
|
||||
amountToStore -= fluid.getStackSize();
|
||||
}
|
||||
|
||||
amountToStore = Math.min(amountToStore, resource.getAmount());
|
||||
|
||||
if (action == FluidAction.EXECUTE) {
|
||||
if (fluid == null) {
|
||||
if (fluid == EMPTY_AE_FLUIDSTACK) {
|
||||
this.setFluidInSlot(slot, AEFluidStack.fromFluidStack(resource));
|
||||
} else {
|
||||
fluid.setStackSize(fluid.getStackSize() + amountToStore);
|
||||
@@ -170,7 +178,7 @@ public class AEFluidInventory implements IAEFluidTank {
|
||||
FluidStack totalDrained = FluidStack.EMPTY;
|
||||
for (int slot = 0; slot < this.getSlots(); ++slot) {
|
||||
FluidStack drain = this.drain(slot, resource, action == FluidAction.EXECUTE);
|
||||
if (drain != null) {
|
||||
if (!drain.isEmpty()) {
|
||||
if (totalDrained.isEmpty()) {
|
||||
totalDrained = drain;
|
||||
} else {
|
||||
@@ -205,7 +213,7 @@ public class AEFluidInventory implements IAEFluidTank {
|
||||
FluidStack copy = totalDrained.copy();
|
||||
copy.setAmount(toDrain);
|
||||
FluidStack drain = this.drain(slot, copy, action == FluidAction.EXECUTE);
|
||||
if (drain != null) {
|
||||
if (!drain.isEmpty()) {
|
||||
totalDrained.setAmount(totalDrained.getAmount() + drain.getAmount());
|
||||
toDrain -= drain.getAmount();
|
||||
}
|
||||
@@ -220,7 +228,7 @@ public class AEFluidInventory implements IAEFluidTank {
|
||||
|
||||
private int indexOfFluid(FluidStack resource) {
|
||||
for (int slot = 0; slot < fluids.length; slot++) {
|
||||
if (fluids[slot] != null && fluids[slot].getFluidStack().isFluidEqual(resource)) {
|
||||
if (fluids[slot] != EMPTY_AE_FLUIDSTACK && fluids[slot].getFluidStack().isFluidEqual(resource)) {
|
||||
return slot;
|
||||
}
|
||||
}
|
||||
@@ -229,7 +237,7 @@ public class AEFluidInventory implements IAEFluidTank {
|
||||
|
||||
private int indexOfEmptySlot() {
|
||||
for (int slot = 0; slot < fluids.length; slot++) {
|
||||
if (fluids[slot] == null) {
|
||||
if (fluids[slot] == EMPTY_AE_FLUIDSTACK) {
|
||||
return slot;
|
||||
}
|
||||
}
|
||||
@@ -238,16 +246,16 @@ public class AEFluidInventory implements IAEFluidTank {
|
||||
|
||||
public FluidStack drain(final int slot, final FluidStack resource, final boolean doDrain) {
|
||||
final IAEFluidStack fluid = this.fluids[slot];
|
||||
if (resource.isEmpty() || fluid == null || !fluid.getFluidStack().equals(resource)) {
|
||||
return null;
|
||||
if (resource.isEmpty() || fluid == EMPTY_AE_FLUIDSTACK || !fluid.getFluidStack().equals(resource)) {
|
||||
return FluidStack.EMPTY;
|
||||
}
|
||||
return this.drain(slot, resource.getAmount(), doDrain);
|
||||
}
|
||||
|
||||
public FluidStack drain(final int slot, final int maxDrain, boolean doDrain) {
|
||||
final IAEFluidStack fluid = this.fluids[slot];
|
||||
if (fluid == null || maxDrain <= 0) {
|
||||
return null;
|
||||
if (fluid == EMPTY_AE_FLUIDSTACK || maxDrain <= 0) {
|
||||
return FluidStack.EMPTY;
|
||||
}
|
||||
|
||||
int drained = maxDrain;
|
||||
@@ -259,7 +267,7 @@ public class AEFluidInventory implements IAEFluidTank {
|
||||
if (doDrain) {
|
||||
fluid.setStackSize(fluid.getStackSize() - drained);
|
||||
if (fluid.getStackSize() <= 0) {
|
||||
this.fluids[slot] = null;
|
||||
this.fluids[slot] = EMPTY_AE_FLUIDSTACK;
|
||||
}
|
||||
this.onContentChanged(slot);
|
||||
}
|
||||
@@ -277,7 +285,7 @@ public class AEFluidInventory implements IAEFluidTank {
|
||||
try {
|
||||
final CompoundNBT c = new CompoundNBT();
|
||||
|
||||
if (this.fluids[x] != null) {
|
||||
if (this.fluids[x] != EMPTY_AE_FLUIDSTACK) {
|
||||
this.fluids[x].writeToNBT(c);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user