Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,19 +1,34 @@
package github.kasuminova.mmce.client.gui;

import appeng.client.gui.implementations.GuiUpgradeable;
import appeng.client.gui.widgets.GuiCustomSlot;
import appeng.container.interfaces.IJEIGhostIngredients;
import appeng.core.localization.GuiText;
import com.mekeng.github.MekEng;
import com.mekeng.github.client.slots.SlotGas;
import com.mekeng.github.client.slots.SlotGasTank;
import com.mekeng.github.common.me.data.impl.AEGasStack;
import com.mekeng.github.common.me.inventory.IGasInventory;
import com.mekeng.github.network.packet.CGasSlotSync;
import com.mekeng.github.util.Utils;
import github.kasuminova.mmce.common.container.ContainerMEGasInputBus;
import github.kasuminova.mmce.common.tile.MEGasInputBus;
import github.kasuminova.mmce.common.tile.base.MEFluidBus;
import hellfirepvp.modularmachinery.ModularMachinery;
import mekanism.api.gas.GasStack;
import mezz.jei.api.gui.IGhostIngredientHandler;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;

public class GuiMEGasInputBus extends GuiUpgradeable {
import javax.annotation.Nonnull;
import java.awt.Rectangle;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class GuiMEGasInputBus extends GuiUpgradeable implements IJEIGhostIngredients {
private static final ResourceLocation TEXTURES_INPUT_BUS = new ResourceLocation(ModularMachinery.MODID, "textures/gui/mefluidinputbus.png");

private final MEGasInputBus bus;
Expand Down Expand Up @@ -54,4 +69,47 @@ public void drawBG(int offsetX, int offsetY, int mouseX, int mouseY) {
this.mc.getTextureManager().bindTexture(TEXTURES_INPUT_BUS);
this.drawTexturedModalRect(offsetX, offsetY, 0, 0, this.xSize, this.ySize);
}

// Code adapted from com.mekeng.github.client.gui.GuiUpgradeable, full credits to the original author
public List<IGhostIngredientHandler.Target<?>> getPhantomTargets(Object ingredient) {
GasStack gas = null;
if (ingredient instanceof GasStack) {
gas = (GasStack) ingredient;
} else if (ingredient instanceof ItemStack i) {
gas = Utils.getGasFromItem(i);
}

if (gas == null) {
return Collections.emptyList();
} else {
final GasStack imGas = gas;
this.mapTargetSlot.clear();
List<IGhostIngredientHandler.Target<?>> targets = new ArrayList<>();
List<SlotGas> slots = new ArrayList<>();
if (!this.getGuiSlots().isEmpty()) {
for (GuiCustomSlot slot : this.getGuiSlots()) {
if (slot instanceof SlotGas) {
slots.add((SlotGas) slot);
}
}
}

for (final SlotGas slot : slots) {
IGhostIngredientHandler.Target<Object> targetItem = new IGhostIngredientHandler.Target<>() {
@Nonnull
public Rectangle getArea() {
return slot.isSlotEnabled() ? new Rectangle(GuiMEGasInputBus.this.getGuiLeft() + slot.xPos(), GuiMEGasInputBus.this.getGuiTop() + slot.yPos(), 16, 16) : new Rectangle();
}

public void accept(@Nonnull Object o) {
MekEng.proxy.netHandler.sendToServer(new CGasSlotSync(Collections.singletonMap(slot.getId(), AEGasStack.of(imGas))));
}
};
targets.add(targetItem);
this.mapTargetSlot.putIfAbsent(targetItem, slot);
}

return targets;
}
}
}
111 changes: 47 additions & 64 deletions src/main/java/github/kasuminova/mmce/client/gui/GuiMEItemInputBus.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
import appeng.core.localization.GuiText;
import appeng.core.sync.network.NetworkHandler;
import appeng.core.sync.packets.PacketInventoryAction;
import appeng.fluids.client.gui.widgets.GuiFluidSlot;
import appeng.fluids.util.AEFluidStack;
import appeng.helpers.InventoryAction;
import appeng.util.item.AEItemStack;
import github.kasuminova.mmce.common.container.ContainerMEItemInputBus;
Expand All @@ -17,6 +15,9 @@
import hellfirepvp.modularmachinery.ModularMachinery;
import hellfirepvp.modularmachinery.client.ClientProxy;
import hellfirepvp.modularmachinery.common.util.MiscUtils;
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
import it.unimi.dsi.fastutil.objects.ObjectLists;
import mezz.jei.api.gui.IGhostIngredientHandler;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.renderer.GlStateManager;
Expand All @@ -26,23 +27,23 @@
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.text.TextFormatting;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidUtil;
import net.minecraftforge.fml.client.config.GuiUtils;
import org.lwjgl.input.Keyboard;
import org.lwjgl.input.Mouse;

import javax.annotation.Nonnull;
import java.awt.*;
import java.awt.Rectangle;
import java.io.IOException;
import java.text.NumberFormat;
import java.util.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Map;

public class GuiMEItemInputBus extends GuiMEItemBus implements IJEIGhostIngredients {
private static final ResourceLocation TEXTURES_INPUT_BUS = new ResourceLocation(ModularMachinery.MODID, "textures/gui/meiteminputbus.png");

protected final Map<IGhostIngredientHandler.Target<?>, Object> mapTargetSlot = new HashMap<>();
protected final Map<IGhostIngredientHandler.Target<?>, Object> mapTargetSlot = new Object2ObjectOpenHashMap<>();
private int invActionAmount = 0;

public GuiMEItemInputBus(final MEItemInputBus te, final EntityPlayer player) {
Expand Down Expand Up @@ -225,73 +226,55 @@ protected void renderToolTip(@Nonnull final ItemStack stack, final int x, final
// Code adapted from appeng.client.gui.implementations.GuiUpgradeable, full credits to the original author
@Override
public List<IGhostIngredientHandler.Target<?>> getPhantomTargets(Object ingredient) {
mapTargetSlot.clear();

FluidStack fluidStack = null;
ItemStack itemStack = ItemStack.EMPTY;
this.mapTargetSlot.clear();
if (ingredient instanceof ItemStack itemStack) {
List<IGhostIngredientHandler.Target<?>> targets = new ObjectArrayList<>();
List<IJEITargetSlot> slots = new ObjectArrayList<>();
if (!this.inventorySlots.inventorySlots.isEmpty()) {
for (Slot slot : this.inventorySlots.inventorySlots) {
if (slot instanceof SlotFake && !itemStack.isEmpty()) {
slots.add((IJEITargetSlot) slot);
}
}
}

if (ingredient instanceof ItemStack) {
itemStack = (ItemStack) ingredient;
fluidStack = FluidUtil.getFluidContained(itemStack);
} else if (ingredient instanceof FluidStack) {
fluidStack = (FluidStack) ingredient;
}
for (final IJEITargetSlot slot : slots) {
var targetItem = getObjectTarget(itemStack, slot);
targets.add(targetItem);
this.mapTargetSlot.putIfAbsent(targetItem, slot);
}

if (!(ingredient instanceof ItemStack) && !(ingredient instanceof FluidStack)) {
return Collections.emptyList();
return targets;
} else {
return ObjectLists.emptyList();
}
}

List<IGhostIngredientHandler.Target<?>> targets = new ArrayList();
List<IJEITargetSlot> slots = new ArrayList();
if (!this.inventorySlots.inventorySlots.isEmpty()) {
for(Slot slot : this.inventorySlots.inventorySlots) {
if (slot instanceof SlotFake && (!itemStack.isEmpty())) {
slots.add((IJEITargetSlot)slot);
private IGhostIngredientHandler.Target<Object> getObjectTarget(ItemStack itemStack, IJEITargetSlot slot) {
final GuiMEItemBus g = this;
return new IGhostIngredientHandler.Target<>() {
@Nonnull
public Rectangle getArea() {
if (slot instanceof SlotFake slotFake && slotFake.isSlotEnabled()) {
return new Rectangle(g.getGuiLeft() + slotFake.xPos, g.getGuiTop() + slotFake.yPos, 16, 16);
}
return new Rectangle();
}
}
for (IJEITargetSlot slot : slots) {
ItemStack finalItemStack = itemStack;
FluidStack finalFluidStack = fluidStack;
IGhostIngredientHandler.Target<Object> targetItem = new IGhostIngredientHandler.Target<>() {
@Nonnull
@Override
public Rectangle getArea() {
if (slot instanceof SlotFake && ((SlotFake) slot).isSlotEnabled()) {
return new Rectangle(getGuiLeft() + ((SlotFake) slot).xPos, getGuiTop() + ((SlotFake) slot).yPos, 16, 16);
} else if (slot instanceof GuiFluidSlot && ((GuiFluidSlot) slot).isSlotEnabled()) {
return new Rectangle(getGuiLeft() + ((GuiFluidSlot) slot).xPos(), getGuiTop() + ((GuiFluidSlot) slot).yPos(), 16, 16);
}
return new Rectangle();
}

@Override
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, slot, AEItemStack.fromItemStack(FluidUtil.getFilledBucket(finalFluidStack)));
} else if (!finalItemStack.isEmpty()) {
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, slot, AEItemStack.fromItemStack(AEFluidStack.fromFluidStack(finalFluidStack).asItemStackRepresentation()));
public void accept(@Nonnull Object ingredient) {
try {
if (slot instanceof SlotFake && ((SlotFake) slot).isSlotEnabled()) {
if (!itemStack.isEmpty()) {
PacketInventoryAction p = new PacketInventoryAction(InventoryAction.PLACE_JEI_GHOST_ITEM, slot, AEItemStack.fromItemStack(itemStack));
NetworkHandler.instance().sendToServer(p);
}
NetworkHandler.instance().sendToServer(p);

} catch (IOException e) {
e.printStackTrace();
}
} catch (IOException ignored) {

}
};
targets.add(targetItem);
mapTargetSlot.putIfAbsent(targetItem, slot);
}
return targets;

}
};
}

@Override
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,23 @@
import mezz.jei.transfer.RecipeTransferErrorInternal;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
import java.util.Map;

public class MEInputRecipeTransferHandler implements IRecipeTransferHandler<ContainerMEItemInputBus> {

@NotNull
@Override
public Class<ContainerMEItemInputBus> getContainerClass() {
return ContainerMEItemInputBus.class;
}

@Nullable
@Override
public IRecipeTransferError transferRecipe(ContainerMEItemInputBus containerMEItemInputBus, IRecipeLayout recipeLayout, EntityPlayer entityPlayer, boolean maxTransfer, boolean doTransfer) {
public IRecipeTransferError transferRecipe(@NotNull ContainerMEItemInputBus containerMEItemInputBus, IRecipeLayout recipeLayout, @NotNull EntityPlayer entityPlayer, boolean maxTransfer, boolean doTransfer) {
final String recipeType = recipeLayout.getRecipeCategory().getUid();

// MM recipes are identified by this prefix
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@

public class PktMEInputBusRecipeTransfer implements IMessage, IMessageHandler<PktMEInputBusRecipeTransfer, IMessage> {

private ArrayList<ItemStack> inputs;
private List<ItemStack> inputs;

public PktMEInputBusRecipeTransfer() {
}

public PktMEInputBusRecipeTransfer(ArrayList<ItemStack> inputs) {
public PktMEInputBusRecipeTransfer(List<ItemStack> inputs) {
this.inputs = inputs;
}

Expand Down Expand Up @@ -60,20 +60,29 @@ public void toBytes(ByteBuf buf) {
public IMessage onMessage(PktMEInputBusRecipeTransfer message, MessageContext ctx) {
final EntityPlayerMP player = ctx.getServerHandler().player;
final Container container = player.openContainer;
ArrayList<ItemStack> inputs = message.inputs;
List<ItemStack> inputs = message.inputs;
List<Slot> inventorySlots = container.inventorySlots;
ext:
for (ItemStack input : inputs) {
for (Slot slot : inventorySlots) {
if (slot instanceof SlotFake slotFake) {
if (!slotFake.getHasStack()) {
slotFake.putStack(input.copy());
continue ext;
}
}
}
var slot = getAvailableSlot(input, inventorySlots);
if (slot != null)
slot.putStack(input.copy());
}

return null;
}

private SlotFake getAvailableSlot(ItemStack stack, List<Slot> slots) {
SlotFake emptySlot = null;
for (Slot slot : slots) {
if (slot instanceof SlotFake slotFake) {
var item = slotFake.getStack();
if (item.isEmpty()) {
if (emptySlot == null) emptySlot = slotFake;
} else if (ItemStack.areItemStacksEqual(item, stack)) {
return null;
}
}
}
return emptySlot;
}
}
Loading
Loading