Added Basic Restrictions on slots in MAC.
This commit is contained in:
@@ -3,11 +3,17 @@ package appeng.container.implementations;
|
|||||||
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.item.ItemStack;
|
||||||
|
import net.minecraft.world.World;
|
||||||
import appeng.api.config.RedstoneMode;
|
import appeng.api.config.RedstoneMode;
|
||||||
import appeng.api.config.SecurityPermissions;
|
import appeng.api.config.SecurityPermissions;
|
||||||
import appeng.api.config.Settings;
|
import appeng.api.config.Settings;
|
||||||
|
import appeng.api.crafting.ICraftingPatternDetails;
|
||||||
|
import appeng.container.slot.SlotMACPattern;
|
||||||
|
import appeng.container.slot.SlotOutput;
|
||||||
import appeng.container.slot.SlotRestrictedInput;
|
import appeng.container.slot.SlotRestrictedInput;
|
||||||
import appeng.container.slot.SlotRestrictedInput.PlaceableItemType;
|
import appeng.container.slot.SlotRestrictedInput.PlaceableItemType;
|
||||||
|
import appeng.items.misc.ItemEncodedPattern;
|
||||||
import appeng.tile.crafting.TileMolecularAssembler;
|
import appeng.tile.crafting.TileMolecularAssembler;
|
||||||
import appeng.util.Platform;
|
import appeng.util.Platform;
|
||||||
|
|
||||||
@@ -30,23 +36,45 @@ public class ContainerMAC extends ContainerUpgradeable
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isValidItemForSlot(int slotIndex, ItemStack i)
|
||||||
|
{
|
||||||
|
IInventory mac = myte.getInventoryByName( "mac" );
|
||||||
|
|
||||||
|
ItemStack is = mac.getStackInSlot( 10 );
|
||||||
|
if ( is == null )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if ( is.getItem() instanceof ItemEncodedPattern )
|
||||||
|
{
|
||||||
|
World w = this.getTileEntity().getWorldObj();
|
||||||
|
ItemEncodedPattern iep = (ItemEncodedPattern) is.getItem();
|
||||||
|
ICraftingPatternDetails ph = iep.getPatternForItem( is, w );
|
||||||
|
return ph.isValidItemForSlot( slotIndex, i, w );
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void setupConfig()
|
protected void setupConfig()
|
||||||
{
|
{
|
||||||
int offx = 29;
|
int offx = 29;
|
||||||
int offy = 30;
|
int offy = 30;
|
||||||
|
|
||||||
IInventory cells = myte.getInventoryByName( "mac" );
|
IInventory mac = myte.getInventoryByName( "mac" );
|
||||||
|
|
||||||
for (int y = 0; y < 3; y++)
|
for (int y = 0; y < 3; y++)
|
||||||
for (int x = 0; x < 3; x++)
|
for (int x = 0; x < 3; x++)
|
||||||
addSlotToContainer( new SlotRestrictedInput( PlaceableItemType.STORAGE_CELLS, cells, x + y * 2, offx + x * 18, offy + y * 18 ) );
|
{
|
||||||
|
SlotMACPattern s = new SlotMACPattern( this, mac, x + y * 3, offx + x * 18, offy + y * 18 );
|
||||||
|
addSlotToContainer( s );
|
||||||
|
}
|
||||||
|
|
||||||
offx = 126;
|
offx = 126;
|
||||||
offy = 16;
|
offy = 16;
|
||||||
|
|
||||||
addSlotToContainer( new SlotRestrictedInput( PlaceableItemType.STORAGE_CELLS, cells, 10, offx, offy ) );
|
addSlotToContainer( new SlotRestrictedInput( PlaceableItemType.ENCODED_PATTERN, mac, 10, offx, offy ) );
|
||||||
addSlotToContainer( new SlotRestrictedInput( PlaceableItemType.STORAGE_CELLS, cells, 9, offx, offy + 32 ) );
|
addSlotToContainer( new SlotOutput( mac, 9, offx, offy + 32, -1 ) );
|
||||||
|
|
||||||
offx = 122;
|
offx = 122;
|
||||||
offy = 17;
|
offy = 17;
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
package appeng.container.slot;
|
||||||
|
|
||||||
|
import net.minecraft.inventory.IInventory;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
import appeng.container.implementations.ContainerMAC;
|
||||||
|
|
||||||
|
public class SlotMACPattern extends AppEngSlot
|
||||||
|
{
|
||||||
|
|
||||||
|
ContainerMAC mac;
|
||||||
|
|
||||||
|
public SlotMACPattern(ContainerMAC mac, IInventory i, int slotIdx, int x, int y) {
|
||||||
|
super( i, slotIdx, x, y );
|
||||||
|
this.mac = mac;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isItemValid(ItemStack i)
|
||||||
|
{
|
||||||
|
return mac.isValidItemForSlot( this.getSlotIndex(), i );
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -58,7 +58,8 @@ public class SlotRestrictedInput extends AppEngSlot
|
|||||||
{
|
{
|
||||||
if ( which == PlaceableItemType.VALID_ENCODED_PATTERN_W_OUPUT )
|
if ( which == PlaceableItemType.VALID_ENCODED_PATTERN_W_OUPUT )
|
||||||
{
|
{
|
||||||
ICraftingPatternDetails ap = is.getItem() instanceof ICraftingPatternItem ? ((ICraftingPatternItem) is.getItem()).getPatternForItem( is ) : null;
|
ICraftingPatternDetails ap = is.getItem() instanceof ICraftingPatternItem ? ((ICraftingPatternItem) is.getItem()).getPatternForItem( is, theWorld )
|
||||||
|
: null;
|
||||||
if ( ap != null )
|
if ( ap != null )
|
||||||
return true;
|
return true;
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -0,0 +1,106 @@
|
|||||||
|
package appeng.helpers;
|
||||||
|
|
||||||
|
import net.minecraft.inventory.InventoryCrafting;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.item.crafting.CraftingManager;
|
||||||
|
import net.minecraft.item.crafting.IRecipe;
|
||||||
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
|
import net.minecraft.nbt.NBTTagList;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
import appeng.api.crafting.ICraftingPatternDetails;
|
||||||
|
import appeng.api.storage.data.IAEItemStack;
|
||||||
|
import appeng.container.ContainerNull;
|
||||||
|
import appeng.util.Platform;
|
||||||
|
|
||||||
|
public class PatternHelper implements ICraftingPatternDetails
|
||||||
|
{
|
||||||
|
|
||||||
|
InventoryCrafting crafting = new InventoryCrafting( new ContainerNull(), 3, 3 );
|
||||||
|
InventoryCrafting testFrame = new InventoryCrafting( new ContainerNull(), 3, 3 );
|
||||||
|
|
||||||
|
ItemStack correctOutput;
|
||||||
|
IRecipe standardRecipe;
|
||||||
|
|
||||||
|
boolean isCrafting = false;
|
||||||
|
|
||||||
|
public PatternHelper(ItemStack is, World w) {
|
||||||
|
NBTTagCompound encodedValue = is.getTagCompound();
|
||||||
|
|
||||||
|
if ( encodedValue == null )
|
||||||
|
return;
|
||||||
|
|
||||||
|
NBTTagList inTag = encodedValue.getTagList( "in", 10 );
|
||||||
|
NBTTagList outTag = encodedValue.getTagList( "out", 10 );
|
||||||
|
isCrafting = encodedValue.getBoolean( "crafting" );
|
||||||
|
|
||||||
|
if ( isCrafting == false )
|
||||||
|
throw new RuntimeException( "Only crafting recipes supported." );
|
||||||
|
|
||||||
|
for (int x = 0; x < inTag.tagCount(); x++)
|
||||||
|
{
|
||||||
|
ItemStack gs = ItemStack.loadItemStackFromNBT( inTag.getCompoundTagAt( x ) );
|
||||||
|
crafting.setInventorySlotContents( x, gs );
|
||||||
|
testFrame.setInventorySlotContents( x, gs );
|
||||||
|
}
|
||||||
|
|
||||||
|
standardRecipe = Platform.findMatchingRecipe( crafting, w );
|
||||||
|
correctOutput = standardRecipe.getCraftingResult( crafting );
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isValidItemForSlot(int slotIndex, ItemStack i, World w)
|
||||||
|
{
|
||||||
|
testFrame.setInventorySlotContents( slotIndex, i );
|
||||||
|
boolean result = standardRecipe.matches( testFrame, w );
|
||||||
|
|
||||||
|
if ( result )
|
||||||
|
{
|
||||||
|
ItemStack testOutput = standardRecipe.getCraftingResult( testFrame );
|
||||||
|
|
||||||
|
if ( Platform.isSameItemPrecise( correctOutput, testOutput ) )
|
||||||
|
{
|
||||||
|
testFrame.setInventorySlotContents( slotIndex, crafting.getStackInSlot( slotIndex ) );
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ItemStack testOutput = CraftingManager.getInstance().findMatchingRecipe( testFrame, w );
|
||||||
|
|
||||||
|
if ( Platform.isSameItemPrecise( correctOutput, testOutput ) )
|
||||||
|
{
|
||||||
|
testFrame.setInventorySlotContents( slotIndex, crafting.getStackInSlot( slotIndex ) );
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canSubstitute()
|
||||||
|
{
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isCraftable()
|
||||||
|
{
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IAEItemStack[] getInputs()
|
||||||
|
{
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IAEItemStack[] getOutputs()
|
||||||
|
{
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -7,12 +7,14 @@ import net.minecraft.entity.player.EntityPlayer;
|
|||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.nbt.NBTTagList;
|
import net.minecraft.nbt.NBTTagList;
|
||||||
|
import net.minecraft.world.World;
|
||||||
import net.minecraftforge.client.MinecraftForgeClient;
|
import net.minecraftforge.client.MinecraftForgeClient;
|
||||||
import appeng.api.crafting.ICraftingPatternDetails;
|
import appeng.api.crafting.ICraftingPatternDetails;
|
||||||
import appeng.api.implementations.ICraftingPatternItem;
|
import appeng.api.implementations.ICraftingPatternItem;
|
||||||
import appeng.client.render.items.ItemEncodedPatternRenderer;
|
import appeng.client.render.items.ItemEncodedPatternRenderer;
|
||||||
import appeng.core.features.AEFeature;
|
import appeng.core.features.AEFeature;
|
||||||
import appeng.core.localization.GuiText;
|
import appeng.core.localization.GuiText;
|
||||||
|
import appeng.helpers.PatternHelper;
|
||||||
import appeng.items.AEBaseItem;
|
import appeng.items.AEBaseItem;
|
||||||
import appeng.util.Platform;
|
import appeng.util.Platform;
|
||||||
|
|
||||||
@@ -128,9 +130,9 @@ public class ItemEncodedPattern extends AEBaseItem implements ICraftingPatternIt
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ICraftingPatternDetails getPatternForItem(ItemStack is)
|
public ICraftingPatternDetails getPatternForItem(ItemStack is, World w)
|
||||||
{
|
{
|
||||||
return null;
|
return new PatternHelper( is, w );
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -71,6 +71,7 @@ public class TileMolecularAssembler extends AENetworkInvTile implements IAEAppEn
|
|||||||
|
|
||||||
public TileMolecularAssembler() {
|
public TileMolecularAssembler() {
|
||||||
settings.registerSetting( Settings.REDSTONE_CONTROLLED, RedstoneMode.IGNORE );
|
settings.registerSetting( Settings.REDSTONE_CONTROLLED, RedstoneMode.IGNORE );
|
||||||
|
inv.setMaxStackSize( 1 );
|
||||||
addNewHandler( new TileMolecularAssemblerHandler() );
|
addNewHandler( new TileMolecularAssemblerHandler() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user