Patterns can now be encoded.

Added a clear button to the Pattern Terminal.
Added description to the Encoded Pattern Item.
This commit is contained in:
AlgorithmX2 2014-04-17 01:15:56 -05:00
parent f14581edae
commit 67d46d57d2
8 changed files with 270 additions and 38 deletions

View file

@ -25,6 +25,7 @@ public class GuiPatternTerm extends GuiMEMonitorable
GuiTabButton tabProcessButton; GuiTabButton tabProcessButton;
GuiImgButton substitutionsBtn; GuiImgButton substitutionsBtn;
GuiImgButton encodeBtn; GuiImgButton encodeBtn;
GuiImgButton clearBtn;
@Override @Override
public void initGui() public void initGui()
@ -34,9 +35,14 @@ public class GuiPatternTerm extends GuiMEMonitorable
GuiText.CraftingPattern.getLocal(), itemRender ) ); GuiText.CraftingPattern.getLocal(), itemRender ) );
buttonList.add( tabProcessButton = new GuiTabButton( this.guiLeft + 173, this.guiTop + this.ySize - 179, new ItemStack( Blocks.furnace ), buttonList.add( tabProcessButton = new GuiTabButton( this.guiLeft + 173, this.guiTop + this.ySize - 179, new ItemStack( Blocks.furnace ),
GuiText.ProcessingPattern.getLocal(), itemRender ) ); GuiText.ProcessingPattern.getLocal(), itemRender ) );
buttonList.add( substitutionsBtn = new GuiImgButton( this.guiLeft + 74, this.guiTop + this.ySize - 163, Settings.ACTIONS, ActionItems.SUBSTITUTION ) );
buttonList.add( encodeBtn = new GuiImgButton( this.guiLeft + 147, this.guiTop + this.ySize - 144, Settings.ACTIONS, ActionItems.ENCODE ) ); buttonList.add( substitutionsBtn = new GuiImgButton( this.guiLeft + 84, this.guiTop + this.ySize - 163, Settings.ACTIONS, ActionItems.SUBSTITUTION ) );
substitutionsBtn.halfSize = true; substitutionsBtn.halfSize = true;
buttonList.add( clearBtn = new GuiImgButton( this.guiLeft + 74, this.guiTop + this.ySize - 163, Settings.ACTIONS, ActionItems.CLOSE ) );
clearBtn.halfSize = true;
buttonList.add( encodeBtn = new GuiImgButton( this.guiLeft + 147, this.guiTop + this.ySize - 144, Settings.ACTIONS, ActionItems.ENCODE ) );
} }
@Override @Override
@ -46,6 +52,7 @@ public class GuiPatternTerm extends GuiMEMonitorable
try try
{ {
if ( tabCraftButton == btn || tabProcessButton == btn ) if ( tabCraftButton == btn || tabProcessButton == btn )
{ {
NetworkHandler.instance.sendToServer( new PacketValueConfig( "PatternTerminal.CraftMode", tabProcessButton == btn ? "0" : "1" ) ); NetworkHandler.instance.sendToServer( new PacketValueConfig( "PatternTerminal.CraftMode", tabProcessButton == btn ? "0" : "1" ) );
@ -55,6 +62,12 @@ public class GuiPatternTerm extends GuiMEMonitorable
{ {
NetworkHandler.instance.sendToServer( new PacketValueConfig( "PatternTerminal.Encode", "1" ) ); NetworkHandler.instance.sendToServer( new PacketValueConfig( "PatternTerminal.Encode", "1" ) );
} }
if ( clearBtn == btn )
{
NetworkHandler.instance.sendToServer( new PacketValueConfig( "PatternTerminal.Clear", "1" ) );
}
} }
catch (IOException e) catch (IOException e)
{ {

View file

@ -744,7 +744,7 @@ public abstract class AEBaseContainer extends Container
updateProgressBar( id, (int) value ); updateProgressBar( id, (int) value );
} }
private void updateHeld(EntityPlayerMP p) protected void updateHeld(EntityPlayerMP p)
{ {
try try
{ {

View file

@ -1,15 +1,24 @@
package appeng.container.implementations; package appeng.container.implementations;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.ICrafting; import net.minecraft.inventory.ICrafting;
import net.minecraft.inventory.IInventory; import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.InventoryCrafting; import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.inventory.Slot;
import net.minecraft.inventory.SlotCrafting; import net.minecraft.inventory.SlotCrafting;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.CraftingManager; import net.minecraft.item.crafting.CraftingManager;
import net.minecraft.item.crafting.IRecipe; 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.common.util.ForgeDirection;
import appeng.api.AEApi;
import appeng.api.config.Actionable; import appeng.api.config.Actionable;
import appeng.api.networking.security.MachineSource; import appeng.api.networking.security.MachineSource;
import appeng.api.storage.IMEMonitor; import appeng.api.storage.IMEMonitor;
@ -103,17 +112,17 @@ public class ContainerPatternTerm extends ContainerMEMonitorable implements IAEA
public void putStackInSlot(int par1, ItemStack par2ItemStack) public void putStackInSlot(int par1, ItemStack par2ItemStack)
{ {
super.putStackInSlot( par1, par2ItemStack ); super.putStackInSlot( par1, par2ItemStack );
updateOutput(); getAndUpdateOutput();
} }
@Override @Override
public void putStacksInSlots(ItemStack[] par1ArrayOfItemStack) public void putStacksInSlots(ItemStack[] par1ArrayOfItemStack)
{ {
super.putStacksInSlots( par1ArrayOfItemStack ); super.putStacksInSlots( par1ArrayOfItemStack );
updateOutput(); getAndUpdateOutput();
} }
public void updateOutput() public ItemStack getAndUpdateOutput()
{ {
InventoryCrafting ic = new InventoryCrafting( this, 3, 3 ); InventoryCrafting ic = new InventoryCrafting( this, 3, 3 );
for (int x = 0; x < ic.getSizeInventory(); x++) for (int x = 0; x < ic.getSizeInventory(); x++)
@ -121,6 +130,7 @@ public class ContainerPatternTerm extends ContainerMEMonitorable implements IAEA
ItemStack is = CraftingManager.getInstance().findMatchingRecipe( ic, this.getPlayerInv().player.worldObj ); ItemStack is = CraftingManager.getInstance().findMatchingRecipe( ic, this.getPlayerInv().player.worldObj );
cOut.setInventorySlotContents( 0, is ); cOut.setInventorySlotContents( 0, is );
return is;
} }
@Override @Override
@ -150,7 +160,7 @@ public class ContainerPatternTerm extends ContainerMEMonitorable implements IAEA
if ( idx == 97 ) if ( idx == 97 )
{ {
craftingMode = value == 1; craftingMode = value == 1;
updateOutput(); getAndUpdateOutput();
updateOrderOfOutputSlots(); updateOrderOfOutputSlots();
} }
} }
@ -163,16 +173,127 @@ public class ContainerPatternTerm extends ContainerMEMonitorable implements IAEA
public void encode() public void encode()
{ {
ItemStack output = patternSlotOUT.getStack();
ItemStack[] in = getInputs();
ItemStack[] out = getOutputs();
// if theres 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 && !isPattern( output ) )
return;
// if nothing is there we should snag a new pattern.
else if ( output == null )
{
output = patternSlotIN.getStack();
if ( output == null || !isPattern( output ) )
return; // no blanks.
// remove one, and clear the input slot.
output.stackSize--;
if ( output.stackSize == 0 )
patternSlotIN.putStack( null );
// add a new encoded pattern.
patternSlotOUT.putStack( output = AEApi.instance().items().itemEncodedPattern.stack( 1 ) );
}
// encode the slot.
NBTTagCompound encodedValue = new NBTTagCompound();
NBTTagList tagIn = new NBTTagList();
NBTTagList tagOut = new NBTTagList();
for (ItemStack i : in)
tagIn.appendTag( createItemTag( i ) );
for (ItemStack i : out)
tagOut.appendTag( createItemTag( i ) );
encodedValue.setTag( "in", tagIn );
encodedValue.setTag( "out", tagOut );
encodedValue.setBoolean( "crafting", craftingMode );
output.setTagCompound( encodedValue );
}
private NBTBase createItemTag(ItemStack i)
{
NBTTagCompound c = new NBTTagCompound();
if ( i != null )
i.writeToNBT( c );
return c;
}
private ItemStack[] getInputs()
{
ItemStack[] input = new ItemStack[9];
boolean hasValue = false;
for (int x = 0; x < craftingSlots.length; x++)
{
input[x] = craftingSlots[x].getStack();
if ( input[x] != null )
hasValue = true;
}
if ( hasValue )
return input;
return null;
}
private ItemStack[] getOutputs()
{
if ( craftingMode )
{
ItemStack out = getAndUpdateOutput();
if ( out != null )
return new ItemStack[] { out };
}
else
{
List<ItemStack> list = new ArrayList( 3 );
boolean hasValue = false;
for (int x = 0; x < outputSlots.length; x++)
{
ItemStack out = outputSlots[x].getStack();
if ( out != null )
{
list.add( out );
hasValue = true;
}
}
if ( hasValue )
return list.toArray( new ItemStack[list.size()] );
}
return null;
}
private boolean isPattern(ItemStack output)
{
if ( output == null )
return false;
return AEApi.instance().items().itemEncodedPattern.sameAs( output ) || AEApi.instance().materials().materialBlankPattern.sameAs( output );
} }
@Override @Override
public boolean isSlotEnabled(int idx) public boolean isSlotEnabled(int idx)
{ {
if ( idx == 1 ) if ( idx == 1 )
return craftingMode == false; return Platform.isServer() ? ct.craftingMode == false : craftingMode == false;
if ( idx == 2 ) if ( idx == 2 )
return craftingMode == true; return Platform.isServer() ? ct.craftingMode == true : craftingMode == true;
return false; return false;
} }
@ -197,9 +318,13 @@ public class ContainerPatternTerm extends ContainerMEMonitorable implements IAEA
return; return;
IAEItemStack extracted = Platform.poweredExtraction( powerSrc, cellInv, out, mySrc ); IAEItemStack extracted = Platform.poweredExtraction( powerSrc, cellInv, out, mySrc );
EntityPlayer p = getPlayerInv().player;
if ( extracted != null ) if ( extracted != null )
{ {
inv.addItems( extracted.getItemStack() ); inv.addItems( extracted.getItemStack() );
if ( p instanceof EntityPlayerMP )
updateHeld( (EntityPlayerMP) p );
detectAndSendChanges(); detectAndSendChanges();
return; return;
} }
@ -211,7 +336,6 @@ public class ContainerPatternTerm extends ContainerMEMonitorable implements IAEA
ic.setInventorySlotContents( x, packetPatternSlot.pattern[x] == null ? null : packetPatternSlot.pattern[x].getItemStack() ); ic.setInventorySlotContents( x, packetPatternSlot.pattern[x] == null ? null : packetPatternSlot.pattern[x].getItemStack() );
} }
EntityPlayer p = getPlayerInv().player;
IRecipe r = Platform.findMatchingRecipe( ic, p.worldObj ); IRecipe r = Platform.findMatchingRecipe( ic, p.worldObj );
if ( r == null ) if ( r == null )
@ -249,6 +373,8 @@ public class ContainerPatternTerm extends ContainerMEMonitorable implements IAEA
} }
inv.addItems( is ); inv.addItems( is );
if ( p instanceof EntityPlayerMP )
updateHeld( (EntityPlayerMP) p );
detectAndSendChanges(); detectAndSendChanges();
} }
else else
@ -265,4 +391,16 @@ public class ContainerPatternTerm extends ContainerMEMonitorable implements IAEA
} }
} }
public void clear()
{
for (Slot s : craftingSlots)
s.putStack( null );
for (Slot s : outputSlots)
s.putStack( null );
detectAndSendChanges();
getAndUpdateOutput();
}
} }

