Pretty much all of security minus the gui.

and all the stuff I did that i forgot to comment.
This commit is contained in:
AlgorithmX2
2014-01-26 22:00:36 -06:00
parent bea039c7b5
commit 0f75db5e80
61 changed files with 2058 additions and 126 deletions
+30 -3
View File
@@ -3,6 +3,7 @@ package appeng.parts;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.List;
import java.util.Random;
@@ -20,8 +21,8 @@ import net.minecraft.world.World;
import net.minecraftforge.common.ForgeDirection;
import appeng.api.config.Upgrades;
import appeng.api.implementations.IUpgradeableHost;
import appeng.api.networking.IGridHost;
import appeng.api.networking.IGridNode;
import appeng.api.networking.security.IActionHost;
import appeng.api.parts.IPart;
import appeng.api.parts.IPartCollsionHelper;
import appeng.api.parts.IPartHost;
@@ -34,8 +35,9 @@ import appeng.api.util.IConfigManager;
import appeng.me.helpers.AENetworkProxy;
import appeng.me.helpers.IGridProxyable;
import appeng.parts.networking.PartCable;
import appeng.util.Platform;
public class AEBasePart implements IPart, IGridProxyable, IGridHost, IUpgradeableHost
public class AEBasePart implements IPart, IGridProxyable, IActionHost, IUpgradeableHost
{
protected AENetworkProxy proxy;
@@ -277,7 +279,7 @@ public class AEBasePart implements IPart, IGridProxyable, IGridHost, IUpgradeabl
@Override
public void onPlacement(EntityPlayer player, ItemStack held, ForgeDirection side)
{
proxy.setOwner( player );
}
@Override
@@ -286,4 +288,29 @@ public class AEBasePart implements IPart, IGridProxyable, IGridHost, IUpgradeabl
return tile;
}
@Override
public void securityBreak()
{
if ( is.stackSize > 0 )
{
List<ItemStack> items = new ArrayList();
items.add( is.copy() );
host.removePart( side, false );
Platform.spawnDrops( tile.worldObj, tile.xCoord, tile.yCoord, tile.zCoord, items );
is.stackSize = 0;
}
}
@Override
public AENetworkProxy getProxy()
{
return proxy;
}
@Override
public IGridNode getActionableNode()
{
return proxy.getNode();
}
}
+66 -14
View File
@@ -23,6 +23,7 @@ import net.minecraft.world.World;
import net.minecraftforge.common.ForgeDirection;
import powercrystals.minefactoryreloaded.api.rednet.RedNetConnectionType;
import appeng.api.AEApi;
import appeng.api.exceptions.FailedConnection;
import appeng.api.implementations.parts.IPartCable;
import appeng.api.networking.IGridHost;
import appeng.api.networking.IGridNode;
@@ -76,7 +77,7 @@ public class CableBusContainer implements AEMultiTile, ICableBusContainer
}
@Override
public void removePart(ForgeDirection side)
public void removePart(ForgeDirection side, boolean supressUpdate)
{
if ( side == ForgeDirection.UNKNOWN )
{
@@ -91,9 +92,12 @@ public class CableBusContainer implements AEMultiTile, ICableBusContainer
sides[side.ordinal()] = null;
}
updateConnections();
markForUpdate();
PartChanged();
if ( !supressUpdate )
{
updateConnections();
markForUpdate();
PartChanged();
}
}
/**
@@ -154,7 +158,7 @@ public class CableBusContainer implements AEMultiTile, ICableBusContainer
}
@Override
public ForgeDirection addPart(ItemStack is, ForgeDirection side)
public ForgeDirection addPart(ItemStack is, ForgeDirection side, EntityPlayer player)
{
if ( canAddPart( is, side ) )
{
@@ -182,6 +186,9 @@ public class CableBusContainer implements AEMultiTile, ICableBusContainer
center = (IPartCable) bp;
bp.setPartHostInfo( ForgeDirection.UNKNOWN, this, tcb.getTile() );
if ( player != null )
bp.onPlacement( player, is, side );
if ( inWorld )
bp.addToWorld();
@@ -195,7 +202,20 @@ public class CableBusContainer implements AEMultiTile, ICableBusContainer
{
IGridNode sn = sbp.getGridNode();
if ( sn != null && cn != null )
new GridConnection( (IGridNode) cn, (IGridNode) sn, ForgeDirection.UNKNOWN );
{
try
{
new GridConnection( (IGridNode) cn, (IGridNode) sn, ForgeDirection.UNKNOWN );
}
catch (FailedConnection e)
{
// ekk!
bp.removeFromWorld();
center = null;
return null;
}
}
}
}
}
@@ -214,6 +234,9 @@ public class CableBusContainer implements AEMultiTile, ICableBusContainer
sides[side.ordinal()] = bp;
bp.setPartHostInfo( side, this, this.getTile() );
if ( player != null )
bp.onPlacement( player, is, side );
if ( inWorld )
bp.addToWorld();
@@ -224,7 +247,18 @@ public class CableBusContainer implements AEMultiTile, ICableBusContainer
if ( cn != null && sn != null )
{
new GridConnection( (IGridNode) cn, (IGridNode) sn, ForgeDirection.UNKNOWN );
try
{
new GridConnection( (IGridNode) cn, (IGridNode) sn, ForgeDirection.UNKNOWN );
}
catch (FailedConnection e)
{
// ekk!
bp.removeFromWorld();
sides[side.ordinal()] = null;
return null;
}
}
}
@@ -270,7 +304,14 @@ public class CableBusContainer implements AEMultiTile, ICableBusContainer
IGridNode cn = center.getGridNode();
if ( cn != null )
{
AEApi.instance().createGridConnection( cn, sn );
try
{
AEApi.instance().createGridConnection( cn, sn );
}
catch (FailedConnection e)
{
// ekk
}
}
}
@@ -645,8 +686,8 @@ public class CableBusContainer implements AEMultiTile, ICableBusContainer
p.readFromStream( data );
else
{
removePart( side );
side = addPart( new ItemStack( Item.itemsList[itemID], 1, dmgValue ), side );
removePart( side, false );
side = addPart( new ItemStack( Item.itemsList[itemID], 1, dmgValue ), side, null );
if ( side != null )
{
p = getPart( side );
@@ -657,7 +698,7 @@ public class CableBusContainer implements AEMultiTile, ICableBusContainer
}
}
else
removePart( side );
removePart( side, false );
}
return fc.readFromStream( data );
@@ -722,8 +763,8 @@ public class CableBusContainer implements AEMultiTile, ICableBusContainer
p.readFromNBT( extra );
else
{
removePart( side );
side = addPart( iss, side );
removePart( side, false );
side = addPart( iss, side, null );
if ( side != null )
{
p = getPart( side );
@@ -734,7 +775,7 @@ public class CableBusContainer implements AEMultiTile, ICableBusContainer
}
}
else
removePart( side );
removePart( side, false );
}
}
@@ -985,4 +1026,15 @@ public class CableBusContainer implements AEMultiTile, ICableBusContainer
// never called
}
@Override
public void securityBreak()
{
for (ForgeDirection d : ForgeDirection.values())
{
IPart p = getPart( d );
if ( p != null && p instanceof IGridHost )
((IGridHost) p).securityBreak();
}
}
}
+83 -8
View File
@@ -5,6 +5,7 @@ import java.util.List;
import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
@@ -13,7 +14,9 @@ import net.minecraftforge.common.ForgeDirection;
import appeng.api.AEApi;
import appeng.api.config.AccessRestriction;
import appeng.api.config.FuzzyMode;
import appeng.api.config.IncludeExclude;
import appeng.api.config.Settings;
import appeng.api.config.Upgrades;
import appeng.api.networking.IGridNode;
import appeng.api.networking.events.MENetworkCellArrayUpdate;
import appeng.api.networking.security.BaseActionSource;
@@ -32,25 +35,35 @@ import appeng.api.storage.IMEMonitor;
import appeng.api.storage.IMEMonitorHandlerReciever;
import appeng.api.storage.StorageChannel;
import appeng.api.storage.data.IAEItemStack;
import appeng.api.storage.data.IItemList;
import appeng.client.texture.CableBusTextures;
import appeng.core.sync.GuiBridge;
import appeng.helpers.IPriorityHost;
import appeng.me.GridAccessException;
import appeng.me.storage.MEInventoryHandler;
import appeng.me.storage.MEMonitorIInventory;
import appeng.parts.automation.PartUpgradeable;
import appeng.tile.inventory.AppEngInternalAEInventory;
import appeng.tile.inventory.InvOperation;
import appeng.util.Platform;
import appeng.util.item.ItemList;
import appeng.util.prioitylist.FuzzyPriorityList;
import appeng.util.prioitylist.PrecisePriorityList;
import buildcraft.api.transport.IPipeConnection;
import buildcraft.api.transport.IPipeTile.PipeType;
import cpw.mods.fml.common.Optional.Interface;
import cpw.mods.fml.common.Optional.Method;
@Interface(modid = "BuildCraft|Transport", iface = "buildcraft.api.transport.IPipeConnection")
public class PartStorageBus extends PartUpgradeable implements IGridTickable, ICellContainer, IMEMonitorHandlerReciever<IAEItemStack>, IPipeConnection
public class PartStorageBus extends PartUpgradeable implements IGridTickable, ICellContainer, IMEMonitorHandlerReciever<IAEItemStack>, IPipeConnection,
IPriorityHost
{
int priority = 0;
BaseActionSource mySrc;
AppEngInternalAEInventory Config = new AppEngInternalAEInventory( this, 63 );
public PartStorageBus(ItemStack is) {
super( PartStorageBus.class, is );
getConfigManager().registerSetting( Settings.ACCESS, AccessRestriction.READ_WRITE );
@@ -91,11 +104,22 @@ public class PartStorageBus extends PartUpgradeable implements IGridTickable, IC
}
@Override
public void onNeighborChanged()
public IInventory getInventoryByName(String name)
{
if ( name.equals( "config" ) )
return Config;
return super.getInventoryByName( name );
}
private void resetCache(boolean fullReset)
{
cached = false;
if ( fullReset )
handlerHash = 0;
try
{
// force grid to update handlers...
proxy.getGrid().postEvent( new MENetworkCellArrayUpdate() );
}
catch (GridAccessException e)
@@ -104,6 +128,36 @@ public class PartStorageBus extends PartUpgradeable implements IGridTickable, IC
}
}
@Override
public void onNeighborChanged()
{
resetCache( false );
}
@Override
public void onChangeInventory(IInventory inv, int slot, InvOperation mc, ItemStack removedStack, ItemStack newStack)
{
super.onChangeInventory( inv, slot, mc, removedStack, newStack );
if ( inv == Config )
resetCache( true );
}
@Override
public void updateSetting(Enum settingName, Enum newValue)
{
resetCache( true );
host.markForSave();
}
@Override
public void setPriority(int newValue)
{
priority = newValue;
host.markForSave();
resetCache( true );
}
private MEInventoryHandler getHandler()
{
if ( cached )
@@ -140,6 +194,25 @@ public class PartStorageBus extends PartUpgradeable implements IGridTickable, IC
{
handler = new MEInventoryHandler( inv );
handler.myAccess = (AccessRestriction) this.getConfigManager().getSetting( Settings.ACCESS );
handler.myWhitelist = getInstalledUpgrades( Upgrades.INVERTER ) > 0 ? IncludeExclude.BLACKLIST : IncludeExclude.WHITELIST;
handler.myPriority = priority;
IItemList priorityList = new ItemList();
int slotsToUse = 18 + getInstalledUpgrades( Upgrades.CAPACITY ) * 9;
for (int x = 0; x < Config.getSizeInventory() && x < slotsToUse; x++)
{
IAEItemStack is = Config.getAEStackInSlot( x );
if ( is != null )
priorityList.add( is );
}
if ( getInstalledUpgrades( Upgrades.FUZZY ) > 0 )
handler.myPartitionList = new FuzzyPriorityList( priorityList, (FuzzyMode) this.getConfigManager().getSetting( Settings.FUZZY_MODE ) );
else
handler.myPartitionList = new PrecisePriorityList( priorityList );
if ( inv instanceof IMEMonitor )
((IMEMonitor) inv).addListener( this, handler );
}
@@ -242,16 +315,18 @@ public class PartStorageBus extends PartUpgradeable implements IGridTickable, IC
}
@Override
public void writeToNBT(NBTTagCompound extra)
public void writeToNBT(NBTTagCompound data)
{
super.writeToNBT( extra );
extra.setInteger( "priority", priority );
super.writeToNBT( data );
Config.writeToNBT( data, "config" );
data.setInteger( "priority", priority );
}
public void readFromNBT(NBTTagCompound extra)
public void readFromNBT(NBTTagCompound data)
{
super.readFromNBT( extra );
priority = extra.getInteger( "priority" );
super.readFromNBT( data );
Config.readFromNBT( data, "config" );
priority = data.getInteger( "priority" );
};
@Override
+33 -1
View File
@@ -1,8 +1,11 @@
package appeng.parts.misc;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.List;
import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
@@ -11,6 +14,7 @@ import net.minecraftforge.common.ForgeDirection;
import org.lwjgl.opengl.GL11;
import appeng.api.AEApi;
import appeng.api.exceptions.FailedConnection;
import appeng.api.networking.IGridConnection;
import appeng.api.networking.IGridNode;
import appeng.api.parts.IPartCollsionHelper;
@@ -20,6 +24,7 @@ import appeng.api.util.AECableType;
import appeng.client.texture.CableBusTextures;
import appeng.me.helpers.AENetworkProxy;
import appeng.parts.PartBasicState;
import appeng.util.Platform;
public class PartToggleBus extends PartBasicState
{
@@ -31,6 +36,13 @@ public class PartToggleBus extends PartBasicState
boolean hasRedstone = false;
@Override
public void onPlacement(EntityPlayer player, ItemStack held, ForgeDirection side)
{
super.onPlacement( player, held, side );
outerProxy.setOwner( player );
}
@Override
protected int populateFlags(int cf)
{
@@ -96,7 +108,14 @@ public class PartToggleBus extends PartBasicState
{
if ( intention )
{
connection = AEApi.instance().createGridConnection( proxy.getNode(), outerProxy.getNode() );
try
{
connection = AEApi.instance().createGridConnection( proxy.getNode(), outerProxy.getNode() );
}
catch (FailedConnection e)
{
// :(
}
}
else
{
@@ -195,4 +214,17 @@ public class PartToggleBus extends PartBasicState
{
return 5;
}
@Override
public void securityBreak()
{
if ( is.stackSize > 0 )
{
List<ItemStack> items = new ArrayList();
items.add( is.copy() );
host.removePart( side, false );
Platform.spawnDrops( tile.worldObj, tile.xCoord, tile.yCoord, tile.zCoord, items );
is.stackSize = 0;
}
}
}
+8
View File
@@ -4,6 +4,7 @@ import java.util.EnumSet;
import java.util.Set;
import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
@@ -36,6 +37,13 @@ public class PartQuartzFiber extends AEBasePart implements IEnergyGridProvider
proxy.setFlags( GridFlags.CANNOT_CARRY );
}
@Override
public void onPlacement(EntityPlayer player, ItemStack held, ForgeDirection side)
{
super.onPlacement( player, held, side );
outerProxy.setOwner( player );
}
@Override
public void setPartHostInfo(ForgeDirection side, IPartHost host, TileEntity tile)
{
+6
View File
@@ -8,6 +8,7 @@ import net.minecraft.util.Icon;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeDirection;
import appeng.api.config.PowerUnits;
import appeng.api.config.TunnelType;
import appeng.api.networking.IGridNode;
import appeng.api.networking.ticking.IGridTickable;
import appeng.api.networking.ticking.TickRateModulation;
@@ -27,6 +28,11 @@ public class PartP2PBCPower extends PartP2PTunnel<PartP2PBCPower> implements IPo
PowerHandler pp;
public TunnelType getTunnelType()
{
return TunnelType.BC_POWER;
}
public PartP2PBCPower(ItemStack is) {
super( is );
pp = new PowerHandler( this, Type.MACHINE );
+6
View File
@@ -8,6 +8,7 @@ import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.Icon;
import net.minecraftforge.common.ForgeDirection;
import appeng.api.config.TunnelType;
import appeng.me.GridAccessException;
import appeng.me.cache.helpers.TunnelCollection;
import appeng.util.Platform;
@@ -17,6 +18,11 @@ import cpw.mods.fml.relauncher.SideOnly;
public class PartP2PIC2Power extends PartP2PTunnel<PartP2PIC2Power> implements ic2.api.energy.tile.IEnergySink, ic2.api.energy.tile.IEnergySource
{
public TunnelType getTunnelType()
{
return TunnelType.IC2_POWER;
}
public PartP2PIC2Power(ItemStack is) {
super( is );
}
+6
View File
@@ -12,6 +12,7 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityChest;
import net.minecraft.util.Icon;
import net.minecraftforge.common.ForgeDirection;
import appeng.api.config.TunnelType;
import appeng.core.AppEng;
import appeng.integration.abstraction.IBC;
import appeng.integration.abstraction.ITE;
@@ -31,6 +32,11 @@ import cpw.mods.fml.relauncher.SideOnly;
public class PartP2PItems extends PartP2PTunnel<PartP2PItems> implements IPipeConnection, IInventory, ISidedInventory
{
public TunnelType getTunnelType()
{
return TunnelType.ITEM;
}
public PartP2PItems(ItemStack is) {
super( is );
}
+6
View File
@@ -14,6 +14,7 @@ import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidTankInfo;
import net.minecraftforge.fluids.IFluidHandler;
import appeng.api.config.TunnelType;
import appeng.me.GridAccessException;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@@ -21,6 +22,11 @@ import cpw.mods.fml.relauncher.SideOnly;
public class PartP2PLiquids extends PartP2PTunnel<PartP2PLiquids> implements IFluidHandler
{
public TunnelType getTunnelType()
{
return TunnelType.FLUID;
}
public PartP2PLiquids(ItemStack is) {
super( is );
}
+6
View File
@@ -6,6 +6,7 @@ import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.Icon;
import net.minecraft.world.World;
import appeng.api.config.TunnelType;
import appeng.api.networking.events.MENetworkBootingStatusChange;
import appeng.api.networking.events.MENetworkChannelsChanged;
import appeng.api.networking.events.MENetworkEventSubscribe;
@@ -17,6 +18,11 @@ import cpw.mods.fml.relauncher.SideOnly;
public class PartP2PRedstone extends PartP2PTunnel<PartP2PRedstone>
{
public TunnelType getTunnelType()
{
return TunnelType.REDSTONE;
}
public PartP2PRedstone(ItemStack is) {
super( is );
}
+9 -4
View File
@@ -65,8 +65,8 @@ public class PartP2PTunnel<T extends PartP2PTunnel> extends PartBasicState
ItemStack newType = ItemStack.loadItemStackFromNBT( data );
long freq = data.getLong( "freq" );
getHost().removePart( side );
ForgeDirection dir = getHost().addPart( newType, side );
getHost().removePart( side, true );
ForgeDirection dir = getHost().addPart( newType, side, player );
IPart newBus = getHost().getPart( dir );
if ( newBus instanceof PartP2PTunnel )
@@ -125,8 +125,8 @@ public class PartP2PTunnel<T extends PartP2PTunnel> extends PartBasicState
boolean oldOutput = output;
long myFreq = freq;
getHost().removePart( side );
ForgeDirection dir = getHost().addPart( newType, side );
getHost().removePart( side, false );
ForgeDirection dir = getHost().addPart( newType, side, player );
IPart newBus = getHost().getPart( dir );
if ( newBus instanceof PartP2PTunnel )
@@ -152,6 +152,11 @@ public class PartP2PTunnel<T extends PartP2PTunnel> extends PartBasicState
return false;
}
public TunnelType getTunnelType()
{
return null;
}
@Override
public boolean onShiftActivate(EntityPlayer player, Vec3 pos)
{
+26 -5
View File
@@ -4,11 +4,14 @@ import java.util.EnumSet;
import java.util.Iterator;
import java.util.LinkedList;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.ForgeDirection;
import appeng.api.AEApi;
import appeng.api.config.TunnelType;
import appeng.api.exceptions.FailedConnection;
import appeng.api.networking.GridFlags;
import appeng.api.networking.IGridNode;
import appeng.api.networking.ticking.IGridTickable;
@@ -16,7 +19,6 @@ import appeng.api.networking.ticking.TickRateModulation;
import appeng.api.networking.ticking.TickingRequest;
import appeng.api.parts.IPartHost;
import appeng.api.util.AECableType;
import appeng.core.AELog;
import appeng.helpers.TickHandler;
import appeng.me.GridAccessException;
import appeng.me.cache.helpers.Connections;
@@ -26,6 +28,11 @@ import appeng.me.helpers.AENetworkProxy;
public class PartP2PTunnelME extends PartP2PTunnel<PartP2PTunnelME> implements IGridTickable
{
public TunnelType getTunnelType()
{
return TunnelType.ME;
}
AENetworkProxy outerProxy = new AENetworkProxy( this, "outer", null, true );
public Connections connection = new Connections( this );
@@ -143,6 +150,13 @@ public class PartP2PTunnelME extends PartP2PTunnel<PartP2PTunnelME> implements I
return TickRateModulation.IDLE;
}
@Override
public void onPlacement(EntityPlayer player, ItemStack held, ForgeDirection side)
{
super.onPlacement( player, held, side );
outerProxy.setOwner( player );
}
public void updateConnections(Connections connections)
{
if ( connections.destroy )
@@ -159,7 +173,6 @@ public class PartP2PTunnelME extends PartP2PTunnel<PartP2PTunnelME> implements I
while (i.hasNext())
{
TunnelConnection cw = i.next();
AELog.info( "Old!" );
try
{
if ( cw.tunnel.proxy.getGrid() != proxy.getGrid() )
@@ -175,7 +188,7 @@ public class PartP2PTunnelME extends PartP2PTunnel<PartP2PTunnelME> implements I
}
catch (GridAccessException e)
{
e.printStackTrace();
// e.printStackTrace();
}
}
@@ -192,8 +205,16 @@ public class PartP2PTunnelME extends PartP2PTunnel<PartP2PTunnelME> implements I
for (PartP2PTunnelME me : newSides)
{
connections.connections.put( me.getGridNode(),
new TunnelConnection( me, AEApi.instance().createGridConnection( outerProxy.getNode(), me.outerProxy.getNode() ) ) );
try
{
connections.connections.put( me.getGridNode(),
new TunnelConnection( me, AEApi.instance().createGridConnection( outerProxy.getNode(), me.outerProxy.getNode() ) ) );
}
catch (FailedConnection e)
{
e.printStackTrace();
// :(
}
}
}
catch (GridAccessException e)