2014-01-27 05:00:36 +01:00
|
|
|
package appeng.container.implementations;
|
|
|
|
|
2014-02-01 06:37:27 +01:00
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
2014-02-02 08:32:10 +01:00
|
|
|
import net.minecraft.entity.player.EntityPlayerMP;
|
2014-01-27 05:00:36 +01:00
|
|
|
import net.minecraft.entity.player.InventoryPlayer;
|
2014-02-01 06:37:27 +01:00
|
|
|
import net.minecraft.inventory.ICrafting;
|
2014-02-02 08:32:10 +01:00
|
|
|
import net.minecraft.inventory.IInventory;
|
2014-02-01 06:37:27 +01:00
|
|
|
import net.minecraft.item.ItemStack;
|
2014-02-02 08:32:10 +01:00
|
|
|
import appeng.api.AEApi;
|
2014-01-27 05:00:36 +01:00
|
|
|
import appeng.api.config.SecurityPermissions;
|
2014-02-24 19:01:16 +01:00
|
|
|
import appeng.api.features.INetworkEncodable;
|
2014-02-02 08:32:10 +01:00
|
|
|
import appeng.api.features.IWirelessTermHandler;
|
2014-02-01 06:37:27 +01:00
|
|
|
import appeng.api.implementations.items.IBiometricCard;
|
2014-02-17 01:50:25 +01:00
|
|
|
import appeng.api.storage.ITerminalHost;
|
2014-02-02 08:32:10 +01:00
|
|
|
import appeng.container.slot.SlotOutput;
|
|
|
|
import appeng.container.slot.SlotRestrictedInput;
|
|
|
|
import appeng.container.slot.SlotRestrictedInput.PlaceableItemType;
|
|
|
|
import appeng.tile.inventory.AppEngInternalInventory;
|
|
|
|
import appeng.tile.inventory.IAEAppEngInventory;
|
|
|
|
import appeng.tile.inventory.InvOperation;
|
2014-02-01 06:37:27 +01:00
|
|
|
import appeng.tile.misc.TileSecurity;
|
|
|
|
import appeng.util.Platform;
|
2014-01-27 05:00:36 +01:00
|
|
|
|
2014-02-02 08:32:10 +01:00
|
|
|
public class ContainerSecurity extends ContainerMEMonitorable implements IAEAppEngInventory
|
2014-01-27 05:00:36 +01:00
|
|
|
{
|
|
|
|
|
2014-02-02 08:32:10 +01:00
|
|
|
SlotRestrictedInput configSlot;
|
|
|
|
|
|
|
|
AppEngInternalInventory wirelessEncoder = new AppEngInternalInventory( this, 2 );
|
|
|
|
|
|
|
|
SlotRestrictedInput wirelessIn;
|
|
|
|
SlotOutput wirelessOut;
|
|
|
|
|
|
|
|
TileSecurity securityBox;
|
2014-02-01 06:37:27 +01:00
|
|
|
|
2014-02-17 01:50:25 +01:00
|
|
|
public ContainerSecurity(InventoryPlayer ip, ITerminalHost montiorable) {
|
2014-02-01 06:37:27 +01:00
|
|
|
super( ip, montiorable, false );
|
|
|
|
|
2014-02-02 08:32:10 +01:00
|
|
|
securityBox = (TileSecurity) montiorable;
|
|
|
|
|
2014-02-05 03:44:54 +01:00
|
|
|
addSlotToContainer( configSlot = new SlotRestrictedInput( PlaceableItemType.BIOMETRIC_CARD, securityBox.configSlot, 0, 37, -33 ) );
|
2014-02-02 08:32:10 +01:00
|
|
|
|
2014-03-25 20:20:51 +01:00
|
|
|
addSlotToContainer( wirelessIn = new SlotRestrictedInput( PlaceableItemType.ENCODEABLE_ITEM, wirelessEncoder, 0, 212, 10 ) );
|
2014-02-02 08:32:10 +01:00
|
|
|
addSlotToContainer( wirelessOut = new SlotOutput( wirelessEncoder, 1, 212, 68, -1 ) );
|
2014-02-01 06:37:27 +01:00
|
|
|
|
|
|
|
bindPlayerInventory( ip, 0, 0 );
|
|
|
|
}
|
|
|
|
|
|
|
|
public int security = 0;
|
|
|
|
|
2014-02-02 08:32:10 +01:00
|
|
|
@Override
|
|
|
|
public void onContainerClosed(EntityPlayer player)
|
|
|
|
{
|
2014-02-05 03:44:54 +01:00
|
|
|
super.onContainerClosed( player );
|
|
|
|
|
2014-02-02 08:32:10 +01:00
|
|
|
if ( wirelessIn.getHasStack() )
|
2014-02-09 02:34:52 +01:00
|
|
|
player.dropPlayerItemWithRandomChoice( wirelessIn.getStack(), false );
|
2014-02-02 08:32:10 +01:00
|
|
|
|
|
|
|
if ( wirelessOut.getHasStack() )
|
2014-02-09 02:34:52 +01:00
|
|
|
player.dropPlayerItemWithRandomChoice( wirelessOut.getStack(), false );
|
2014-02-02 08:32:10 +01:00
|
|
|
}
|
|
|
|
|
2014-02-01 06:37:27 +01:00
|
|
|
public void toggleSetting(String value, EntityPlayer player)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
SecurityPermissions permission = SecurityPermissions.valueOf( value );
|
|
|
|
|
|
|
|
ItemStack a = configSlot.getStack();
|
|
|
|
if ( a != null && a.getItem() instanceof IBiometricCard )
|
|
|
|
{
|
|
|
|
IBiometricCard bc = (IBiometricCard) a.getItem();
|
|
|
|
if ( bc.hasPermission( a, permission ) )
|
|
|
|
bc.removePermission( a, permission );
|
|
|
|
else
|
|
|
|
bc.addPermission( a, permission );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (EnumConstantNotPresentException ex)
|
|
|
|
{
|
|
|
|
// :(
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void updateProgressBar(int key, int value)
|
|
|
|
{
|
2014-03-28 05:31:06 +01:00
|
|
|
super.updateProgressBar( key, value );
|
|
|
|
|
2014-02-01 06:37:27 +01:00
|
|
|
if ( key == 0 )
|
|
|
|
security = value;
|
2014-01-27 05:00:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void detectAndSendChanges()
|
|
|
|
{
|
2014-03-28 05:31:06 +01:00
|
|
|
verifyPermissions( SecurityPermissions.SECURITY, false );
|
2014-01-27 05:00:36 +01:00
|
|
|
|
2014-02-01 06:37:27 +01:00
|
|
|
int newSecurity = 0;
|
|
|
|
|
|
|
|
ItemStack a = configSlot.getStack();
|
|
|
|
if ( a != null && a.getItem() instanceof IBiometricCard )
|
|
|
|
{
|
|
|
|
IBiometricCard bc = (IBiometricCard) a.getItem();
|
|
|
|
|
|
|
|
for (SecurityPermissions sp : bc.getPermissions( a ))
|
|
|
|
newSecurity = newSecurity | (1 << sp.ordinal());
|
|
|
|
}
|
|
|
|
|
2014-03-28 05:31:06 +01:00
|
|
|
updatePowerStatus();
|
|
|
|
|
2014-02-01 06:37:27 +01:00
|
|
|
if ( newSecurity != security )
|
|
|
|
{
|
|
|
|
if ( Platform.isServer() )
|
|
|
|
{
|
|
|
|
for (int i = 0; i < this.crafters.size(); ++i)
|
|
|
|
{
|
|
|
|
ICrafting icrafting = (ICrafting) this.crafters.get( i );
|
|
|
|
|
|
|
|
icrafting.sendProgressBarUpdate( this, 0, newSecurity );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
security = newSecurity;
|
|
|
|
}
|
|
|
|
|
2014-01-27 05:00:36 +01:00
|
|
|
super.detectAndSendChanges();
|
|
|
|
}
|
2014-02-01 06:37:27 +01:00
|
|
|
|
2014-02-02 08:32:10 +01:00
|
|
|
@Override
|
|
|
|
public void saveChanges()
|
|
|
|
{
|
|
|
|
// :P
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onChangeInventory(IInventory inv, int slot, InvOperation mc, ItemStack removedStack, ItemStack newStack)
|
|
|
|
{
|
|
|
|
if ( !wirelessOut.getHasStack() )
|
|
|
|
{
|
|
|
|
if ( wirelessIn.getHasStack() )
|
|
|
|
{
|
|
|
|
ItemStack term = wirelessIn.getStack().copy();
|
2014-02-24 19:01:16 +01:00
|
|
|
INetworkEncodable netEncodeable = null;
|
2014-03-28 05:31:06 +01:00
|
|
|
|
2014-02-24 19:01:16 +01:00
|
|
|
if ( term.getItem() instanceof INetworkEncodable )
|
|
|
|
netEncodeable = (INetworkEncodable) term.getItem();
|
2014-03-28 05:31:06 +01:00
|
|
|
|
2014-02-24 19:01:16 +01:00
|
|
|
IWirelessTermHandler wTermHandler = AEApi.instance().registries().wireless().getWirelessTerminalHandler( term );
|
|
|
|
if ( wTermHandler != null )
|
|
|
|
netEncodeable = wTermHandler;
|
2014-03-28 05:31:06 +01:00
|
|
|
|
2014-02-24 19:01:16 +01:00
|
|
|
if ( netEncodeable != null )
|
2014-02-02 08:32:10 +01:00
|
|
|
{
|
2014-02-24 19:01:16 +01:00
|
|
|
netEncodeable.setEncryptionKey( term, "" + securityBox.securityKey, "" );
|
2014-02-02 08:32:10 +01:00
|
|
|
|
|
|
|
wirelessIn.putStack( null );
|
|
|
|
wirelessOut.putStack( term );
|
|
|
|
|
|
|
|
// update the two slots in question...
|
|
|
|
for (int i = 0; i < this.crafters.size(); ++i)
|
|
|
|
{
|
|
|
|
ICrafting icrafting = (ICrafting) this.crafters.get( i );
|
|
|
|
((EntityPlayerMP) icrafting).sendSlotContents( this, wirelessIn.slotNumber, wirelessIn.getStack() );
|
|
|
|
((EntityPlayerMP) icrafting).sendSlotContents( this, wirelessOut.slotNumber, wirelessOut.getStack() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-01-27 05:00:36 +01:00
|
|
|
}
|