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;
|
|
|
|
|
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-12-29 21:59:05 +01:00
|
|
|
|
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;
|
|
|
|
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;
|
|
|
|
|
2014-10-04 08:08:28 +02:00
|
|
|
public class PartUpgradeable extends PartBasicState implements IAEAppEngInventory, IConfigManagerHost
|
2013-12-30 06:55:02 +01:00
|
|
|
{
|
|
|
|
|
2014-09-29 09:54:34 +02:00
|
|
|
final IConfigManager settings = new ConfigManager( this );
|
2014-12-29 15:13:47 +01:00
|
|
|
private final UpgradeInventory upgrades = new UpgradeInventory( this.is, this, this.getUpgradeSlots() );
|
2013-12-30 06:55:02 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getInstalledUpgrades(Upgrades u)
|
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
return this.upgrades.getInstalledUpgrades( u );
|
2013-12-30 06:55:02 +01:00
|
|
|
}
|
|
|
|
|
2014-06-26 04:19:20 +02:00
|
|
|
@Override
|
|
|
|
public boolean canConnectRedstone()
|
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
return this.upgrades.getMaxInstalled( Upgrades.REDSTONE ) > 0;
|
2014-06-26 04:19:20 +02:00
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
for (ItemStack is : this.upgrades)
|
2014-02-05 03:44:54 +01:00
|
|
|
if ( is != null )
|
|
|
|
drops.add( is );
|
|
|
|
}
|
|
|
|
|
2014-09-28 20:34:00 +02:00
|
|
|
@Override
|
2013-12-30 06:55:02 +01:00
|
|
|
public void writeToNBT(net.minecraft.nbt.NBTTagCompound extra)
|
|
|
|
{
|
|
|
|
super.writeToNBT( extra );
|
2014-12-29 15:13:47 +01:00
|
|
|
this.settings.writeToNBT( extra );
|
|
|
|
this.upgrades.writeToNBT( extra, "upgrades" );
|
2013-12-30 06:55:02 +01:00
|
|
|
}
|
|
|
|
|
2014-09-28 20:34:00 +02:00
|
|
|
@Override
|
2013-12-30 06:55:02 +01:00
|
|
|
public void readFromNBT(net.minecraft.nbt.NBTTagCompound extra)
|
|
|
|
{
|
|
|
|
super.readFromNBT( extra );
|
2014-12-29 15:13:47 +01:00
|
|
|
this.settings.readFromNBT( extra );
|
|
|
|
this.upgrades.readFromNBT( extra, "upgrades" );
|
2013-12-30 06:55:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public PartUpgradeable(Class c, ItemStack is) {
|
|
|
|
super( c, is );
|
2014-12-29 15:13:47 +01:00
|
|
|
this.upgrades.setMaxStackSize( 1 );
|
2013-12-30 06:55:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public IConfigManager getConfigManager()
|
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
return this.settings;
|
2013-12-30 06:55:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public IInventory getInventoryByName(String name)
|
|
|
|
{
|
|
|
|
if ( name.equals( "upgrades" ) )
|
2014-12-29 15:13:47 +01:00
|
|
|
return this.upgrades;
|
2013-12-30 06:55:02 +01:00
|
|
|
|
|
|
|
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-12-29 15:13:47 +01:00
|
|
|
if ( inv == this.upgrades )
|
2014-01-02 06:51:41 +01:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.upgradesChanged();
|
2014-01-02 06:51:41 +01:00
|
|
|
}
|
|
|
|
}
|
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()
|
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
if ( this.getInstalledUpgrades( Upgrades.REDSTONE ) > 0 )
|
2014-01-02 06:51:41 +01:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
switch (this.getRSMode())
|
2014-01-02 06:51:41 +01:00
|
|
|
{
|
|
|
|
case IGNORE:
|
|
|
|
return false;
|
|
|
|
|
|
|
|
case HIGH_SIGNAL:
|
2014-12-29 15:13:47 +01:00
|
|
|
if ( this.host.hasRedstone( this.side ) )
|
2014-01-02 06:51:41 +01:00
|
|
|
return false;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LOW_SIGNAL:
|
2014-12-29 15:13:47 +01:00
|
|
|
if ( !this.host.hasRedstone( this.side ) )
|
2014-01-02 06:51:41 +01:00
|
|
|
return false;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SIGNAL_PULSE:
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2013-12-30 06:55:02 +01:00
|
|
|
}
|