2014-11-14 12:02:52 +01:00
|
|
|
/*
|
|
|
|
* This file is part of Applied Energistics 2.
|
|
|
|
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
|
|
|
*
|
|
|
|
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
|
|
|
*/
|
|
|
|
|
2014-05-07 07:22:42 +02:00
|
|
|
package appeng.container.implementations;
|
|
|
|
|
|
|
|
import java.util.Iterator;
|
|
|
|
|
|
|
|
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.inventory.IInventory;
|
|
|
|
import net.minecraft.item.ItemStack;
|
2014-12-29 21:59:05 +01:00
|
|
|
|
2014-05-07 07:22:42 +02:00
|
|
|
import appeng.api.AEApi;
|
|
|
|
import appeng.api.config.CopyMode;
|
|
|
|
import appeng.api.config.FuzzyMode;
|
|
|
|
import appeng.api.config.Settings;
|
|
|
|
import appeng.api.storage.ICellWorkbenchItem;
|
|
|
|
import appeng.api.storage.IMEInventory;
|
|
|
|
import appeng.api.storage.StorageChannel;
|
|
|
|
import appeng.api.storage.data.IAEItemStack;
|
|
|
|
import appeng.api.storage.data.IItemList;
|
|
|
|
import appeng.container.guisync.GuiSync;
|
|
|
|
import appeng.container.slot.OptionalSlotRestrictedInput;
|
|
|
|
import appeng.container.slot.SlotFakeTypeOnly;
|
|
|
|
import appeng.container.slot.SlotRestrictedInput;
|
|
|
|
import appeng.tile.inventory.AppEngNullInventory;
|
|
|
|
import appeng.tile.misc.TileCellWorkbench;
|
|
|
|
import appeng.util.Platform;
|
|
|
|
import appeng.util.iterators.NullIterator;
|
|
|
|
|
|
|
|
public class ContainerCellWorkbench extends ContainerUpgradeable
|
|
|
|
{
|
|
|
|
|
2014-09-29 09:54:34 +02:00
|
|
|
final TileCellWorkbench workBench;
|
|
|
|
final AppEngNullInventory ni = new AppEngNullInventory();
|
2014-05-07 07:22:42 +02:00
|
|
|
|
|
|
|
public IInventory getCellUpgradeInventory()
|
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
IInventory ri = this.workBench.getCellUpgradeInventory();
|
|
|
|
return ri == null ? this.ni : ri;
|
2014-05-07 07:22:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void setFuzzy(FuzzyMode valueOf)
|
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
ICellWorkbenchItem cwi = this.workBench.getCell();
|
2014-05-07 07:22:42 +02:00
|
|
|
if ( cwi != null )
|
2014-12-29 15:13:47 +01:00
|
|
|
cwi.setFuzzyMode( this.workBench.getInventoryByName( "cell" ).getStackInSlot( 0 ), valueOf );
|
2014-05-07 07:22:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private FuzzyMode getFuzzyMode()
|
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
ICellWorkbenchItem cwi = this.workBench.getCell();
|
2014-05-07 07:22:42 +02:00
|
|
|
if ( cwi != null )
|
2014-12-29 15:13:47 +01:00
|
|
|
return cwi.getFuzzyMode( this.workBench.getInventoryByName( "cell" ).getStackInSlot( 0 ) );
|
2014-05-07 07:22:42 +02:00
|
|
|
return FuzzyMode.IGNORE_ALL;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void nextCopyMode()
|
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.workBench.getConfigManager().putSetting( Settings.COPY_MODE, Platform.nextEnum( this.getCopyMode() ) );
|
2014-05-07 07:22:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public CopyMode getCopyMode()
|
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
return (CopyMode) this.workBench.getConfigManager().getSetting( Settings.COPY_MODE );
|
2014-05-07 07:22:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
class Upgrades implements IInventory
|
|
|
|
{
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getSizeInventory()
|
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
return ContainerCellWorkbench.this.getCellUpgradeInventory().getSizeInventory();
|
2014-05-07 07:22:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ItemStack getStackInSlot(int i)
|
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
return ContainerCellWorkbench.this.getCellUpgradeInventory().getStackInSlot( i );
|
2014-05-07 07:22:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ItemStack decrStackSize(int i, int j)
|
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
IInventory inv = ContainerCellWorkbench.this.getCellUpgradeInventory();
|
2014-05-07 07:22:42 +02:00
|
|
|
ItemStack is = inv.decrStackSize( i, j );
|
|
|
|
inv.markDirty();
|
|
|
|
return is;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ItemStack getStackInSlotOnClosing(int i)
|
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
IInventory inv = ContainerCellWorkbench.this.getCellUpgradeInventory();
|
2014-05-07 07:22:42 +02:00
|
|
|
ItemStack is = inv.getStackInSlotOnClosing( i );
|
|
|
|
inv.markDirty();
|
|
|
|
return is;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setInventorySlotContents(int i, ItemStack itemstack)
|
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
IInventory inv = ContainerCellWorkbench.this.getCellUpgradeInventory();
|
2014-05-07 07:22:42 +02:00
|
|
|
inv.setInventorySlotContents( i, itemstack );
|
|
|
|
inv.markDirty();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getInventoryName()
|
|
|
|
{
|
|
|
|
return "Upgrades";
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean hasCustomInventoryName()
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getInventoryStackLimit()
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void markDirty()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isUseableByPlayer(EntityPlayer entityplayer)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void openInventory()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void closeInventory()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isItemValidForSlot(int i, ItemStack itemstack)
|
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
return ContainerCellWorkbench.this.getCellUpgradeInventory().isItemValidForSlot( i, itemstack );
|
2014-05-07 07:22:42 +02:00
|
|
|
}
|
2014-09-28 00:50:06 +02:00
|
|
|
}
|
2014-05-07 07:22:42 +02:00
|
|
|
|
|
|
|
IInventory UpgradeInventoryWrapper;
|
|
|
|
|
|
|
|
ItemStack prevStack = null;
|
|
|
|
int lastUpgrades = 0;
|
|
|
|
|
|
|
|
@GuiSync(2)
|
|
|
|
public CopyMode copyMode = CopyMode.CLEAR_ON_REMOVE;
|
|
|
|
|
|
|
|
public ContainerCellWorkbench(InventoryPlayer ip, TileCellWorkbench te) {
|
|
|
|
super( ip, te );
|
2014-12-29 15:13:47 +01:00
|
|
|
this.workBench = te;
|
2014-05-07 07:22:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected int getHeight()
|
|
|
|
{
|
|
|
|
return 251;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int availableUpgrades()
|
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
ItemStack is = this.workBench.getInventoryByName( "cell" ).getStackInSlot( 0 );
|
|
|
|
if ( this.prevStack != is )
|
2014-05-07 07:22:42 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.prevStack = is;
|
|
|
|
return this.lastUpgrades = this.getCellUpgradeInventory().getSizeInventory();
|
2014-05-07 07:22:42 +02:00
|
|
|
}
|
2014-12-29 15:13:47 +01:00
|
|
|
return this.lastUpgrades;
|
2014-05-07 07:22:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isSlotEnabled(int idx)
|
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
return idx < this.availableUpgrades();
|
2014-05-07 07:22:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void setupConfig()
|
|
|
|
{
|
|
|
|
int x = 8;
|
|
|
|
int y = 29;
|
|
|
|
int offset = 0;
|
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
IInventory cell = this.upgradeable.getInventoryByName( "cell" );
|
|
|
|
this.addSlotToContainer( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.WORKBENCH_CELL, cell, 0, 152, 8, this.invPlayer ) );
|
2014-05-07 07:22:42 +02:00
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
IInventory inv = this.upgradeable.getInventoryByName( "config" );
|
|
|
|
this.UpgradeInventoryWrapper = new Upgrades();// Platform.isServer() ? new Upgrades() : new AppEngInternalInventory(
|
2014-05-07 07:22:42 +02:00
|
|
|
// null, 3 * 8 );
|
|
|
|
|
|
|
|
for (int w = 0; w < 7; w++)
|
|
|
|
for (int z = 0; z < 9; z++)
|
2014-12-29 15:13:47 +01:00
|
|
|
this.addSlotToContainer( new SlotFakeTypeOnly( inv, offset++, x + z * 18, y + w * 18 ) );
|
2014-05-07 07:22:42 +02:00
|
|
|
|
|
|
|
for (int zz = 0; zz < 3; zz++)
|
|
|
|
for (int z = 0; z < 8; z++)
|
|
|
|
{
|
|
|
|
int iSLot = zz * 8 + z;
|
2014-12-29 15:13:47 +01:00
|
|
|
this.addSlotToContainer( new OptionalSlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, this.UpgradeInventoryWrapper, this, iSLot, 187 + zz * 18,
|
|
|
|
8 + 18 * z, iSLot, this.invPlayer ) );
|
2014-05-07 07:22:42 +02:00
|
|
|
}
|
|
|
|
/*
|
|
|
|
* if ( supportCapacity() ) { for (int w = 0; w < 2; w++) for (int z = 0; z < 9; z++) addSlotToContainer( new
|
|
|
|
* OptionalSlotFakeTypeOnly( inv, this, offset++, x, y, z, w, 1 ) );
|
2015-02-03 12:04:13 +01:00
|
|
|
*
|
2014-05-07 07:22:42 +02:00
|
|
|
* for (int w = 0; w < 2; w++) for (int z = 0; z < 9; z++) addSlotToContainer( new OptionalSlotFakeTypeOnly(
|
|
|
|
* inv, this, offset++, x, y, z, w + 2, 2 ) );
|
2015-02-03 12:04:13 +01:00
|
|
|
*
|
2014-05-07 07:22:42 +02:00
|
|
|
* for (int w = 0; w < 2; w++) for (int z = 0; z < 9; z++) addSlotToContainer( new OptionalSlotFakeTypeOnly(
|
|
|
|
* inv, this, offset++, x, y, z, w + 4, 3 ) ); }
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
|
|
|
ItemStack LastCell;
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onUpdate(String field, Object oldValue, Object newValue)
|
|
|
|
{
|
|
|
|
if ( field.equals( "copyMode" ) )
|
2014-12-29 15:13:47 +01:00
|
|
|
this.workBench.getConfigManager().putSetting( Settings.COPY_MODE, this.copyMode );
|
2014-05-07 07:22:42 +02:00
|
|
|
|
|
|
|
super.onUpdate( field, oldValue, newValue );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void detectAndSendChanges()
|
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
ItemStack is = this.workBench.getInventoryByName( "cell" ).getStackInSlot( 0 );
|
2014-05-07 07:22:42 +02:00
|
|
|
if ( Platform.isServer() )
|
|
|
|
{
|
2014-09-29 09:23:02 +02:00
|
|
|
for (Object crafter : this.crafters)
|
2014-05-07 07:22:42 +02:00
|
|
|
{
|
2014-09-29 09:23:02 +02:00
|
|
|
ICrafting icrafting = (ICrafting) crafter;
|
2014-05-07 07:22:42 +02:00
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
if ( this.prevStack != is )
|
2014-05-07 07:22:42 +02:00
|
|
|
{
|
|
|
|
// if the bars changed an item was probably made, so just send shit!
|
2014-12-29 15:13:47 +01:00
|
|
|
for (Object s : this.inventorySlots)
|
2014-05-07 07:22:42 +02:00
|
|
|
{
|
|
|
|
if ( s instanceof OptionalSlotRestrictedInput )
|
|
|
|
{
|
|
|
|
OptionalSlotRestrictedInput sri = (OptionalSlotRestrictedInput) s;
|
|
|
|
icrafting.sendSlotContents( this, sri.slotNumber, sri.getStack() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
((EntityPlayerMP) icrafting).isChangingQuantityOnly = false;
|
|
|
|
}
|
|
|
|
}
|
2014-07-13 03:03:17 +02:00
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
this.copyMode = this.getCopyMode();
|
|
|
|
this.fzMode = this.getFuzzyMode();
|
2014-05-07 07:22:42 +02:00
|
|
|
}
|
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
this.prevStack = is;
|
|
|
|
this.standardDetectAndSendChanges();
|
2014-05-07 07:22:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void clear()
|
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
IInventory inv = this.upgradeable.getInventoryByName( "config" );
|
2014-05-07 07:22:42 +02:00
|
|
|
for (int x = 0; x < inv.getSizeInventory(); x++)
|
|
|
|
inv.setInventorySlotContents( x, null );
|
2014-12-29 15:13:47 +01:00
|
|
|
this.detectAndSendChanges();
|
2014-05-07 07:22:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void partition()
|
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
IInventory inv = this.upgradeable.getInventoryByName( "config" );
|
2014-05-07 07:22:42 +02:00
|
|
|
|
|
|
|
IMEInventory<IAEItemStack> cellInv = AEApi.instance().registries().cell()
|
2014-12-29 15:13:47 +01:00
|
|
|
.getCellInventory( this.upgradeable.getInventoryByName( "cell" ).getStackInSlot( 0 ), null, StorageChannel.ITEMS );
|
2014-05-07 07:22:42 +02:00
|
|
|
|
|
|
|
Iterator<IAEItemStack> i = new NullIterator<IAEItemStack>();
|
|
|
|
if ( cellInv != null )
|
|
|
|
{
|
|
|
|
IItemList<IAEItemStack> list = cellInv.getAvailableItems( AEApi.instance().storage().createItemList() );
|
|
|
|
i = list.iterator();
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int x = 0; x < inv.getSizeInventory(); x++)
|
|
|
|
{
|
|
|
|
if ( i.hasNext() )
|
|
|
|
{
|
|
|
|
ItemStack g = i.next().getItemStack();
|
|
|
|
g.stackSize = 1;
|
|
|
|
inv.setInventorySlotContents( x, g );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
inv.setInventorySlotContents( x, null );
|
|
|
|
}
|
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
this.detectAndSendChanges();
|
2014-05-07 07:22:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|