Skip to content

Commit

Permalink
Fix ME Input Hatch and Output Bus (GregTechCEu#1065)
Browse files Browse the repository at this point in the history
* hey it works (added a theorical fix to ME output bus and fixed ME Input Hatch)

* Remove a missing debug line and change all ME parts (busses and hatches) to use EV hull texture

* Do review requested changes
  • Loading branch information
StarL0st authored Apr 5, 2024
1 parent 146d4b6 commit f1d893e
Show file tree
Hide file tree
Showing 18 changed files with 90 additions and 75 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -291,11 +291,11 @@ public ModularUI createUI(Player entityPlayer) {
.setProgressTexture(GuiTextures.PROGRESS_BAR_BOILER_EMPTY.get(isHighPressure), GuiTextures.PROGRESS_BAR_BOILER_HEAT)
.setFillDirection(ProgressTexture.FillDirection.DOWN_TO_UP)
.setDynamicHoverTips(pct -> I18n.get("gtceu.multiblock.large_boiler.temperature", (int) (currentTemperature + 274.15), (int) (getMaxTemperature() + 274.15))))
.widget(new TankWidget(waterTank.storages[0], 83, 26, 10, 54, false, true)
.widget(new TankWidget(waterTank.getStorages()[0], 83, 26, 10, 54, false, true)
.setShowAmount(false)
.setFillDirection(ProgressTexture.FillDirection.DOWN_TO_UP)
.setBackground(GuiTextures.PROGRESS_BAR_BOILER_EMPTY.get(isHighPressure)))
.widget(new TankWidget(steamTank.storages[0], 70, 26, 10, 54, true, false)
.widget(new TankWidget(steamTank.getStorages()[0], 70, 26, 10, 54, true, false)
.setShowAmount(false)
.setFillDirection(ProgressTexture.FillDirection.DOWN_TO_UP)
.setBackground(GuiTextures.PROGRESS_BAR_BOILER_EMPTY.get(isHighPressure)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ public class NotifiableFluidTank extends NotifiableRecipeHandlerTrait<FluidIngre
public final IO handlerIO;
@Getter
public final IO capabilityIO;
@Persisted
public final FluidStorage[] storages;
@Persisted @Getter
private final FluidStorage[] storages;
@Setter
protected boolean allowSameFluids; // Can different tanks be filled with the same fluid. It should be determined while creating tanks.
private Boolean isEmpty;
Expand All @@ -58,7 +58,7 @@ public NotifiableFluidTank(MetaMachine machine, List<FluidStorage> storages, IO
this.handlerIO = io;
this.storages = storages.toArray(FluidStorage[]::new);
this.capabilityIO = capabilityIO;
for (FluidStorage storage : this.storages) {
for (FluidStorage storage : this.getStorages()) {
storage.setOnContentsChanged(this::onContentsChanged);
}
if (io == IO.IN) {
Expand Down Expand Up @@ -148,7 +148,7 @@ public static List<FluidIngredient> handleIngredient(IO io, List<FluidIngredient
}

public NotifiableFluidTank setFilter(Predicate<FluidStack> filter) {
for (FluidStorage storage : storages) {
for (FluidStorage storage : getStorages()) {
storage.setValidator(filter);
}
return this;
Expand All @@ -160,7 +160,7 @@ public RecipeCapability<FluidIngredient> getCapability() {
}

public int getTanks() {
return storages.length;
return getStorages().length;
}

@Override
Expand All @@ -183,7 +183,7 @@ public List<Object> getContents() {
public boolean isEmpty() {
if (isEmpty == null) {
isEmpty = true;
for (FluidStorage storage : storages) {
for (FluidStorage storage : getStorages()) {
if (!storage.getFluid().isEmpty()) {
isEmpty = false;
break;
Expand Down Expand Up @@ -216,22 +216,22 @@ public void importFromNearby(@NotNull Direction... facings) {
@NotNull
@Override
public FluidStack getFluidInTank(int tank) {
return storages[tank].getFluid();
return getStorages()[tank].getFluid();
}

@Override
public void setFluidInTank(int tank, @NotNull FluidStack fluidStack) {
storages[tank].setFluid(fluidStack);
getStorages()[tank].setFluid(fluidStack);
}

@Override
public long getTankCapacity(int tank) {
return storages[tank].getCapacity();
return getStorages()[tank].getCapacity();
}

@Override
public boolean isFluidValid(int tank, @NotNull FluidStack stack) {
return storages[tank].isFluidValid(stack);
return getStorages()[tank].isFluidValid(stack);
}

@Override
Expand All @@ -240,7 +240,7 @@ public long fill(FluidStack resource, boolean simulate, boolean notifyChanges) {
long filled = 0;
FluidStorage existingStorage = null;
if (!allowSameFluids) {
for (var storage : storages) {
for (var storage : getStorages()) {
if (!storage.getFluid().isEmpty() && storage.getFluid().isFluidEqual(resource)) {
existingStorage = storage;
break;
Expand All @@ -266,8 +266,8 @@ public long fill(FluidStack resource, boolean simulate, boolean notifyChanges) {

@Override
public long fill(int tank, FluidStack resource, boolean simulate, boolean notifyChanges) {
if (tank >= 0 && tank < storages.length && canCapInput()) {
return storages[tank].fill(resource, simulate, notifyChanges);
if (tank >= 0 && tank < getStorages().length && canCapInput()) {
return getStorages()[tank].fill(resource, simulate, notifyChanges);
}
return 0;
}
Expand All @@ -285,15 +285,15 @@ public long fillInternal(FluidStack resource, boolean simulate) {
var copied = resource.copy();
FluidStorage existingStorage = null;
if (!allowSameFluids) {
for (var storage : storages) {
for (var storage : getStorages()) {
if (!storage.getFluid().isEmpty() && storage.getFluid().isFluidEqual(resource)) {
existingStorage = storage;
break;
}
}
}
if (existingStorage == null) {
for (var storage : storages) {
for (var storage : getStorages()) {
var filled = storage.fill(copied.copy(), simulate);
if (filled > 0) {
copied.shrink(filled);
Expand All @@ -312,8 +312,8 @@ public long fillInternal(FluidStack resource, boolean simulate) {
@NotNull
@Override
public FluidStack drain(int tank, FluidStack resource, boolean simulate, boolean notifyChanges) {
if (tank >= 0 && tank < storages.length && canCapOutput()) {
return storages[tank].drain(resource, simulate, notifyChanges);
if (tank >= 0 && tank < getStorages().length && canCapOutput()) {
return getStorages()[tank].drain(resource, simulate, notifyChanges);
}
return FluidStack.empty();
}
Expand All @@ -330,7 +330,7 @@ public FluidStack drain(FluidStack resource, boolean simulate) {
public FluidStack drainInternal(FluidStack resource, boolean simulate) {
if (!resource.isEmpty()) {
var copied = resource.copy();
for (var transfer : storages) {
for (var transfer : getStorages()) {
var candidate = copied.copy();
copied.shrink(transfer.drain(candidate, simulate).getAmount());
if (copied.isEmpty()) break;
Expand All @@ -355,7 +355,7 @@ public FluidStack drainInternal(long maxDrain, boolean simulate) {
return FluidStack.empty();
}
FluidStack totalDrained = null;
for (var storage : storages) {
for (var storage : getStorages()) {
if (totalDrained == null || totalDrained.isEmpty()) {
totalDrained = storage.drain(maxDrain, simulate);
if (totalDrained.isEmpty()) {
Expand Down Expand Up @@ -389,14 +389,14 @@ public boolean supportsDrain(int i) {
@NotNull
@Override
public Object createSnapshot() {
return Arrays.stream(storages).map(IFluidTransfer::createSnapshot).toArray(Object[]::new);
return Arrays.stream(getStorages()).map(IFluidTransfer::createSnapshot).toArray(Object[]::new);
}

@Override
public void restoreFromSnapshot(Object snapshot) {
if (snapshot instanceof Object[] array && array.length == storages.length) {
if (snapshot instanceof Object[] array && array.length == getStorages().length) {
for (int i = 0; i < array.length; i++) {
storages[i].restoreFromSnapshot(array[i]);
getStorages()[i].restoreFromSnapshot(array[i]);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ public ModularUI createUI(Player entityPlayer) {
.widget(new LabelWidget(11, 20, "gtceu.gui.fluid_amount"))
.widget(new LabelWidget(11, 30, () -> cache.getFluidInTank(0).getAmount() + "").setTextColor(-1).setDropShadow(true))
.widget(new LabelWidget(6, 6, getBlockState().getBlock().getDescriptionId()))
.widget(new TankWidget(cache.storages[0], 90, 35, true, true)
.widget(new TankWidget(cache.getStorages()[0], 90, 35, true, true)
.setBackground(GuiTextures.FLUID_SLOT))
.widget(new ToggleButtonWidget(7, 53, 18, 18,
GuiTextures.BUTTON_FLUID_OUTPUT, this::isAutoOutputFluids, this::setAutoOutputFluids)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ protected Widget createSingleSlotGUI() {
group.addWidget(new ImageWidget(4, 4, 81, 55, GuiTextures.DISPLAY))
.addWidget(new LabelWidget(8, 8, "gtceu.gui.fluid_amount"))
.addWidget(new LabelWidget(8, 18, () -> String.valueOf(tank.getFluidInTank(0).getAmount())).setTextColor(-1).setDropShadow(true))
.addWidget(new TankWidget(tank.storages[0], 67, 22, true, io.support(IO.IN)).setBackground(GuiTextures.FLUID_SLOT));
.addWidget(new TankWidget(tank.getStorages()[0], 67, 22, true, io.support(IO.IN)).setBackground(GuiTextures.FLUID_SLOT));

group.setBackground(GuiTextures.BACKGROUND_INVERSE);
return group;
Expand All @@ -171,7 +171,7 @@ protected Widget createMultiSlotGUI() {
int index = 0;
for (int y = 0; y < colSize; y++) {
for (int x = 0; x < rowSize; x++) {
container.addWidget(new TankWidget(tank.storages[index++], 4 + x * 18, 4 + y * 18, true, io.support(IO.IN)).setBackground(GuiTextures.FLUID_SLOT));
container.addWidget(new TankWidget(tank.getStorages()[index++], 4 + x * 18, 4 + y * 18, true, io.support(IO.IN)).setBackground(GuiTextures.FLUID_SLOT));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public ModularUI createUI(Player entityPlayer) {
.widget(new LabelWidget(11, 20, "gtceu.gui.fluid_amount"))
.widget(new LabelWidget(11, 30, () -> String.valueOf(tank.getFluidInTank(0).getAmount())).setTextColor(-1).setDropShadow(true))
.widget(new LabelWidget(6, 6, getBlockState().getBlock().getDescriptionId()))
.widget(new TankWidget(tank.storages[0], 90, 35, true, io.support(IO.IN))
.widget(new TankWidget(tank.getStorages()[0], 90, 35, true, io.support(IO.IN))
.setBackground(GuiTextures.FLUID_SLOT))
.widget(new ToggleButtonWidget(7, 53, 18, 18,
GuiTextures.BUTTON_FLUID_OUTPUT, this::isWorkingEnabled, this::setWorkingEnabled)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public ModularUI createUI(Player entityPlayer) {
.widget(new LabelWidget(11, 20, "gtceu.gui.fluid_amount"))
.widget(new LabelWidget(11, 30, () -> tank.getFluidInTank(0).getAmount() + "").setTextColor(-1).setDropShadow(true))
.widget(new LabelWidget(6, 6, getBlockState().getBlock().getDescriptionId()))
.widget(new TankWidget(tank.storages[0], 90, 35, true, true)
.widget(new TankWidget(tank.getStorages()[0], 90, 35, true, true)
.setBackground(GuiTextures.FLUID_SLOT))
.widget(UITemplate.bindPlayerInventory(entityPlayer.getInventory(), GuiTextures.SLOT_STEAM.get(IS_STEEL), 7, 84, true));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public ModularUI createUI(Player entityPlayer) {
.widget(new ProgressWidget(recipeLogic::getProgressPercent, 76, 32, 20, 15, GuiTextures.PRIMITIVE_BLAST_FURNACE_PROGRESS_BAR))
.widget(new SlotWidget(exportItems.storage, 0, 103, 30, true, false)
.setBackgroundTexture(new GuiTextureGroup(GuiTextures.PRIMITIVE_SLOT, GuiTextures.PRIMITIVE_FURNACE_OVERLAY)))
.widget(new TankWidget(exportFluids.storages[0], 134, 13, 20, 58, true, false)
.widget(new TankWidget(exportFluids.getStorages()[0], 134, 13, 20, 58, true, false)
.setBackground(GuiTextures.PRIMITIVE_LARGE_FLUID_TANK)
.setOverlay(GuiTextures.PRIMITIVE_LARGE_FLUID_TANK_OVERLAY)
.setFillDirection(ProgressTexture.FillDirection.DOWN_TO_UP)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ protected long getBaseSteamOutput() {
@Override
public ModularUI createUI(Player entityPlayer) {
return super.createUI(entityPlayer)
.widget(new TankWidget(fuelTank.storages[0], 119, 26, 10, 54, true, true)
.widget(new TankWidget(fuelTank.getStorages()[0], 119, 26, 10, 54, true, true)
.setShowAmount(false)
.setFillDirection(ProgressTexture.FillDirection.DOWN_TO_UP)
.setBackground(GuiTextures.PROGRESS_BAR_BOILER_EMPTY.get(isHighPressure)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ protected void checkAutoOutput() {
@Override
public WidgetGroup createUIWidget() {
var group = new WidgetGroup(0, 0, 176, 131);
group.addWidget(new PhantomFluidWidget(this.cache.storages[0], 36, 6, 18, 18).setShowAmount(false).setBackground(GuiTextures.FLUID_SLOT));
group.addWidget(new PhantomFluidWidget(this.cache.getStorages()[0], 36, 6, 18, 18).setShowAmount(false).setBackground(GuiTextures.FLUID_SLOT));
group.addWidget(new LabelWidget(7, 9, "gtceu.creative.tank.fluid"));
group.addWidget(new ImageWidget(7, 45, 154, 14, GuiTextures.DISPLAY));
group.addWidget(new TextFieldWidget(9, 47, 152, 10, () -> String.valueOf(mBPerCycle), value -> {
Expand Down Expand Up @@ -105,12 +105,12 @@ public WidgetGroup createUIWidget() {
}

public void updateFluidTick() {
if (ticksPerCycle == 0 || getOffsetTimer() % ticksPerCycle != 0 || cache.storages[0].getFluid().isEmpty() || getLevel().isClientSide || !isWorkingEnabled())
if (ticksPerCycle == 0 || getOffsetTimer() % ticksPerCycle != 0 || cache.getStorages()[0].getFluid().isEmpty() || getLevel().isClientSide || !isWorkingEnabled())
return;

IFluidTransfer transfer = FluidTransferHelper.getFluidTransfer(getLevel(), getPos().relative(getOutputFacingFluids()), getOutputFacingFluids().getOpposite());
if (transfer != null) {
FluidStack stack = cache.storages[0].getFluid().copy();
FluidStack stack = cache.getStorages()[0].getFluid().copy();
stack.setAmount(mBPerCycle);
long canInsertAmount = transfer.fill(stack, true);
stack.setAmount(Math.min(mBPerCycle, canInsertAmount));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public void loadFromItem(CompoundTag tag) {
stored = FluidStack.empty();
}
// "stored" may not be same as cache (due to item's fluid cap). we should update it.
cache.storages[0].setFluid(stored.copy());
cache.getStorages()[0].setFluid(stored.copy());
}

@Override
Expand Down Expand Up @@ -192,9 +192,9 @@ public InteractionResult onUse(BlockState state, Level world, BlockPos pos, Play
var currentStack = player.getMainHandItem();
if (!currentStack.isEmpty()) {
var handler = FluidTransferHelper.getFluidTransfer(player, InteractionHand.MAIN_HAND);
var fluidTank = cache.storages[0];
var fluidTank = cache.getStorages()[0];
if (handler != null && !isRemote()) {
if (cache.storages[0].getFluidAmount() > 0) {
if (cache.getStorages()[0].getFluidAmount() > 0) {
FluidStack initialFluid = fluidTank.getFluid();
FluidActionResult result = FluidTransferHelper.tryFillContainer(currentStack, fluidTank, Integer.MAX_VALUE, null, false);
if (result.isSuccess()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,9 +221,9 @@ public InteractionResult onUse(BlockState state, Level world, BlockPos pos, Play
var currentStack = player.getMainHandItem();
if (hit.getDirection() == getFrontFacing() && !currentStack.isEmpty()) {
var handler = FluidTransferHelper.getFluidTransfer(player, InteractionHand.MAIN_HAND);
var fluidTank = cache.storages[0];
var fluidTank = cache.getStorages()[0];
if (handler != null && !isRemote()) {
if (cache.storages[0].getFluidAmount() > 0) {
if (cache.getStorages()[0].getFluidAmount() > 0) {
FluidStack initialFluid = fluidTank.getFluid();
FluidActionResult result = FluidTransferHelper.tryFillContainer(currentStack, fluidTank, Integer.MAX_VALUE, null, false);
if (result.isSuccess()) {
Expand Down Expand Up @@ -316,7 +316,7 @@ public Widget createUIWidget() {
.addWidget(new LabelWidget(8, 18, () ->
String.valueOf(cache.getFluidInTank(0).getAmount() / (FluidHelper.getBucket() / 1000))
).setTextColor(-1).setDropShadow(true))
.addWidget(new TankWidget(cache.storages[0], 68, 23, true, true)
.addWidget(new TankWidget(cache.getStorages()[0], 68, 23, true, true)
.setBackground(GuiTextures.FLUID_SLOT))
.addWidget(new PhantomFluidWidget(lockedFluid, 68, 41, 18, 18)
.setShowAmount(false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.gregtechceu.gtceu.integration.ae2.machine.*;
import net.minecraft.network.chat.Component;

import static com.gregtechceu.gtceu.api.GTValues.EV;
import static com.gregtechceu.gtceu.api.GTValues.UHV;
import static com.gregtechceu.gtceu.common.registry.GTRegistration.REGISTRATE;

Expand All @@ -14,7 +15,7 @@ public class GTAEMachines {

public final static MachineDefinition ITEM_IMPORT_BUS = REGISTRATE.machine("me_input_bus", MEInputBusPartMachine::new)
.langValue("ME Stocking Input Bus")
.tier(UHV)
.tier(EV)
.rotationState(RotationState.ALL)
.abilities(PartAbility.IMPORT_ITEMS)
.overlayTieredHullRenderer("me_item_bus.import")
Expand All @@ -24,7 +25,7 @@ public class GTAEMachines {

public final static MachineDefinition ITEM_EXPORT_BUS = REGISTRATE.machine("me_output_bus", MEOutputBusPartMachine::new)
.langValue("ME Output Bus")
.tier(UHV)
.tier(EV)
.rotationState(RotationState.ALL)
.abilities(PartAbility.IMPORT_ITEMS)
.overlayTieredHullRenderer("me_item_bus.export")
Expand All @@ -37,7 +38,7 @@ public class GTAEMachines {

public final static MachineDefinition FLUID_IMPORT_HATCH = REGISTRATE.machine("me_input_hatch", MEInputHatchPartMachine::new)
.langValue("ME Stocking Input Hatch")
.tier(UHV)
.tier(EV)
.rotationState(RotationState.ALL)
.abilities(PartAbility.IMPORT_FLUIDS)
.overlayTieredHullRenderer("me_fluid_hatch.import")
Expand All @@ -47,7 +48,7 @@ public class GTAEMachines {

public final static MachineDefinition FLUID_EXPORT_HATCH = REGISTRATE.machine("me_output_hatch", MEOutputHatchPartMachine::new)
.langValue("ME Output Hatch")
.tier(UHV)
.tier(EV)
.rotationState(RotationState.ALL)
.abilities(PartAbility.EXPORT_FLUIDS)
.overlayTieredHullRenderer("me_fluid_hatch.export")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public AEConfigWidget(int x, int y, IConfigurableSlot[] config) {
super(new Position(x, y), new Size(config.length / 2 * 18, 18 * 4 + 2));
this.config = config;
this.init();
this.amountSetWidget = new AmountSetSlot(80, -40, this);
this.amountSetWidget = new AmountSetSlot(31, -50, this);
this.addWidget(this.amountSetWidget);
this.addWidget(this.amountSetWidget.getAmountText());
this.amountSetWidget.setVisible(false);
Expand Down
Loading

0 comments on commit f1d893e

Please sign in to comment.