View file

@ -95,12 +95,12 @@ import appeng.hooks.TickHandler;
import appeng.items.materials.ItemMaterial; import appeng.items.materials.ItemMaterial;
import appeng.items.materials.MaterialType; import appeng.items.materials.MaterialType;
import appeng.items.misc.ItemCrystalSeed; import appeng.items.misc.ItemCrystalSeed;
import appeng.items.misc.ItemEncodedPattern;
import appeng.items.parts.ItemFacade; import appeng.items.parts.ItemFacade;
import appeng.items.parts.ItemPart; import appeng.items.parts.ItemPart;
import appeng.items.parts.PartType; import appeng.items.parts.PartType;
import appeng.items.storage.ItemBasicStorageCell; import appeng.items.storage.ItemBasicStorageCell;
import appeng.items.storage.ItemCreativeStorageCell; import appeng.items.storage.ItemCreativeStorageCell;
import appeng.items.storage.ItemEncodedPattern;
import appeng.items.storage.ItemSpatialStorageCell; import appeng.items.storage.ItemSpatialStorageCell;
import appeng.items.storage.ItemViewCell; import appeng.items.storage.ItemViewCell;
import appeng.items.tools.ToolBiometricCard; import appeng.items.tools.ToolBiometricCard;

View file

@ -28,7 +28,7 @@ public enum GuiText
StoredPower, MaxPower, RequiredPower, Efficiency, CopyMode, CopyModeDesc, PatternTerminal, StoredPower, MaxPower, RequiredPower, Efficiency, CopyMode, CopyModeDesc, PatternTerminal,
CraftingPattern, ProcessingPattern; CraftingPattern, ProcessingPattern, Crafts, Creates, And, With;
String root; String root;

