HotFix, potentially fixes #260 through catching a null node

Added copyright
Reformatted code
Rearranged code
This commit is contained in:
thatsIch
2014-11-14 17:56:34 +01:00
parent 38b9241846
commit 0f541484de
@@ -1,5 +1,24 @@
/*
* 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>.
*/
package appeng.parts.misc; package appeng.parts.misc;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
@@ -11,6 +30,13 @@ import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.Vec3; import net.minecraft.util.Vec3;
import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.common.util.ForgeDirection;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import buildcraft.api.transport.IPipeConnection;
import buildcraft.api.transport.IPipeTile.PipeType;
import appeng.api.AEApi; import appeng.api.AEApi;
import appeng.api.config.AccessRestriction; import appeng.api.config.AccessRestriction;
import appeng.api.config.FuzzyMode; import appeng.api.config.FuzzyMode;
@@ -60,22 +86,19 @@ import appeng.transformer.annotations.integration.Method;
import appeng.util.Platform; import appeng.util.Platform;
import appeng.util.prioitylist.FuzzyPriorityList; import appeng.util.prioitylist.FuzzyPriorityList;
import appeng.util.prioitylist.PrecisePriorityList; import appeng.util.prioitylist.PrecisePriorityList;
import buildcraft.api.transport.IPipeConnection;
import buildcraft.api.transport.IPipeTile.PipeType;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@Interface(iname = "BC", iface = "buildcraft.api.transport.IPipeConnection")
public class PartStorageBus extends PartUpgradeable implements IGridTickable, ICellContainer, IMEMonitorHandlerReceiver<IAEItemStack>, IPipeConnection, @Interface( iname = "BC", iface = "buildcraft.api.transport.IPipeConnection" )
IPriorityHost public class PartStorageBus
extends PartUpgradeable
implements IGridTickable, ICellContainer, IMEMonitorHandlerReceiver<IAEItemStack>, IPipeConnection, IPriorityHost
{ {
int priority = 0; int priority = 0;
final BaseActionSource mySrc; final BaseActionSource mySrc;
final AppEngInternalAEInventory Config = new AppEngInternalAEInventory( this, 63 ); final AppEngInternalAEInventory Config = new AppEngInternalAEInventory( this, 63 );
public PartStorageBus(ItemStack is) public PartStorageBus( ItemStack is )
{ {
super( PartStorageBus.class, is ); super( PartStorageBus.class, is );
getConfigManager().registerSetting( Settings.ACCESS, AccessRestriction.READ_WRITE ); getConfigManager().registerSetting( Settings.ACCESS, AccessRestriction.READ_WRITE );
@@ -93,13 +116,13 @@ public class PartStorageBus extends PartUpgradeable implements IGridTickable, IC
@Override @Override
@MENetworkEventSubscribe @MENetworkEventSubscribe
public void powerRender(MENetworkPowerStatusChange c) public void powerRender( MENetworkPowerStatusChange c )
{ {
updateStatus(); updateStatus();
} }
@MENetworkEventSubscribe @MENetworkEventSubscribe
public void updateChannels(MENetworkChannelsChanged changedChannels) public void updateChannels( MENetworkChannelsChanged changedChannels )
{ {
updateStatus(); updateStatus();
} }
@@ -115,7 +138,7 @@ public class PartStorageBus extends PartUpgradeable implements IGridTickable, IC
proxy.getGrid().postEvent( new MENetworkCellArrayUpdate() ); proxy.getGrid().postEvent( new MENetworkCellArrayUpdate() );
host.markForUpdate(); host.markForUpdate();
} }
catch (GridAccessException e) catch ( GridAccessException e )
{ {
// :P // :P
} }
@@ -123,7 +146,7 @@ public class PartStorageBus extends PartUpgradeable implements IGridTickable, IC
} }
@Override @Override
public boolean onPartActivate(EntityPlayer player, Vec3 pos) public boolean onPartActivate( EntityPlayer player, Vec3 pos )
{ {
if ( !player.isSneaking() ) if ( !player.isSneaking() )
{ {
@@ -144,13 +167,13 @@ public class PartStorageBus extends PartUpgradeable implements IGridTickable, IC
} }
@Override @Override
public boolean isValid(Object verificationToken) public boolean isValid( Object verificationToken )
{ {
return handler == verificationToken; return handler == verificationToken;
} }
@Override @Override
public IInventory getInventoryByName(String name) public IInventory getInventoryByName( String name )
{ {
if ( name.equals( "config" ) ) if ( name.equals( "config" ) )
return Config; return Config;
@@ -160,7 +183,7 @@ public class PartStorageBus extends PartUpgradeable implements IGridTickable, IC
private byte resetCacheLogic = 0; private byte resetCacheLogic = 0;
private void resetCache(boolean fullReset) private void resetCache( boolean fullReset )
{ {
if ( host == null || host.getTile() == null || host.getTile().getWorldObj() == null || host.getTile().getWorldObj().isRemote ) if ( host == null || host.getTile() == null || host.getTile().getWorldObj() == null || host.getTile().getWorldObj().isRemote )
return; return;
@@ -174,7 +197,7 @@ public class PartStorageBus extends PartUpgradeable implements IGridTickable, IC
{ {
proxy.getTick().alertDevice( proxy.getNode() ); proxy.getTick().alertDevice( proxy.getNode() );
} }
catch (GridAccessException e) catch ( GridAccessException e )
{ {
// :P // :P
} }
@@ -213,7 +236,7 @@ public class PartStorageBus extends PartUpgradeable implements IGridTickable, IC
} }
@Override @Override
public void onChangeInventory(IInventory inv, int slot, InvOperation mc, ItemStack removedStack, ItemStack newStack) public void onChangeInventory( IInventory inv, int slot, InvOperation mc, ItemStack removedStack, ItemStack newStack )
{ {
super.onChangeInventory( inv, slot, mc, removedStack, newStack ); super.onChangeInventory( inv, slot, mc, removedStack, newStack );
@@ -229,14 +252,14 @@ public class PartStorageBus extends PartUpgradeable implements IGridTickable, IC
} }
@Override @Override
public void updateSetting(IConfigManager manager, Enum settingName, Enum newValue) public void updateSetting( IConfigManager manager, Enum settingName, Enum newValue )
{ {
resetCache( true ); resetCache( true );
host.markForSave(); host.markForSave();
} }
@Override @Override
public void setPriority(int newValue) public void setPriority( int newValue )
{ {
priority = newValue; priority = newValue;
host.markForSave(); host.markForSave();
@@ -264,7 +287,7 @@ public class PartStorageBus extends PartUpgradeable implements IGridTickable, IC
// force grid to update handlers... // force grid to update handlers...
proxy.getGrid().postEvent( new MENetworkCellArrayUpdate() ); proxy.getGrid().postEvent( new MENetworkCellArrayUpdate() );
} }
catch (GridAccessException e) catch ( GridAccessException e )
{ {
// :3 // :3
} }
@@ -281,13 +304,13 @@ public class PartStorageBus extends PartUpgradeable implements IGridTickable, IC
if ( inv instanceof MEMonitorIInventory ) if ( inv instanceof MEMonitorIInventory )
{ {
MEMonitorIInventory h = (MEMonitorIInventory) inv; MEMonitorIInventory h = ( MEMonitorIInventory ) inv;
h.mode = (StorageFilter) getConfigManager().getSetting( Settings.STORAGE_FILTER ); h.mode = ( StorageFilter ) getConfigManager().getSetting( Settings.STORAGE_FILTER );
h.mySource = new MachineSource( this ); h.mySource = new MachineSource( this );
} }
if ( inv instanceof MEMonitorIInventory ) if ( inv instanceof MEMonitorIInventory )
monitor = (MEMonitorIInventory) inv; monitor = ( MEMonitorIInventory ) inv;
if ( inv != null ) if ( inv != null )
{ {
@@ -295,14 +318,14 @@ public class PartStorageBus extends PartUpgradeable implements IGridTickable, IC
handler = new MEInventoryHandler( inv, StorageChannel.ITEMS ); handler = new MEInventoryHandler( inv, StorageChannel.ITEMS );
handler.myAccess = (AccessRestriction) this.getConfigManager().getSetting( Settings.ACCESS ); handler.myAccess = ( AccessRestriction ) this.getConfigManager().getSetting( Settings.ACCESS );
handler.myWhitelist = getInstalledUpgrades( Upgrades.INVERTER ) > 0 ? IncludeExclude.BLACKLIST : IncludeExclude.WHITELIST; handler.myWhitelist = getInstalledUpgrades( Upgrades.INVERTER ) > 0 ? IncludeExclude.BLACKLIST : IncludeExclude.WHITELIST;
handler.myPriority = priority; handler.myPriority = priority;
IItemList<IAEItemStack> priorityList = AEApi.instance().storage().createItemList(); IItemList<IAEItemStack> priorityList = AEApi.instance().storage().createItemList();
int slotsToUse = 18 + getInstalledUpgrades( Upgrades.CAPACITY ) * 9; int slotsToUse = 18 + getInstalledUpgrades( Upgrades.CAPACITY ) * 9;
for (int x = 0; x < Config.getSizeInventory() && x < slotsToUse; x++) for ( int x = 0; x < Config.getSizeInventory() && x < slotsToUse; x++ )
{ {
IAEItemStack is = Config.getAEStackInSlot( x ); IAEItemStack is = Config.getAEStackInSlot( x );
if ( is != null ) if ( is != null )
@@ -310,18 +333,18 @@ public class PartStorageBus extends PartUpgradeable implements IGridTickable, IC
} }
if ( getInstalledUpgrades( Upgrades.FUZZY ) > 0 ) if ( getInstalledUpgrades( Upgrades.FUZZY ) > 0 )
handler.myPartitionList = new FuzzyPriorityList( priorityList, (FuzzyMode) this.getConfigManager().getSetting( Settings.FUZZY_MODE ) ); handler.myPartitionList = new FuzzyPriorityList( priorityList, ( FuzzyMode ) this.getConfigManager().getSetting( Settings.FUZZY_MODE ) );
else else
handler.myPartitionList = new PrecisePriorityList( priorityList ); handler.myPartitionList = new PrecisePriorityList( priorityList );
if ( inv instanceof IMEMonitor ) if ( inv instanceof IMEMonitor )
((IMEMonitor) inv).addListener( this, handler ); ( ( IMEMonitor ) inv ).addListener( this, handler );
} }
} }
} }
// update sleep state... // update sleep state...
if ( wasSleeping != (monitor == null) ) if ( wasSleeping != ( monitor == null ) )
{ {
try try
{ {
@@ -331,7 +354,7 @@ public class PartStorageBus extends PartUpgradeable implements IGridTickable, IC
else else
tm.wakeDevice( proxy.getNode() ); tm.wakeDevice( proxy.getNode() );
} }
catch (GridAccessException e) catch ( GridAccessException e )
{ {
// :( // :(
} }
@@ -340,30 +363,30 @@ public class PartStorageBus extends PartUpgradeable implements IGridTickable, IC
return handler; return handler;
} }
private void checkInterfaceVsStorageBus(TileEntity target, ForgeDirection side) private void checkInterfaceVsStorageBus( TileEntity target, ForgeDirection side )
{ {
IInterfaceHost achievement = null; IInterfaceHost achievement = null;
if ( target instanceof IInterfaceHost ) if ( target instanceof IInterfaceHost )
achievement = (IInterfaceHost) target; achievement = ( IInterfaceHost ) target;
if ( target instanceof IPartHost ) if ( target instanceof IPartHost )
{ {
Object part = ((IPartHost) target).getPart( side ); Object part = ( ( IPartHost ) target ).getPart( side );
if ( part instanceof IInterfaceHost ) if ( part instanceof IInterfaceHost )
achievement = (IInterfaceHost) part; achievement = ( IInterfaceHost ) part;
} }
if ( achievement != null ) if ( achievement != null && achievement.getActionableNode() != null )
{ {
Platform.addStat( achievement.getActionableNode().getPlayerID(), Achievements.Recursive.getAchievement() ); Platform.addStat( achievement.getActionableNode().getPlayerID(), Achievements.Recursive.getAchievement() );
//Platform.addStat( getActionableNode().getPlayerID(), Achievements.Recursive.getAchievement() ); // Platform.addStat( getActionableNode().getPlayerID(), Achievements.Recursive.getAchievement() );
} }
} }
@Override @Override
@SideOnly(Side.CLIENT) @SideOnly( Side.CLIENT )
public void renderInventory(IPartRenderHelper rh, RenderBlocks renderer) public void renderInventory( IPartRenderHelper rh, RenderBlocks renderer )
{ {
rh.setTexture( CableBusTextures.PartStorageSides.getIcon(), CableBusTextures.PartStorageSides.getIcon(), CableBusTextures.PartStorageBack.getIcon(), rh.setTexture( CableBusTextures.PartStorageSides.getIcon(), CableBusTextures.PartStorageSides.getIcon(), CableBusTextures.PartStorageBack.getIcon(),
is.getIconIndex(), CableBusTextures.PartStorageSides.getIcon(), CableBusTextures.PartStorageSides.getIcon() ); is.getIconIndex(), CableBusTextures.PartStorageSides.getIcon(), CableBusTextures.PartStorageSides.getIcon() );
@@ -379,12 +402,11 @@ public class PartStorageBus extends PartUpgradeable implements IGridTickable, IC
} }
@Override @Override
@SideOnly(Side.CLIENT) @SideOnly( Side.CLIENT )
public void renderStatic(int x, int y, int z, IPartRenderHelper rh, RenderBlocks renderer) public void renderStatic( int x, int y, int z, IPartRenderHelper rh, RenderBlocks renderer )
{ {
renderCache = rh.useSimplifiedRendering( x, y, z, this, renderCache ); renderCache = rh.useSimplifiedRendering( x, y, z, this, renderCache );
rh.setTexture( CableBusTextures.PartStorageSides.getIcon(), CableBusTextures.PartStorageSides.getIcon(), CableBusTextures.PartStorageBack.getIcon(), rh.setTexture( CableBusTextures.PartStorageSides.getIcon(), CableBusTextures.PartStorageSides.getIcon(), CableBusTextures.PartStorageBack.getIcon(), is.getIconIndex(), CableBusTextures.PartStorageSides.getIcon(), CableBusTextures.PartStorageSides.getIcon() );
is.getIconIndex(), CableBusTextures.PartStorageSides.getIcon(), CableBusTextures.PartStorageSides.getIcon() );
rh.setBounds( 3, 3, 15, 13, 13, 16 ); rh.setBounds( 3, 3, 15, 13, 13, 16 );
rh.renderBlock( x, y, z, renderer ); rh.renderBlock( x, y, z, renderer );
@@ -409,7 +431,7 @@ public class PartStorageBus extends PartUpgradeable implements IGridTickable, IC
} }
@Override @Override
public void getBoxes(IPartCollisionHelper bch) public void getBoxes( IPartCollisionHelper bch )
{ {
bch.addBox( 3, 3, 15, 13, 13, 16 ); bch.addBox( 3, 3, 15, 13, 13, 16 );
bch.addBox( 2, 2, 14, 14, 14, 15 ); bch.addBox( 2, 2, 14, 14, 14, 15 );
@@ -423,13 +445,13 @@ public class PartStorageBus extends PartUpgradeable implements IGridTickable, IC
} }
@Override @Override
public TickingRequest getTickingRequest(IGridNode node) public TickingRequest getTickingRequest( IGridNode node )
{ {
return new TickingRequest( TickRates.StorageBus.min, TickRates.StorageBus.max, monitor == null, true ); return new TickingRequest( TickRates.StorageBus.min, TickRates.StorageBus.max, monitor == null, true );
} }
@Override @Override
public TickRateModulation tickingRequest(IGridNode node, int TicksSinceLastCall) public TickRateModulation tickingRequest( IGridNode node, int TicksSinceLastCall )
{ {
if ( resetCacheLogic != 0 ) if ( resetCacheLogic != 0 )
resetCache(); resetCache();
@@ -441,7 +463,7 @@ public class PartStorageBus extends PartUpgradeable implements IGridTickable, IC
} }
@Override @Override
public void writeToNBT(NBTTagCompound data) public void writeToNBT( NBTTagCompound data )
{ {
super.writeToNBT( data ); super.writeToNBT( data );
Config.writeToNBT( data, "config" ); Config.writeToNBT( data, "config" );
@@ -449,7 +471,7 @@ public class PartStorageBus extends PartUpgradeable implements IGridTickable, IC
} }
@Override @Override
public void readFromNBT(NBTTagCompound data) public void readFromNBT( NBTTagCompound data )
{ {
super.readFromNBT( data ); super.readFromNBT( data );
Config.readFromNBT( data, "config" ); Config.readFromNBT( data, "config" );
@@ -457,7 +479,7 @@ public class PartStorageBus extends PartUpgradeable implements IGridTickable, IC
} }
@Override @Override
public List<IMEInventoryHandler> getCellArray(StorageChannel channel) public List<IMEInventoryHandler> getCellArray( StorageChannel channel )
{ {
if ( channel == StorageChannel.ITEMS ) if ( channel == StorageChannel.ITEMS )
{ {
@@ -475,27 +497,26 @@ public class PartStorageBus extends PartUpgradeable implements IGridTickable, IC
} }
@Override @Override
public void blinkCell(int slot) public void blinkCell( int slot )
{ {}
}
@Override @Override
public void postChange(IBaseMonitor<IAEItemStack> monitor, Iterable<IAEItemStack> change, BaseActionSource source) public void postChange( IBaseMonitor<IAEItemStack> monitor, Iterable<IAEItemStack> change, BaseActionSource source )
{ {
try try
{ {
if ( proxy.isActive() ) if ( proxy.isActive() )
proxy.getStorage().postAlterationOfStoredItems( StorageChannel.ITEMS, change, mySrc ); proxy.getStorage().postAlterationOfStoredItems( StorageChannel.ITEMS, change, mySrc );
} }
catch (GridAccessException e) catch ( GridAccessException e )
{ {
// :( // :(
} }
} }
@Override @Override
@Method(iname = "BC") @Method( iname = "BC" )
public ConnectOverride overridePipeConnection(PipeType type, ForgeDirection with) public ConnectOverride overridePipeConnection( PipeType type, ForgeDirection with )
{ {
return type == PipeType.ITEM && with == side ? ConnectOverride.CONNECT : ConnectOverride.DISCONNECT; return type == PipeType.ITEM && with == side ? ConnectOverride.CONNECT : ConnectOverride.DISCONNECT;
} }
@@ -507,9 +528,8 @@ public class PartStorageBus extends PartUpgradeable implements IGridTickable, IC
} }
@Override @Override
public void saveChanges(IMEInventory cellInventory) public void saveChanges( IMEInventory cellInventory )
{ {
// nope! // nope!
} }
} }