Add LevelMaintainer

This commit is contained in:
asdflj committed 2022-11-09 11:03:46 +08:00
1 parent 89068c4dff
commit 5d31d6d6fb
15 files changed
+373 -170

No files matched your search

@@ -130,7 +130,6 @@ public class GuiBaseFluidPatternTerminal extends GuiFCBaseMonitor {
this.guiLeft + 84, this.guiTop + this.ySize - 153, Settings.ACTIONS, PatternBeSubstitution.DISABLED);
this.beSubstitutionsDisabledBtn.setHalfSize(true);
this.buttonList.add(this.beSubstitutionsDisabledBtn);
}
this.combineEnableBtn = new GuiFCImgButton(this.guiLeft + combineLeft, this.guiTop + this.ySize - combineTop, "FORCE_COMBINE", "DO_COMBINE");
this.combineEnableBtn.setHalfSize(true);
@@ -101,12 +101,12 @@ public class GuiBaseFluidPatternTerminalEx extends GuiFCBaseMonitor {
this.substitutionsDisabledBtn.setHalfSize( true );
this.buttonList.add( this.substitutionsDisabledBtn );
this.fluidPrioritizedEnabledBtn = new GuiFCImgButton( this.guiLeft + 97, this.guiTop + this.ySize - 143, "FORCE_PRIO", "DO_PRIO" );
this.fluidPrioritizedEnabledBtn.setHalfSize( true );
this.fluidPrioritizedEnabledBtn = new GuiFCImgButton(this.guiLeft + 97, this.guiTop + this.ySize - 114, "FORCE_PRIO", "DO_PRIO");
this.fluidPrioritizedEnabledBtn.setHalfSize(true);
this.buttonList.add( this.fluidPrioritizedEnabledBtn );
this.fluidPrioritizedDisabledBtn = new GuiFCImgButton( this.guiLeft + 97, this.guiTop + this.ySize - 143, "NOT_PRIO", "DONT_PRIO" );
this.fluidPrioritizedDisabledBtn.setHalfSize( true );
this.fluidPrioritizedDisabledBtn = new GuiFCImgButton(this.guiLeft + 97, this.guiTop + this.ySize - 114, "NOT_PRIO", "DONT_PRIO");
this.fluidPrioritizedDisabledBtn.setHalfSize(true);
this.buttonList.add( this.fluidPrioritizedDisabledBtn );
invertBtn = new GuiImgButton( this.guiLeft + 87, this.guiTop + this.ySize - 153, Settings.ACTIONS, container.inverted ? PatternSlotConfig.C_4_16 : PatternSlotConfig.C_16_4);
@@ -126,21 +126,21 @@ public class GuiBaseFluidPatternTerminalEx extends GuiFCBaseMonitor {
this.buttonList.add(this.doubleBtn);
}
this.combineEnableBtn = new GuiFCImgButton(this.guiLeft + 87, this.guiTop + this.ySize - 143, "FORCE_COMBINE", "DO_COMBINE");
this.combineEnableBtn = new GuiFCImgButton(this.guiLeft + 87, this.guiTop + this.ySize - 114, "FORCE_COMBINE", "DO_COMBINE");
this.combineEnableBtn.setHalfSize(true);
this.buttonList.add(this.combineEnableBtn);
this.combineDisableBtn = new GuiFCImgButton(this.guiLeft + 87, this.guiTop + this.ySize - 143, "NOT_COMBINE", "DONT_COMBINE");
this.combineDisableBtn = new GuiFCImgButton(this.guiLeft + 87, this.guiTop + this.ySize - 114, "NOT_COMBINE", "DONT_COMBINE");
this.combineDisableBtn.setHalfSize(true);
this.buttonList.add(this.combineDisableBtn);
if (ModAndClassUtil.isBeSubstitutionsButton) {
this.beSubstitutionsEnabledBtn = new GuiImgButton(
this.guiLeft + 87, this.guiTop + this.ySize - 133, Settings.ACTIONS, PatternBeSubstitution.ENABLED);
this.guiLeft + 87, this.guiTop + this.ySize - 103, Settings.ACTIONS, PatternBeSubstitution.ENABLED);
this.beSubstitutionsEnabledBtn.setHalfSize(true);
this.buttonList.add(this.beSubstitutionsEnabledBtn);
this.beSubstitutionsDisabledBtn = new GuiImgButton(
this.guiLeft + 87, this.guiTop + this.ySize - 133, Settings.ACTIONS, PatternBeSubstitution.DISABLED);
this.guiLeft + 87, this.guiTop + this.ySize - 103, Settings.ACTIONS, PatternBeSubstitution.DISABLED);
this.beSubstitutionsDisabledBtn.setHalfSize(true);
this.buttonList.add(this.beSubstitutionsDisabledBtn);
}
@@ -8,10 +8,7 @@ import appeng.api.storage.data.IAEItemStack;
import appeng.api.util.IConfigManager;
import appeng.api.util.IConfigurableObject;
import appeng.client.gui.AEBaseMEGui;
import appeng.client.gui.widgets.GuiImgButton;
import appeng.client.gui.widgets.GuiScrollbar;
import appeng.client.gui.widgets.GuiTabButton;
import appeng.client.gui.widgets.ISortSource;
import appeng.client.gui.widgets.*;
import appeng.client.me.InternalSlotME;
import appeng.client.me.SlotDisconnected;
import appeng.client.me.SlotME;
@@ -32,6 +29,8 @@ import appeng.integration.IntegrationType;
import appeng.util.IConfigManagerHost;
import appeng.util.Platform;
import appeng.util.item.AEItemStack;
import codechicken.nei.LayoutManager;
import codechicken.nei.util.TextHistory;
import com.glodblock.github.FluidCraft;
import com.glodblock.github.client.gui.container.FCBaseFluidMonitorContain;
import com.glodblock.github.client.me.FluidRepo;
@@ -40,6 +39,7 @@ import com.glodblock.github.network.CPacketInventoryAction;
import com.glodblock.github.util.Ae2ReflectClient;
import com.glodblock.github.util.ModAndClassUtil;
import com.glodblock.github.util.NameConst;
import com.glodblock.github.util.Util;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.resources.I18n;
@@ -52,9 +52,10 @@ import org.lwjgl.input.Keyboard;
import org.lwjgl.input.Mouse;
import java.io.IOException;
import java.lang.reflect.Field;
import java.util.List;
public class GuiFCBaseFluidMonitor extends AEBaseMEGui implements ISortSource, IConfigManagerHost {
public class GuiFCBaseFluidMonitor extends AEBaseMEGui implements ISortSource, IConfigManagerHost, IDropToFillTextField {
public static int craftingGridOffsetX;
public static int craftingGridOffsetY;
@@ -309,11 +310,9 @@ public class GuiFCBaseFluidMonitor extends AEBaseMEGui implements ISortSource, I
@Override
protected void mouseClicked(final int xCoord, final int yCoord, final int btn) {
final Enum<?> searchMode = AEConfig.instance.settings.getSetting(Settings.SEARCH_MODE);
if (searchMode != SearchBoxMode.AUTOSEARCH && searchMode != SearchBoxMode.NEI_AUTOSEARCH) {
this.searchField.mouseClicked(xCoord, yCoord, btn);
}
if (btn == 1 && this.searchField.isMouseIn(xCoord, yCoord)) {
setSearchString("", true);
}
@@ -321,6 +320,39 @@ public class GuiFCBaseFluidMonitor extends AEBaseMEGui implements ISortSource, I
super.mouseClicked(xCoord, yCoord, btn);
}
@Override
public void handleMouseInput() {
final int wheel = Mouse.getEventDWheel();
final int x = Mouse.getEventX() * this.width / this.mc.displayWidth;
final int y = this.height - Mouse.getEventY() * this.height / this.mc.displayHeight;
if (wheel != 0 && this.searchField.isMouseIn(x, y) && isCtrlKeyDown()) {
final Enum<?> searchMode = AEConfig.instance.settings.getSetting(Settings.SEARCH_MODE);
if (searchMode == SearchBoxMode.NEI_MANUAL_SEARCH || searchMode == SearchBoxMode.NEI_AUTOSEARCH) {
try {
Field cls = LayoutManager.searchField.getClass().getDeclaredField("history");
cls.setAccessible(true);
TextHistory history = ((TextHistory) cls.get("get"));
TextHistory.Direction direction;
if (wheel > 0) {
direction = TextHistory.Direction.PREVIOUS;
} else {
direction = TextHistory.Direction.NEXT;
}
history.get(direction, this.searchField.getText())
.map(newText -> {
setSearchString(newText, true);
return true;
})
.orElse(false);
return;
} catch (NoSuchFieldException | IllegalAccessException e) {
}
}
}
super.handleMouseInput();
}
@Override
protected void handleMouseClick(final Slot slot, final int slotIdx, final int ctrlDown, final int mouseButton) {
final EntityPlayer player = Minecraft.getMinecraft().thePlayer;
@@ -686,4 +718,15 @@ public class GuiFCBaseFluidMonitor extends AEBaseMEGui implements ISortSource, I
return false;
}
@Override
public boolean isOverTextField(int mousex, int mousey) {
return searchField.isMouseIn(mousex, mousey);
}
@Override
public void setTextFieldValue(String displayName, int mousex, int mousey, ItemStack stack) {
if (Util.getFluidFromItem(stack) != null) {
setSearchString(Util.getFluidFromItem(stack).getFluid().getLocalizedName(), true);
}
}
}
@@ -7,10 +7,7 @@ import appeng.api.storage.data.IAEItemStack;
import appeng.api.util.IConfigManager;
import appeng.api.util.IConfigurableObject;
import appeng.client.gui.AEBaseMEGui;
import appeng.client.gui.widgets.GuiImgButton;
import appeng.client.gui.widgets.GuiScrollbar;
import appeng.client.gui.widgets.GuiTabButton;
import appeng.client.gui.widgets.ISortSource;
import appeng.client.gui.widgets.*;
import appeng.client.me.InternalSlotME;
import appeng.client.me.ItemRepo;
import appeng.client.me.SlotDisconnected;
@@ -32,6 +29,8 @@ import appeng.integration.IntegrationType;
import appeng.util.IConfigManagerHost;
import appeng.util.Platform;
import appeng.util.item.AEItemStack;
import codechicken.nei.LayoutManager;
import codechicken.nei.util.TextHistory;
import com.glodblock.github.FluidCraft;
import com.glodblock.github.client.gui.container.FCBaseMonitorContain;
import com.glodblock.github.network.CPacketInventoryAction;
@@ -48,10 +47,10 @@ import org.lwjgl.input.Keyboard;
import org.lwjgl.input.Mouse;
import java.io.IOException;
import java.lang.reflect.Field;
import java.util.List;
public class GuiFCBaseMonitor extends AEBaseMEGui implements ISortSource, IConfigManagerHost
{
public class GuiFCBaseMonitor extends AEBaseMEGui implements ISortSource, IConfigManagerHost, IDropToFillTextField {
public static int craftingGridOffsetX;
public static int craftingGridOffsetY;
@@ -343,29 +342,58 @@ public class GuiFCBaseMonitor extends AEBaseMEGui implements ISortSource, IConfi
}
@Override
protected void mouseClicked( final int xCoord, final int yCoord, final int btn )
{
final Enum<?> searchMode = AEConfig.instance.settings.getSetting( Settings.SEARCH_MODE );
if( searchMode != SearchBoxMode.AUTOSEARCH && searchMode != SearchBoxMode.NEI_AUTOSEARCH )
{
this.searchField.mouseClicked( xCoord, yCoord, btn );
protected void mouseClicked( final int xCoord, final int yCoord, final int btn ) {
final Enum<?> searchMode = AEConfig.instance.settings.getSetting(Settings.SEARCH_MODE);
final EntityPlayer player = Minecraft.getMinecraft().thePlayer;
ItemStack is = player.inventory.getItemStack();
if (searchMode != SearchBoxMode.AUTOSEARCH && searchMode != SearchBoxMode.NEI_AUTOSEARCH) {
this.searchField.mouseClicked(xCoord, yCoord, btn);
}
if( btn == 1 && this.searchField.isMouseIn( xCoord, yCoord ) )
{
if (btn == 1 && this.searchField.isMouseIn(xCoord, yCoord)) {
setSearchString("", true);
}
super.mouseClicked( xCoord, yCoord, btn );
super.mouseClicked(xCoord, yCoord, btn);
}
@Override
protected void handleMouseClick( final Slot slot, final int slotIdx, final int ctrlDown, final int mouseButton )
{
public void handleMouseInput() {
final int wheel = Mouse.getEventDWheel();
final int x = Mouse.getEventX() * this.width / this.mc.displayWidth;
final int y = this.height - Mouse.getEventY() * this.height / this.mc.displayHeight;
if (wheel != 0 && this.searchField.isMouseIn(x, y) && isCtrlKeyDown()) {
final Enum<?> searchMode = AEConfig.instance.settings.getSetting(Settings.SEARCH_MODE);
if (searchMode == SearchBoxMode.NEI_MANUAL_SEARCH || searchMode == SearchBoxMode.NEI_AUTOSEARCH) {
try {
Field cls = LayoutManager.searchField.getClass().getDeclaredField("history");
cls.setAccessible(true);
TextHistory history = ((TextHistory) cls.get("get"));
TextHistory.Direction direction;
if (wheel > 0) {
direction = TextHistory.Direction.PREVIOUS;
} else {
direction = TextHistory.Direction.NEXT;
}
history.get(direction, this.searchField.getText())
.map(newText -> {
setSearchString(newText, true);
return true;
})
.orElse(false);
return;
} catch (NoSuchFieldException | IllegalAccessException e) {
}
}
}
super.handleMouseInput();
}
@Override
protected void handleMouseClick(final Slot slot, final int slotIdx, final int ctrlDown, final int mouseButton) {
final EntityPlayer player = Minecraft.getMinecraft().thePlayer;
if (mouseButton == 3 ){
if (mouseButton == 3) {
if (slot instanceof OptionalSlotFake || slot instanceof SlotFakeCraftingMatrix) {
if (slot.getHasStack()) {
InventoryAction action = InventoryAction.valueOf("SET_PATTERN_VALUE");
@@ -790,4 +818,13 @@ public class GuiFCBaseMonitor extends AEBaseMEGui implements ISortSource, IConfi
return false;
}
@Override
public boolean isOverTextField(int mousex, int mousey) {
return searchField.isMouseIn(mousex, mousey);
}
@Override
public void setTextFieldValue(String displayName, int mousex, int mousey, ItemStack stack) {
setSearchString(displayName, true);
}
}
@@ -4,9 +4,13 @@ import appeng.api.storage.data.IAEItemStack;
import appeng.client.gui.AEBaseGui;
import appeng.client.render.AppEngRenderItem;
import appeng.container.slot.SlotFake;
import appeng.core.sync.network.NetworkHandler;
import appeng.core.sync.packets.PacketNEIDragClick;
import codechicken.nei.VisiblityData;
import codechicken.nei.api.INEIGuiHandler;
import codechicken.nei.api.TaggedInventoryArea;
import com.glodblock.github.FluidCraft;
import com.glodblock.github.client.gui.container.ContainerLevelMaintainer;
import com.glodblock.github.common.item.ItemFluidPacket;
import com.glodblock.github.common.tile.TileLevelMaintainer;
import com.glodblock.github.inventory.gui.MouseRegionManager;
import com.glodblock.github.inventory.slot.SlotSingleItem;
@@ -14,16 +18,22 @@ import com.glodblock.github.network.CPacketLevelMaintainer;
import com.glodblock.github.util.Ae2ReflectClient;
import com.glodblock.github.util.ModAndClassUtil;
import com.glodblock.github.util.NameConst;
import cpw.mods.fml.common.Optional;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import org.lwjgl.input.Keyboard;
import java.awt.*;
import java.util.Collections;
import java.util.List;
public class GuiLevelMaintainer extends AEBaseGui {
@Optional.Interface(modid = "NotEnoughItems", iface = "codechicken.nei.api.INEIGuiHandler")
public class GuiLevelMaintainer extends AEBaseGui implements INEIGuiHandler {
private static final ResourceLocation TEX_BG = FluidCraft.resource("textures/gui/level_maintainer.png");
private final ContainerLevelMaintainer cont;
@@ -44,7 +54,7 @@ public class GuiLevelMaintainer extends AEBaseGui {
public void postUpdate(List<IAEItemStack> list) {
for (IAEItemStack is : list) {
long size = is.getItemStack().getTagCompound().getLong("BatchSize");
long size = is.getItemStack().getTagCompound().getLong("Batch");
int i = is.getItemStack().getTagCompound().getInteger("Index");
qtyInputs[i].textField.setText(String.valueOf(is.getStackSize()));
batchInputs[i].textField.setText(String.valueOf(size));
@@ -109,9 +119,10 @@ public class GuiLevelMaintainer extends AEBaseGui {
super.func_146977_a(new SlotSingleItem(slot));
if (stack == null) return true;
IAEItemStack fake = stack.copy();
if (fake.getItemStack().getItem() instanceof ItemFluidPacket) {
if (ItemFluidPacket.getFluidStack(stack) != null && ItemFluidPacket.getFluidStack(stack).amount > 0)
fake.setStackSize(ItemFluidPacket.getFluidStack(stack).amount);
if (this.qtyInputs[slot.getSlotIndex()].textField.getText().matches("[0-9]+")) {
fake.setStackSize(Long.parseLong(this.qtyInputs[slot.getSlotIndex()].textField.getText()));
} else {
fake.setStackSize(0);
}
stackSizeRenderer.setAeStack(fake);
stackSizeRenderer.renderItemOverlayIntoGUI(fontRendererObj, mc.getTextureManager(), stack.getItemStack(), slot.xDisplayPosition, slot.yDisplayPosition);
@@ -172,10 +183,11 @@ public class GuiLevelMaintainer extends AEBaseGui {
@Override
protected void handleMouseClick(final Slot slot, final int slotIdx, final int ctrlDown, final int mouseButton) {
super.handleMouseClick(slot, slotIdx, ctrlDown, mouseButton);
if (slot instanceof ContainerLevelMaintainer.FakeSlot && this.cont.getPlayerInv().getItemStack() != null) {
this.qtyInputs[slot.getSlotIndex()].textField.setText(String.valueOf(this.cont.getPlayerInv().getItemStack().stackSize));
return;
}
super.handleMouseClick(slot, slotIdx, ctrlDown, mouseButton);
}
public void updateAmount(int idx, int stackSize) {
@@ -184,7 +196,8 @@ public class GuiLevelMaintainer extends AEBaseGui {
private boolean sendToServer(Widget widget) {
if (((ContainerLevelMaintainer.FakeSlot) cont.inventorySlots.get(widget.idx)).getHasStack()) {
if (!widget.textField.getText().isEmpty() && widget.textField.getText().matches("[0-9]+") && Long.parseLong(widget.textField.getText()) <= Integer.MAX_VALUE) {
if (!widget.textField.getText().isEmpty() && widget.textField.getText().matches("[0-9]+")) {
widget.textField.setText(widget.textField.getText().replaceAll("^(0+)", ""));
FluidCraft.proxy.netHandler.sendToServer(new CPacketLevelMaintainer(widget.action, widget.idx, widget.textField.getText()));
widget.textField.setTextColor(0xFFFFFF);
return true;
@@ -213,6 +226,49 @@ public class GuiLevelMaintainer extends AEBaseGui {
}
}
@Override
public VisiblityData modifyVisiblity(GuiContainer gui, VisiblityData currentVisibility) {
return currentVisibility;
}
@Override
public Iterable<Integer> getItemSpawnSlots(GuiContainer gui, ItemStack item) {
return Collections.emptyList();
}
@Override
public List<TaggedInventoryArea> getInventoryAreas(GuiContainer gui) {
return null;
}
private Rectangle getSlotArea(SlotFake slot) {
return new Rectangle(guiLeft + slot.getX(), guiTop + slot.getY(), 16, 16);
}
@Override
public boolean handleDragNDrop(GuiContainer gui, int mouseX, int mouseY, ItemStack draggedStack, int button) {
for (ContainerLevelMaintainer.FakeSlot slot : this.cont.getRequestSlots()) {
if (getSlotArea(slot).contains(mouseX, mouseY)) {
slot.putStack(draggedStack);
NetworkHandler.instance.sendToServer(new PacketNEIDragClick(draggedStack, slot.getSlotIndex()));
if (draggedStack != null) {
this.updateAmount(slot.getSlotIndex(), draggedStack.stackSize);
draggedStack.stackSize = 0;
}
return true;
}
}
if (draggedStack != null) {
draggedStack.stackSize = 0;
}
return false;
}
@Override
public boolean hideItemPanelSlot(GuiContainer gui, int x, int y, int w, int h) {
return false;
}
private class Widget {
public final int idx;
public final int action;
@@ -224,6 +280,7 @@ public class GuiLevelMaintainer extends AEBaseGui {
this.textField.setMessage(tooltip);
this.textField.setEnableBackgroundDrawing(false);
this.textField.setText("0");
this.textField.setMaxStringLength(10); // it's enough to useful
this.button = button;
this.idx = idx;
this.action = action;
@@ -1,34 +1,27 @@
package com.glodblock.github.client.gui.container;
import appeng.container.AEBaseContainer;
import appeng.container.slot.OptionalSlotFake;
import appeng.container.slot.SlotFakeCraftingMatrix;
import appeng.util.Platform;
import appeng.util.item.AEItemStack;
import com.glodblock.github.client.gui.GuiLevelMaintainer;
import com.glodblock.github.common.tile.TileLevelMaintainer;
import com.glodblock.github.inventory.AeItemStackHandler;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.ICrafting;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
public class ContainerLevelMaintainer extends AEBaseContainer {
private final TileLevelMaintainer tile;
private final FakeSlot[] craftingSlots = new FakeSlot[TileLevelMaintainer.REQ_COUNT];
private final FakeSlot[] requestSlots = new FakeSlot[TileLevelMaintainer.REQ_COUNT];
public ContainerLevelMaintainer(InventoryPlayer ipl, TileLevelMaintainer tile) {
super(ipl, tile);
this.tile = tile;
AeItemStackHandler crafting = new AeItemStackHandler(tile.getCraftingSlots());
AeItemStackHandler request = new AeItemStackHandler(tile.getRequestSlots());
for (int y = 0; y < TileLevelMaintainer.REQ_COUNT; y++) {
FakeSlot slot = new FakeSlot(crafting, y, 17, 19 + y * 20);
FakeSlot slot = new FakeSlot(request, y, 17, 19 + y * 20);
addSlotToContainer(slot);
craftingSlots[y] = slot;
requestSlots[y] = slot;
}
bindPlayerInventory(ipl, 0, 132);
}
@@ -37,15 +30,15 @@ public class ContainerLevelMaintainer extends AEBaseContainer {
return tile;
}
public FakeSlot[] getRequestSlots() {
return this.requestSlots;
}
@Override
public ItemStack transferStackInSlot(EntityPlayer player, int idx) {
for (ContainerFluidPatternEncoder.SlotFluidConvertingFake slot : craftingSlots) {
for (FakeSlot slot : this.getRequestSlots()) {
if (!slot.getHasStack()) {
slot.setAeStack(AEItemStack.create(((Slot) this.inventorySlots.get(idx)).getStack()), true);
if (Platform.isClient()) {
GuiLevelMaintainer gui = (GuiLevelMaintainer) Minecraft.getMinecraft().currentScreen;
gui.updateAmount(slot.getSlotIndex(), ((Slot) this.inventorySlots.get(idx)).getStack().stackSize);
}
break;
}
}
@@ -62,24 +55,6 @@ public class ContainerLevelMaintainer extends AEBaseContainer {
}
}
@Override
public void onSlotChange(final Slot s) {
if (Platform.isServer()) {
for (final Object crafter : this.crafters) {
final ICrafting icrafting = (ICrafting) crafter;
for (final Object g : this.inventorySlots) {
if (g instanceof OptionalSlotFake || g instanceof SlotFakeCraftingMatrix) {
final Slot sri = (Slot) g;
icrafting.sendSlotContents(this, sri.slotNumber, sri.getStack());
}
}
((EntityPlayerMP) icrafting).isChangingQuantityOnly = false;
}
this.detectAndSendChanges();
}
}
public static class FakeSlot extends ContainerFluidPatternEncoder.SlotFluidConvertingFake {
public FakeSlot(AeItemStackHandler inv, int idx, int x, int y) {
@@ -613,22 +613,10 @@ public class FCBasePartContainer extends FCBaseMonitorContain implements IAEAppE
assert !ow.hasNext();
}
public void doubleStacks(boolean isShift)
{
if (!isCraftingMode() && canDoubleStacks(craftingSlots) && canDoubleStacks(outputSlots))
{
doubleStacksInternal(this.craftingSlots);
doubleStacksInternal(this.outputSlots);
if (isShift && !containsFluid(outputSlots) && !containsFluid(craftingSlots))
{
while (canDoubleStacks(craftingSlots) && canDoubleStacks(outputSlots))
{
doubleStacksInternal(this.craftingSlots);
doubleStacksInternal(this.outputSlots);
}
}
this.detectAndSendChanges();
}
static boolean containsItem(SlotFake[] slots) {
List<SlotFake> enabledSlots = Arrays.stream(slots).filter(SlotFake::isEnabled).collect(Collectors.toList());
long item = enabledSlots.stream().filter(s -> s.getStack() != null && !Util.isFluidPacket(s.getStack())).count();
return item > 0;
}
static boolean containsFluid(SlotFake[] slots) {
@@ -637,4 +625,18 @@ public class FCBasePartContainer extends FCBaseMonitorContain implements IAEAppE
return fluid > 0;
}
public void doubleStacks(boolean isShift) {
if (!isCraftingMode() && canDoubleStacks(craftingSlots) && canDoubleStacks(outputSlots)) {
doubleStacksInternal(this.craftingSlots);
doubleStacksInternal(this.outputSlots);
if (isShift && (containsItem(outputSlots) || containsItem(craftingSlots))) {
while (canDoubleStacks(craftingSlots) && canDoubleStacks(outputSlots)) {
doubleStacksInternal(this.craftingSlots);
doubleStacksInternal(this.outputSlots);
}
}
this.detectAndSendChanges();
}
}
}
@@ -447,20 +447,10 @@ public class FCBasePartContainerEx extends FCBaseMonitorContain implements IAEAp
assert !ow.hasNext();
}
public void doubleStacks(boolean isShift)
{
if (canDoubleStacks(craftingSlots) && canDoubleStacks(outputSlots))
{
doubleStacksInternal(this.craftingSlots);
doubleStacksInternal(this.outputSlots);
if (isShift && !containsFluid(outputSlots) && !containsFluid(craftingSlots)) {
while (canDoubleStacks(craftingSlots) && canDoubleStacks(outputSlots)) {
doubleStacksInternal(this.craftingSlots);
doubleStacksInternal(this.outputSlots);
}
}
this.detectAndSendChanges();
}
static boolean containsItem(SlotFake[] slots) {
List<SlotFake> enabledSlots = Arrays.stream(slots).filter(SlotFake::isEnabled).collect(Collectors.toList());
long item = enabledSlots.stream().filter(s -> s.getStack() != null && !Util.isFluidPacket(s.getStack())).count();
return item > 0;
}
private boolean canBeSubstitute() {
@@ -473,6 +463,20 @@ public class FCBasePartContainerEx extends FCBaseMonitorContain implements IAEAp
return fluid > 0;
}
public void doubleStacks(boolean isShift) {
if (canDoubleStacks(craftingSlots) && canDoubleStacks(outputSlots)) {
doubleStacksInternal(this.craftingSlots);
doubleStacksInternal(this.outputSlots);
if (isShift && (containsItem(outputSlots) || containsItem(craftingSlots))) {
while (canDoubleStacks(craftingSlots) && canDoubleStacks(outputSlots)) {
doubleStacksInternal(this.craftingSlots);
doubleStacksInternal(this.outputSlots);
}
}
this.detectAndSendChanges();
}
}
public void setActivePage(final int activePage) {
this.activePage = activePage;
}
@@ -95,6 +95,25 @@ public class ItemFluidDrop extends Item {
return stack;
}
public static boolean isFluidStack(ItemStack stack) {
if (getFluidStack(stack) != null) {
return true;
} else {
return false;
}
}
public static boolean isFluidStack(@Nullable IAEItemStack stack) {
if (stack == null) {
return false;
}
if (getFluidStack(stack.getItemStack()) != null) {
return true;
} else {
return false;
}
}
public static FluidStack getFluidStack(ItemStack stack) {
if (stack == null || stack.getItem() != ItemAndBlockHolder.DROP || !stack.hasTagCompound()) {
return null;
@@ -149,7 +149,7 @@ public class FluidCellInventory implements IFluidCellInventory {
@Override
public long getUsedBytes() {
long bytesForItemCount = this.getStoredFluidCount() / singleByteAmount;
long tmp = (this.getStoredFluidTypes() * this.getBytesPerType()) * singleByteAmount + bytesForItemCount;
long tmp = (this.getStoredFluidTypes() * this.getBytesPerType()) + bytesForItemCount;
if (this.getUnusedFluidCount() > 0 && tmp < this.getTotalBytes()) tmp++;
return tmp;
}
@@ -1,6 +1,8 @@
package com.glodblock.github.common.tile;
import appeng.api.AEApi;
import appeng.api.config.Actionable;
import appeng.api.config.PowerMultiplier;
import appeng.api.networking.GridFlags;
import appeng.api.networking.IGrid;
import appeng.api.networking.IGridNode;
@@ -8,24 +10,26 @@ import appeng.api.networking.crafting.ICraftingGrid;
import appeng.api.networking.crafting.ICraftingJob;
import appeng.api.networking.crafting.ICraftingLink;
import appeng.api.networking.crafting.ICraftingRequester;
import appeng.api.networking.energy.IEnergyGrid;
import appeng.api.networking.security.BaseActionSource;
import appeng.api.networking.security.MachineSource;
import appeng.api.networking.storage.IStackWatcher;
import appeng.api.networking.storage.IStackWatcherHost;
import appeng.api.networking.ticking.IGridTickable;
import appeng.api.networking.ticking.TickRateModulation;
import appeng.api.networking.ticking.TickingRequest;
import appeng.api.storage.StorageChannel;
import appeng.api.storage.data.IAEFluidStack;
import appeng.api.storage.data.IAEItemStack;
import appeng.api.storage.data.IAEStack;
import appeng.api.storage.data.IItemList;
import appeng.helpers.MultiCraftingTracker;
import appeng.core.AELog;
import appeng.crafting.CraftingLink;
import appeng.helpers.NonNullArrayIterator;
import appeng.me.GridAccessException;
import appeng.tile.TileEvent;
import appeng.tile.events.TileEventType;
import appeng.tile.grid.AENetworkTile;
import appeng.tile.inventory.IAEAppEngInventory;
import appeng.tile.inventory.InvOperation;
import com.glodblock.github.common.item.ItemFluidDrop;
import com.glodblock.github.inventory.AeStackInventory;
import com.glodblock.github.inventory.AeStackInventoryImpl;
import com.google.common.collect.ImmutableSet;
@@ -35,12 +39,11 @@ import net.minecraft.nbt.NBTTagCompound;
import java.util.concurrent.Future;
public class TileLevelMaintainer extends AENetworkTile implements IAEAppEngInventory, IStackWatcherHost, IGridTickable, ICraftingRequester {
public class TileLevelMaintainer extends AENetworkTile implements IAEAppEngInventory, IGridTickable, ICraftingRequester {
public static final int REQ_COUNT = 5;
public final InventoryRequest requests = new InventoryRequest(this);
private final BaseActionSource source;
private final MultiCraftingTracker craftingTracker = new MultiCraftingTracker(this, REQ_COUNT);
public TileLevelMaintainer() {
@@ -49,23 +52,46 @@ public class TileLevelMaintainer extends AENetworkTile implements IAEAppEngInven
this.source = new MachineSource(this);
}
public AeStackInventory<IAEItemStack> getCraftingSlots() {
return requests.getCraftingSlots();
public AeStackInventory<IAEItemStack> getRequestSlots() {
return requests.getRequestStacks();
}
@Override
public ImmutableSet<ICraftingLink> getRequestedJobs() {
return this.craftingTracker.getRequestedJobs();
return ImmutableSet.copyOf(new NonNullArrayIterator<ICraftingLink>(this.requests.getLinks()));
}
@Override
public IAEItemStack injectCraftedItems(ICraftingLink link, IAEItemStack items, Actionable mode) {
return null;
try {
if (this.getProxy().isActive()) {
final IEnergyGrid energy = this.getProxy().getEnergy();
final double power = Math.ceil(ItemFluidDrop.isFluidStack(items) ? items.getStackSize() / 1000D : items.getStackSize());
if (energy.extractAEPower(power, mode, PowerMultiplier.CONFIG) > power - 0.01) {
if (ItemFluidDrop.isFluidStack(items)) {
IAEFluidStack notInserted = this.getProxy().getStorage().getFluidInventory().injectItems(ItemFluidDrop.getAeFluidStack(items), mode, this.source);
items.setStackSize(notInserted.getStackSize());
return items;
} else {
return this.getProxy().getStorage().getItemInventory().injectItems(items, mode, this.source);
}
}
}
} catch (GridAccessException e) {
AELog.debug(e);
}
return items;
}
@Override
public void jobStateChange(ICraftingLink link) {
this.craftingTracker.jobStateChange(link);
if (this.requests.getLinks() != null) {
for (int x = 0; x < this.requests.getLinks().length; x++) {
if (this.requests.getLinks()[x] == link) {
this.requests.getLinks()[x] = link;
return;
}
}
}
}
@Override
@@ -77,7 +103,6 @@ public class TileLevelMaintainer extends AENetworkTile implements IAEAppEngInven
public TickRateModulation tickingRequest(IGridNode node, int TicksSinceLastCall) {
return this.canDoBusWork() ? this.doWork() : TickRateModulation.IDLE;
}
private TickRateModulation doWork() {
if (!this.getProxy().isActive() || !this.canDoBusWork()) {
return TickRateModulation.IDLE;
@@ -91,24 +116,23 @@ public class TileLevelMaintainer extends AENetworkTile implements IAEAppEngInven
IAEItemStack is = requests.getQuantity(i);
if (is != null && requests.getBatchSize(i) > 0) {
IAEItemStack craftItem = requests.getCraftItem(i);
if (inv.findPrecise(is) == null || inv.findPrecise(is).getStackSize() >= is.getStackSize() || cg.isRequesting(craftItem))
if (cg.canEmitFor(craftItem) || cg.isRequesting(craftItem) ||
(inv.findPrecise(is) != null && inv.findPrecise(is).getStackSize() >= is.getStackSize()) || !this.requests.isDone(i)
)
continue;
// do crafting
Future<ICraftingJob> jobTask = requests.getJobs()[i];
if (jobTask == null) {
requests.getJobs()[i] = cg.beginCraftingJob(getWorldObj(), grid, this.source, craftItem, null);
} else if (jobTask.isDone()) {
try {
ICraftingJob job = jobTask.get();
if (job != null) {
ICraftingLink link = cg.submitJob(job, null, null, false, this.source);
ICraftingLink link = cg.submitJob(job, this, null, false, this.source);
didSomething = true;
requests.jobs[i] = null;
if (link != null) {
requests.links[i] = link;
requests.getLinks()[i] = link;
}
}
} catch (Exception ignored) {
@@ -137,25 +161,16 @@ public class TileLevelMaintainer extends AENetworkTile implements IAEAppEngInven
}
}
@Override
public void updateWatcher(IStackWatcher newWatcher) {
}
protected boolean canDoBusWork() {
return this.getProxy().isActive();
}
@Override
public void onStackChange(IItemList o, IAEStack fullStack, IAEStack diffStack, BaseActionSource src, StorageChannel chan) {
}
public InventoryRequest getRequestInventory() {
return this.requests;
}
public IInventory getInventory() {
return (IInventory) this.requests.getCraftingSlots();
return (IInventory) this.requests.getRequestStacks();
}
public void updateQuantity(int idx, long size) {
@@ -166,71 +181,120 @@ public class TileLevelMaintainer extends AENetworkTile implements IAEAppEngInven
this.requests.updateBatchSize(idx, size);
}
private void readLinkFromNBT(NBTTagCompound data) {
try {
for (int i = 0; i < this.requests.getLinks().length; i++) {
final NBTTagCompound link = data.getCompoundTag("links-" + i);
if (link != null && link.hasNoTags()) {
this.requests.getLinks()[i] = null;
} else {
this.requests.getLinks()[i] = AEApi.instance().storage().loadCraftingLink(link, this);
}
}
} catch (Exception e) {
// :P You don't have job to do XD
}
}
private NBTTagCompound writeLinkToNBT(NBTTagCompound data) {
for (int i = 0; i < this.requests.getLinks().length; i++) {
if (this.requests.getLinks()[i] != null) {
CraftingLink link = (CraftingLink) this.requests.getLinks()[i];
NBTTagCompound linkData = new NBTTagCompound();
link.writeToNBT(linkData);
data.setTag("links-" + i, linkData);
}
}
return data;
}
@TileEvent(TileEventType.WORLD_NBT_WRITE)
public NBTTagCompound writeToNBTEvent(NBTTagCompound data) {
this.requests.crafting.writeToNbt(data, "Inventory");
this.requests.batchSize.writeToNbt(data, "BatchSize");
return data;
this.requests.requestStacks.writeToNbt(data, "Inventory");
this.requests.requestBatches.writeToNbt(data, "Batch");
this.requests.requestQtys.writeToNbt(data, "Count");
return writeLinkToNBT(data);
}
@TileEvent(TileEventType.WORLD_NBT_READ)
public void readFromNBTEvent(NBTTagCompound data) {
this.requests.crafting.readFromNbt(data, "Inventory");
this.requests.batchSize.readFromNbt(data, "BatchSize");
this.requests.requestStacks.readFromNbt(data, "Inventory");
this.requests.requestBatches.readFromNbt(data, "Batch");
this.requests.requestQtys.readFromNbt(data, "Count");
this.readLinkFromNBT(data);
}
public static class InventoryRequest {
private final AeStackInventoryImpl<IAEItemStack> crafting;
private final AeStackInventoryImpl<IAEItemStack> batchSize;
private Future<ICraftingJob>[] jobs;
private ICraftingLink[] links;
private final AeStackInventoryImpl<IAEItemStack> requestStacks;
private final AeStackInventoryImpl<IAEItemStack> requestBatches;
private final AeStackInventoryImpl<IAEItemStack> requestQtys;
private final Future<ICraftingJob>[] jobs;
private final ICraftingLink[] links;
public InventoryRequest(TileLevelMaintainer tile) {
this.crafting = new AeStackInventoryImpl<>(StorageChannel.ITEMS, REQ_COUNT, tile);
this.batchSize = new AeStackInventoryImpl<>(StorageChannel.ITEMS, REQ_COUNT, tile);
this.requestStacks = new AeStackInventoryImpl<>(StorageChannel.ITEMS, REQ_COUNT, tile);
this.requestBatches = new AeStackInventoryImpl<>(StorageChannel.ITEMS, REQ_COUNT, tile);
this.requestQtys = new AeStackInventoryImpl<>(StorageChannel.ITEMS, REQ_COUNT, tile);
this.jobs = new Future[REQ_COUNT];
this.links = new ICraftingLink[REQ_COUNT];
}
public boolean isDone(int index) {
if (this.getLinks()[index] != null) {
return this.getLinks()[index].isDone() || this.getLinks()[index].isCanceled();
}
return true;
}
public Future<ICraftingJob>[] getJobs() {
return jobs;
return this.jobs;
}
public ICraftingLink[] getLinks() {
return links;
}
public AeStackInventory<IAEItemStack> getBatchInputs() {
return this.batchSize;
public AeStackInventory<IAEItemStack> getRequestQtys() {
return this.requestQtys;
}
public AeStackInventory<IAEItemStack> getCraftingSlots() {
return this.crafting;
public AeStackInventory<IAEItemStack> getRequestBatches() {
return this.requestBatches;
}
public AeStackInventory<IAEItemStack> getRequestStacks() {
return this.requestStacks;
}
public void updateQuantity(int idx, long size) {
IAEItemStack is = this.crafting.getStack(idx);
IAEItemStack is = this.getRequestStacks().getStack(idx);
if (is != null) {
is.setStackSize(size);
IAEItemStack i = is.copy();
i.setStackSize(size);
this.getRequestQtys().setStack(idx, i);
}
}
public void updateBatchSize(int idx, long size) {
IAEItemStack is = this.crafting.getStack(idx);
IAEItemStack is = this.getRequestStacks().getStack(idx);
if (is != null) {
IAEItemStack i = is.copy();
i.setStackSize(size);
this.batchSize.setStack(idx, i);
this.getRequestBatches().setStack(idx, i);
}
}
public IAEItemStack getQuantity(int idx) {
return this.crafting.getStack(idx);
IAEItemStack is = this.getRequestStacks().getStack(idx);
if (is == null) return null;
IAEItemStack qis = this.getRequestQtys().getStack(idx);
if (qis == null || !is.isSameType(qis)) return null;
return this.getRequestQtys().getStack(idx);
}
public long getBatchSize(int idx) {
IAEItemStack is = this.crafting.getStack(idx);
IAEItemStack is1 = this.batchSize.getStack(idx);
IAEItemStack is = this.getRequestStacks().getStack(idx);
IAEItemStack is1 = this.getRequestBatches().getStack(idx);
if (is != null && is1 != null && is.isSameType(is1)) {
return is1.getStackSize();
}
@@ -238,7 +302,7 @@ public class TileLevelMaintainer extends AENetworkTile implements IAEAppEngInven
}
public IAEItemStack getCraftItem(int idx) {
IAEItemStack is = this.crafting.getStack(idx);
IAEItemStack is = this.getQuantity(idx);
if (is != null) {
IAEItemStack ias = is.copy();
ias.setStackSize(this.getBatchSize(idx));
@@ -35,6 +35,8 @@ public class RecipeLoader implements Runnable {
public final static ItemStack PISTON = new ItemStack(Blocks.piston, 1);
public final static ItemStack AE2_BLANK_PATTERN = new ItemStack(GameRegistry.findItem("appliedenergistics2", "item.ItemMultiMaterial"), 1, 52);
public final static ItemStack AE2_TERMINAL = new ItemStack(GameRegistry.findItem("appliedenergistics2", "item.ItemMultiPart"), 1, 380);
public final static ItemStack AE2_CRAFTING_CP_UNIT = new ItemStack(GameRegistry.findItem("appliedenergistics2", "tile.BlockCraftingUnit"), 1, 1);
public final static ItemStack AE2_PATTERN_CAPACITY_CARD = new ItemStack(GameRegistry.findItem("appliedenergistics2", "item.ItemMultiMaterial"), 1, 54);
public final static ItemStack BUCKET = new ItemStack(Items.bucket, 1);
public final static ItemStack IRON_BAR = new ItemStack(Blocks.iron_bars, 1);
@@ -52,6 +54,7 @@ public class RecipeLoader implements Runnable {
GameRegistry.addRecipe(new ShapedOreRecipe(LARGE_BUFFER.stack(), "BGB", "GEG", "BGB", 'B', BUFFER.stack(), 'G', AE2_QUARTZ_GLASS, 'E', AE2_PROCESS_ENG));
GameRegistry.addShapelessRecipe(AE2_BLANK_PATTERN, PATTERN.stack());
GameRegistry.addShapelessRecipe(FLUID_TERM.stack(), AE2_TERMINAL, BUFFER);
GameRegistry.addShapelessRecipe(LEVEL_MAINTAINER.stack(), AE2_CRAFTING_CP_UNIT, ENCODER, AE2_PATTERN_CAPACITY_CARD);
if (Config.fluidCells) {
OreDictionary.registerOre("anyCertusCrystal", AE2_PURE_CERTUS);
for (ItemStack it : OreDictionary.getOres("crystalCertusQuartz"))
@@ -42,10 +42,10 @@ public class CPacketLevelMaintainer implements IMessage {
this.size = Long.parseLong(size);
}
public static IAEItemStack setTag(IAEItemStack ias, long size, int slotIndex) {
public static IAEItemStack setTag(IAEItemStack ias, long batch, int slotIndex) {
NBTTagCompound data = new NBTTagCompound();
ItemStack is = ias.getItemStack();
data.setLong("BatchSize", size);
data.setLong("Batch", batch);
data.setLong("Index", slotIndex);
is.setTagCompound(data);
IAEItemStack iaeItemStack = AEItemStack.create(is);
@@ -78,8 +78,8 @@ public class CPacketLevelMaintainer implements IMessage {
if (message.action == -1) {
SPacketMEInventoryUpdate piu = new SPacketMEInventoryUpdate(false);
for (int i = 0; i < TileLevelMaintainer.REQ_COUNT; i++) {
IAEItemStack is = cca.getTile().requests.getCraftingSlots().getStack(i);
IAEItemStack is1 = cca.getTile().requests.getBatchInputs().getStack(i);
IAEItemStack is = cca.getTile().requests.getQuantity(i);
IAEItemStack is1 = cca.getTile().requests.getRequestBatches().getStack(i);
if (is != null) {
piu.appendItem(setTag(is, is1 != null ? is1.getStackSize() : 0, i));
}