begin work

This commit is contained in:
GlodBlock committed 2022-05-10 17:57:38 +08:00
commit db2ad29b52
124 files changed
+11799

No files matched your search

@@ -0,0 +1,163 @@
package com.glodblock.github.client.gui;
import appeng.api.config.ActionItems;
import appeng.api.config.ItemSubstitution;
import appeng.api.config.Settings;
import appeng.api.storage.ITerminalHost;
import appeng.client.gui.widgets.GuiImgButton;
import appeng.client.gui.widgets.GuiTabButton;
import appeng.container.slot.AppEngSlot;
import appeng.core.localization.GuiText;
import com.glodblock.github.FluidCraft;
import com.glodblock.github.client.gui.container.FCBasePartContainer;
import com.glodblock.github.network.CPacketFluidPatternTermBtns;
import com.glodblock.github.util.Ae2Reflect;
import com.glodblock.github.util.ModAndClassUtil;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import org.lwjgl.input.Keyboard;
public class GuiBaseFluidPatternTerminal extends GuiFCBaseMonitor {
private static final String SUBSITUTION_DISABLE = "0";
private static final String SUBSITUTION_ENABLE = "1";
private static final String CRAFTMODE_CRFTING = "1";
private static final String CRAFTMODE_PROCESSING = "0";
public final FCBasePartContainer container;
private GuiTabButton tabCraftButton;
private GuiTabButton tabProcessButton;
private GuiImgButton substitutionsEnabledBtn;
private GuiImgButton substitutionsDisabledBtn;
private GuiImgButton encodeBtn;
private GuiImgButton clearBtn;
private GuiImgButton doubleBtn;
public GuiBaseFluidPatternTerminal(final InventoryPlayer inventoryPlayer, final ITerminalHost te )
{
super( inventoryPlayer, te, new FCBasePartContainer( inventoryPlayer, te ) );
this.container = (FCBasePartContainer) this.inventorySlots;
Ae2Reflect.setReservedSpace(this, 81);
}
@Override
protected void actionPerformed( final GuiButton btn )
{
super.actionPerformed( btn );
if( this.tabCraftButton == btn || this.tabProcessButton == btn )
{
FluidCraft.proxy.netHandler.sendToServer( new CPacketFluidPatternTermBtns( "PatternTerminal.CraftMode", this.tabProcessButton == btn ? CRAFTMODE_CRFTING : CRAFTMODE_PROCESSING ) );
}
else if( this.encodeBtn == btn )
{
FluidCraft.proxy.netHandler.sendToServer( new CPacketFluidPatternTermBtns( "PatternTerminal.Encode", isShiftKeyDown() ? "2" : "1" ) );
}
else if( this.clearBtn == btn )
{
FluidCraft.proxy.netHandler.sendToServer( new CPacketFluidPatternTermBtns( "PatternTerminal.Clear", "1" ) );
}
else if( this.substitutionsEnabledBtn == btn || this.substitutionsDisabledBtn == btn )
{
FluidCraft.proxy.netHandler.sendToServer( new CPacketFluidPatternTermBtns( "PatternTerminal.Substitute", this.substitutionsEnabledBtn == btn ? SUBSITUTION_DISABLE : SUBSITUTION_ENABLE ) );
}
else if (ModAndClassUtil.isDoubleButton && doubleBtn == btn)
{
FluidCraft.proxy.netHandler.sendToServer( new CPacketFluidPatternTermBtns( "PatternTerminal.Double", Keyboard.isKeyDown( Keyboard.KEY_LSHIFT ) ? "1": "0") );
}
}
@Override
@SuppressWarnings("unchecked")
public void initGui()
{
super.initGui();
this.tabCraftButton = new GuiTabButton( this.guiLeft + 173, this.guiTop + this.ySize - 177, new ItemStack( Blocks.crafting_table ), GuiText.CraftingPattern.getLocal(), itemRender );
this.buttonList.add( this.tabCraftButton );
this.tabProcessButton = new GuiTabButton( this.guiLeft + 173, this.guiTop + this.ySize - 177, new ItemStack( Blocks.furnace ), GuiText.ProcessingPattern.getLocal(), itemRender );
this.buttonList.add( this.tabProcessButton );
this.substitutionsEnabledBtn = new GuiImgButton( this.guiLeft + 84, this.guiTop + this.ySize - 163, Settings.ACTIONS, ItemSubstitution.ENABLED );
this.substitutionsEnabledBtn.setHalfSize( true );
this.buttonList.add( this.substitutionsEnabledBtn );
this.substitutionsDisabledBtn = new GuiImgButton( this.guiLeft + 84, this.guiTop + this.ySize - 163, Settings.ACTIONS, ItemSubstitution.DISABLED );
this.substitutionsDisabledBtn.setHalfSize( true );
this.buttonList.add( this.substitutionsDisabledBtn );
this.clearBtn = new GuiImgButton( this.guiLeft + 74, this.guiTop + this.ySize - 163, Settings.ACTIONS, ActionItems.CLOSE );
this.clearBtn.setHalfSize( true );
this.buttonList.add( this.clearBtn );
this.encodeBtn = new GuiImgButton( this.guiLeft + 147, this.guiTop + this.ySize - 142, Settings.ACTIONS, ActionItems.ENCODE );
this.buttonList.add( this.encodeBtn );
if (ModAndClassUtil.isDoubleButton) {
this.doubleBtn = new GuiImgButton( this.guiLeft + 74, this.guiTop + this.ySize - 153, Settings.ACTIONS, ActionItems.DOUBLE );
this.doubleBtn.setHalfSize( true );
this.buttonList.add( this.doubleBtn );
}
}
@Override
public void drawFG( final int offsetX, final int offsetY, final int mouseX, final int mouseY )
{
if( !this.container.isCraftingMode() )
{
this.tabCraftButton.visible = false;
this.tabProcessButton.visible = true;
if (ModAndClassUtil.isDoubleButton)
this.doubleBtn.visible = true;
}
else
{
this.tabCraftButton.visible = true;
this.tabProcessButton.visible = false;
if (ModAndClassUtil.isDoubleButton)
this.doubleBtn.visible = false;
}
if( this.container.substitute )
{
this.substitutionsEnabledBtn.visible = true;
this.substitutionsDisabledBtn.visible = false;
}
else
{
this.substitutionsEnabledBtn.visible = false;
this.substitutionsDisabledBtn.visible = true;
}
super.drawFG( offsetX, offsetY, mouseX, mouseY );
this.fontRendererObj.drawString( GuiText.PatternTerminal.getLocal(), 8, this.ySize - 96 + 2 - Ae2Reflect.getReservedSpace(this), 4210752 );
}
@Override
protected String getBackground()
{
if( this.container.isCraftingMode() )
{
return "guis/pattern.png";
}
return "guis/pattern2.png";
}
@Override
protected void repositionSlot( final AppEngSlot s )
{
if( s.isPlayerSide() )
{
s.yDisplayPosition = s.getY() + this.ySize - 78 - 5;
}
else
{
s.yDisplayPosition = s.getY() + this.ySize - 78 - 3;
}
}
}
@@ -0,0 +1,750 @@
package com.glodblock.github.client.gui;
import appeng.api.config.*;
import appeng.api.implementations.tiles.IViewCellStorage;
import appeng.api.storage.ITerminalHost;
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.*;
import appeng.client.me.InternalSlotME;
import appeng.client.me.ItemRepo;
import appeng.client.me.SlotDisconnected;
import appeng.client.me.SlotME;
import appeng.container.AEBaseContainer;
import appeng.container.slot.*;
import appeng.core.AEConfig;
import appeng.core.AELog;
import appeng.core.localization.ButtonToolTips;
import appeng.core.localization.GuiText;
import appeng.core.sync.GuiBridge;
import appeng.core.sync.network.NetworkHandler;
import appeng.core.sync.packets.PacketInventoryAction;
import appeng.core.sync.packets.PacketSwitchGuis;
import appeng.core.sync.packets.PacketValueConfig;
import appeng.helpers.InventoryAction;
import appeng.integration.IntegrationRegistry;
import appeng.integration.IntegrationType;
import appeng.util.IConfigManagerHost;
import appeng.util.Platform;
import com.glodblock.github.FluidCraft;
import com.glodblock.github.client.gui.container.FCBaseMonitorContain;
import com.glodblock.github.client.gui.container.FCBasePartContainer;
import com.glodblock.github.common.parts.PartFluidPatternTerminal;
import com.glodblock.github.network.CPacketInventoryAction;
import com.glodblock.github.network.CPacketSetTargetItem;
import com.glodblock.github.util.Ae2Reflect;
import com.glodblock.github.util.NameConst;
import com.google.common.base.Stopwatch;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import org.lwjgl.input.Keyboard;
import org.lwjgl.input.Mouse;
import java.io.IOException;
import java.util.List;
import java.util.concurrent.TimeUnit;
public class GuiFCBaseMonitor extends AEBaseMEGui implements ISortSource, IConfigManagerHost
{
public static int craftingGridOffsetX;
public static int craftingGridOffsetY;
private static String memoryText = "";
private final ItemRepo repo;
private final int offsetX = 9;
private final int lowerTextureOffset = 0;
private final IConfigManager configSrc;
private final boolean viewCell;
private final ItemStack[] myCurrentViewCells = new ItemStack[5];
private final FCBaseMonitorContain monitorableContainer;
private GuiTabButton craftingStatusBtn;
private GuiImgButton craftingStatusImgBtn;
private MEGuiTextField searchField;
private String myName;
private int perRow = 9;
private int reservedSpace = 0;
private boolean customSortOrder = true;
private int rows = 0;
private int maxRows = Integer.MAX_VALUE;
private int standardSize;
private GuiImgButton ViewBox;
private GuiImgButton SortByBox;
private GuiImgButton SortDirBox;
private GuiImgButton searchBoxSettings;
private GuiImgButton terminalStyleBox;
private GuiImgButton searchStringSave;
public GuiFCBaseMonitor(final InventoryPlayer inventoryPlayer, final ITerminalHost te )
{
this( inventoryPlayer, te, new FCBasePartContainer( inventoryPlayer, te ) );
}
public GuiFCBaseMonitor( final InventoryPlayer inventoryPlayer, final ITerminalHost te, final FCBasePartContainer c )
{
super( c );
final GuiScrollbar scrollbar = new GuiScrollbar();
this.setScrollBar( scrollbar );
this.repo = new ItemRepo( scrollbar, this );
this.xSize = 185;
this.ySize = 204;
if( te instanceof IViewCellStorage)
{
this.xSize += 33;
}
this.standardSize = this.xSize;
this.configSrc = ( (IConfigurableObject) this.inventorySlots ).getConfigManager();
( this.monitorableContainer = (FCBaseMonitorContain) this.inventorySlots ).setGui( this );
this.viewCell = te instanceof IViewCellStorage;
if( te instanceof PartFluidPatternTerminal)
{
this.myName = NameConst.GUI_FLUID_PATTERN_TERMINAL;
}
}
public void postUpdate( final List<IAEItemStack> list )
{
for( final IAEItemStack is : list )
{
this.repo.postUpdate( is );
}
this.repo.updateView();
this.setScrollBar();
}
private void setScrollBar()
{
this.getScrollBar().setTop( 18 ).setLeft( 175 ).setHeight( this.rows * 18 - 2 );
this.getScrollBar().setRange( 0, ( this.repo.size() + this.perRow - 1 ) / this.perRow - this.rows, Math.max( 1, this.rows / 6 ) );
}
@Override
protected void actionPerformed( final GuiButton btn )
{
if( btn == this.craftingStatusBtn || btn == this.craftingStatusImgBtn )
{
NetworkHandler.instance.sendToServer( new PacketSwitchGuis( GuiBridge.GUI_CRAFTING_STATUS ) );
}
if( btn instanceof GuiImgButton )
{
final boolean backwards = Mouse.isButtonDown( 1 );
final GuiImgButton iBtn = (GuiImgButton) btn;
if( iBtn.getSetting() != Settings.ACTIONS )
{
final Enum cv = iBtn.getCurrentValue();
final Enum next = Platform.rotateEnum( cv, backwards, iBtn.getSetting().getPossibleValues() );
if( btn == this.terminalStyleBox )
{
AEConfig.instance.settings.putSetting( iBtn.getSetting(), next );
}
else if( btn == this.searchBoxSettings )
{
AEConfig.instance.settings.putSetting( iBtn.getSetting(), next );
}
else if( btn == this.searchStringSave )
{
AEConfig.instance.preserveSearchBar = next == YesNo.YES;
}
else
{
try
{
NetworkHandler.instance.sendToServer( new PacketValueConfig( iBtn.getSetting().name(), next.name() ) );
}
catch( final IOException e )
{
AELog.debug( e );
}
}
iBtn.set( next );
if( next.getClass() == SearchBoxMode.class || next.getClass() == TerminalStyle.class )
{
this.reinitalize();
}
}
}
}
private void reinitalize()
{
this.buttonList.clear();
this.initGui();
}
@Override
public void initGui()
{
Keyboard.enableRepeatEvents( true );
this.maxRows = this.getMaxRows();
this.perRow = AEConfig.instance.getConfigManager().getSetting( Settings.TERMINAL_STYLE ) != TerminalStyle.FULL ? 9 : 9 + ( ( this.width - this.standardSize ) / 18 );
final boolean hasNEI = IntegrationRegistry.INSTANCE.isEnabled( IntegrationType.NEI );
final int NEI = hasNEI ? 0 : 0;
int top = hasNEI ? 22 : 0;
final int magicNumber = 114 + 1;
final int extraSpace = this.height - magicNumber - NEI - top - this.reservedSpace;
this.rows = (int) Math.floor( extraSpace / 18 );
if( this.rows > this.maxRows )
{
top += ( this.rows - this.maxRows ) * 18 / 2;
this.rows = this.maxRows;
}
if( hasNEI )
{
this.rows--;
}
if( this.rows < 3 )
{
this.rows = 3;
}
this.getMeSlots().clear();
for( int y = 0; y < this.rows; y++ )
{
for( int x = 0; x < this.perRow; x++ )
{
this.getMeSlots().add( new InternalSlotME( this.repo, x + y * this.perRow, this.offsetX + x * 18, 18 + y * 18 ) );
}
}
if( AEConfig.instance.getConfigManager().getSetting( Settings.TERMINAL_STYLE ) != TerminalStyle.FULL )
{
this.xSize = this.standardSize + ( ( this.perRow - 9 ) * 18 );
}
else
{
this.xSize = this.standardSize;
}
super.initGui();
// full size : 204
// extra slots : 72
// slot 18
this.ySize = magicNumber + this.rows * 18 + this.reservedSpace;
// this.guiTop = top;
final int unusedSpace = this.height - this.ySize;
this.guiTop = (int) Math.floor( unusedSpace / ( unusedSpace < 0 ? 3.8f : 2.0f ) );
int offset = this.guiTop + 8;
if( this.customSortOrder )
{
this.buttonList.add( this.SortByBox = new GuiImgButton( this.guiLeft - 18, offset, Settings.SORT_BY, this.configSrc.getSetting( Settings.SORT_BY ) ) );
offset += 20;
}
this.buttonList.add( this.ViewBox = new GuiImgButton( this.guiLeft - 18, offset, Settings.VIEW_MODE, this.configSrc.getSetting( Settings.VIEW_MODE ) ) );
offset += 20;
this.buttonList.add( this.SortDirBox = new GuiImgButton( this.guiLeft - 18, offset, Settings.SORT_DIRECTION, this.configSrc.getSetting( Settings.SORT_DIRECTION ) ) );
offset += 20;
this.buttonList.add( this.searchBoxSettings = new GuiImgButton( this.guiLeft - 18, offset, Settings.SEARCH_MODE, AEConfig.instance.settings.getSetting( Settings.SEARCH_MODE ) ) );
offset += 20;
this.buttonList.add( this.searchStringSave = new GuiImgButton( this.guiLeft - 18, offset, Settings.SAVE_SEARCH, AEConfig.instance.preserveSearchBar ? YesNo.YES : YesNo.NO ) );
offset += 20;
this.buttonList.add( this.terminalStyleBox = new GuiImgButton( this.guiLeft - 18, offset, Settings.TERMINAL_STYLE, AEConfig.instance.settings.getSetting( Settings.TERMINAL_STYLE ) ) );
offset += 20;
this.searchField = new MEGuiTextField( this.fontRendererObj, this.guiLeft + Math.max( 80, this.offsetX ), this.guiTop + 4, 90, 12 );
this.searchField.setEnableBackgroundDrawing( false );
this.searchField.setMaxStringLength( 25 );
this.searchField.setTextColor( 0xFFFFFF );
this.searchField.setVisible( true );
searchField.setMessage(ButtonToolTips.SearchStringTooltip.getLocal());
if( this.viewCell)
{
if (AEConfig.instance.getConfigManager().getSetting(Settings.CRAFTING_STATUS).equals(CraftingStatus.BUTTON)) {
this.buttonList.add(this.craftingStatusImgBtn = new GuiImgButton(this.guiLeft - 18, offset, Settings.CRAFTING_STATUS, AEConfig.instance.settings.getSetting(Settings.CRAFTING_STATUS)));
} else {
this.buttonList.add(this.craftingStatusBtn = new GuiTabButton(this.guiLeft + 170, this.guiTop - 4, 2 + 11 * 16, GuiText.CraftingStatus.getLocal(), itemRender));
this.craftingStatusBtn.setHideEdge( 13 ); // GuiTabButton implementation //
}
}
// Enum setting = AEConfig.INSTANCE.getSetting( "Terminal", SearchBoxMode.class, SearchBoxMode.AUTOSEARCH );
final Enum setting = AEConfig.instance.settings.getSetting( Settings.SEARCH_MODE );
this.searchField.setFocused( SearchBoxMode.AUTOSEARCH == setting || SearchBoxMode.NEI_AUTOSEARCH == setting );
if (AEConfig.instance.preserveSearchBar || this.isSubGui())
{
setSearchString(memoryText, false);
}
if( this.isSubGui() )
{
this.repo.updateView();
this.setScrollBar();
}
craftingGridOffsetX = Integer.MAX_VALUE;
craftingGridOffsetY = Integer.MAX_VALUE;
for( final Object s : this.inventorySlots.inventorySlots )
{
if( s instanceof AppEngSlot)
{
if( ( (Slot) s ).xDisplayPosition < 197 )
{
this.repositionSlot( (AppEngSlot) s );
}
}
if( s instanceof SlotCraftingMatrix || s instanceof SlotFakeCraftingMatrix)
{
final Slot g = (Slot) s;
if( g.xDisplayPosition > 0 && g.yDisplayPosition > 0 )
{
craftingGridOffsetX = Math.min( craftingGridOffsetX, g.xDisplayPosition );
craftingGridOffsetY = Math.min( craftingGridOffsetY, g.yDisplayPosition );
}
}
}
craftingGridOffsetX -= 25;
craftingGridOffsetY -= 6;
}
public void setSearchString(String memoryText, boolean updateView)
{
this.searchField.setText(memoryText);
this.repo.setSearchString(memoryText);
if (updateView)
{
this.repo.updateView();
this.setScrollBar();
}
}
@Override
public void drawFG( final int offsetX, final int offsetY, final int mouseX, final int mouseY )
{
this.fontRendererObj.drawString( this.getGuiDisplayName( GuiText.Terminal.getLocal() ), 8, 6, 4210752 );
this.fontRendererObj.drawString( GuiText.inventory.getLocal(), 8, this.ySize - 96 + 3, 4210752 );
}
@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);
}
super.mouseClicked( xCoord, yCoord, btn );
}
@Override
protected void handleMouseClick( final Slot slot, final int slotIdx, final int ctrlDown, final int mouseButton )
{
final EntityPlayer player = Minecraft.getMinecraft().thePlayer;
if( slot instanceof SlotFake)
{
final InventoryAction action = ctrlDown == 1 ? InventoryAction.SPLIT_OR_PLACE_SINGLE : InventoryAction.PICKUP_OR_SET_DOWN;
if( Ae2Reflect.getDragClick(this).size() > 1 )
{
return;
}
final PacketInventoryAction p = new PacketInventoryAction( action, slotIdx, 0 );
NetworkHandler.instance.sendToServer( p );
return;
}
if( slot instanceof SlotPatternTerm)
{
if( mouseButton == 6 )
{
return; // prevent weird double clicks..
}
try
{
NetworkHandler.instance.sendToServer( ( (SlotPatternTerm) slot ).getRequest( isShiftKeyDown() ) );
}
catch( final IOException e )
{
AELog.debug( e );
}
}
else if( slot instanceof SlotCraftingTerm )
{
if( mouseButton == 6 )
{
return; // prevent weird double clicks..
}
InventoryAction action = null;
if( isShiftKeyDown() )
{
action = InventoryAction.CRAFT_SHIFT;
}
else
{
// Craft stack on right-click, craft single on left-click
action = ( mouseButton == 1 ) ? InventoryAction.CRAFT_STACK : InventoryAction.CRAFT_ITEM;
}
final PacketInventoryAction p = new PacketInventoryAction( action, slotIdx, 0 );
NetworkHandler.instance.sendToServer( p );
return;
}
if( Keyboard.isKeyDown( Keyboard.KEY_SPACE ) )
{
if( this.enableSpaceClicking() && !( slot instanceof SlotPatternTerm ) )
{
IAEItemStack stack = null;
if( slot instanceof SlotME )
{
stack = ( (SlotME) slot ).getAEStack();
}
int slotNum = Ae2Reflect.getInventorySlots(this).size();
if( !( slot instanceof SlotME ) && slot != null )
{
slotNum = slot.slotNumber;
}
( (AEBaseContainer) this.inventorySlots ).setTargetStack( stack );
final PacketInventoryAction p = new PacketInventoryAction( InventoryAction.MOVE_REGION, slotNum, 0 );
NetworkHandler.instance.sendToServer( p );
return;
}
}
if( slot instanceof SlotDisconnected)
{
if( Ae2Reflect.getDragClick(this).size() > 1 )
{
return;
}
InventoryAction action = null;
switch( mouseButton )
{
case 0: // pickup / set-down.
{
ItemStack heldStack = player.inventory.getItemStack();
if (slot.getStack() == null && heldStack != null)
action = InventoryAction.SPLIT_OR_PLACE_SINGLE;
else if (slot.getStack() != null && (heldStack == null || heldStack.stackSize <= 1))
action = InventoryAction.PICKUP_OR_SET_DOWN;
}
break;
case 1:
action = ctrlDown == 1 ? InventoryAction.PICKUP_SINGLE : InventoryAction.SHIFT_CLICK;
break;
case 3: // creative dupe:
if( player.capabilities.isCreativeMode )
{
action = InventoryAction.CREATIVE_DUPLICATE;
}
break;
default:
case 4: // drop item:
case 6:
}
if( action != null )
{
final PacketInventoryAction p = new PacketInventoryAction( action, slot.getSlotIndex(), ( (SlotDisconnected) slot ).getSlot().getId() );
NetworkHandler.instance.sendToServer( p );
}
return;
}
if( slot instanceof SlotME )
{
InventoryAction action = null;
IAEItemStack stack = null;
switch( mouseButton )
{
case 0: // pickup / set-down.
action = ctrlDown == 1 ? InventoryAction.SPLIT_OR_PLACE_SINGLE : InventoryAction.PICKUP_OR_SET_DOWN;
stack = ( (SlotME) slot ).getAEStack();
if( stack != null && action == InventoryAction.PICKUP_OR_SET_DOWN && stack.getStackSize() == 0 && player.inventory.getItemStack() == null )
{
action = InventoryAction.AUTO_CRAFT;
}
break;
case 1:
action = ctrlDown == 1 ? InventoryAction.PICKUP_SINGLE : InventoryAction.SHIFT_CLICK;
stack = ( (SlotME) slot ).getAEStack();
break;
case 3: // creative dupe:
stack = ( (SlotME) slot ).getAEStack();
if( stack != null && stack.isCraftable() )
{
action = InventoryAction.AUTO_CRAFT;
}
else if( player.capabilities.isCreativeMode )
{
final IAEItemStack slotItem = ( (SlotME) slot ).getAEStack();
if( slotItem != null )
{
action = InventoryAction.CREATIVE_DUPLICATE;
}
}
break;
default:
case 4: // drop item:
case 6:
}
if (action == InventoryAction.AUTO_CRAFT) {
((AEBaseContainer) this.inventorySlots).setTargetStack( stack );
FluidCraft.proxy.netHandler.sendToServer(new CPacketInventoryAction(action, Ae2Reflect.getInventorySlots(this).size(), 0, stack));
}
else if( action != null )
{
( (AEBaseContainer) this.inventorySlots ).setTargetStack( stack );
final PacketInventoryAction p = new PacketInventoryAction( action, Ae2Reflect.getInventorySlots(this).size(), 0 );
NetworkHandler.instance.sendToServer( p );
}
return;
}
super.handleMouseClick( slot, slotIdx, ctrlDown, mouseButton );
}
@Override
public void onGuiClosed()
{
super.onGuiClosed();
Keyboard.enableRepeatEvents( false );
memoryText = this.searchField.getText();
}
@Override
public void drawBG( final int offsetX, final int offsetY, final int mouseX, final int mouseY )
{
this.bindTexture( this.getBackground() );
final int x_width = 197;
this.drawTexturedModalRect( offsetX, offsetY, 0, 0, x_width, 18 );
if( this.viewCell )
{
this.drawTexturedModalRect( offsetX + x_width, offsetY, x_width, 0, 46, 128 );
}
for( int x = 0; x < this.rows; x++ )
{
this.drawTexturedModalRect( offsetX, offsetY + 18 + x * 18, 0, 18, x_width, 18 );
}
this.drawTexturedModalRect( offsetX, offsetY + 16 + this.rows * 18 + this.lowerTextureOffset, 0, 106 - 18 - 18, x_width, 99 + this.reservedSpace - this.lowerTextureOffset );
if( this.viewCell )
{
boolean update = false;
for( int i = 0; i < 5; i++ )
{
if( this.myCurrentViewCells[i] != this.monitorableContainer.getCellViewSlot( i ).getStack() )
{
update = true;
this.myCurrentViewCells[i] = this.monitorableContainer.getCellViewSlot( i ).getStack();
}
}
if( update )
{
this.repo.setViewCell( this.myCurrentViewCells );
}
}
if( this.searchField != null )
{
this.searchField.drawTextBox();
}
}
protected String getBackground()
{
return "guis/terminal.png";
}
@Override
protected boolean isPowered()
{
return this.repo.hasPower();
}
int getMaxRows()
{
return AEConfig.instance.getConfigManager().getSetting( Settings.TERMINAL_STYLE ) == TerminalStyle.SMALL ? 6 : Integer.MAX_VALUE;
}
protected void repositionSlot( final AppEngSlot s )
{
s.yDisplayPosition = s.getY() + this.ySize - 78 - 5;
}
@Override
protected void keyTyped( final char character, final int key )
{
if( !this.checkHotbarKeys( key ) )
{
if( character == ' ' && this.searchField.getText().isEmpty() )
{
return;
}
if( this.searchField.textboxKeyTyped( character, key ) )
{
this.repo.setSearchString( this.searchField.getText() );
this.repo.updateView();
this.setScrollBar();
}
else
{
super.keyTyped( character, key );
}
}
}
@Override
public void updateScreen()
{
this.repo.setPower( this.monitorableContainer.isPowered() );
super.updateScreen();
}
@Override
public Enum getSortBy()
{
return this.configSrc.getSetting( Settings.SORT_BY );
}
@Override
public Enum getSortDir()
{
return this.configSrc.getSetting( Settings.SORT_DIRECTION );
}
@Override
public Enum getSortDisplay()
{
return this.configSrc.getSetting( Settings.VIEW_MODE );
}
@Override
public void updateSetting( final IConfigManager manager, final Enum settingName, final Enum newValue )
{
if( this.SortByBox != null )
{
this.SortByBox.set( this.configSrc.getSetting( Settings.SORT_BY ) );
}
if( this.SortDirBox != null )
{
this.SortDirBox.set( this.configSrc.getSetting( Settings.SORT_DIRECTION ) );
}
if( this.ViewBox != null )
{
this.ViewBox.set( this.configSrc.getSetting( Settings.VIEW_MODE ) );
}
this.repo.updateView();
}
int getReservedSpace()
{
return this.reservedSpace;
}
void setReservedSpace( final int reservedSpace )
{
this.reservedSpace = reservedSpace;
}
public boolean isCustomSortOrder()
{
return this.customSortOrder;
}
void setCustomSortOrder( final boolean customSortOrder )
{
this.customSortOrder = customSortOrder;
}
public int getStandardSize()
{
return this.standardSize;
}
void setStandardSize( final int standardSize )
{
this.standardSize = standardSize;
}
@Override
public void drawScreen( final int mouseX, final int mouseY, final float btn ) {
super.drawScreen(mouseX, mouseY, btn);
if (AEConfig.instance.preserveSearchBar && searchField != null)
handleTooltip(mouseX, mouseY, searchField.new TooltipProvider());
}
public boolean isOverSearchField(int x, int y)
{
return searchField.isMouseIn(x,y);
}
}
@@ -0,0 +1,257 @@
package com.glodblock.github.client.gui;
import appeng.api.AEApi;
import appeng.api.definitions.IDefinitions;
import appeng.api.definitions.IParts;
import appeng.api.storage.ITerminalHost;
import appeng.client.gui.AEBaseGui;
import appeng.client.gui.widgets.GuiNumberBox;
import appeng.client.gui.widgets.GuiTabButton;
import appeng.container.AEBaseContainer;
import appeng.container.implementations.ContainerCraftAmount;
import appeng.core.AEConfig;
import appeng.core.localization.GuiText;
import appeng.helpers.Reflected;
import com.glodblock.github.FluidCraft;
import com.glodblock.github.common.parts.PartFluidPatternTerminal;
import com.glodblock.github.inventory.gui.GuiType;
import com.glodblock.github.loader.ItemAndBlockHolder;
import com.glodblock.github.network.CPacketCraftRequest;
import com.glodblock.github.network.CPacketSwitchGuis;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.item.ItemStack;
public class GuiFluidCraftAmount extends AEBaseGui
{
private GuiNumberBox amountToCraft;
private GuiTabButton originalGuiBtn;
private GuiButton next;
private GuiButton plus1;
private GuiButton plus10;
private GuiButton plus100;
private GuiButton plus1000;
private GuiButton minus1;
private GuiButton minus10;
private GuiButton minus100;
private GuiButton minus1000;
private GuiType originalGui;
@Reflected
public GuiFluidCraftAmount(final InventoryPlayer inventoryPlayer, final ITerminalHost te )
{
super( new ContainerCraftAmount( inventoryPlayer, te ) );
}
@Override
public void initGui()
{
super.initGui();
final int a = AEConfig.instance.craftItemsByStackAmounts( 0 );
final int b = AEConfig.instance.craftItemsByStackAmounts( 1 );
final int c = AEConfig.instance.craftItemsByStackAmounts( 2 );
final int d = AEConfig.instance.craftItemsByStackAmounts( 3 );
this.buttonList.add( this.plus1 = new GuiButton( 0, this.guiLeft + 20, this.guiTop + 26, 22, 20, "+" + a ) );
this.buttonList.add( this.plus10 = new GuiButton( 0, this.guiLeft + 48, this.guiTop + 26, 28, 20, "+" + b ) );
this.buttonList.add( this.plus100 = new GuiButton( 0, this.guiLeft + 82, this.guiTop + 26, 32, 20, "+" + c ) );
this.buttonList.add( this.plus1000 = new GuiButton( 0, this.guiLeft + 120, this.guiTop + 26, 38, 20, "+" + d ) );
this.buttonList.add( this.minus1 = new GuiButton( 0, this.guiLeft + 20, this.guiTop + 75, 22, 20, "-" + a ) );
this.buttonList.add( this.minus10 = new GuiButton( 0, this.guiLeft + 48, this.guiTop + 75, 28, 20, "-" + b ) );
this.buttonList.add( this.minus100 = new GuiButton( 0, this.guiLeft + 82, this.guiTop + 75, 32, 20, "-" + c ) );
this.buttonList.add( this.minus1000 = new GuiButton( 0, this.guiLeft + 120, this.guiTop + 75, 38, 20, "-" + d ) );
this.buttonList.add( this.next = new GuiButton( 0, this.guiLeft + 128, this.guiTop + 51, 38, 20, GuiText.Next.getLocal() ) );
ItemStack myIcon = null;
final Object target = ( (AEBaseContainer) this.inventorySlots ).getTarget();
final IDefinitions definitions = AEApi.instance().definitions();
final IParts parts = definitions.parts();
if( target instanceof PartFluidPatternTerminal)
{
myIcon = new ItemStack(ItemAndBlockHolder.FLUID_TERMINAL, 1);
this.originalGui = GuiType.FLUID_PATTERN_TERMINAL;
}
if( this.originalGui != null && myIcon != null )
{
this.buttonList.add( this.originalGuiBtn = new GuiTabButton( this.guiLeft + 154, this.guiTop, myIcon, myIcon.getDisplayName(), itemRender ) );
}
this.amountToCraft = new GuiNumberBox( this.fontRendererObj, this.guiLeft + 62, this.guiTop + 57, 59, this.fontRendererObj.FONT_HEIGHT, Integer.class );
this.amountToCraft.setEnableBackgroundDrawing( false );
this.amountToCraft.setMaxStringLength( 16 );
this.amountToCraft.setTextColor( 0xFFFFFF );
this.amountToCraft.setVisible( true );
this.amountToCraft.setFocused( true );
this.amountToCraft.setText( "1" );
this.amountToCraft.setSelectionPos(0);
}
@Override
public void drawFG( final int offsetX, final int offsetY, final int mouseX, final int mouseY )
{
this.fontRendererObj.drawString( GuiText.SelectAmount.getLocal(), 8, 6, 4210752 );
}
@Override
public void drawBG( final int offsetX, final int offsetY, final int mouseX, final int mouseY )
{
this.next.displayString = isShiftKeyDown() ? GuiText.Start.getLocal() : GuiText.Next.getLocal();
this.bindTexture( "guis/craftAmt.png" );
this.drawTexturedModalRect( offsetX, offsetY, 0, 0, this.xSize, this.ySize );
try
{
Long.parseLong( this.amountToCraft.getText() );
this.next.enabled = this.amountToCraft.getText().length() > 0;
}
catch( final NumberFormatException e )
{
this.next.enabled = false;
}
this.amountToCraft.drawTextBox();
}
@Override
protected void keyTyped( final char character, final int key )
{
if( !this.checkHotbarKeys( key ) )
{
if( key == 28 )
{
this.actionPerformed( this.next );
}
if( ( key == 211 || key == 205 || key == 203 || key == 14 || character == '-' || Character.isDigit( character ) ) && this.amountToCraft.textboxKeyTyped( character, key ) )
{
try
{
String out = this.amountToCraft.getText();
boolean fixed = false;
while( out.startsWith( "0" ) && out.length() > 1 )
{
out = out.substring( 1 );
fixed = true;
}
if( fixed )
{
this.amountToCraft.setText( out );
}
if( out.isEmpty() )
{
out = "0";
}
final long result = Long.parseLong( out );
if( result < 0 )
{
this.amountToCraft.setText( "1" );
}
}
catch( final NumberFormatException e )
{
// :P
}
}
else
{
super.keyTyped( character, key );
}
}
}
@Override
protected void actionPerformed( final GuiButton btn )
{
super.actionPerformed( btn );
try
{
if( btn == this.originalGuiBtn )
{
FluidCraft.proxy.netHandler.sendToServer( new CPacketSwitchGuis( this.originalGui ) );
}
if( btn == this.next )
{
FluidCraft.proxy.netHandler.sendToServer( new CPacketCraftRequest( Integer.parseInt( this.amountToCraft.getText() ), isShiftKeyDown() ) );
}
}
catch( final NumberFormatException e )
{
// nope..
this.amountToCraft.setText( "1" );
}
final boolean isPlus = btn == this.plus1 || btn == this.plus10 || btn == this.plus100 || btn == this.plus1000;
final boolean isMinus = btn == this.minus1 || btn == this.minus10 || btn == this.minus100 || btn == this.minus1000;
if( isPlus || isMinus )
{
this.addQty( this.getQty( btn ) );
}
}
private void addQty( final int i )
{
try
{
String out = this.amountToCraft.getText();
boolean fixed = false;
while( out.startsWith( "0" ) && out.length() > 1 )
{
out = out.substring( 1 );
fixed = true;
}
if( fixed )
{
this.amountToCraft.setText( out );
}
if( out.isEmpty() )
{
out = "0";
}
long result = Integer.parseInt( out );
if( result == 1 && i > 1 )
{
result = 0;
}
result += i;
if( result < 1 )
{
result = 1;
}
out = Long.toString( result );
Integer.parseInt( out );
this.amountToCraft.setText( out );
}
catch( final NumberFormatException e )
{
// :P
}
}
protected String getBackground()
{
return "guis/craftAmt.png";
}
}
@@ -0,0 +1,531 @@
package com.glodblock.github.client.gui;
import appeng.api.AEApi;
import appeng.api.storage.ITerminalHost;
import appeng.api.storage.data.IAEItemStack;
import appeng.api.storage.data.IItemList;
import appeng.client.gui.AEBaseGui;
import appeng.client.gui.widgets.GuiScrollbar;
import appeng.core.AELog;
import appeng.core.localization.GuiText;
import appeng.util.Platform;
import com.glodblock.github.FluidCraft;
import com.glodblock.github.client.gui.container.ContainerFluidCraftConfirm;
import com.glodblock.github.common.parts.PartFluidPatternTerminal;
import com.glodblock.github.inventory.gui.GuiType;
import com.glodblock.github.network.CPacketFluidPatternTermBtns;
import com.glodblock.github.network.CPacketSwitchGuis;
import com.google.common.base.Joiner;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.item.ItemStack;
import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.GL11;
import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
public class GuiFluidCraftConfirm extends AEBaseGui {
private final ContainerFluidCraftConfirm ccc;
private final int rows = 5;
private final IItemList<IAEItemStack> storage = AEApi.instance().storage().createItemList();
private final IItemList<IAEItemStack> pending = AEApi.instance().storage().createItemList();
private final IItemList<IAEItemStack> missing = AEApi.instance().storage().createItemList();
private final List<IAEItemStack> visual = new ArrayList<IAEItemStack>();
private GuiType OriginalGui;
private GuiButton cancel;
private GuiButton start;
private GuiButton selectCPU;
private int tooltip = -1;
public GuiFluidCraftConfirm(final InventoryPlayer inventoryPlayer, final ITerminalHost te )
{
super( new ContainerFluidCraftConfirm( inventoryPlayer, te ) );
this.xSize = 238;
this.ySize = 206;
final GuiScrollbar scrollbar = new GuiScrollbar();
this.setScrollBar( scrollbar );
this.ccc = (ContainerFluidCraftConfirm) this.inventorySlots;
if( te instanceof PartFluidPatternTerminal)
{
this.OriginalGui = GuiType.FLUID_PATTERN_TERMINAL;
}
}
boolean isAutoStart()
{
return ( (ContainerFluidCraftConfirm) this.inventorySlots ).isAutoStart();
}
@Override
public void initGui()
{
super.initGui();
this.start = new GuiButton( 0, this.guiLeft + 162, this.guiTop + this.ySize - 25, 50, 20, GuiText.Start.getLocal() );
this.start.enabled = false;
this.buttonList.add( this.start );
this.selectCPU = new GuiButton( 0, this.guiLeft + ( 219 - 180 ) / 2, this.guiTop + this.ySize - 68, 180, 20, GuiText.CraftingCPU.getLocal() + ": " + GuiText.Automatic );
this.selectCPU.enabled = false;
this.buttonList.add( this.selectCPU );
if( this.OriginalGui != null )
{
this.cancel = new GuiButton( 0, this.guiLeft + 6, this.guiTop + this.ySize - 25, 50, 20, GuiText.Cancel.getLocal() );
}
this.buttonList.add( this.cancel );
}
@Override
public void drawScreen( final int mouseX, final int mouseY, final float btn )
{
this.updateCPUButtonText();
this.start.enabled = !( this.ccc.hasNoCPU() || this.isSimulation() );
this.selectCPU.enabled = !this.isSimulation();
final int gx = ( this.width - this.xSize ) / 2;
final int gy = ( this.height - this.ySize ) / 2;
this.tooltip = -1;
final int offY = 23;
int y = 0;
int x = 0;
for( int z = 0; z <= 4 * 5; z++ )
{
final int minX = gx + 9 + x * 67;
final int minY = gy + 22 + y * offY;
if( minX < mouseX && minX + 67 > mouseX )
{
if( minY < mouseY && minY + offY - 2 > mouseY )
{
this.tooltip = z;
break;
}
}
x++;
if( x > 2 )
{
y++;
x = 0;
}
}
super.drawScreen( mouseX, mouseY, btn );
}
private void updateCPUButtonText()
{
String btnTextText = GuiText.CraftingCPU.getLocal() + ": " + GuiText.Automatic.getLocal();
if( this.ccc.getSelectedCpu() >= 0 )// && status.selectedCpu < status.cpus.size() )
{
if( this.ccc.getName().length() > 0 )
{
final String name = this.ccc.getName().substring( 0, Math.min( 20, this.ccc.getName().length() ) );
btnTextText = GuiText.CraftingCPU.getLocal() + ": " + name;
}
else
{
btnTextText = GuiText.CraftingCPU.getLocal() + ": #" + this.ccc.getSelectedCpu();
}
}
if( this.ccc.hasNoCPU() )
{
btnTextText = GuiText.NoCraftingCPUs.getLocal();
}
this.selectCPU.displayString = btnTextText;
}
private boolean isSimulation()
{
return ( (ContainerFluidCraftConfirm) this.inventorySlots ).isSimulation();
}
@Override
public void drawFG( final int offsetX, final int offsetY, final int mouseX, final int mouseY )
{
final long BytesUsed = this.ccc.getUsedBytes();
final String byteUsed = NumberFormat.getInstance().format( BytesUsed );
final String Add = BytesUsed > 0 ? ( byteUsed + ' ' + GuiText.BytesUsed.getLocal() ) : GuiText.CalculatingWait.getLocal();
this.fontRendererObj.drawString( GuiText.CraftingPlan.getLocal() + " - " + Add, 8, 7, 4210752 );
String dsp = null;
if( this.isSimulation() )
{
dsp = GuiText.Simulation.getLocal();
}
else
{
dsp = this.ccc.getCpuAvailableBytes() > 0 ? ( GuiText.Bytes.getLocal() + ": " + this.ccc.getCpuAvailableBytes() + " : " + GuiText.CoProcessors.getLocal() + ": " + this.ccc.getCpuCoProcessors() ) : GuiText.Bytes.getLocal() + ": N/A : " + GuiText.CoProcessors.getLocal() + ": N/A";
}
final int offset = ( 219 - this.fontRendererObj.getStringWidth( dsp ) ) / 2;
this.fontRendererObj.drawString( dsp, offset, 165, 4210752 );
final int sectionLength = 67;
int x = 0;
int y = 0;
final int xo = 9;
final int yo = 22;
final int viewStart = this.getScrollBar().getCurrentScroll() * 3;
final int viewEnd = viewStart + 3 * this.rows;
String dspToolTip = "";
final List<String> lineList = new LinkedList<String>();
int toolPosX = 0;
int toolPosY = 0;
final int offY = 23;
for( int z = viewStart; z < Math.min( viewEnd, this.visual.size() ); z++ )
{
final IAEItemStack refStack = this.visual.get( z );// repo.getReferenceItem( z );
if( refStack != null )
{
GL11.glPushMatrix();
GL11.glScaled( 0.5, 0.5, 0.5 );
final IAEItemStack stored = this.storage.findPrecise( refStack );
final IAEItemStack pendingStack = this.pending.findPrecise( refStack );
final IAEItemStack missingStack = this.missing.findPrecise( refStack );
int lines = 0;
if( stored != null && stored.getStackSize() > 0 )
{
lines++;
}
if( pendingStack != null && pendingStack.getStackSize() > 0 )
{
lines++;
}
if( pendingStack != null && pendingStack.getStackSize() > 0 )
{
lines++;
}
final int negY = ( ( lines - 1 ) * 5 ) / 2;
int downY = 0;
if( stored != null && stored.getStackSize() > 0 )
{
String str = Long.toString( stored.getStackSize() );
if( stored.getStackSize() >= 10000 )
{
str = Long.toString( stored.getStackSize() / 1000 ) + 'k';
}
if( stored.getStackSize() >= 10000000 )
{
str = Long.toString( stored.getStackSize() / 1000000 ) + 'm';
}
str = GuiText.FromStorage.getLocal() + ": " + str;
final int w = 4 + this.fontRendererObj.getStringWidth( str );
this.fontRendererObj.drawString( str, (int) ( ( x * ( 1 + sectionLength ) + xo + sectionLength - 19 - ( w * 0.5 ) ) * 2 ), ( y * offY + yo + 6 - negY + downY ) * 2, 4210752 );
if( this.tooltip == z - viewStart )
{
lineList.add( GuiText.FromStorage.getLocal() + ": " + Long.toString( stored.getStackSize() ) );
}
downY += 5;
}
boolean red = false;
if( missingStack != null && missingStack.getStackSize() > 0 )
{
String str = Long.toString( missingStack.getStackSize() );
if( missingStack.getStackSize() >= 10000 )
{
str = Long.toString( missingStack.getStackSize() / 1000 ) + 'k';
}
if( missingStack.getStackSize() >= 10000000 )
{
str = Long.toString( missingStack.getStackSize() / 1000000 ) + 'm';
}
str = GuiText.Missing.getLocal() + ": " + str;
final int w = 4 + this.fontRendererObj.getStringWidth( str );
this.fontRendererObj.drawString( str, (int) ( ( x * ( 1 + sectionLength ) + xo + sectionLength - 19 - ( w * 0.5 ) ) * 2 ), ( y * offY + yo + 6 - negY + downY ) * 2, 4210752 );
if( this.tooltip == z - viewStart )
{
lineList.add( GuiText.Missing.getLocal() + ": " + Long.toString( missingStack.getStackSize() ) );
}
red = true;
downY += 5;
}
if( pendingStack != null && pendingStack.getStackSize() > 0 )
{
String str = Long.toString( pendingStack.getStackSize() );
if( pendingStack.getStackSize() >= 10000 )
{
str = Long.toString( pendingStack.getStackSize() / 1000 ) + 'k';
}
if( pendingStack.getStackSize() >= 10000000 )
{
str = Long.toString( pendingStack.getStackSize() / 1000000 ) + 'm';
}
str = GuiText.ToCraft.getLocal() + ": " + str;
final int w = 4 + this.fontRendererObj.getStringWidth( str );
this.fontRendererObj.drawString( str, (int) ( ( x * ( 1 + sectionLength ) + xo + sectionLength - 19 - ( w * 0.5 ) ) * 2 ), ( y * offY + yo + 6 - negY + downY ) * 2, 4210752 );
if( this.tooltip == z - viewStart )
{
lineList.add( GuiText.ToCraft.getLocal() + ": " + Long.toString( pendingStack.getStackSize() ) );
}
}
GL11.glPopMatrix();
final int posX = x * ( 1 + sectionLength ) + xo + sectionLength - 19;
final int posY = y * offY + yo;
final ItemStack is = refStack.copy().getItemStack();
if( this.tooltip == z - viewStart )
{
dspToolTip = Platform.getItemDisplayName( is );
if( lineList.size() > 0 )
{
addItemTooltip(is, lineList);
dspToolTip = dspToolTip + '\n' + Joiner.on( "\n" ).join( lineList );
}
toolPosX = x * ( 1 + sectionLength ) + xo + sectionLength - 8;
toolPosY = y * offY + yo;
}
this.drawItem( posX, posY, is );
if( red )
{
final int startX = x * ( 1 + sectionLength ) + xo;
final int startY = posY - 4;
drawRect( startX, startY, startX + sectionLength, startY + offY, 0x1AFF0000 );
}
x++;
if( x > 2 )
{
y++;
x = 0;
}
}
}
if( this.tooltip >= 0 && dspToolTip.length() > 0 )
{
this.drawTooltip( toolPosX, toolPosY + 10, 0, dspToolTip );
}
}
@Override
public void drawBG( final int offsetX, final int offsetY, final int mouseX, final int mouseY )
{
this.setScrollBar();
this.bindTexture( "guis/craftingreport.png" );
this.drawTexturedModalRect( offsetX, offsetY, 0, 0, this.xSize, this.ySize );
}
private void setScrollBar()
{
final int size = this.visual.size();
this.getScrollBar().setTop( 19 ).setLeft( 218 ).setHeight( 114 );
this.getScrollBar().setRange( 0, ( size + 2 ) / 3 - this.rows, 1 );
}
public void postUpdate( final List<IAEItemStack> list, final byte ref )
{
switch( ref )
{
case 0:
for( final IAEItemStack l : list )
{
this.handleInput( this.storage, l );
}
break;
case 1:
for( final IAEItemStack l : list )
{
this.handleInput( this.pending, l );
}
break;
case 2:
for( final IAEItemStack l : list )
{
this.handleInput( this.missing, l );
}
break;
}
for( final IAEItemStack l : list )
{
final long amt = this.getTotal( l );
if( amt <= 0 )
{
this.deleteVisualStack( l );
}
else
{
final IAEItemStack is = this.findVisualStack( l );
is.setStackSize( amt );
}
}
this.setScrollBar();
}
private void handleInput( final IItemList<IAEItemStack> s, final IAEItemStack l )
{
IAEItemStack a = s.findPrecise( l );
if( l.getStackSize() <= 0 )
{
if( a != null )
{
a.reset();
}
}
else
{
if( a == null )
{
s.add( l.copy() );
a = s.findPrecise( l );
}
if( a != null )
{
a.setStackSize( l.getStackSize() );
}
}
}
private long getTotal( final IAEItemStack is )
{
final IAEItemStack a = this.storage.findPrecise( is );
final IAEItemStack c = this.pending.findPrecise( is );
final IAEItemStack m = this.missing.findPrecise( is );
long total = 0;
if( a != null )
{
total += a.getStackSize();
}
if( c != null )
{
total += c.getStackSize();
}
if( m != null )
{
total += m.getStackSize();
}
return total;
}
private void deleteVisualStack( final IAEItemStack l )
{
final Iterator<IAEItemStack> i = this.visual.iterator();
while( i.hasNext() )
{
final IAEItemStack o = i.next();
if( o.equals( l ) )
{
i.remove();
return;
}
}
}
private IAEItemStack findVisualStack( final IAEItemStack l )
{
for( final IAEItemStack o : this.visual )
{
if( o.equals( l ) )
{
return o;
}
}
final IAEItemStack stack = l.copy();
this.visual.add( stack );
return stack;
}
@Override
protected void keyTyped( final char character, final int key )
{
if( !this.checkHotbarKeys( key ) )
{
if( key == 28 )
{
this.actionPerformed( this.start );
}
super.keyTyped( character, key );
}
}
@Override
protected void actionPerformed( final GuiButton btn )
{
super.actionPerformed( btn );
final boolean backwards = Mouse.isButtonDown( 1 );
if( btn == this.selectCPU )
{
FluidCraft.proxy.netHandler.sendToServer( new CPacketFluidPatternTermBtns( "Terminal.Cpu", backwards ? "Prev" : "Next" ) );
}
if( btn == this.cancel )
{
FluidCraft.proxy.netHandler.sendToServer( new CPacketSwitchGuis( this.OriginalGui ) );
}
if( btn == this.start )
{
try
{
FluidCraft.proxy.netHandler.sendToServer( new CPacketFluidPatternTermBtns( "Terminal.Start", "Start" ) );
}
catch( final Throwable e )
{
AELog.debug( e );
}
}
}
}
@@ -0,0 +1,33 @@
package com.glodblock.github.client.gui;
import appeng.client.gui.AEBaseGui;
import appeng.core.localization.GuiText;
import com.glodblock.github.FluidCraft;
import com.glodblock.github.client.gui.container.ContainerFluidPacketDecoder;
import com.glodblock.github.common.tile.TileFluidPacketDecoder;
import com.glodblock.github.util.NameConst;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.util.ResourceLocation;
public class GuiFluidPacketDecoder extends AEBaseGui {
private static final ResourceLocation TEX_BG = FluidCraft.resource("textures/gui/fluid_packet_decoder.png");
public GuiFluidPacketDecoder(InventoryPlayer ipl, TileFluidPacketDecoder tile) {
super(new ContainerFluidPacketDecoder(ipl, tile));
}
@Override
public void drawBG(int offsetX, int offsetY, int mouseX, int mouseY) {
mc.getTextureManager().bindTexture(TEX_BG);
drawTexturedModalRect(offsetX, offsetY, 0, 0, 176, ySize);
}
@Override
public void drawFG(int offsetX, int offsetY, int mouseX, int mouseY) {
fontRendererObj.drawString(getGuiDisplayName(I18n.format(NameConst.GUI_FLUID_PACKET_DECODER)), 8, 6, 0x404040);
fontRendererObj.drawString(GuiText.inventory.getLocal(), 8, ySize - 94, 0x404040);
}
}
@@ -0,0 +1,136 @@
package com.glodblock.github.client.gui;
import appeng.api.storage.data.IAEItemStack;
import appeng.client.gui.AEBaseGui;
import appeng.client.render.AppEngRenderItem;
import appeng.core.localization.GuiText;
import com.glodblock.github.FluidCraft;
import com.glodblock.github.client.gui.container.ContainerFluidPatternEncoder;
import com.glodblock.github.common.item.ItemFluidPacket;
import com.glodblock.github.common.tile.TileFluidPatternEncoder;
import com.glodblock.github.inventory.gui.MouseRegionManager;
import com.glodblock.github.inventory.slot.SlotFluid;
import com.glodblock.github.inventory.slot.SlotSingleItem;
import com.glodblock.github.network.CPacketEncodePattern;
import com.glodblock.github.util.Ae2Reflect;
import com.glodblock.github.util.NameConst;
import com.glodblock.github.util.Util;
import net.minecraft.client.gui.FontRenderer;
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.EnumChatFormatting;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fluids.FluidStack;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
public class GuiFluidPatternEncoder extends AEBaseGui {
private static final ResourceLocation TEX_BG = FluidCraft.resource("textures/gui/fluid_pattern_encoder.png");
private final ContainerFluidPatternEncoder cont;
private final MouseRegionManager mouseRegions = new MouseRegionManager(this, fontRendererObj);
private final AppEngRenderItem stackSizeRenderer = Ae2Reflect.getStackSizeRenderer(this);
public GuiFluidPatternEncoder(InventoryPlayer ipl, TileFluidPatternEncoder tile) {
super(new ContainerFluidPatternEncoder(ipl, tile));
this.cont = (ContainerFluidPatternEncoder)inventorySlots;
mouseRegions.addRegion(141, 38, 10, 10, new MouseRegionManager.Handler() {
@Override
public List<String> getTooltip() {
return Collections.singletonList(I18n.format(NameConst.TT_ENCODE_PATTERN));
}
@Override
public boolean onClick(int button) {
if (button == 0) {
if (cont.canEncodePattern()) {
FluidCraft.proxy.netHandler.sendToServer(new CPacketEncodePattern());
}
return true;
}
return false;
}
});
}
@Override
protected void mouseClicked(int xCoord, int yCoord, int btn) {
if (mouseRegions.onClick(xCoord, yCoord, btn)) {
super.mouseClicked(xCoord, yCoord, btn);
}
}
@Override
public void drawBG(int offsetX, int offsetY, int mouseX, int mouseY) {
mc.getTextureManager().bindTexture(TEX_BG);
drawTexturedModalRect(offsetX, offsetY, 0, 0, 176, ySize);
}
@Override
public void drawFG(int offsetX, int offsetY, int mouseX, int mouseY) {
fontRendererObj.drawString(getGuiDisplayName(I18n.format(NameConst.GUI_FLUID_PATTERN_ENCODER)), 8, 6, 0x404040);
fontRendererObj.drawString(GuiText.inventory.getLocal(), 8, ySize - 94, 0x404040);
mouseRegions.render(mouseX, mouseY);
}
@Override
public void func_146977_a( final Slot s )
{
this.drawSlot0( s );
}
public void drawSlot0(Slot slot) {
if (slot instanceof SlotFluid) {
IAEItemStack stack = ((SlotFluid)slot).getAeStack();
super.func_146977_a(new SlotSingleItem(slot));
if (stack == null) return;
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);
}
stackSizeRenderer.setAeStack(fake);
stackSizeRenderer.renderItemOverlayIntoGUI(fontRendererObj, mc.getTextureManager(), stack.getItemStack(), slot.xDisplayPosition, slot.yDisplayPosition);
} else {
super.func_146977_a(slot);
}
}
@Override
@SuppressWarnings({"unchecked", "rawtypes"})
protected void renderToolTip(ItemStack stack, int x, int y) {
List list;
if (stack.getItem() instanceof ItemFluidPacket) {
FluidStack fluid = ItemFluidPacket.getFluidStack(stack);
if (fluid != null) {
list = Arrays.asList(fluid.getLocalizedName(), String.format(EnumChatFormatting.GRAY + "%,d mB", fluid.amount));
}
else {
list = stack.getTooltip(this.mc.thePlayer, this.mc.gameSettings.advancedItemTooltips);
}
}
else {
list = stack.getTooltip(this.mc.thePlayer, this.mc.gameSettings.advancedItemTooltips);
}
for (int k = 0; k < list.size(); ++k)
{
if (k == 0)
{
list.set(k, stack.getRarity().rarityColor + (String)list.get(k));
}
else
{
list.set(k, EnumChatFormatting.GRAY + (String)list.get(k));
}
}
FontRenderer font = stack.getItem().getFontRenderer(stack);
drawHoveringText(list, x, y, (font == null ? fontRendererObj : font));
}
}
@@ -0,0 +1,73 @@
package com.glodblock.github.client.gui;
import appeng.api.storage.ITerminalHost;
import appeng.api.storage.data.IAEItemStack;
import appeng.client.gui.widgets.GuiTabButton;
import appeng.client.render.AppEngRenderItem;
import appeng.container.slot.SlotFake;
import appeng.util.item.AEItemStack;
import com.glodblock.github.client.gui.container.ContainerFluidPatternTerminal;
import com.glodblock.github.common.item.ItemFluidPacket;
import com.glodblock.github.inventory.InventoryHandler;
import com.glodblock.github.inventory.gui.GuiType;
import com.glodblock.github.inventory.slot.SlotSingleItem;
import com.glodblock.github.util.Ae2Reflect;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Slot;
public class GuiFluidPatternTerminal extends GuiBaseFluidPatternTerminal {
private GuiTabButton craftingStatusBtn;
private final AppEngRenderItem stackSizeRenderer = Ae2Reflect.getStackSizeRenderer(this);
public GuiFluidPatternTerminal(InventoryPlayer inventoryPlayer, ITerminalHost te) {
super(inventoryPlayer, te);
ContainerFluidPatternTerminal container = new ContainerFluidPatternTerminal(inventoryPlayer, te);
container.setGui(this);
this.inventorySlots = container;
Ae2Reflect.setGuiContainer(this, container);
}
@Override
public void initGui() {
super.initGui();
craftingStatusBtn = Ae2Reflect.getCraftingStatusButton(this);
}
@Override
public void func_146977_a( final Slot s )
{
if (drawSlot0(s))
super.func_146977_a( s );
}
public boolean drawSlot0(Slot slot) {
if (slot instanceof SlotFake && !this.container.isCraftingMode()) {
AEItemStack stack = AEItemStack.create(slot.getStack());
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);
}
else
return true;
stackSizeRenderer.setAeStack(fake);
stackSizeRenderer.renderItemOverlayIntoGUI(fontRendererObj, mc.getTextureManager(), stack.getItemStack(), slot.xDisplayPosition, slot.yDisplayPosition);
return false;
}
return true;
}
@Override
protected void actionPerformed(final GuiButton btn) {
if (btn == craftingStatusBtn) {
InventoryHandler.switchGui(GuiType.FLUID_PAT_TERM_CRAFTING_STATUS);
} else {
super.actionPerformed(btn);
}
}
}
@@ -0,0 +1,38 @@
package com.glodblock.github.client.gui;
import appeng.api.storage.ITerminalHost;
import appeng.client.gui.implementations.GuiCraftingStatus;
import appeng.client.gui.widgets.GuiTabButton;
import com.glodblock.github.inventory.InventoryHandler;
import com.glodblock.github.inventory.gui.GuiType;
import com.glodblock.github.loader.ItemAndBlockHolder;
import com.glodblock.github.util.Ae2Reflect;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.item.ItemStack;
public class GuiFluidPatternTerminalCraftingStatus extends GuiCraftingStatus {
private GuiTabButton originalGuiBtn;
public GuiFluidPatternTerminalCraftingStatus(InventoryPlayer inventoryPlayer, ITerminalHost te) {
super(inventoryPlayer, te);
}
@Override
public void initGui() {
Ae2Reflect.rewriteIcon(this, new ItemStack(ItemAndBlockHolder.FLUID_TERMINAL, 1));
super.initGui();
originalGuiBtn = Ae2Reflect.getOriginalGuiButton(this);
}
@Override
protected void actionPerformed(final GuiButton btn) {
if (btn == originalGuiBtn) {
InventoryHandler.switchGui(GuiType.FLUID_PATTERN_TERMINAL);
} else {
super.actionPerformed(btn);
}
}
}
@@ -0,0 +1,9 @@
package com.glodblock.github.client.gui;
import appeng.api.storage.data.IAEFluidStack;
import java.util.Map;
public interface IFluidSyncContainer {
void receiveFluidSlots( final Map<Integer, IAEFluidStack> fluids );
}
@@ -0,0 +1,382 @@
package com.glodblock.github.client.gui.container;
import appeng.api.config.Upgrades;
import appeng.api.implementations.IUpgradeableHost;
import appeng.api.storage.data.IAEFluidStack;
import appeng.client.me.InternalSlotME;
import appeng.client.me.SlotME;
import appeng.container.implementations.ContainerUpgradeable;
import appeng.container.slot.*;
import appeng.util.Platform;
import appeng.util.item.AEFluidStack;
import com.glodblock.github.client.gui.IFluidSyncContainer;
import com.glodblock.github.inventory.IAEFluidTank;
import com.glodblock.github.util.Ae2Reflect;
import com.glodblock.github.util.FluidSyncHelper;
import com.glodblock.github.util.Util;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.ICrafting;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
public abstract class ContainerFluidConfigurable extends ContainerUpgradeable implements IFluidSyncContainer
{
private FluidSyncHelper sync = null;
public ContainerFluidConfigurable(InventoryPlayer ip, IUpgradeableHost te )
{
super( ip, te );
}
public abstract IAEFluidTank getFluidConfigInventory();
private FluidSyncHelper getSynchHelper()
{
if( this.sync == null )
{
this.sync = new FluidSyncHelper( this.getFluidConfigInventory(), 0 );
}
return this.sync;
}
@Override
public ItemStack transferStackInSlot(final EntityPlayer p, final int idx )
{
if( Platform.isClient() )
{
return null;
}
boolean hasMETiles = false;
for( final Object is : this.inventorySlots )
{
if( is instanceof InternalSlotME)
{
hasMETiles = true;
break;
}
}
if( hasMETiles && Platform.isClient() )
{
return null;
}
final AppEngSlot clickSlot = (AppEngSlot) this.inventorySlots.get( idx ); // require AE SLots!
if( clickSlot instanceof SlotDisabled || clickSlot instanceof SlotInaccessible)
{
return null;
}
if( clickSlot != null && clickSlot.getHasStack() )
{
ItemStack tis = clickSlot.getStack();
if( tis == null )
{
return null;
}
final List<Slot> selectedSlots = new ArrayList<Slot>();
/**
* Gather a list of valid destinations.
*/
if( clickSlot.isPlayerSide() )
{
tis = this.transferStackToContainer( tis );
// target slots in the container...
for( final Object inventorySlot : this.inventorySlots )
{
final AppEngSlot cs = (AppEngSlot) inventorySlot;
if( !( cs.isPlayerSide() ) && !( cs instanceof SlotFake) && !( cs instanceof SlotCraftingMatrix) )
{
if( cs.isItemValid( tis ) )
{
selectedSlots.add( cs );
}
}
}
}
else
{
// target slots in the container...
for( final Object inventorySlot : this.inventorySlots )
{
final AppEngSlot cs = (AppEngSlot) inventorySlot;
if( ( cs.isPlayerSide() ) && !( cs instanceof SlotFake ) && !( cs instanceof SlotCraftingMatrix ) )
{
if( cs.isItemValid( tis ) )
{
selectedSlots.add( cs );
}
}
}
}
/**
* Handle Fake Slot Shift clicking.
*/
if( selectedSlots.isEmpty() && clickSlot.isPlayerSide() )
{
if( tis != null )
{
// target slots in the container...
for( final Object inventorySlot : this.inventorySlots )
{
final AppEngSlot cs = (AppEngSlot) inventorySlot;
final ItemStack destination = cs.getStack();
if( !( cs.isPlayerSide() ) && cs instanceof SlotFake )
{
if( Platform.isSameItemPrecise( destination, tis ) )
{
break;
}
else if( destination == null )
{
cs.putStack( tis.copy() );
cs.onSlotChanged();
this.detectAndSendChanges();
break;
}
}
}
}
}
if( tis != null )
{
// find partials..
for( final Slot d : selectedSlots )
{
if( d instanceof SlotDisabled || d instanceof SlotME)
{
continue;
}
if( d.isItemValid( tis ) )
{
if( d.getHasStack() )
{
final ItemStack t = d.getStack();
if( Platform.isSameItemPrecise( tis, t ) ) // t.isItemEqual(tis))
{
int maxSize = t.getMaxStackSize();
if( maxSize > d.getSlotStackLimit() )
{
maxSize = d.getSlotStackLimit();
}
int placeAble = maxSize - t.stackSize;
if( tis.stackSize < placeAble )
{
placeAble = tis.stackSize;
}
t.stackSize += placeAble;
tis.stackSize -= placeAble;
if( tis.stackSize <= 0 )
{
clickSlot.putStack( null );
d.onSlotChanged();
// if ( hasMETiles ) updateClient();
this.detectAndSendChanges();
this.detectAndSendChanges();
return null;
}
else
{
this.detectAndSendChanges();
}
}
}
}
}
// any match..
for( final Slot d : selectedSlots )
{
if( d instanceof SlotDisabled || d instanceof SlotME )
{
continue;
}
if( d.isItemValid( tis ) )
{
if( d.getHasStack() )
{
final ItemStack t = d.getStack();
if( Platform.isSameItemPrecise( t, tis ) )
{
int maxSize = t.getMaxStackSize();
if( d.getSlotStackLimit() < maxSize )
{
maxSize = d.getSlotStackLimit();
}
int placeAble = maxSize - t.stackSize;
if( tis.stackSize < placeAble )
{
placeAble = tis.stackSize;
}
t.stackSize += placeAble;
tis.stackSize -= placeAble;
if( tis.stackSize <= 0 )
{
clickSlot.putStack( null );
d.onSlotChanged();
// if ( worldEntity != null )
// worldEntity.markDirty();
// if ( hasMETiles ) updateClient();
this.detectAndSendChanges();
this.detectAndSendChanges();
return null;
}
else
{
this.detectAndSendChanges();
}
}
}
else
{
int maxSize = tis.getMaxStackSize();
if( maxSize > d.getSlotStackLimit() )
{
maxSize = d.getSlotStackLimit();
}
final ItemStack tmp = tis.copy();
if( tmp.stackSize > maxSize )
{
tmp.stackSize = maxSize;
}
tis.stackSize -= tmp.stackSize;
d.putStack( tmp );
if( tis.stackSize <= 0 )
{
clickSlot.putStack( null );
d.onSlotChanged();
// if ( worldEntity != null )
// worldEntity.markDirty();
// if ( hasMETiles ) updateClient();
this.detectAndSendChanges();
this.detectAndSendChanges();
return null;
}
else
{
this.detectAndSendChanges();
}
}
}
}
}
clickSlot.putStack( tis != null ? tis.copy() : null );
}
this.detectAndSendChanges();
return null;
}
protected ItemStack transferStackToContainer(ItemStack input )
{
FluidStack fs = Util.getFluidFromItem( input );
if( fs != null )
{
final IAEFluidTank t = this.getFluidConfigInventory();
final IAEFluidStack stack = AEFluidStack.create( fs );
for( int i = 0; i < t.getSlots(); ++i )
{
if( t.getFluidInSlot( i ) == null && this.isValidForConfig( i, stack ) )
{
t.setFluidInSlot( i, stack );
break;
}
}
}
return input;
}
protected boolean isValidForConfig( int slot, IAEFluidStack fs )
{
if( this.supportCapacity() )
{
// assumes 4 slots per upgrade
final int upgrades = Ae2Reflect.getUpgrade(this).getInstalledUpgrades( Upgrades.CAPACITY );
if( slot > 0 && upgrades < 1 )
{
return false;
}
if( slot > 4 && upgrades < 2 )
{
return false;
}
}
return true;
}
@Override
@SuppressWarnings("unchecked")
protected void standardDetectAndSendChanges()
{
if( Platform.isServer() )
{
this.getSynchHelper().sendDiff( this.crafters );
// clear out config items that are no longer valid (eg capacity upgrade removed)
final IAEFluidTank t = this.getFluidConfigInventory();
for( int i = 0; i < t.getSlots(); ++i )
{
if( t.getFluidInSlot( i ) != null && !this.isValidForConfig( i, t.getFluidInSlot( i ) ) )
{
t.setFluidInSlot( i, null );
}
}
}
super.standardDetectAndSendChanges();
}
@Override
public void addCraftingToCrafters( ICrafting listener )
{
super.addCraftingToCrafters( listener );
this.getSynchHelper().sendFull( Collections.singleton( listener ) );
}
@Override
public void receiveFluidSlots( Map<Integer, IAEFluidStack> fluids )
{
this.getSynchHelper().readPacket( fluids );
}
}
@@ -0,0 +1,436 @@
package com.glodblock.github.client.gui.container;
import appeng.api.AEApi;
import appeng.api.config.Actionable;
import appeng.api.config.SecurityPermissions;
import appeng.api.networking.IGrid;
import appeng.api.networking.crafting.ICraftingCPU;
import appeng.api.networking.crafting.ICraftingGrid;
import appeng.api.networking.crafting.ICraftingJob;
import appeng.api.networking.crafting.ICraftingLink;
import appeng.api.networking.security.BaseActionSource;
import appeng.api.networking.security.IActionHost;
import appeng.api.networking.security.PlayerSource;
import appeng.api.networking.storage.IStorageGrid;
import appeng.api.storage.IMEInventory;
import appeng.api.storage.ITerminalHost;
import appeng.api.storage.data.IAEItemStack;
import appeng.api.storage.data.IItemList;
import appeng.container.AEBaseContainer;
import appeng.container.guisync.GuiSync;
import appeng.container.implementations.CraftingCPURecord;
import appeng.core.AELog;
import appeng.util.Platform;
import com.glodblock.github.FluidCraft;
import com.glodblock.github.common.parts.PartFluidPatternTerminal;
import com.glodblock.github.inventory.InventoryHandler;
import com.glodblock.github.inventory.gui.GuiType;
import com.glodblock.github.network.SPacketMEInventoryUpdate;
import com.glodblock.github.util.Ae2Reflect;
import com.google.common.collect.ImmutableSet;
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.util.ChatComponentText;
import net.minecraft.world.World;
import javax.annotation.Nonnull;
import java.util.ArrayList;
import java.util.Collections;
import java.util.concurrent.Future;
public class ContainerFluidCraftConfirm extends AEBaseContainer {
private final ArrayList<CraftingCPURecord> cpus = new ArrayList<CraftingCPURecord>();
private Future<ICraftingJob> job;
private ICraftingJob result;
@GuiSync( 0 )
public long bytesUsed;
@GuiSync( 1 )
public long cpuBytesAvail;
@GuiSync( 2 )
public int cpuCoProcessors;
@GuiSync( 3 )
public boolean autoStart = false;
@GuiSync( 4 )
public boolean simulation = true;
@GuiSync( 5 )
public int selectedCpu = -1;
@GuiSync( 6 )
public boolean noCPU = true;
@GuiSync( 7 )
public String myName = "";
public ContainerFluidCraftConfirm(final InventoryPlayer ip, final ITerminalHost te )
{
super( ip, te );
}
public void cycleCpu( final boolean next )
{
if( next )
{
this.setSelectedCpu( this.getSelectedCpu() + 1 );
}
else
{
this.setSelectedCpu( this.getSelectedCpu() - 1 );
}
if( this.getSelectedCpu() < -1 )
{
this.setSelectedCpu( this.cpus.size() - 1 );
}
else if( this.getSelectedCpu() >= this.cpus.size() )
{
this.setSelectedCpu( -1 );
}
if( this.getSelectedCpu() == -1 )
{
this.setCpuAvailableBytes( 0 );
this.setCpuCoProcessors( 0 );
this.setName( "" );
}
else
{
this.setName(Ae2Reflect.getName(this.cpus.get(this.getSelectedCpu())));
this.setCpuAvailableBytes(Ae2Reflect.getSize(this.cpus.get(this.getSelectedCpu())));
this.setCpuCoProcessors(Ae2Reflect.getProcessors(this.cpus.get(this.getSelectedCpu())));
}
}
@Override
public void detectAndSendChanges()
{
if( Platform.isClient() )
{
return;
}
if (getGrid() == null)
return;
final ICraftingGrid cc = this.getGrid().getCache( ICraftingGrid.class );
final ImmutableSet<ICraftingCPU> cpuSet = cc.getCpus();
int matches = 0;
boolean changed = false;
for( final ICraftingCPU c : cpuSet )
{
boolean found = false;
for( final CraftingCPURecord ccr : this.cpus )
{
if( Ae2Reflect.getCPU(ccr) == c )
{
found = true;
}
}
final boolean matched = this.cpuMatches( c );
if( matched )
{
matches++;
}
if( found == !matched )
{
changed = true;
}
}
if( changed || this.cpus.size() != matches )
{
this.cpus.clear();
for( final ICraftingCPU c : cpuSet )
{
if( this.cpuMatches( c ) )
{
this.cpus.add( new CraftingCPURecord( c.getAvailableStorage(), c.getCoProcessors(), c ) );
}
}
this.sendCPUs();
}
this.setNoCPU( this.cpus.isEmpty() );
super.detectAndSendChanges();
if( this.getJob() != null && this.getJob().isDone() )
{
try
{
this.result = this.getJob().get();
if( !this.result.isSimulation() )
{
this.setSimulation( false );
if( this.isAutoStart() )
{
this.startJob();
return;
}
}
else
{
this.setSimulation( true );
}
final SPacketMEInventoryUpdate a = new SPacketMEInventoryUpdate( (byte) 0 );
final SPacketMEInventoryUpdate b = new SPacketMEInventoryUpdate( (byte) 1 );
final SPacketMEInventoryUpdate c = this.result.isSimulation() ? new SPacketMEInventoryUpdate( (byte) 2 ) : null;
final IItemList<IAEItemStack> plan = AEApi.instance().storage().createItemList();
this.result.populatePlan( plan );
this.setUsedBytes( this.result.getByteTotal() );
for( final IAEItemStack out : plan )
{
IAEItemStack o = out.copy();
o.reset();
o.setStackSize( out.getStackSize() );
final IAEItemStack p = out.copy();
p.reset();
p.setStackSize( out.getCountRequestable() );
final IStorageGrid sg = this.getGrid().getCache( IStorageGrid.class );
final IMEInventory<IAEItemStack> items = sg.getItemInventory();
IAEItemStack m = null;
if( c != null && this.result.isSimulation() )
{
m = o.copy();
o = items.extractItems( o, Actionable.SIMULATE, this.getActionSource() );
if( o == null )
{
o = m.copy();
o.setStackSize( 0 );
}
m.setStackSize( m.getStackSize() - o.getStackSize() );
}
if( o.getStackSize() > 0 )
{
a.appendItem( o );
}
if( p.getStackSize() > 0 )
{
b.appendItem( p );
}
if( c != null && m != null && m.getStackSize() > 0 )
{
c.appendItem( m );
}
}
for( final Object g : this.crafters )
{
if( g instanceof EntityPlayer)
{
FluidCraft.proxy.netHandler.sendTo( a, (EntityPlayerMP) g );
FluidCraft.proxy.netHandler.sendTo( b, (EntityPlayerMP) g );
if( c != null )
{
FluidCraft.proxy.netHandler.sendTo( c, (EntityPlayerMP) g );
}
}
}
}
catch( final Throwable e )
{
this.getPlayerInv().player.addChatMessage( new ChatComponentText( "Error: " + e.toString() ) );
AELog.debug( e );
this.setValidContainer( false );
this.result = null;
}
this.setJob( null );
}
this.verifyPermissions( SecurityPermissions.CRAFT, false );
}
private IGrid getGrid()
{
final IActionHost h = ( (IActionHost) this.getTarget() );
if (h == null || h.getActionableNode() == null)
return null;
return h.getActionableNode().getGrid();
}
private boolean cpuMatches( final ICraftingCPU c )
{
return c.getAvailableStorage() >= this.getUsedBytes() && !c.isBusy();
}
private void sendCPUs()
{
Collections.sort( this.cpus );
if( this.getSelectedCpu() >= this.cpus.size() )
{
this.setSelectedCpu( -1 );
this.setCpuAvailableBytes( 0 );
this.setCpuCoProcessors( 0 );
this.setName( "" );
}
else if( this.getSelectedCpu() != -1 )
{
this.setName(Ae2Reflect.getName(this.cpus.get(this.getSelectedCpu())));
this.setCpuAvailableBytes(Ae2Reflect.getSize(this.cpus.get(this.getSelectedCpu())));
this.setCpuCoProcessors(Ae2Reflect.getProcessors(this.cpus.get(this.getSelectedCpu())));
}
}
public void startJob()
{
GuiType originalGui = null;
final IActionHost ah = this.getActionHost();
if( ah instanceof PartFluidPatternTerminal)
{
originalGui = GuiType.FLUID_PATTERN_TERMINAL;
}
if( this.result != null && !this.isSimulation() && getGrid() != null)
{
final ICraftingGrid cc = this.getGrid().getCache( ICraftingGrid.class );
final ICraftingLink g = cc.submitJob( this.result, null, this.getSelectedCpu() == -1 ? null : Ae2Reflect.getCPU(this.cpus.get(this.getSelectedCpu())), true, this.getActionSrc() );
this.setAutoStart( false );
if( g != null && originalGui != null && this.getOpenContext() != null )
{
InventoryHandler.switchGui(originalGui);
}
}
}
private BaseActionSource getActionSrc()
{
return new PlayerSource( this.getPlayerInv().player, (IActionHost) this.getTarget() );
}
@Override
public void removeCraftingFromCrafters( final ICrafting c )
{
super.removeCraftingFromCrafters( c );
if( this.getJob() != null )
{
this.getJob().cancel( true );
this.setJob( null );
}
}
@Override
public void onContainerClosed( final EntityPlayer par1EntityPlayer )
{
super.onContainerClosed( par1EntityPlayer );
if( this.getJob() != null )
{
this.getJob().cancel( true );
this.setJob( null );
}
}
public World getWorld()
{
return this.getPlayerInv().player.worldObj;
}
public boolean isAutoStart()
{
return this.autoStart;
}
public void setAutoStart( final boolean autoStart )
{
this.autoStart = autoStart;
}
public long getUsedBytes()
{
return this.bytesUsed;
}
private void setUsedBytes( final long bytesUsed )
{
this.bytesUsed = bytesUsed;
}
public long getCpuAvailableBytes()
{
return this.cpuBytesAvail;
}
private void setCpuAvailableBytes( final long cpuBytesAvail )
{
this.cpuBytesAvail = cpuBytesAvail;
}
public int getCpuCoProcessors()
{
return this.cpuCoProcessors;
}
private void setCpuCoProcessors( final int cpuCoProcessors )
{
this.cpuCoProcessors = cpuCoProcessors;
}
public int getSelectedCpu()
{
return this.selectedCpu;
}
private void setSelectedCpu( final int selectedCpu )
{
this.selectedCpu = selectedCpu;
}
public String getName()
{
return this.myName;
}
private void setName( @Nonnull final String myName )
{
this.myName = myName;
}
public boolean hasNoCPU()
{
return this.noCPU;
}
private void setNoCPU( final boolean noCPU )
{
this.noCPU = noCPU;
}
public boolean isSimulation()
{
return this.simulation;
}
private void setSimulation( final boolean simulation )
{
this.simulation = simulation;
}
private Future<ICraftingJob> getJob()
{
return this.job;
}
public void setJob( final Future<ICraftingJob> job )
{
this.job = job;
}
}
@@ -0,0 +1,16 @@
package com.glodblock.github.client.gui.container;
import appeng.container.AEBaseContainer;
import appeng.container.slot.SlotNormal;
import com.glodblock.github.common.tile.TileFluidPacketDecoder;
import net.minecraft.entity.player.InventoryPlayer;
public class ContainerFluidPacketDecoder extends AEBaseContainer {
public ContainerFluidPacketDecoder(InventoryPlayer ipl, TileFluidPacketDecoder tile) {
super(ipl, tile);
addSlotToContainer(new SlotNormal(tile.getInventory(), 0, 80, 35));
bindPlayerInventory(ipl, 0, 84);
}
}
@@ -0,0 +1,226 @@
package com.glodblock.github.client.gui.container;
import appeng.api.AEApi;
import appeng.api.storage.data.IAEItemStack;
import appeng.container.AEBaseContainer;
import appeng.container.slot.SlotFake;
import appeng.container.slot.SlotRestrictedInput;
import appeng.helpers.InventoryAction;
import appeng.util.item.AEItemStack;
import com.glodblock.github.common.item.ItemFluidDrop;
import com.glodblock.github.common.item.ItemFluidEncodedPattern;
import com.glodblock.github.common.item.ItemFluidPacket;
import com.glodblock.github.common.tile.TileFluidPatternEncoder;
import com.glodblock.github.inventory.AeItemStackHandler;
import com.glodblock.github.inventory.AeStackInventory;
import com.glodblock.github.inventory.PatternConsumer;
import com.glodblock.github.inventory.slot.SlotFluid;
import com.glodblock.github.loader.ItemAndBlockHolder;
import com.glodblock.github.util.FluidPatternDetails;
import com.glodblock.github.util.Util;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidContainerRegistry;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.IFluidContainerItem;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
public class ContainerFluidPatternEncoder extends AEBaseContainer implements PatternConsumer {
private final TileFluidPatternEncoder tile;
public ContainerFluidPatternEncoder(InventoryPlayer ipl, TileFluidPatternEncoder tile) {
super(ipl, tile);
this.tile = tile;
AeItemStackHandler crafting = new AeItemStackHandler(tile.getCraftingSlots());
AeItemStackHandler output = new AeItemStackHandler(tile.getOutputSlots());
for (int y = 0; y < 3; y++) {
for (int x = 0; x < 3; x++) {
addSlotToContainer(new SlotFluidConvertingFake(crafting, y * 3 + x, 23 + x * 18, 17 + y * 18));
}
addSlotToContainer(new SlotFluidConvertingFake(output, y, 113, 17 + y * 18));
}
addSlotToContainer(new SlotRestrictedInput(
SlotRestrictedInput.PlacableItemType.BLANK_PATTERN, tile.getInventory(), 0, 138, 20, ipl));
addSlotToContainer(new SlotRestrictedInput(
SlotRestrictedInput.PlacableItemType.ENCODED_PATTERN, tile.getInventory(), 1, 138, 50, ipl));
bindPlayerInventory(ipl, 0, 84);
}
public TileFluidPatternEncoder getTile() {
return tile;
}
public boolean canEncodePattern() {
if (isNotPattern(tile.getInventory().getStackInSlot(0)) && isNotPattern(tile.getInventory().getStackInSlot(1))) {
return false;
}
find_input:
{
for (IAEItemStack stack : tile.getCraftingSlots()) {
if (stack != null && stack.getStackSize() > 0) {
break find_input;
}
}
return false;
}
for (IAEItemStack stack : tile.getOutputSlots()) {
if (stack != null && stack.getStackSize() > 0) {
return true;
}
}
return false;
}
private static boolean isNotPattern(ItemStack stack) {
return stack == null || !(AEApi.instance().definitions().materials().blankPattern().isSameAs(stack)
|| (stack.getItem() instanceof ItemFluidEncodedPattern));
}
public void encodePattern() {
if (canEncodePattern()) {
// if there is an encoded pattern, overwrite it; otherwise, consume a blank
if (tile.getInventory().getStackInSlot(1) == null) {
tile.getInventory().decrStackSize(0, 1); // this better work
}
ItemStack patternStack = new ItemStack(ItemAndBlockHolder.PATTERN);
FluidPatternDetails pattern = new FluidPatternDetails(patternStack);
pattern.setInputs(collectAeInventory(tile.getCraftingSlots()));
pattern.setOutputs(collectAeInventory(tile.getOutputSlots()));
tile.getInventory().setInventorySlotContents(1, pattern.writeToStack());
}
}
private static IAEItemStack[] collectAeInventory(AeStackInventory<IAEItemStack> inv) {
// see note at top of DensePatternDetails
List<IAEItemStack> acc = new ArrayList<>();
for (IAEItemStack stack : inv) {
if (stack != null) {
if (stack.getItem() instanceof ItemFluidPacket) {
IAEItemStack dropStack = ItemFluidDrop.newAeStack(ItemFluidPacket.getFluidStack(stack));
if (dropStack != null) {
acc.add(dropStack);
continue;
}
}
acc.add(stack);
}
}
return acc.toArray(new IAEItemStack[0]);
}
// adapted from ae2's AEBaseContainer#doAction
@Override
public void doAction(EntityPlayerMP player, InventoryAction action, int slotId, long id) {
Slot slot = getSlot(slotId);
if (slot instanceof SlotFluidConvertingFake) {
final ItemStack stack = player.inventory.getItemStack();
switch (action) {
case PICKUP_OR_SET_DOWN:
if (stack == null) {
slot.putStack(null);
} else {
((SlotFluidConvertingFake)slot).putConvertedStack(stack.copy());
}
break;
case PLACE_SINGLE:
if (stack != null) {
((SlotFluidConvertingFake)slot).putConvertedStack(Objects.requireNonNull(Util.copyStackWithSize(stack, 1)));
}
break;
case SPLIT_OR_PLACE_SINGLE:
ItemStack inSlot = slot.getStack();
if (inSlot != null) {
if (stack == null) {
slot.putStack(Util.copyStackWithSize(inSlot, Math.max(1, inSlot.stackSize - 1)));
} else if (stack.isItemEqual(inSlot)) {
slot.putStack(Util.copyStackWithSize(inSlot,
Math.min(inSlot.getMaxStackSize(), inSlot.stackSize + 1)));
} else {
((SlotFluidConvertingFake)slot).putConvertedStack(Objects.requireNonNull(Util.copyStackWithSize(stack, 1)));
}
} else if (stack != null) {
((SlotFluidConvertingFake)slot).putConvertedStack(Objects.requireNonNull(Util.copyStackWithSize(stack, 1)));
}
break;
}
} else {
super.doAction(player, action, slotId, id);
}
}
@Override
public void acceptPattern(IAEItemStack[] inputs, IAEItemStack[] outputs) {
copyStacks(inputs, tile.getCraftingSlots());
copyStacks(outputs, tile.getOutputSlots());
}
private static void copyStacks(IAEItemStack[] src, AeStackInventory<IAEItemStack> dest) {
int bound = Math.min(src.length, dest.getSlotCount());
for (int i = 0; i < bound; i++) {
dest.setStack(i, src[i]);
}
}
private static class SlotFluidConvertingFake extends SlotFake implements SlotFluid {
private final AeStackInventory<IAEItemStack> inv;
public SlotFluidConvertingFake(AeItemStackHandler inv, int idx, int x, int y) {
super(inv, idx, x, y);
this.inv = inv.getAeInventory();
}
@Override
public void putStack(ItemStack stack) {
inv.setStack(getSlotIndex(), AEItemStack.create(stack));
}
@Override
public void setAeStack(@Nullable IAEItemStack stack, boolean sync) {
inv.setStack(getSlotIndex(), stack);
}
public void putConvertedStack(ItemStack stack) {
if (stack == null) {
setAeStack(null, false);
return;
} else if (stack.getItem() instanceof IFluidContainerItem) {
FluidStack fluid = ((IFluidContainerItem) stack.getItem()).getFluid(stack);
if (fluid != null) {
fluid.amount *= stack.stackSize;
IAEItemStack aeStack = ItemFluidPacket.newAeStack(fluid);
if (aeStack != null) {
setAeStack(aeStack, false);
return;
}
}
} else if (FluidContainerRegistry.isContainer(stack)) {
FluidStack fluid = FluidContainerRegistry.getFluidForFilledItem(stack);
if (fluid != null) {
fluid.amount *= stack.stackSize;
IAEItemStack aeStack = ItemFluidPacket.newAeStack(fluid);
if (aeStack != null) {
setAeStack(aeStack, false);
return;
}
}
}
putStack(stack);
}
@Nullable
@Override
public IAEItemStack getAeStack() {
return inv.getStack(getSlotIndex());
}
}
}
@@ -0,0 +1,185 @@
package com.glodblock.github.client.gui.container;
import appeng.api.AEApi;
import appeng.api.definitions.IDefinitions;
import appeng.api.storage.ITerminalHost;
import appeng.api.storage.data.IAEItemStack;
import appeng.container.slot.SlotFakeCraftingMatrix;
import appeng.container.slot.SlotPatternOutputs;
import appeng.helpers.InventoryAction;
import appeng.util.item.AEItemStack;
import com.glodblock.github.common.item.ItemFluidDrop;
import com.glodblock.github.common.item.ItemFluidEncodedPattern;
import com.glodblock.github.common.item.ItemFluidPacket;
import com.glodblock.github.inventory.PatternConsumer;
import com.glodblock.github.loader.ItemAndBlockHolder;
import com.glodblock.github.util.FluidPatternDetails;
import com.glodblock.github.util.Util;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidContainerRegistry;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.IFluidContainerItem;
import java.util.ArrayList;
import java.util.List;
public class ContainerFluidPatternTerminal extends FCBasePartContainer implements PatternConsumer {
public ContainerFluidPatternTerminal(InventoryPlayer ip, ITerminalHost monitorable) {
super(ip, monitorable);
}
@Override
public void encode() {
if (!checkHasFluidPattern()) {
super.encode();
return;
}
ItemStack stack = this.patternSlotOUT.getStack();
if (stack == null) {
stack = this.patternSlotIN.getStack();
if (!isPattern(stack)) {
return;
}
if (stack.stackSize == 1) {
this.patternSlotIN.putStack(null);
} else {
stack.stackSize --;
}
encodeFluidPattern();
} else if (isPattern(stack)) {
encodeFluidPattern();
}
}
private static boolean isPattern(final ItemStack output) {
if (output == null) {
return false;
}
if (output.getItem() instanceof ItemFluidEncodedPattern) {
return true;
}
final IDefinitions defs = AEApi.instance().definitions();
return defs.items().encodedPattern().isSameAs(output) || defs.materials().blankPattern().isSameAs(output);
}
private boolean checkHasFluidPattern() {
if (this.craftingMode) {
return false;
}
boolean hasFluid = false, search = false;
for (Slot craftingSlot : this.craftingSlots) {
final ItemStack crafting = craftingSlot.getStack();
if (crafting == null) {
continue;
}
search = true;
if (crafting.getItem() instanceof ItemFluidPacket) {
hasFluid = true;
break;
}
}
if (!search) { // search=false -> inputs were empty
return false;
}
// `search` should be true at this point
for (Slot outputSlot : this.outputSlots) {
final ItemStack out = outputSlot.getStack();
if (out == null) {
continue;
}
search = false;
if (hasFluid) {
break;
} else if (out.getItem() instanceof ItemFluidPacket) {
hasFluid = true;
break;
}
}
return hasFluid && !search; // search=true -> outputs were empty
}
private void encodeFluidPattern() {
ItemStack patternStack = new ItemStack(ItemAndBlockHolder.PATTERN);
FluidPatternDetails pattern = new FluidPatternDetails(patternStack);
pattern.setInputs(collectInventory(craftingSlots));
pattern.setOutputs(collectInventory(outputSlots));
patternSlotOUT.putStack(pattern.writeToStack());
}
private static IAEItemStack[] collectInventory(Slot[] slots) {
// see note at top of FluidPatternDetails
List<IAEItemStack> acc = new ArrayList<>();
for (Slot slot : slots) {
ItemStack stack = slot.getStack();
if (stack == null) {
continue;
}
if (stack.getItem() instanceof ItemFluidPacket) {
IAEItemStack dropStack = ItemFluidDrop.newAeStack(ItemFluidPacket.getFluidStack(stack));
if (dropStack != null) {
acc.add(dropStack);
continue;
}
}
IAEItemStack aeStack = AEItemStack.create(stack);
acc.add(aeStack);
}
return acc.toArray(new IAEItemStack[0]);
}
@Override
public void acceptPattern(IAEItemStack[] inputs, IAEItemStack[] outputs) {
if (getPatternTerminal() != null) {
getPatternTerminal().onChangeCrafting(inputs, outputs);
}
}
@Override
public void doAction(EntityPlayerMP player, InventoryAction action, int slotId, long id) {
if (this.isCraftingMode()) {
super.doAction(player, action, slotId, id);
return;
}
if (slotId < 0 || slotId >= this.inventorySlots.size()) {
super.doAction(player, action, slotId, id);
return;
}
Slot slot = getSlot(slotId);
ItemStack stack = player.inventory.getItemStack();
if ((slot instanceof SlotFakeCraftingMatrix || slot instanceof SlotPatternOutputs) && stack != null
&& (stack.getItem() instanceof IFluidContainerItem || FluidContainerRegistry.isContainer(stack))) {
FluidStack fluid = null;
switch (action) {
case PICKUP_OR_SET_DOWN:
fluid = Util.getFluidFromItem(stack);
slot.putStack(ItemFluidPacket.newStack(fluid));
break;
case SPLIT_OR_PLACE_SINGLE:
fluid = Util.getFluidFromItem(Util.copyStackWithSize(stack, 1));
FluidStack origin = ItemFluidPacket.getFluidStack(slot.getStack());
if (fluid != null && fluid.equals(origin)) {
fluid.amount += origin.amount;
if (fluid.amount <= 0) fluid = null;
}
slot.putStack(ItemFluidPacket.newStack(fluid));
break;
}
if (fluid == null) {
super.doAction(player, action, slotId, id);
return;
}
return;
}
if (action == InventoryAction.SPLIT_OR_PLACE_SINGLE) {
if (stack == null && slot.getStack() != null && slot.getStack().getItem() instanceof ItemFluidPacket) {
return;
}
}
super.doAction(player, action, slotId, id);
}
}
@@ -0,0 +1,408 @@
package com.glodblock.github.client.gui.container;
import appeng.api.AEApi;
import appeng.api.config.*;
import appeng.api.implementations.guiobjects.IPortableCell;
import appeng.api.implementations.tiles.IMEChest;
import appeng.api.implementations.tiles.IViewCellStorage;
import appeng.api.networking.IGrid;
import appeng.api.networking.IGridHost;
import appeng.api.networking.IGridNode;
import appeng.api.networking.energy.IEnergyGrid;
import appeng.api.networking.energy.IEnergySource;
import appeng.api.networking.security.BaseActionSource;
import appeng.api.networking.storage.IBaseMonitor;
import appeng.api.parts.IPart;
import appeng.api.storage.IMEMonitor;
import appeng.api.storage.IMEMonitorHandlerReceiver;
import appeng.api.storage.ITerminalHost;
import appeng.api.storage.data.IAEItemStack;
import appeng.api.storage.data.IItemList;
import appeng.api.util.IConfigManager;
import appeng.api.util.IConfigurableObject;
import appeng.container.AEBaseContainer;
import appeng.container.guisync.GuiSync;
import appeng.container.slot.SlotRestrictedInput;
import appeng.core.AELog;
import appeng.core.sync.network.NetworkHandler;
import appeng.core.sync.packets.PacketValueConfig;
import appeng.helpers.WirelessTerminalGuiObject;
import appeng.me.helpers.ChannelPowerSrc;
import appeng.util.ConfigManager;
import appeng.util.IConfigManagerHost;
import appeng.util.Platform;
import com.glodblock.github.FluidCraft;
import com.glodblock.github.network.SPacketMEInventoryUpdate;
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.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
import javax.annotation.Nonnull;
import java.io.IOException;
import java.nio.BufferOverflowException;
public class FCBaseMonitorContain extends AEBaseContainer implements IConfigManagerHost, IConfigurableObject, IMEMonitorHandlerReceiver<IAEItemStack>
{
private final SlotRestrictedInput[] cellView = new SlotRestrictedInput[5];
private final IMEMonitor<IAEItemStack> monitor;
private final IItemList<IAEItemStack> items = AEApi.instance().storage().createItemList();
private final IConfigManager clientCM;
private final ITerminalHost host;
@GuiSync( 99 )
public boolean canAccessViewCells = false;
@GuiSync( 98 )
public boolean hasPower = false;
private IConfigManagerHost gui;
private IConfigManager serverCM;
private IGridNode networkNode;
public FCBaseMonitorContain(final InventoryPlayer ip, final ITerminalHost monitorable )
{
this( ip, monitorable, true );
}
protected FCBaseMonitorContain( final InventoryPlayer ip, final ITerminalHost monitorable, final boolean bindInventory )
{
super( ip, monitorable instanceof TileEntity ? (TileEntity) monitorable : null, monitorable instanceof IPart ? (IPart) monitorable : null );
this.host = monitorable;
this.clientCM = new ConfigManager( this );
this.clientCM.registerSetting( Settings.SORT_BY, SortOrder.NAME );
this.clientCM.registerSetting( Settings.VIEW_MODE, ViewItems.ALL );
this.clientCM.registerSetting( Settings.SORT_DIRECTION, SortDir.ASCENDING );
if( Platform.isServer() )
{
this.serverCM = monitorable.getConfigManager();
this.monitor = monitorable.getItemInventory();
if( this.monitor != null )
{
this.monitor.addListener( this, null );
this.setCellInventory( this.monitor );
if( monitorable instanceof IPortableCell)
{
this.setPowerSource( (IEnergySource) monitorable );
}
else if( monitorable instanceof IMEChest)
{
this.setPowerSource( (IEnergySource) monitorable );
}
else if( monitorable instanceof IGridHost)
{
final IGridNode node = ( (IGridHost) monitorable ).getGridNode( ForgeDirection.UNKNOWN );
if( node != null )
{
this.networkNode = node;
final IGrid g = node.getGrid();
if( g != null )
{
this.setPowerSource( new ChannelPowerSrc( this.networkNode, (IEnergySource) g.getCache( IEnergyGrid.class ) ) );
}
}
}
}
else
{
this.setValidContainer( false );
}
}
else
{
this.monitor = null;
}
this.canAccessViewCells = false;
if( monitorable instanceof IViewCellStorage)
{
for( int y = 0; y < 5; y++ )
{
this.cellView[y] = new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.VIEW_CELL, ( (IViewCellStorage) monitorable ).getViewCellStorage(), y, 206, y * 18 + 8, this.getInventoryPlayer() );
this.cellView[y].setAllowEdit( this.canAccessViewCells );
this.addSlotToContainer( this.cellView[y] );
}
}
if( bindInventory )
{
this.bindPlayerInventory( ip, 0, 0 );
}
}
public IGridNode getNetworkNode()
{
return this.networkNode;
}
@Override
public void detectAndSendChanges()
{
if( Platform.isServer() )
{
if( this.monitor != this.host.getItemInventory() )
{
this.setValidContainer( false );
}
for( final Settings set : this.serverCM.getSettings() )
{
final Enum<?> sideLocal = this.serverCM.getSetting( set );
final Enum<?> sideRemote = this.clientCM.getSetting( set );
if( sideLocal != sideRemote )
{
this.clientCM.putSetting( set, sideLocal );
for( final Object crafter : this.crafters )
{
try
{
NetworkHandler.instance.sendTo( new PacketValueConfig( set.name(), sideLocal.name() ), (EntityPlayerMP) crafter );
}
catch( final IOException e )
{
AELog.debug( e );
}
}
}
}
if( !this.items.isEmpty() )
{
final IItemList<IAEItemStack> monitorCache = this.monitor.getStorageList();
final SPacketMEInventoryUpdate piu = new SPacketMEInventoryUpdate();
for( final IAEItemStack is : this.items )
{
final IAEItemStack send = monitorCache.findPrecise( is );
if( send == null )
{
is.setStackSize( 0 );
piu.appendItem( is );
}
else
{
piu.appendItem( send );
}
}
if( !piu.isEmpty() )
{
this.items.resetStatus();
for( final Object c : this.crafters )
{
if( c instanceof EntityPlayer)
{
FluidCraft.proxy.netHandler.sendTo(piu, (EntityPlayerMP) c);
}
}
}
}
this.updatePowerStatus();
final boolean oldAccessible = this.canAccessViewCells;
this.canAccessViewCells =
this.host instanceof WirelessTerminalGuiObject
|| this.hasAccess( SecurityPermissions.BUILD, false );
if( this.canAccessViewCells != oldAccessible )
{
for( int y = 0; y < 5; y++ )
{
if( this.cellView[y] != null )
{
this.cellView[y].setAllowEdit( this.canAccessViewCells );
}
}
}
super.detectAndSendChanges();
}
}
protected void updatePowerStatus()
{
try
{
if( this.networkNode != null )
{
this.setPowered( this.networkNode.isActive() );
}
else if( this.getPowerSource() instanceof IEnergyGrid )
{
this.setPowered( ( (IEnergyGrid) this.getPowerSource() ).isNetworkPowered() );
}
else
{
this.setPowered( this.getPowerSource().extractAEPower( 1, Actionable.SIMULATE, PowerMultiplier.CONFIG ) > 0.8 );
}
}
catch( final Throwable t )
{
// :P
}
}
@Override
public void onUpdate( final String field, final Object oldValue, final Object newValue )
{
if( field.equals( "canAccessViewCells" ) )
{
for( int y = 0; y < 5; y++ )
{
if( this.cellView[y] != null )
{
this.cellView[y].setAllowEdit( this.canAccessViewCells );
}
}
}
super.onUpdate( field, oldValue, newValue );
}
@Override
public void addCraftingToCrafters( final ICrafting c )
{
super.addCraftingToCrafters( c );
this.queueInventory( c );
}
private void queueInventory( final ICrafting c )
{
if( Platform.isServer() && c instanceof EntityPlayer && this.monitor != null )
{
SPacketMEInventoryUpdate piu = new SPacketMEInventoryUpdate();
final IItemList<IAEItemStack> monitorCache = this.monitor.getStorageList();
for( final IAEItemStack send : monitorCache )
{
try
{
piu.appendItem( send );
}
catch( final BufferOverflowException boe )
{
FluidCraft.proxy.netHandler.sendTo( piu, (EntityPlayerMP) c );
piu = new SPacketMEInventoryUpdate();
piu.appendItem( send );
}
}
FluidCraft.proxy.netHandler.sendTo( piu, (EntityPlayerMP) c );
}
}
@Override
public void removeCraftingFromCrafters( final ICrafting c )
{
super.removeCraftingFromCrafters( c );
if( this.crafters.isEmpty() && this.monitor != null )
{
this.monitor.removeListener( this );
}
}
@Override
public void onContainerClosed( final EntityPlayer player )
{
super.onContainerClosed( player );
if( this.monitor != null )
{
this.monitor.removeListener( this );
}
}
@Override
public boolean isValid( final Object verificationToken )
{
return true;
}
@Override
public void postChange(final IBaseMonitor<IAEItemStack> monitor, final Iterable<IAEItemStack> change, final BaseActionSource source )
{
for( final IAEItemStack is : change )
{
this.items.add( is );
}
}
@Override
public void onListUpdate()
{
for( final Object c : this.crafters )
{
if( c instanceof ICrafting )
{
final ICrafting cr = (ICrafting) c;
this.queueInventory( cr );
}
}
}
@Override
public void updateSetting( final IConfigManager manager, final Enum settingName, final Enum newValue )
{
if( this.getGui() != null )
{
this.getGui().updateSetting( manager, settingName, newValue );
}
}
@Override
public IConfigManager getConfigManager()
{
if( Platform.isServer() )
{
return this.serverCM;
}
return this.clientCM;
}
public ItemStack[] getViewCells()
{
final ItemStack[] list = new ItemStack[this.cellView.length];
for( int x = 0; x < this.cellView.length; x++ )
{
list[x] = this.cellView[x].getStack();
}
return list;
}
public SlotRestrictedInput getCellViewSlot( final int index )
{
return this.cellView[index];
}
public boolean isPowered()
{
return this.hasPower;
}
private void setPowered( final boolean isPowered )
{
this.hasPower = isPowered;
}
private IConfigManagerHost getGui()
{
return this.gui;
}
public void setGui( @Nonnull final IConfigManagerHost gui )
{
this.gui = gui;
}
}
@@ -0,0 +1,625 @@
package com.glodblock.github.client.gui.container;
import appeng.api.AEApi;
import appeng.api.config.Actionable;
import appeng.api.definitions.IDefinitions;
import appeng.api.networking.security.MachineSource;
import appeng.api.storage.IMEMonitor;
import appeng.api.storage.ITerminalHost;
import appeng.api.storage.data.IAEItemStack;
import appeng.api.storage.data.IItemList;
import appeng.container.ContainerNull;
import appeng.container.guisync.GuiSync;
import appeng.container.slot.*;
import appeng.core.sync.packets.PacketPatternSlot;
import appeng.helpers.IContainerCraftingPacket;
import appeng.items.storage.ItemViewCell;
import appeng.tile.inventory.AppEngInternalInventory;
import appeng.tile.inventory.IAEAppEngInventory;
import appeng.tile.inventory.InvOperation;
import appeng.util.InventoryAdaptor;
import appeng.util.Platform;
import appeng.util.inv.AdaptorPlayerHand;
import appeng.util.item.AEItemStack;
import com.glodblock.github.common.item.ItemFluidPacket;
import com.glodblock.github.common.parts.PartFluidPatternTerminal;
import com.glodblock.github.util.Util;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.*;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.CraftingManager;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.nbt.NBTBase;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.FluidStack;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.stream.Collectors;
public class FCBasePartContainer extends FCBaseMonitorContain implements IAEAppEngInventory, IOptionalSlotHost, IContainerCraftingPacket {
private final PartFluidPatternTerminal patternTerminal;
private final AppEngInternalInventory cOut = new AppEngInternalInventory( null, 1 );
private final IInventory crafting;
protected final SlotFakeCraftingMatrix[] craftingSlots = new SlotFakeCraftingMatrix[9];
protected final OptionalSlotFake[] outputSlots = new OptionalSlotFake[3];
protected final SlotPatternTerm craftSlot;
protected final SlotRestrictedInput patternSlotIN;
protected final SlotRestrictedInput patternSlotOUT;
@GuiSync( 97 )
public boolean craftingMode = true;
@GuiSync( 96 )
public boolean substitute = false;
public FCBasePartContainer(final InventoryPlayer ip, final ITerminalHost monitorable )
{
super( ip, monitorable, false );
this.patternTerminal = (PartFluidPatternTerminal) monitorable;
final IInventory patternInv = this.getPatternTerminal().getInventoryByName( "pattern" );
final IInventory output = this.getPatternTerminal().getInventoryByName( "output" );
this.crafting = this.getPatternTerminal().getInventoryByName( "crafting" );
for( int y = 0; y < 3; y++ )
{
for( int x = 0; x < 3; x++ )
{
this.addSlotToContainer( this.craftingSlots[x + y * 3] = new SlotFakeCraftingMatrix( this.crafting, x + y * 3, 18 + x * 18, -76 + y * 18 ) );
}
}
this.addSlotToContainer( this.craftSlot = new SlotPatternTerm( ip.player, this.getActionSource(), this.getPowerSource(), monitorable, this.crafting, patternInv, this.cOut, 110, -76 + 18, this, 2, this ) );
this.craftSlot.setIIcon( -1 );
for( int y = 0; y < 3; y++ )
{
this.addSlotToContainer( this.outputSlots[y] = new SlotPatternOutputs( output, this, y, 110, -76 + y * 18, 0, 0, 1 ) );
this.outputSlots[y].setRenderDisabled( false );
}
this.addSlotToContainer( this.patternSlotIN = new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.BLANK_PATTERN, patternInv, 0, 147, -72 - 9, this.getInventoryPlayer() ) );
this.addSlotToContainer( this.patternSlotOUT = new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.ENCODED_PATTERN, patternInv, 1, 147, -72 + 34, this.getInventoryPlayer() ) );
this.patternSlotOUT.setStackLimit( 1 );
this.bindPlayerInventory( ip, 0, 0 );
this.updateOrderOfOutputSlots();
}
private void updateOrderOfOutputSlots()
{
if( !this.isCraftingMode() )
{
this.craftSlot.xDisplayPosition = -9000;
for( int y = 0; y < 3; y++ )
{
this.outputSlots[y].xDisplayPosition = this.outputSlots[y].getX();
}
}
else
{
this.craftSlot.xDisplayPosition = this.craftSlot.getX();
for( int y = 0; y < 3; y++ )
{
this.outputSlots[y].xDisplayPosition = -9000;
}
}
}
@Override
public void putStackInSlot( final int par1, final ItemStack par2ItemStack )
{
super.putStackInSlot( par1, par2ItemStack );
this.getAndUpdateOutput();
}
@Override
public void putStacksInSlots( final ItemStack[] par1ArrayOfItemStack )
{
super.putStacksInSlots( par1ArrayOfItemStack );
this.getAndUpdateOutput();
}
private ItemStack getAndUpdateOutput()
{
final InventoryCrafting ic = new InventoryCrafting( this, 3, 3 );
for( int x = 0; x < ic.getSizeInventory(); x++ )
{
ic.setInventorySlotContents( x, this.crafting.getStackInSlot( x ) );
}
final ItemStack is = CraftingManager.getInstance().findMatchingRecipe( ic, this.getPlayerInv().player.worldObj );
this.cOut.setInventorySlotContents( 0, is );
return is;
}
@Override
public void saveChanges()
{
}
@Override
public void onChangeInventory(final IInventory inv, final int slot, final InvOperation mc, final ItemStack removedStack, final ItemStack newStack )
{
}
public void encodeAndMoveToInventory()
{
encode();
ItemStack output = this.patternSlotOUT.getStack();
if ( output != null )
{
if (!getPlayerInv().addItemStackToInventory( output )){
getPlayerInv().player.entityDropItem(output, 0);
}
this.patternSlotOUT.putStack( null );
}
}
public void encode()
{
ItemStack output = this.patternSlotOUT.getStack();
final ItemStack[] in = this.getInputs();
final ItemStack[] out = this.getOutputs();
// if there is no input, this would be silly.
if( in == null || out == null )
{
return;
}
// first check the output slots, should either be null, or a pattern
if( output != null && !this.isPattern( output ) )
{
return;
}// if nothing is there we should snag a new pattern.
else if( output == null )
{
output = this.patternSlotIN.getStack();
if (!this.isPattern( output ))
{
return; // no blanks.
}
// remove one, and clear the input slot.
output.stackSize--;
if( output.stackSize == 0 )
{
this.patternSlotIN.putStack( null );
}
// add a new encoded pattern.
for( final ItemStack encodedPatternStack : AEApi.instance().definitions().items().encodedPattern().maybeStack( 1 ).asSet() )
{
output = encodedPatternStack;
this.patternSlotOUT.putStack( output );
}
}
// encode the slot.
final NBTTagCompound encodedValue = new NBTTagCompound();
final NBTTagList tagIn = new NBTTagList();
final NBTTagList tagOut = new NBTTagList();
for( final ItemStack i : in )
{
tagIn.appendTag( this.createItemTag( i ) );
}
for( final ItemStack i : out )
{
tagOut.appendTag( this.createItemTag( i ) );
}
encodedValue.setTag( "in", tagIn );
encodedValue.setTag( "out", tagOut );
encodedValue.setBoolean( "crafting", this.isCraftingMode() );
encodedValue.setBoolean( "substitute", this.isSubstitute() );
output.setTagCompound( encodedValue );
}
private ItemStack[] getInputs()
{
final ItemStack[] input = new ItemStack[9];
boolean hasValue = false;
for( int x = 0; x < this.craftingSlots.length; x++ )
{
input[x] = this.craftingSlots[x].getStack();
if( input[x] != null )
{
hasValue = true;
}
}
if( hasValue )
{
return input;
}
return null;
}
private ItemStack[] getOutputs()
{
if( this.isCraftingMode() )
{
final ItemStack out = this.getAndUpdateOutput();
if( out != null && out.stackSize > 0 )
{
return new ItemStack[] { out };
}
}
else
{
final List<ItemStack> list = new ArrayList<>( 3 );
boolean hasValue = false;
for( final OptionalSlotFake outputSlot : this.outputSlots )
{
final ItemStack out = outputSlot.getStack();
if( out != null && out.stackSize > 0 )
{
list.add( out );
hasValue = true;
}
}
if( hasValue )
{
return list.toArray( new ItemStack[list.size()] );
}
}
return null;
}
private boolean isPattern( final ItemStack output )
{
if( output == null )
{
return false;
}
final IDefinitions definitions = AEApi.instance().definitions();
boolean isPattern = definitions.items().encodedPattern().isSameAs( output );
isPattern |= definitions.materials().blankPattern().isSameAs( output );
return isPattern;
}
private NBTBase createItemTag(final ItemStack i )
{
final NBTTagCompound c = new NBTTagCompound();
if( i != null )
{
i.writeToNBT( c );
}
return c;
}
@Override
public boolean isSlotEnabled( final int idx )
{
if( idx == 1 )
{
return Platform.isServer() ? !this.getPatternTerminal().isCraftingRecipe() : !this.isCraftingMode();
}
else if( idx == 2 )
{
return Platform.isServer() ? this.getPatternTerminal().isCraftingRecipe() : this.isCraftingMode();
}
else
{
return false;
}
}
public void craftOrGetItem( final PacketPatternSlot packetPatternSlot )
{
if( packetPatternSlot.slotItem != null && this.getCellInventory() != null )
{
final IAEItemStack out = packetPatternSlot.slotItem.copy();
InventoryAdaptor inv = new AdaptorPlayerHand( this.getPlayerInv().player );
final InventoryAdaptor playerInv = InventoryAdaptor.getAdaptor( this.getPlayerInv().player, ForgeDirection.UNKNOWN );
if( packetPatternSlot.shift )
{
inv = playerInv;
}
if( inv.simulateAdd( out.getItemStack() ) != null )
{
return;
}
final IAEItemStack extracted = Platform.poweredExtraction( this.getPowerSource(), this.getCellInventory(), out, this.getActionSource() );
final EntityPlayer p = this.getPlayerInv().player;
if( extracted != null )
{
inv.addItems( extracted.getItemStack() );
if( p instanceof EntityPlayerMP)
{
this.updateHeld( (EntityPlayerMP) p );
}
this.detectAndSendChanges();
return;
}
final InventoryCrafting ic = new InventoryCrafting( new ContainerNull(), 3, 3 );
final InventoryCrafting real = new InventoryCrafting( new ContainerNull(), 3, 3 );
for( int x = 0; x < 9; x++ )
{
ic.setInventorySlotContents( x, packetPatternSlot.pattern[x] == null ? null : packetPatternSlot.pattern[x].getItemStack() );
}
final IRecipe r = Platform.findMatchingRecipe( ic, p.worldObj );
if( r == null )
{
return;
}
final IMEMonitor<IAEItemStack> storage = this.getPatternTerminal().getItemInventory();
final IItemList<IAEItemStack> all = storage.getStorageList();
final ItemStack is = r.getCraftingResult( ic );
for( int x = 0; x < ic.getSizeInventory(); x++ )
{
if( ic.getStackInSlot( x ) != null )
{
final ItemStack pulled = Platform.extractItemsByRecipe( this.getPowerSource(), this.getActionSource(), storage, p.worldObj, r, is, ic, ic.getStackInSlot( x ), x, all, Actionable.MODULATE, ItemViewCell.createFilter( this.getViewCells() ) );
real.setInventorySlotContents( x, pulled );
}
}
final IRecipe rr = Platform.findMatchingRecipe( real, p.worldObj );
if( rr == r && Platform.isSameItemPrecise( rr.getCraftingResult( real ), is ) )
{
final SlotCrafting sc = new SlotCrafting( p, real, this.cOut, 0, 0, 0 );
sc.onPickupFromSlot( p, is );
for( int x = 0; x < real.getSizeInventory(); x++ )
{
final ItemStack failed = playerInv.addItems( real.getStackInSlot( x ) );
if( failed != null )
{
p.dropPlayerItemWithRandomChoice( failed, false );
}
}
inv.addItems( is );
if( p instanceof EntityPlayerMP )
{
this.updateHeld( (EntityPlayerMP) p );
}
this.detectAndSendChanges();
}
else
{
for( int x = 0; x < real.getSizeInventory(); x++ )
{
final ItemStack failed = real.getStackInSlot( x );
if( failed != null )
{
this.getCellInventory().injectItems( AEItemStack.create( failed ), Actionable.MODULATE, new MachineSource( this.getPatternTerminal() ) );
}
}
}
}
}
@Override
public void detectAndSendChanges()
{
super.detectAndSendChanges();
if( Platform.isServer() )
{
if( this.isCraftingMode() != this.getPatternTerminal().isCraftingRecipe() )
{
this.setCraftingMode( this.getPatternTerminal().isCraftingRecipe() );
this.updateOrderOfOutputSlots();
}
this.substitute = this.patternTerminal.isSubstitution();
}
}
@Override
public void onUpdate( final String field, final Object oldValue, final Object newValue )
{
super.onUpdate( field, oldValue, newValue );
if( field.equals( "craftingMode" ) )
{
this.getAndUpdateOutput();
this.updateOrderOfOutputSlots();
}
}
@Override
public void onSlotChange( final Slot s )
{
if( s == this.patternSlotOUT && 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 void clear()
{
for( final Slot s : this.craftingSlots )
{
s.putStack( null );
}
for( final Slot s : this.outputSlots )
{
s.putStack( null );
}
this.detectAndSendChanges();
this.getAndUpdateOutput();
}
@Override
public IInventory getInventoryByName( final String name )
{
if( name.equals( "player" ) )
{
return this.getInventoryPlayer();
}
return this.getPatternTerminal().getInventoryByName( name );
}
@Override
public boolean useRealItems()
{
return false;
}
public void toggleSubstitute()
{
this.substitute = !this.substitute;
this.detectAndSendChanges();
this.getAndUpdateOutput();
}
public boolean isCraftingMode()
{
return this.craftingMode;
}
private void setCraftingMode( final boolean craftingMode )
{
this.craftingMode = craftingMode;
}
public PartFluidPatternTerminal getPatternTerminal()
{
return this.patternTerminal;
}
private boolean isSubstitute()
{
return this.substitute;
}
public void setSubstitute( final boolean substitute )
{
this.substitute = substitute;
}
static boolean canDoubleStacks(SlotFake[] slots)
{
List<SlotFake> enabledSlots = Arrays.stream(slots).filter(SlotFake::isEnabled).collect(Collectors.toList());
long emptyStots = enabledSlots.stream().filter(s -> s.getStack() == null).count();
long fullSlots = enabledSlots.stream().filter(s-> s.getStack() != null && s.getStack().stackSize * 2 > 127).count();
return fullSlots <= emptyStots;
}
static void doubleStacksInternal(SlotFake[] slots)
{
List<ItemStack> overFlowStacks = new ArrayList<>();
List<SlotFake> enabledSlots = Arrays.stream(slots).filter(SlotFake::isEnabled).collect(Collectors.toList());
for (final Slot s : enabledSlots)
{
ItemStack st = s.getStack();
if (st == null)
continue;
if (Util.isFluidPacket(st)) {
FluidStack fluidStack = ItemFluidPacket.getFluidStack(st);
if (fluidStack != null) {
fluidStack = ItemFluidPacket.getFluidStack(st).copy();
if (fluidStack.amount < Integer.MAX_VALUE / 2)
fluidStack.amount *= 2;
}
s.putStack(ItemFluidPacket.newStack(fluidStack));
}
else if (st.stackSize * 2 > 127)
{
overFlowStacks.add(st.copy());
}
else
{
st.stackSize *= 2;
s.putStack(st);
}
}
Iterator<ItemStack> ow = overFlowStacks.iterator();
for (final Slot s : enabledSlots) {
if (!ow.hasNext())
break;
if (s.getStack() != null)
continue;
s.putStack(ow.next());
}
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 containsFluid(SlotFake[] slots) {
List<SlotFake> enabledSlots = Arrays.stream(slots).filter(SlotFake::isEnabled).collect(Collectors.toList());
long fluid = enabledSlots.stream().filter(s -> Util.isFluidPacket(s.getStack())).count();
return fluid > 0;
}
}