Compare commits

...

2 Commits

Author SHA1 Message Date
Ghzdude 6425ef6ecd Fix NPE when posting changes for storage busses (#405) 2024-02-24 10:25:51 +08:00
Yang Xizhi 7ebb2a0fbb allow custom slot jei check and fix fluid color in cell workbanch (#401) 2024-02-18 23:06:07 -06:00
8 changed files with 46 additions and 24 deletions
@@ -1,10 +1,14 @@
package appeng.client.gui;
import appeng.api.storage.data.IAEItemStack;
import appeng.client.gui.implementations.*;
import appeng.client.gui.implementations.GuiCraftAmount;
import appeng.client.gui.implementations.GuiCraftConfirm;
import appeng.client.gui.implementations.GuiCraftingCPU;
import appeng.client.gui.implementations.GuiExpandedProcessingPatternTerm;
import appeng.client.gui.implementations.GuiPatternTerm;
import appeng.client.gui.implementations.GuiUpgradeable;
import appeng.container.interfaces.IJEIGhostIngredients;
import appeng.container.slot.SlotFake;
import appeng.fluids.client.gui.widgets.GuiFluidSlot;
import appeng.container.slot.IJEITargetSlot;
import mezz.jei.api.gui.IAdvancedGuiHandler;
import mezz.jei.api.gui.IGhostIngredientHandler;
import net.minecraft.client.gui.GuiScreen;
@@ -78,12 +82,12 @@ public class AEGuiHandler implements IAdvancedGuiHandler<AEBaseGui>, IGhostIngre
return (guiSloty * 3) + guiSlotx + (currentScroll * 3);
}
@SuppressWarnings("unchecked")
@Override
@Nonnull
public <I> List<Target<I>> getTargets(@Nonnull AEBaseGui gui, @Nonnull I ingredient, boolean doStart) {
ArrayList<Target<I>> targets = new ArrayList<>();
if (gui instanceof IJEIGhostIngredients) {
IJEIGhostIngredients g = (IJEIGhostIngredients) gui;
if (gui instanceof IJEIGhostIngredients g) {
List<Target<?>> phantomTargets = g.getPhantomTargets(ingredient);
targets.addAll((List<Target<I>>) (Object) phantomTargets);
}
@@ -91,13 +95,8 @@ public class AEGuiHandler implements IAdvancedGuiHandler<AEBaseGui>, IGhostIngre
if (gui instanceof GuiUpgradeable || gui instanceof GuiPatternTerm || gui instanceof GuiExpandedProcessingPatternTerm) {
IJEIGhostIngredients ghostGui = ((IJEIGhostIngredients) gui);
for (Target<I> target : targets) {
if (ghostGui.getFakeSlotTargetMap().get(target) instanceof SlotFake) {
if (((SlotFake) ghostGui.getFakeSlotTargetMap().get(target)).getStack().isEmpty()) {
target.accept(ingredient);
break;
}
} else if (ghostGui.getFakeSlotTargetMap().get(target) instanceof GuiFluidSlot) {
if (((GuiFluidSlot) ghostGui.getFakeSlotTargetMap().get(target)).getFluidStack() == null) {
if (ghostGui.getFakeSlotTargetMap().get(target) instanceof IJEITargetSlot jeiSlot) {
if (jeiSlot.needAccept()) {
target.accept(ingredient);
break;
}
@@ -47,6 +47,7 @@ import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidUtil;
import org.lwjgl.input.Mouse;
import javax.annotation.Nonnull;
import java.awt.*;
import java.io.IOException;
import java.util.List;
@@ -54,7 +55,7 @@ import java.util.*;
public class GuiUpgradeable extends AEBaseGui implements IJEIGhostIngredients {
private final Map<Target<?>, Object> mapTargetSlot = new HashMap<>();
protected final Map<Target<?>, Object> mapTargetSlot = new HashMap<>();
protected final ContainerUpgradeable cvb;
protected final IUpgradeableHost bc;
@@ -218,24 +219,25 @@ public class GuiUpgradeable extends AEBaseGui implements IJEIGhostIngredients {
List<Target<?>> targets = new ArrayList<>();
List<IJEITargetSlot> slots = new ArrayList<>();
if (this.inventorySlots.inventorySlots.size() > 0) {
if (!this.inventorySlots.inventorySlots.isEmpty()) {
for (Slot slot : this.inventorySlots.inventorySlots) {
if (slot instanceof SlotFake && (!itemStack.isEmpty() || this instanceof GuiCellWorkbench && fluidStack != null)) {
slots.add((IJEITargetSlot) slot);
}
}
}
if (this.getGuiSlots().size() > 0) {
if (!this.getGuiSlots().isEmpty()) {
for (GuiCustomSlot slot : this.getGuiSlots()) {
if (slot instanceof GuiFluidSlot && fluidStack != null) {
slots.add((IJEITargetSlot) slot);
}
}
}
for (Object slot : slots) {
for (IJEITargetSlot slot : slots) {
ItemStack finalItemStack = itemStack;
FluidStack finalFluidStack = fluidStack;
Target<Object> targetItem = new Target<Object>() {
Target<Object> targetItem = new Target<>() {
@Nonnull
@Override
public Rectangle getArea() {
if (slot instanceof SlotFake && ((SlotFake) slot).isSlotEnabled()) {
@@ -247,20 +249,20 @@ public class GuiUpgradeable extends AEBaseGui implements IJEIGhostIngredients {
}
@Override
public void accept(Object ingredient) {
public void accept(@Nonnull Object ingredient) {
PacketInventoryAction p = null;
try {
if (slot instanceof SlotFake && ((SlotFake) slot).isSlotEnabled()) {
if (finalItemStack.isEmpty() && finalFluidStack != null) {
p = new PacketInventoryAction(InventoryAction.PLACE_JEI_GHOST_ITEM, (IJEITargetSlot) slot, AEItemStack.fromItemStack(FluidUtil.getFilledBucket(finalFluidStack)));
p = new PacketInventoryAction(InventoryAction.PLACE_JEI_GHOST_ITEM, slot, AEItemStack.fromItemStack(FluidUtil.getFilledBucket(finalFluidStack)));
} else if (!finalItemStack.isEmpty()) {
p = new PacketInventoryAction(InventoryAction.PLACE_JEI_GHOST_ITEM, (IJEITargetSlot) slot, AEItemStack.fromItemStack(finalItemStack));
p = new PacketInventoryAction(InventoryAction.PLACE_JEI_GHOST_ITEM, slot, AEItemStack.fromItemStack(finalItemStack));
}
} else {
if (finalFluidStack == null) {
return;
}
p = new PacketInventoryAction(InventoryAction.PLACE_JEI_GHOST_ITEM, (IJEITargetSlot) slot, AEItemStack.fromItemStack(AEFluidStack.fromFluidStack(finalFluidStack).asItemStackRepresentation()));
p = new PacketInventoryAction(InventoryAction.PLACE_JEI_GHOST_ITEM, slot, AEItemStack.fromItemStack(AEFluidStack.fromFluidStack(finalFluidStack).asItemStackRepresentation()));
}
NetworkHandler.instance().sendToServer(p);
@@ -1,4 +1,9 @@
package appeng.container.slot;
public interface IJEITargetSlot {
default boolean needAccept() {
return false;
}
}
@@ -50,7 +50,6 @@ public class SlotFake extends AppEngSlot implements IJEITargetSlot {
if (!is.isEmpty()) {
is = is.copy();
}
super.putStack(is);
}
@@ -58,4 +57,10 @@ public class SlotFake extends AppEngSlot implements IJEITargetSlot {
public boolean canTakeStack(final EntityPlayer par1EntityPlayer) {
return false;
}
@Override
public boolean needAccept() {
return this.getStack().isEmpty();
}
}
@@ -93,4 +93,10 @@ public class GuiFluidSlot extends GuiCustomSlot implements IJEITargetSlot {
this.fluids.setFluidInSlot(this.slot, stack);
NetworkHandler.instance().sendToServer(new PacketFluidSlot(Collections.singletonMap(this.getId(), this.getFluidStack())));
}
@Override
public boolean needAccept() {
return this.getFluidStack() == null;
}
}
@@ -22,6 +22,7 @@ package appeng.fluids.items;
import appeng.bootstrap.IItemRendering;
import appeng.bootstrap.ItemRenderingCustomizer;
import appeng.client.render.DummyFluidItemModel;
import net.minecraftforge.fluids.FluidStack;
/**
@@ -33,5 +34,9 @@ public class FluidDummyItemRendering extends ItemRenderingCustomizer {
@Override
public void customize(IItemRendering rendering) {
rendering.builtInModel("models/item/dummy_fluid_item", new DummyFluidItemModel());
rendering.color(((s, i) -> {
FluidStack fluid = ((FluidDummyItem) s.getItem()).getFluidStack(s);
return fluid != null ? fluid.getFluid().getColor() : 0xFFFFFFFF;
}));
}
}
@@ -551,7 +551,7 @@ public class PartFluidStorageBus extends PartUpgradeable implements IGridTickabl
*/
protected Iterable<IAEFluidStack> filterChanges(Iterable<IAEFluidStack> change) {
var storageFilter = this.getConfigManager().getSetting(Settings.STORAGE_FILTER);
if (storageFilter == StorageFilter.EXTRACTABLE_ONLY) {
if (storageFilter == StorageFilter.EXTRACTABLE_ONLY && handler != null) {
var filteredList = new ArrayList<IAEFluidStack>();
for (final IAEFluidStack stack : change) {
if (this.handler.passesBlackOrWhitelist(stack)) {
@@ -585,7 +585,7 @@ public class PartStorageBus extends PartUpgradeable implements IGridTickable, IC
*/
protected Iterable<IAEItemStack> filterChanges(Iterable<IAEItemStack> change) {
var storageFilter = this.getConfigManager().getSetting(Settings.STORAGE_FILTER);
if (storageFilter == StorageFilter.EXTRACTABLE_ONLY) {
if (storageFilter == StorageFilter.EXTRACTABLE_ONLY && handler != null) {
var filteredList = new ArrayList<IAEItemStack>();
for (final IAEItemStack stack : change) {
if (this.handler.passesBlackOrWhitelist(stack)) {