2013-12-27 23:59:59 +01:00
|
|
|
package appeng.container.slot;
|
|
|
|
|
2014-03-05 04:12:23 +01:00
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
2014-07-13 03:03:17 +02:00
|
|
|
import net.minecraft.entity.player.InventoryPlayer;
|
2014-03-07 04:02:15 +01:00
|
|
|
import net.minecraft.init.Items;
|
2013-12-27 23:59:59 +01:00
|
|
|
import net.minecraft.inventory.IInventory;
|
|
|
|
import net.minecraft.inventory.Slot;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.tileentity.TileEntityFurnace;
|
|
|
|
import net.minecraft.world.World;
|
2014-03-07 04:02:15 +01:00
|
|
|
import net.minecraftforge.oredict.OreDictionary;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.api.AEApi;
|
|
|
|
import appeng.api.IAppEngApi;
|
2014-03-25 20:20:51 +01:00
|
|
|
import appeng.api.features.INetworkEncodable;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.api.implementations.ICraftingPatternItem;
|
2014-02-02 08:32:10 +01:00
|
|
|
import appeng.api.implementations.items.IBiometricCard;
|
2014-01-23 20:02:48 +01:00
|
|
|
import appeng.api.implementations.items.ISpatialStorageCell;
|
|
|
|
import appeng.api.implementations.items.IStorageComponent;
|
|
|
|
import appeng.api.implementations.items.IUpgradeModule;
|
2014-05-09 06:10:12 +02:00
|
|
|
import appeng.api.networking.crafting.ICraftingPatternDetails;
|
2014-01-20 17:41:37 +01:00
|
|
|
import appeng.api.storage.ICellWorkbenchItem;
|
2014-04-23 07:30:29 +02:00
|
|
|
import appeng.items.misc.ItemEncodedPattern;
|
2014-03-09 04:35:53 +01:00
|
|
|
import appeng.recipes.handlers.Inscribe;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.util.Platform;
|
|
|
|
|
|
|
|
public class SlotRestrictedInput extends AppEngSlot
|
|
|
|
{
|
|
|
|
|
|
|
|
public enum PlaceableItemType
|
|
|
|
{
|
2014-03-07 04:02:15 +01:00
|
|
|
STORAGE_CELLS(15), ORE(1 * 16 + 15), STORAGE_COMPONENT(3 * 16 + 15),
|
|
|
|
|
2014-03-25 20:20:51 +01:00
|
|
|
ENCODEABLE_ITEM(4 * 16 + 15), TRASH(5 * 16 + 15), VALID_ENCODED_PATTERN_W_OUPUT(7 * 16 + 15), ENCODED_PATTERN_W_OUTPUT(7 * 16 + 15),
|
2014-03-07 04:02:15 +01:00
|
|
|
|
2014-07-13 03:03:17 +02:00
|
|
|
ENCODED_CRAFTING_PATTERN(7 * 16 + 15), ENCODED_PATTERN(7 * 16 + 15), PATTERN(8 * 16 + 15), BLANK_PATTERN(8 * 16 + 15), POWERED_TOOL(9 * 16 + 15),
|
2014-03-07 04:02:15 +01:00
|
|
|
|
|
|
|
RANGE_BOOSTER(6 * 16 + 15), QE_SINGULARTIY(10 * 16 + 15), SPATIAL_STORAGE_CELLS(11 * 16 + 15),
|
|
|
|
|
|
|
|
FUEL(12 * 16 + 15), UPGRADES(13 * 16 + 15), WORKBENCH_CELL(15), BIOMETRIC_CARD(14 * 16 + 15), VIEWCELL(4 * 16 + 14),
|
|
|
|
|
|
|
|
INSCRIBER_PLATE(2 * 16 + 14), INSCRIBER_INPUT(3 * 16 + 14), METAL_INGOTS(3 * 16 + 14);
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2014-02-09 02:34:52 +01:00
|
|
|
public final int IIcon;
|
2013-12-27 23:59:59 +01:00
|
|
|
|
|
|
|
private PlaceableItemType(int o) {
|
2014-02-09 02:34:52 +01:00
|
|
|
IIcon = o;
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getSlotStackLimit()
|
|
|
|
{
|
|
|
|
if ( stackLimit != -1 )
|
|
|
|
return stackLimit;
|
|
|
|
return super.getSlotStackLimit();
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isValid(ItemStack is, World theWorld)
|
|
|
|
{
|
|
|
|
if ( which == PlaceableItemType.VALID_ENCODED_PATTERN_W_OUPUT )
|
|
|
|
{
|
2014-04-25 03:55:29 +02:00
|
|
|
ICraftingPatternDetails ap = is.getItem() instanceof ICraftingPatternItem ? ((ICraftingPatternItem) is.getItem()).getPatternForItem( is, theWorld )
|
|
|
|
: null;
|
2014-04-09 04:56:59 +02:00
|
|
|
if ( ap != null )
|
2013-12-27 23:59:59 +01:00
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public PlaceableItemType which;
|
2014-03-05 04:12:23 +01:00
|
|
|
public boolean allowEdit = true;
|
2013-12-27 23:59:59 +01:00
|
|
|
public int stackLimit = -1;
|
2014-07-13 03:03:17 +02:00
|
|
|
private InventoryPlayer p;
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2014-03-05 04:12:23 +01:00
|
|
|
@Override
|
|
|
|
public boolean canTakeStack(EntityPlayer par1EntityPlayer)
|
|
|
|
{
|
|
|
|
return allowEdit;
|
|
|
|
}
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
public Slot setStackLimit(int i)
|
|
|
|
{
|
|
|
|
stackLimit = i;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2014-07-13 03:03:17 +02:00
|
|
|
public SlotRestrictedInput(PlaceableItemType valid, IInventory i, int slotnum, int x, int y, InventoryPlayer p) {
|
2013-12-27 23:59:59 +01:00
|
|
|
super( i, slotnum, x, y );
|
|
|
|
which = valid;
|
2014-02-09 02:34:52 +01:00
|
|
|
IIcon = valid.IIcon;
|
2014-07-13 03:03:17 +02:00
|
|
|
this.p = p;
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ItemStack getDisplayStack()
|
|
|
|
{
|
2014-04-23 07:30:29 +02:00
|
|
|
if ( Platform.isClient() && (which == PlaceableItemType.ENCODED_PATTERN) )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
ItemStack is = super.getStack();
|
2014-04-23 07:30:29 +02:00
|
|
|
if ( is != null && is.getItem() instanceof ItemEncodedPattern )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2014-04-23 07:30:29 +02:00
|
|
|
ItemEncodedPattern iep = (ItemEncodedPattern) is.getItem();
|
|
|
|
ItemStack out = iep.getOutput( is );
|
2014-07-24 17:59:57 +02:00
|
|
|
if ( out != null )
|
|
|
|
return out;
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return super.getStack();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isItemValid(ItemStack i)
|
|
|
|
{
|
2014-07-19 21:33:28 +02:00
|
|
|
if ( !myContainer.isValidForSlot( this, i ) )
|
|
|
|
return false;
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
if ( i == null )
|
|
|
|
return false;
|
|
|
|
if ( i.getItem() == null )
|
|
|
|
return false;
|
|
|
|
|
2014-02-12 06:26:19 +01:00
|
|
|
if ( !inventory.isItemValidForSlot( this.getSlotIndex(), i ) )
|
2013-12-30 06:52:00 +01:00
|
|
|
return false;
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
IAppEngApi api = AEApi.instance();
|
2014-03-05 04:12:23 +01:00
|
|
|
|
|
|
|
if ( !allowEdit )
|
|
|
|
return false;
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
switch (which)
|
|
|
|
{
|
2014-07-13 03:03:17 +02:00
|
|
|
case ENCODED_CRAFTING_PATTERN:
|
|
|
|
if ( i.getItem() instanceof ICraftingPatternItem )
|
|
|
|
{
|
|
|
|
ICraftingPatternItem b = (ICraftingPatternItem) i.getItem();
|
|
|
|
ICraftingPatternDetails de = b.getPatternForItem( i, p.player.worldObj );
|
|
|
|
if ( de != null )
|
|
|
|
return de.isCraftable();
|
|
|
|
}
|
|
|
|
return false;
|
2013-12-27 23:59:59 +01:00
|
|
|
case VALID_ENCODED_PATTERN_W_OUPUT:
|
|
|
|
case ENCODED_PATTERN_W_OUTPUT:
|
|
|
|
case ENCODED_PATTERN: {
|
2014-04-10 06:51:08 +02:00
|
|
|
if ( i.getItem() instanceof ICraftingPatternItem )
|
|
|
|
return true;
|
|
|
|
// ICraftingPatternDetails pattern = i.getItem() instanceof ICraftingPatternItem ? ((ICraftingPatternItem)
|
|
|
|
// i.getItem()).getPatternForItem( i ) : null;
|
|
|
|
return false;// pattern != null;
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
2014-04-10 06:51:08 +02:00
|
|
|
case BLANK_PATTERN:
|
2014-05-10 07:00:02 +02:00
|
|
|
return AEApi.instance().materials().materialBlankPattern.sameAsStack( i );
|
2014-04-08 04:25:41 +02:00
|
|
|
case PATTERN:
|
|
|
|
|
2014-04-09 04:56:59 +02:00
|
|
|
if ( i.getItem() instanceof ICraftingPatternItem )
|
|
|
|
return true;
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2014-05-10 07:00:02 +02:00
|
|
|
return AEApi.instance().materials().materialBlankPattern.sameAsStack( i );
|
2014-03-07 04:02:15 +01:00
|
|
|
|
|
|
|
case INSCRIBER_PLATE:
|
|
|
|
|
2014-05-10 07:00:02 +02:00
|
|
|
if ( AEApi.instance().materials().materialNamePress.sameAsStack( i ) )
|
2014-03-13 04:14:55 +01:00
|
|
|
return true;
|
|
|
|
|
2014-03-09 04:35:53 +01:00
|
|
|
for (ItemStack is : Inscribe.plates)
|
2014-03-07 04:02:15 +01:00
|
|
|
if ( Platform.isSameItemPrecise( is, i ) )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
case INSCRIBER_INPUT:
|
2014-03-13 04:14:55 +01:00
|
|
|
return true;/*
|
|
|
|
* for (ItemStack is : Inscribe.inputs) if ( Platform.isSameItemPrecise( is, i ) ) return true;
|
|
|
|
*
|
|
|
|
* return false;
|
|
|
|
*/
|
2014-03-07 04:02:15 +01:00
|
|
|
|
|
|
|
case METAL_INGOTS:
|
|
|
|
|
|
|
|
return isMetalIngot( i );
|
|
|
|
|
2014-03-04 08:52:07 +01:00
|
|
|
case VIEWCELL:
|
2014-05-10 07:00:02 +02:00
|
|
|
return AEApi.instance().items().itemViewCell.sameAsStack( i );
|
2013-12-27 23:59:59 +01:00
|
|
|
case ORE:
|
|
|
|
return appeng.api.AEApi.instance().registries().grinder().getRecipeForInput( i ) != null;
|
|
|
|
case FUEL:
|
|
|
|
return TileEntityFurnace.getItemBurnTime( i ) > 0;
|
|
|
|
case POWERED_TOOL:
|
|
|
|
return Platform.isChargeable( i );
|
|
|
|
case QE_SINGULARTIY:
|
2014-05-10 07:00:02 +02:00
|
|
|
return api.materials().materialQESingularity.sameAsStack( i );
|
2013-12-27 23:59:59 +01:00
|
|
|
case RANGE_BOOSTER:
|
2014-05-10 07:00:02 +02:00
|
|
|
return api.materials().materialWirelessBooster.sameAsStack( i );
|
2013-12-27 23:59:59 +01:00
|
|
|
case SPATIAL_STORAGE_CELLS:
|
|
|
|
return i.getItem() instanceof ISpatialStorageCell && ((ISpatialStorageCell) i.getItem()).isSpatialStorage( i );
|
|
|
|
case STORAGE_CELLS:
|
|
|
|
return AEApi.instance().registries().cell().isCellHandled( i );
|
2014-01-20 17:41:37 +01:00
|
|
|
case WORKBENCH_CELL:
|
|
|
|
return i != null && i.getItem() instanceof ICellWorkbenchItem && ((ICellWorkbenchItem) i.getItem()).isEditable( i );
|
2013-12-27 23:59:59 +01:00
|
|
|
case STORAGE_COMPONENT:
|
|
|
|
boolean isComp = i.getItem() instanceof IStorageComponent && ((IStorageComponent) i.getItem()).isStorageComponent( i );
|
|
|
|
return isComp;
|
|
|
|
case TRASH:
|
|
|
|
if ( AEApi.instance().registries().cell().isCellHandled( i ) )
|
|
|
|
return false;
|
|
|
|
if ( i.getItem() instanceof IStorageComponent && ((IStorageComponent) i.getItem()).isStorageComponent( i ) )
|
|
|
|
return false;
|
|
|
|
return true;
|
2014-03-25 20:20:51 +01:00
|
|
|
case ENCODEABLE_ITEM:
|
2014-04-08 04:25:41 +02:00
|
|
|
return i.getItem() instanceof INetworkEncodable || AEApi.instance().registries().wireless().isWirelessTerminal( i );
|
2014-02-02 08:32:10 +01:00
|
|
|
case BIOMETRIC_CARD:
|
|
|
|
return i.getItem() instanceof IBiometricCard;
|
2013-12-30 06:52:00 +01:00
|
|
|
case UPGRADES:
|
|
|
|
return i.getItem() instanceof IUpgradeModule && ((IUpgradeModule) i.getItem()).getType( i ) != null;
|
|
|
|
default:
|
|
|
|
break;
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2014-03-07 04:02:15 +01:00
|
|
|
|
|
|
|
static public boolean isMetalIngot(ItemStack i)
|
|
|
|
{
|
|
|
|
if ( Platform.isSameItemPrecise( i, new ItemStack( Items.iron_ingot ) ) )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
for (String name : new String[] { "Copper", "Tin", "Obsidian", "Iron", "Lead", "Bronze", "Brass", "Nickel", "Aluminium" })
|
|
|
|
{
|
|
|
|
for (ItemStack ingot : OreDictionary.getOres( "ingot" + name ))
|
|
|
|
{
|
|
|
|
if ( Platform.isSameItemPrecise( i, ingot ) )
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|