View file

@ -78,6 +78,10 @@ public class PacketValueConfig extends AppEngPacket
{ {
cpt.encode(); cpt.encode();
} }
else if ( Name.equals( "PatternTerminal.Clear" ) )
{
cpt.clear();
}
} }
else if ( Name.startsWith( "CellWorkbench." ) && c instanceof ContainerCellWorkbench ) else if ( Name.startsWith( "CellWorkbench." ) && c instanceof ContainerCellWorkbench )
{ {

View file

@ -0,0 +1,103 @@
package appeng.items.misc;
import java.util.EnumSet;
import java.util.List;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import appeng.api.crafting.ICraftingPatternDetails;
import appeng.api.implementations.ICraftingPatternItem;
import appeng.core.features.AEFeature;
import appeng.core.localization.GuiText;
import appeng.items.AEBaseItem;
import appeng.util.Platform;
public class ItemEncodedPattern extends AEBaseItem implements ICraftingPatternItem
{
public ItemEncodedPattern() {
super( ItemEncodedPattern.class );
setfeature( EnumSet.of( AEFeature.Crafting ) );
setMaxStackSize( 1 );
}
@Override
public void addInformation(ItemStack is, EntityPlayer p, List l, boolean more)
{
NBTTagCompound encodedValue = is.getTagCompound();
if ( encodedValue == null )
return;
NBTTagList inTag = encodedValue.getTagList( "in", 10 );
NBTTagList outTag = encodedValue.getTagList( "out", 10 );
boolean isCrafting = encodedValue.getBoolean( "crafting" );
// kinda needs info..
if ( inTag.tagCount() == 0 || outTag.tagCount() == 0 )
return;
ItemStack[] in = new ItemStack[inTag.tagCount()];
ItemStack[] out = new ItemStack[outTag.tagCount()];
readItems( in, inTag );
readItems( out, outTag );
String label = (isCrafting ? GuiText.Crafts.getLocal() : GuiText.Creates.getLocal()) + ": ";
String and = " " + GuiText.And.getLocal() + " ";
String with = GuiText.With.getLocal() + ": ";
boolean first = true;
for (int x = 0; x < out.length; x++)
{
if ( out[x] == null )
continue;
l.add( (first ? label : and) + out[x].stackSize + " " + Platform.getItemDisplayName( out[x] ) );
first = false;
}
first = true;
for (int x = 0; x < in.length; x++)
{
if ( in[x] == null )
continue;
l.add( (first ? with : and) + in[x].stackSize + " " + Platform.getItemDisplayName( in[x] ) );
first = false;
}
}
private void readItems(ItemStack[] itemList, NBTTagList tagSrc)
{
for (int x = 0; x < itemList.length; x++)
{
ItemStack readItem = ItemStack.loadItemStackFromNBT( tagSrc.getCompoundTagAt( x ) );
if ( readItem != null )
{
boolean used = false;
for (int y = 0; y < x; y++)
{
if ( itemList[y] != null && Platform.isSameItemPrecise( readItem, itemList[y] ) )
{
itemList[y].stackSize += readItem.stackSize;
used = true;
}
}
if ( !used )
itemList[x] = readItem;
}
}
}
@Override
public ICraftingPatternDetails getPatternForItem(ItemStack is)
{
return null;
}
}

View file

@ -1,26 +0,0 @@
package appeng.items.storage;
import java.util.EnumSet;
import net.minecraft.item.ItemStack;
import appeng.api.crafting.ICraftingPatternDetails;
import appeng.api.implementations.ICraftingPatternItem;
import appeng.core.features.AEFeature;
import appeng.items.AEBaseItem;
public class ItemEncodedPattern extends AEBaseItem implements ICraftingPatternItem
{
public ItemEncodedPattern() {
super( ItemEncodedPattern.class );
setfeature( EnumSet.of( AEFeature.Crafting ) );
setMaxStackSize( 1 );
}
@Override
public ICraftingPatternDetails getPatternForItem(ItemStack is)
{
return null;
}
}