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>.
|
|
|
|
*/
|
|
|
|
|
2013-12-30 06:55:02 +01:00
|
|
|
package appeng.parts.automation;
|
|
|
|
|
2015-01-03 02:53:14 +01:00
|
|
|
|
2013-12-30 06:55:02 +01:00
|
|
|
import net.minecraft.inventory.IInventory;
|
|
|
|
import net.minecraft.item.Item;
|
|
|
|
import net.minecraft.item.ItemStack;
|
2014-01-05 09:46:00 +01:00
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
2014-12-29 21:59:05 +01:00
|
|
|
|
2013-12-30 06:55:02 +01:00
|
|
|
import appeng.api.config.Upgrades;
|
2014-01-23 20:02:48 +01:00
|
|
|
import appeng.api.implementations.items.IUpgradeModule;
|
2013-12-30 06:55:02 +01:00
|
|
|
import appeng.tile.inventory.AppEngInternalInventory;
|
|
|
|
import appeng.tile.inventory.IAEAppEngInventory;
|
|
|
|
import appeng.tile.inventory.InvOperation;
|
|
|
|
import appeng.util.Platform;
|
|
|
|
|
|
|
|
|
2015-01-03 02:53:14 +01:00
|
|
|
public abstract class UpgradeInventory extends AppEngInternalInventory implements IAEAppEngInventory
|
|
|
|
{
|
2014-01-20 17:41:37 +01:00
|
|
|
private final IAEAppEngInventory parent;
|
|
|
|
|
2014-01-01 10:04:54 +01:00
|
|
|
private boolean cached = false;
|
2015-01-03 02:53:14 +01:00
|
|
|
private int fuzzyUpgrades = 0;
|
|
|
|
private int speedUpgrades = 0;
|
|
|
|
private int redstoneUpgrades = 0;
|
|
|
|
private int capacityUpgrades = 0;
|
|
|
|
private int inverterUpgrades = 0;
|
|
|
|
private int craftingUpgrades = 0;
|
|
|
|
|
|
|
|
public UpgradeInventory( IAEAppEngInventory parent, int s )
|
|
|
|
{
|
2013-12-30 06:55:02 +01:00
|
|
|
super( null, s );
|
2014-12-29 15:13:47 +01:00
|
|
|
this.te = this;
|
2015-01-03 02:53:14 +01:00
|
|
|
this.parent = parent;
|
2013-12-30 06:55:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected boolean eventsEnabled()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-01-03 02:53:14 +01:00
|
|
|
public int getInventoryStackLimit()
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isItemValidForSlot( int i, ItemStack itemstack )
|
2013-12-30 06:55:02 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( itemstack == null )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2013-12-30 06:55:02 +01:00
|
|
|
return false;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2013-12-30 06:55:02 +01:00
|
|
|
Item it = itemstack.getItem();
|
2015-04-03 08:54:31 +02:00
|
|
|
if( it instanceof IUpgradeModule )
|
2013-12-30 06:55:02 +01:00
|
|
|
{
|
2015-01-03 02:53:14 +01:00
|
|
|
Upgrades u = ( (IUpgradeModule) it ).getType( itemstack );
|
2015-04-03 08:54:31 +02:00
|
|
|
if( u != null )
|
2013-12-30 06:55:02 +01:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
return this.getInstalledUpgrades( u ) < this.getMaxInstalled( u );
|
2013-12-30 06:55:02 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-01-03 02:53:14 +01:00
|
|
|
public int getInstalledUpgrades( Upgrades u )
|
2013-12-30 06:55:02 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( !this.cached )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-01-03 02:53:14 +01:00
|
|
|
this.updateUpgradeInfo();
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2013-12-30 06:55:02 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
switch( u )
|
2013-12-30 06:55:02 +01:00
|
|
|
{
|
|
|
|
case CAPACITY:
|
2015-01-03 02:53:14 +01:00
|
|
|
return this.capacityUpgrades;
|
2013-12-30 06:55:02 +01:00
|
|
|
case FUZZY:
|
2015-01-03 02:53:14 +01:00
|
|
|
return this.fuzzyUpgrades;
|
2013-12-30 06:55:02 +01:00
|
|
|
case REDSTONE:
|
2015-01-03 02:53:14 +01:00
|
|
|
return this.redstoneUpgrades;
|
2013-12-30 06:55:02 +01:00
|
|
|
case SPEED:
|
2015-01-03 02:53:14 +01:00
|
|
|
return this.speedUpgrades;
|
2014-01-20 17:41:37 +01:00
|
|
|
case INVERTER:
|
2015-01-03 02:53:14 +01:00
|
|
|
return this.inverterUpgrades;
|
2014-07-02 03:44:12 +02:00
|
|
|
case CRAFTING:
|
2015-01-03 02:53:14 +01:00
|
|
|
return this.craftingUpgrades;
|
2013-12-30 06:55:02 +01:00
|
|
|
default:
|
2015-01-03 02:53:14 +01:00
|
|
|
return 0;
|
2013-12-30 06:55:02 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-03 02:53:14 +01:00
|
|
|
public abstract int getMaxInstalled( Upgrades upgrades );
|
|
|
|
|
|
|
|
private void updateUpgradeInfo()
|
2013-12-30 06:55:02 +01:00
|
|
|
{
|
2015-01-03 02:53:14 +01:00
|
|
|
this.cached = true;
|
|
|
|
this.inverterUpgrades = this.capacityUpgrades = this.redstoneUpgrades = this.speedUpgrades = this.fuzzyUpgrades = this.craftingUpgrades = 0;
|
2014-01-01 10:04:54 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
for( ItemStack is : this )
|
2013-12-30 06:55:02 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( is == null || is.getItem() == null || !( is.getItem() instanceof IUpgradeModule ) )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-01-03 02:53:14 +01:00
|
|
|
continue;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-01-03 02:53:14 +01:00
|
|
|
|
|
|
|
Upgrades myUpgrade = ( (IUpgradeModule) is.getItem() ).getType( is );
|
2015-04-03 08:54:31 +02:00
|
|
|
switch( myUpgrade )
|
2015-01-03 02:53:14 +01:00
|
|
|
{
|
|
|
|
case CAPACITY:
|
|
|
|
this.capacityUpgrades++;
|
|
|
|
break;
|
|
|
|
case FUZZY:
|
|
|
|
this.fuzzyUpgrades++;
|
|
|
|
break;
|
|
|
|
case REDSTONE:
|
|
|
|
this.redstoneUpgrades++;
|
|
|
|
break;
|
|
|
|
case SPEED:
|
|
|
|
this.speedUpgrades++;
|
|
|
|
break;
|
|
|
|
case INVERTER:
|
|
|
|
this.inverterUpgrades++;
|
|
|
|
break;
|
|
|
|
case CRAFTING:
|
|
|
|
this.craftingUpgrades++;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2013-12-30 06:55:02 +01:00
|
|
|
}
|
2015-01-03 02:53:14 +01:00
|
|
|
|
|
|
|
this.capacityUpgrades = Math.min( this.capacityUpgrades, this.getMaxInstalled( Upgrades.CAPACITY ) );
|
|
|
|
this.fuzzyUpgrades = Math.min( this.fuzzyUpgrades, this.getMaxInstalled( Upgrades.FUZZY ) );
|
|
|
|
this.redstoneUpgrades = Math.min( this.redstoneUpgrades, this.getMaxInstalled( Upgrades.REDSTONE ) );
|
|
|
|
this.speedUpgrades = Math.min( this.speedUpgrades, this.getMaxInstalled( Upgrades.SPEED ) );
|
|
|
|
this.inverterUpgrades = Math.min( this.inverterUpgrades, this.getMaxInstalled( Upgrades.INVERTER ) );
|
|
|
|
this.craftingUpgrades = Math.min( this.craftingUpgrades, this.getMaxInstalled( Upgrades.CRAFTING ) );
|
2013-12-30 06:55:02 +01:00
|
|
|
}
|
|
|
|
|
2014-01-05 09:46:00 +01:00
|
|
|
@Override
|
2015-01-03 02:53:14 +01:00
|
|
|
public void readFromNBT( NBTTagCompound target )
|
2014-01-05 09:46:00 +01:00
|
|
|
{
|
|
|
|
super.readFromNBT( target );
|
2014-12-29 15:13:47 +01:00
|
|
|
this.updateUpgradeInfo();
|
2014-01-05 09:46:00 +01:00
|
|
|
}
|
|
|
|
|
2013-12-30 06:55:02 +01:00
|
|
|
@Override
|
2015-01-03 02:53:14 +01:00
|
|
|
public void saveChanges()
|
2013-12-30 06:55:02 +01:00
|
|
|
{
|
2015-01-03 02:53:14 +01:00
|
|
|
this.parent.saveChanges();
|
2013-12-30 06:55:02 +01:00
|
|
|
}
|
|
|
|
|
2014-01-31 01:50:11 +01:00
|
|
|
@Override
|
2015-01-03 02:53:14 +01:00
|
|
|
public void onChangeInventory( IInventory inv, int slot, InvOperation mc, ItemStack removedStack, ItemStack newStack )
|
2014-01-31 01:50:11 +01:00
|
|
|
{
|
2015-01-03 02:53:14 +01:00
|
|
|
this.cached = false;
|
2015-04-03 08:54:31 +02:00
|
|
|
if( this.parent != null && Platform.isServer() )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-01-03 02:53:14 +01:00
|
|
|
this.parent.onChangeInventory( inv, slot, mc, removedStack, newStack );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-01-31 01:50:11 +01:00
|
|
|
}
|
2013-12-30 06:55:02 +01:00
|
|
|
}
|