Fix issues with Pattern Terminal.

This commit is contained in:
AlgorithmX2
2014-07-01 20:43:08 -05:00
parent 8705180bae
commit 4ce40869f4
5 changed files with 108 additions and 14 deletions
@@ -144,8 +144,8 @@ public class GuiMEMonitorable extends AEBaseMEGui implements ISortSource, IConfi
boolean hasNEI = AppEng.instance.isIntegrationEnabled( "NEI" ); boolean hasNEI = AppEng.instance.isIntegrationEnabled( "NEI" );
int NEI = hasNEI ? 4 : 0; int NEI = hasNEI ? 0 : 0;
int top = hasNEI ? 22 : 4; int top = hasNEI ? 22 : 0;
int magicNumber = 114 + 1; int magicNumber = 114 + 1;
int extraSpace = height - magicNumber - NEI - top - reservedSpace; int extraSpace = height - magicNumber - NEI - top - reservedSpace;
@@ -183,7 +183,9 @@ public class GuiMEMonitorable extends AEBaseMEGui implements ISortSource, IConfi
// slot 18 // slot 18
this.ySize = magicNumber + rows * 18 + reservedSpace; this.ySize = magicNumber + rows * 18 + reservedSpace;
this.guiTop = top; // this.guiTop = top;
int unusedSpace = height - ySize;
guiTop = (int) Math.floor( (float) unusedSpace / (unusedSpace < 0 ? 3.8f : 2.0f) );
int offset = guiTop + 8; int offset = guiTop + 8;
@@ -235,9 +237,15 @@ public class GuiMEMonitorable extends AEBaseMEGui implements ISortSource, IConfi
if ( s instanceof AppEngSlot ) if ( s instanceof AppEngSlot )
{ {
if ( ((AppEngSlot) s).xDisplayPosition < 197 ) if ( ((AppEngSlot) s).xDisplayPosition < 197 )
((AppEngSlot) s).yDisplayPosition = ((AppEngSlot) s).defY + ySize - 78 - 5; repositionSlot( (AppEngSlot) s );
} }
} }
}
protected void repositionSlot(AppEngSlot s)
{
s.yDisplayPosition = s.defY + ySize - 78 - 5;
} }
@Override @Override
+11 -2
View File
@@ -12,6 +12,7 @@ import appeng.api.storage.ITerminalHost;
import appeng.client.gui.widgets.GuiImgButton; import appeng.client.gui.widgets.GuiImgButton;
import appeng.client.gui.widgets.GuiTabButton; import appeng.client.gui.widgets.GuiTabButton;
import appeng.container.implementations.ContainerPatternTerm; import appeng.container.implementations.ContainerPatternTerm;
import appeng.container.slot.AppEngSlot;
import appeng.core.localization.GuiText; import appeng.core.localization.GuiText;
import appeng.core.sync.network.NetworkHandler; import appeng.core.sync.network.NetworkHandler;
import appeng.core.sync.packets.PacketValueConfig; import appeng.core.sync.packets.PacketValueConfig;
@@ -42,7 +43,7 @@ public class GuiPatternTerm extends GuiMEMonitorable
buttonList.add( clearBtn = new GuiImgButton( this.guiLeft + 74, this.guiTop + this.ySize - 163, Settings.ACTIONS, ActionItems.CLOSE ) ); buttonList.add( clearBtn = new GuiImgButton( this.guiLeft + 74, this.guiTop + this.ySize - 163, Settings.ACTIONS, ActionItems.CLOSE ) );
clearBtn.halfSize = true; clearBtn.halfSize = true;
buttonList.add( encodeBtn = new GuiImgButton( this.guiLeft + 147, this.guiTop + this.ySize - 144, Settings.ACTIONS, ActionItems.ENCODE ) ); buttonList.add( encodeBtn = new GuiImgButton( this.guiLeft + 147, this.guiTop + this.ySize - 142, Settings.ACTIONS, ActionItems.ENCODE ) );
} }
@Override @Override
@@ -81,10 +82,18 @@ public class GuiPatternTerm extends GuiMEMonitorable
} }
} }
protected void repositionSlot(AppEngSlot s)
{
if ( s.isPlayerSide() )
s.yDisplayPosition = s.defY + ySize - 78 - 5;
else
s.yDisplayPosition = s.defY + ySize - 78 - 3;
}
public GuiPatternTerm(InventoryPlayer inventoryPlayer, ITerminalHost te) { public GuiPatternTerm(InventoryPlayer inventoryPlayer, ITerminalHost te) {
super( inventoryPlayer, te, new ContainerPatternTerm( inventoryPlayer, te ) ); super( inventoryPlayer, te, new ContainerPatternTerm( inventoryPlayer, te ) );
container = (ContainerPatternTerm) this.inventorySlots; container = (ContainerPatternTerm) this.inventorySlots;
reservedSpace = 85; reservedSpace = 81;
} }
protected String getBackground() protected String getBackground()
@@ -141,9 +141,9 @@ public class ContainerPatternTerm extends ContainerMEMonitorable implements IAEA
super.detectAndSendChanges(); super.detectAndSendChanges();
if ( Platform.isServer() ) if ( Platform.isServer() )
{ {
if ( craftingMode != ct.craftingMode ) if ( craftingMode != ct.isCraftingRecipe() )
{ {
craftingMode = ct.craftingMode; craftingMode = ct.isCraftingRecipe();
updateOrderOfOutputSlots(); updateOrderOfOutputSlots();
} }
} }
@@ -285,9 +285,9 @@ public class ContainerPatternTerm extends ContainerMEMonitorable implements IAEA
public boolean isSlotEnabled(int idx) public boolean isSlotEnabled(int idx)
{ {
if ( idx == 1 ) if ( idx == 1 )
return Platform.isServer() ? ct.craftingMode == false : craftingMode == false; return Platform.isServer() ? ct.isCraftingRecipe() == false : craftingMode == false;
if ( idx == 2 ) if ( idx == 2 )
return Platform.isServer() ? ct.craftingMode == true : craftingMode == true; return Platform.isServer() ? ct.isCraftingRecipe() == true : craftingMode == true;
return false; return false;
} }
@@ -386,6 +386,26 @@ public class ContainerPatternTerm extends ContainerMEMonitorable implements IAEA
} }
} }
@Override
public ItemStack slotClick(int slotNum, int p_75144_2_, int p_75144_3_, EntityPlayer p_75144_4_)
{
Slot s = null;
for (Object g : inventorySlots)
{
if ( g instanceof Slot )
{
Slot gg = (Slot) g;
if ( gg.slotNumber == slotNum )
s = gg;
}
}
ItemStack is = super.slotClick( slotNum, p_75144_2_, p_75144_3_, p_75144_4_ );
if ( s == patternSlotOUT )
detectAndSendChanges();
return is;
}
public void clear() public void clear()
{ {
for (Slot s : craftingSlots) for (Slot s : craftingSlots)
+1 -1
View File
@@ -96,7 +96,7 @@ public class PacketValueConfig extends AppEngPacket
ContainerPatternTerm cpt = (ContainerPatternTerm) c; ContainerPatternTerm cpt = (ContainerPatternTerm) c;
if ( Name.equals( "PatternTerminal.CraftMode" ) ) if ( Name.equals( "PatternTerminal.CraftMode" ) )
{ {
cpt.ct.craftingMode = Value.equals( "1" ); cpt.ct.setCraftingRecipe( Value.equals( "1" ) );
} }
else if ( Name.equals( "PatternTerminal.Encode" ) ) else if ( Name.equals( "PatternTerminal.Encode" ) )
{ {
+60 -3
View File
@@ -5,6 +5,9 @@ import java.util.List;
import net.minecraft.inventory.IInventory; import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import appeng.api.implementations.ICraftingPatternItem;
import appeng.api.networking.crafting.ICraftingPatternDetails;
import appeng.api.storage.data.IAEItemStack;
import appeng.client.texture.CableBusTextures; import appeng.client.texture.CableBusTextures;
import appeng.core.sync.GuiBridge; import appeng.core.sync.GuiBridge;
import appeng.tile.inventory.AppEngInternalInventory; import appeng.tile.inventory.AppEngInternalInventory;
@@ -18,13 +21,13 @@ public class PartPatternTerminal extends PartTerminal implements IAEAppEngInvent
AppEngInternalInventory output = new AppEngInternalInventory( this, 3 ); AppEngInternalInventory output = new AppEngInternalInventory( this, 3 );
AppEngInternalInventory pattern = new AppEngInternalInventory( this, 2 ); AppEngInternalInventory pattern = new AppEngInternalInventory( this, 2 );
public boolean craftingMode = true; private boolean craftingMode = true;
@Override @Override
public void writeToNBT(NBTTagCompound data) public void writeToNBT(NBTTagCompound data)
{ {
super.writeToNBT( data ); super.writeToNBT( data );
data.setBoolean( "craftingMode", craftingMode ); data.setBoolean( "craftingMode", isCraftingRecipe() );
pattern.writeToNBT( data, "pattern" ); pattern.writeToNBT( data, "pattern" );
output.writeToNBT( data, "outputList" ); output.writeToNBT( data, "outputList" );
crafting.writeToNBT( data, "craftingGrid" ); crafting.writeToNBT( data, "craftingGrid" );
@@ -34,7 +37,7 @@ public class PartPatternTerminal extends PartTerminal implements IAEAppEngInvent
public void readFromNBT(NBTTagCompound data) public void readFromNBT(NBTTagCompound data)
{ {
super.readFromNBT( data ); super.readFromNBT( data );
craftingMode = data.getBoolean( "craftingMode" ); setCraftingRecipe( data.getBoolean( "craftingMode" ) );
pattern.readFromNBT( data, "pattern" ); pattern.readFromNBT( data, "pattern" );
output.readFromNBT( data, "outputList" ); output.readFromNBT( data, "outputList" );
crafting.readFromNBT( data, "craftingGrid" ); crafting.readFromNBT( data, "craftingGrid" );
@@ -78,6 +81,60 @@ public class PartPatternTerminal extends PartTerminal implements IAEAppEngInvent
@Override @Override
public void onChangeInventory(IInventory inv, int slot, InvOperation mc, ItemStack removedStack, ItemStack newStack) public void onChangeInventory(IInventory inv, int slot, InvOperation mc, ItemStack removedStack, ItemStack newStack)
{ {
if ( inv == pattern && slot == 1 )
{
ItemStack is = pattern.getStackInSlot( 1 );
if ( is != null && is.getItem() instanceof ICraftingPatternItem )
{
ICraftingPatternItem pattern = (ICraftingPatternItem) is.getItem();
ICraftingPatternDetails details = pattern.getPatternForItem( is, this.getHost().getTile().getWorldObj() );
if ( details != null )
{
setCraftingRecipe( details.isCraftable() );
for (int x = 0; x < crafting.getSizeInventory() && x < details.getInputs().length; x++)
{
IAEItemStack aeis = details.getInputs()[x];
crafting.setInventorySlotContents( x, aeis == null ? null : aeis.getItemStack() );
}
for (int x = 0; x < output.getSizeInventory() && x < details.getOutputs().length; x++)
{
IAEItemStack aeis = details.getOutputs()[x];
output.setInventorySlotContents( x, aeis == null ? null : aeis.getItemStack() );
}
}
}
}
else if ( inv == crafting )
{
fixCraftingRecipes();
}
host.markForSave(); host.markForSave();
} }
public boolean isCraftingRecipe()
{
return craftingMode;
}
public void setCraftingRecipe(boolean craftingMode)
{
this.craftingMode = craftingMode;
fixCraftingRecipes();
}
private void fixCraftingRecipes()
{
if ( isCraftingRecipe() )
{
for (int x = 0; x < crafting.getSizeInventory(); x++)
{
ItemStack is = crafting.getStackInSlot( x );
if ( is != null )
is.stackSize = 1;
}
}
}
} }