2013-12-30 06:55:02 +01:00
|
|
|
package appeng.parts.automation;
|
|
|
|
|
2014-02-05 03:44:54 +01:00
|
|
|
import java.util.List;
|
|
|
|
|
2013-12-30 06:55:02 +01:00
|
|
|
import net.minecraft.inventory.IInventory;
|
|
|
|
import net.minecraft.item.ItemStack;
|
2014-01-02 06:51:41 +01:00
|
|
|
import appeng.api.config.RedstoneMode;
|
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.tiles.ISegmentedInventory;
|
2013-12-30 06:55:02 +01:00
|
|
|
import appeng.api.util.IConfigManager;
|
|
|
|
import appeng.parts.PartBasicState;
|
|
|
|
import appeng.tile.inventory.IAEAppEngInventory;
|
|
|
|
import appeng.tile.inventory.InvOperation;
|
|
|
|
import appeng.util.ConfigManager;
|
|
|
|
import appeng.util.IConfigManagerHost;
|
|
|
|
|
|
|
|
public class PartUpgradeable extends PartBasicState implements ISegmentedInventory, IAEAppEngInventory, IConfigManagerHost
|
|
|
|
{
|
|
|
|
|
|
|
|
IConfigManager settings = new ConfigManager( this );
|
2014-01-24 17:35:35 +01:00
|
|
|
private UpgradeInventory upgrades = new UpgradeInventory( is, this, getUpgradeSlots() );
|
2013-12-30 06:55:02 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getInstalledUpgrades(Upgrades u)
|
|
|
|
{
|
|
|
|
return upgrades.getInstalledUpgrades( u );
|
|
|
|
}
|
|
|
|
|
2014-06-26 04:19:20 +02:00
|
|
|
@Override
|
|
|
|
public boolean canConnectRedstone()
|
|
|
|
{
|
|
|
|
return upgrades.getMaxInstalled( Upgrades.REDSTONE ) > 0;
|
|
|
|
}
|
|
|
|
|
2014-01-24 17:35:35 +01:00
|
|
|
protected int getUpgradeSlots()
|
|
|
|
{
|
|
|
|
return 4;
|
|
|
|
}
|
|
|
|
|
2014-02-05 03:44:54 +01:00
|
|
|
@Override
|
|
|
|
public void getDrops(List<ItemStack> drops, boolean wrenched)
|
|
|
|
{
|
|
|
|
for (ItemStack is : upgrades)
|
|
|
|
if ( is != null )
|
|
|
|
drops.add( is );
|
|
|
|
}
|
|
|
|
|
2013-12-30 06:55:02 +01:00
|
|
|
public void writeToNBT(net.minecraft.nbt.NBTTagCompound extra)
|
|
|
|
{
|
|
|
|
super.writeToNBT( extra );
|
|
|
|
settings.writeToNBT( extra );
|
|
|
|
upgrades.writeToNBT( extra, "upgrades" );
|
|
|
|
}
|
|
|
|
|
|
|
|
public void readFromNBT(net.minecraft.nbt.NBTTagCompound extra)
|
|
|
|
{
|
|
|
|
super.readFromNBT( extra );
|
|
|
|
settings.readFromNBT( extra );
|
|
|
|
upgrades.readFromNBT( extra, "upgrades" );
|
|
|
|
}
|
|
|
|
|
|
|
|
public PartUpgradeable(Class c, ItemStack is) {
|
|
|
|
super( c, is );
|
|
|
|
upgrades.setMaxStackSize( 1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public IConfigManager getConfigManager()
|
|
|
|
{
|
2014-01-02 06:51:41 +01:00
|
|
|
return settings;
|
2013-12-30 06:55:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public IInventory getInventoryByName(String name)
|
|
|
|
{
|
|
|
|
if ( name.equals( "upgrades" ) )
|
|
|
|
return upgrades;
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-02-17 01:50:25 +01:00
|
|
|
public void updateSetting(IConfigManager manager, Enum settingName, Enum newValue)
|
2013-12-30 06:55:02 +01:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-01-02 06:51:41 +01:00
|
|
|
public void upgradesChanged()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-12-30 06:55:02 +01:00
|
|
|
@Override
|
|
|
|
public void onChangeInventory(IInventory inv, int slot, InvOperation mc, ItemStack removedStack, ItemStack newStack)
|
|
|
|
{
|
2014-01-02 06:51:41 +01:00
|
|
|
if ( inv == upgrades )
|
|
|
|
{
|
|
|
|
upgradesChanged();
|
|
|
|
}
|
|
|
|
}
|
2013-12-30 06:55:02 +01:00
|
|
|
|
2014-01-02 06:51:41 +01:00
|
|
|
public RedstoneMode getRSMode()
|
|
|
|
{
|
|
|
|
return null;
|
2013-12-30 06:55:02 +01:00
|
|
|
}
|
|
|
|
|
2014-01-02 06:51:41 +01:00
|
|
|
protected boolean isSleeping()
|
|
|
|
{
|
|
|
|
if ( getInstalledUpgrades( Upgrades.REDSTONE ) > 0 )
|
|
|
|
{
|
|
|
|
switch (getRSMode())
|
|
|
|
{
|
|
|
|
case IGNORE:
|
|
|
|
return false;
|
|
|
|
|
|
|
|
case HIGH_SIGNAL:
|
|
|
|
if ( host.hasRedstone( side ) )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LOW_SIGNAL:
|
|
|
|
if ( !host.hasRedstone( side ) )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SIGNAL_PULSE:
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2013-12-30 06:55:02 +01:00
|
|
|
}
|