Merge pull request #652 from thatsIch/b-644-NPE-on-disabled-features

Fixes #644 Several missing null checks when disabling huge chunks of the mod via config
This commit is contained in:
thatsIch 2014-12-29 20:20:38 +01:00
commit 2b34ba5840
7 changed files with 144 additions and 98 deletions

View file

@ -23,27 +23,32 @@
package appeng.api.config;
import java.util.HashMap;
import net.minecraft.item.ItemStack;
import appeng.api.util.AEItemDefinition;
public enum Upgrades
{
/**
* Gold Tier Upgrades.
*/
CAPACITY(0), REDSTONE(0), CRAFTING(0),
CAPACITY( 0 ), REDSTONE( 0 ), CRAFTING( 0 ),
/**
* Diamond Tier Upgrades.
*/
FUZZY(1), SPEED(1), INVERTER(1);
FUZZY( 1 ), SPEED( 1 ), INVERTER( 1 );
public final int myTier;
public final HashMap<ItemStack, Integer> supportedMax = new HashMap<ItemStack, Integer>();
private Upgrades(int tier) {
myTier = tier;
private Upgrades( int tier )
{
this.myTier = tier;
}
/**
@ -51,12 +56,26 @@ public enum Upgrades
*/
public HashMap<ItemStack, Integer> getSupported()
{
return supportedMax;
return this.supportedMax;
}
public void registerItem(ItemStack myItem, int maxSupported)
public void registerItem( AEItemDefinition myItem, int maxSupported )
{
if ( myItem != null )
supportedMax.put( myItem, maxSupported );
{
final ItemStack stack = myItem.stack( 1 );
this.registerItem( stack, maxSupported );
}
}
public void registerItem( ItemStack stack, int maxSupported )
{
if ( stack != null )
{
this.supportedMax.put( stack, maxSupported );
}
}
}

View file

@ -74,4 +74,5 @@ public class Parts
public AEItemDefinition partStorageMonitor;
public AEItemDefinition partConversionMonitor;
// entweder optional oder null pattern, wahrscheinlich besser mit optional für API
}

View file

@ -119,7 +119,7 @@ public class AppEng
if ( Platform.isClient() )
CommonHelper.proxy.init();
Registration.instance.PreInit( event );
Registration.INSTANCE.preInitialize( event );
if ( AEConfig.instance.isFeatureEnabled( AEFeature.VersionChecker ) )
{
@ -143,7 +143,7 @@ public class AppEng
Stopwatch star = Stopwatch.createStarted();
AELog.info( "Init" );
Registration.instance.Init( event );
Registration.INSTANCE.initialize( event );
IntegrationRegistry.INSTANCE.init();
AELog.info( "Init ( end " + star.elapsed( TimeUnit.MILLISECONDS ) + "ms )" );
@ -155,7 +155,7 @@ public class AppEng
Stopwatch star = Stopwatch.createStarted();
AELog.info( "PostInit" );
Registration.instance.PostInit( event );
Registration.INSTANCE.postInit( event );
IntegrationRegistry.INSTANCE.postInit();
FMLCommonHandler.instance().registerCrashCallable( new CrashEnhancement( CrashInfo.INTEGRATION ) );

View file

@ -18,22 +18,34 @@
package appeng.core;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import appeng.api.AEApi;
import appeng.api.IAppEngApi;
import appeng.api.definitions.Items;
import appeng.api.definitions.Materials;
import appeng.api.util.AEItemDefinition;
public final class CreativeTab extends CreativeTabs
{
public static CreativeTab instance = null;
public CreativeTab() {
public CreativeTab()
{
super( "appliedenergistics2" );
}
public static void init()
{
instance = new CreativeTab();
}
@Override
public Item getTabIconItem()
{
@ -43,26 +55,28 @@ public final class CreativeTab extends CreativeTabs
@Override
public ItemStack getIconItemStack()
{
return this.findFirst( AEApi.instance().blocks().blockController, AEApi.instance().blocks().blockChest, AEApi.instance().blocks().blockCellWorkbench, AEApi
.instance().blocks().blockFluix, AEApi.instance().items().itemCell1k, AEApi.instance().items().itemNetworkTool,
AEApi.instance().materials().materialFluixCrystal, AEApi.instance().materials().materialCertusQuartzCrystal );
final IAppEngApi api = AEApi.instance();
final appeng.api.definitions.Blocks blocks = api.blocks();
final Items items = api.items();
final Materials materials = api.materials();
return this.findFirst( blocks.blockController, blocks.blockChest, blocks.blockCellWorkbench, blocks.blockFluix, items.itemCell1k, items.itemNetworkTool, materials.materialFluixCrystal, materials.materialCertusQuartzCrystal );
}
private ItemStack findFirst(AEItemDefinition... choices)
private ItemStack findFirst( AEItemDefinition... choices )
{
for (AEItemDefinition a : choices)
for ( AEItemDefinition a : choices )
{
if ( a != null )
{
ItemStack is = a.stack( 1 );
if ( is != null )
{
return is;
}
}
}
return new ItemStack( Blocks.chest );
}
public static void init()
{
instance = new CreativeTab();
}
}

View file

@ -42,12 +42,14 @@ import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.Multimap;
import appeng.api.AEApi;
import appeng.api.IAppEngApi;
import appeng.api.config.Upgrades;
import appeng.api.definitions.Blocks;
import appeng.api.definitions.Items;
import appeng.api.definitions.Materials;
import appeng.api.definitions.Parts;
import appeng.api.features.IRecipeHandlerRegistry;
import appeng.api.features.IRegistryContainer;
import appeng.api.features.IWirelessTermHandler;
import appeng.api.features.IWorldGen.WorldGenType;
import appeng.api.movable.IMovableRegistry;
@ -209,9 +211,9 @@ import appeng.util.ClassInstantiation;
import appeng.util.Platform;
public class Registration
public final class Registration
{
final public static Registration instance = new Registration();
final public static Registration INSTANCE = new Registration();
private final RecipeHandler recipeHandler;
private final Multimap<AEFeature, Class<? extends IAEFeature>> featuresToEntities;
@ -223,7 +225,7 @@ public class Registration
this.featuresToEntities = ArrayListMultimap.create();
}
public void PreInit( FMLPreInitializationEvent event )
public void preInitialize( FMLPreInitializationEvent event )
{
this.registerSpatial( false );
@ -431,7 +433,8 @@ public class Registration
items.itemFacade = this.addFeature( ItemFacade.class );
items.itemCrystalSeed = this.addFeature( ItemCrystalSeed.class );
ColoredItemDefinition paintBall, lumenPaintBall;
ColoredItemDefinition paintBall;
ColoredItemDefinition lumenPaintBall;
items.itemPaintBall = paintBall = new ColoredItemDefinition();
items.itemLumenPaintBall = lumenPaintBall = new ColoredItemDefinition();
AEItemDefinition pb = this.addFeature( ItemPaintBall.class );
@ -537,7 +540,7 @@ public class Registration
}
}
public void Init( FMLInitializationEvent event )
public void initialize( FMLInitializationEvent event )
{
// Perform ore camouflage!
ItemMultiMaterial.instance.makeUnique();
@ -607,92 +610,101 @@ public class Registration
CraftingManager.getInstance().getRecipeList().add( new FacadeRecipe() );
}
public void PostInit( FMLPostInitializationEvent event )
public void postInit( FMLPostInitializationEvent event )
{
this.registerSpatial( true );
final IAppEngApi api = AEApi.instance();
final IRegistryContainer registries = api.registries();
final Parts parts = api.parts();
final Blocks blocks = api.blocks();
final Items items = api.items();
// default settings..
( ( P2PTunnelRegistry ) AEApi.instance().registries().p2pTunnel() ).configure();
( ( P2PTunnelRegistry ) registries.p2pTunnel() ).configure();
// add to localization..
PlayerMessages.values();
GuiText.values();
Api.instance.partHelper.initFMPSupport();
( ( BlockCableBus ) AEApi.instance().blocks().blockMultiPart.block() ).setupTile();
( ( BlockCableBus ) blocks.blockMultiPart.block() ).setupTile();
// Interface
Upgrades.CRAFTING.registerItem( AEApi.instance().parts().partInterface.stack( 1 ), 1 );
Upgrades.CRAFTING.registerItem( AEApi.instance().blocks().blockInterface.stack( 1 ), 1 );
Upgrades.CRAFTING.registerItem( parts.partInterface, 1 );
Upgrades.CRAFTING.registerItem( blocks.blockInterface, 1 );
// IO Port!
Upgrades.SPEED.registerItem( AEApi.instance().blocks().blockIOPort.stack( 1 ), 3 );
Upgrades.REDSTONE.registerItem( AEApi.instance().blocks().blockIOPort.stack( 1 ), 1 );
Upgrades.SPEED.registerItem( blocks.blockIOPort, 3 );
Upgrades.REDSTONE.registerItem( blocks.blockIOPort, 1 );
// Level Emitter!
Upgrades.FUZZY.registerItem( AEApi.instance().parts().partLevelEmitter.stack( 1 ), 1 );
Upgrades.CRAFTING.registerItem( AEApi.instance().parts().partLevelEmitter.stack( 1 ), 1 );
Upgrades.FUZZY.registerItem( parts.partLevelEmitter, 1 );
Upgrades.CRAFTING.registerItem( parts.partLevelEmitter, 1 );
// Import Bus
Upgrades.FUZZY.registerItem( AEApi.instance().parts().partImportBus.stack( 1 ), 1 );
Upgrades.REDSTONE.registerItem( AEApi.instance().parts().partImportBus.stack( 1 ), 1 );
Upgrades.CAPACITY.registerItem( AEApi.instance().parts().partImportBus.stack( 1 ), 2 );
Upgrades.SPEED.registerItem( AEApi.instance().parts().partImportBus.stack( 1 ), 4 );
Upgrades.FUZZY.registerItem( parts.partImportBus, 1 );
Upgrades.REDSTONE.registerItem( parts.partImportBus, 1 );
Upgrades.CAPACITY.registerItem( parts.partImportBus, 2 );
Upgrades.SPEED.registerItem( parts.partImportBus, 4 );
// Export Bus
Upgrades.FUZZY.registerItem( AEApi.instance().parts().partExportBus.stack( 1 ), 1 );
Upgrades.REDSTONE.registerItem( AEApi.instance().parts().partExportBus.stack( 1 ), 1 );
Upgrades.CAPACITY.registerItem( AEApi.instance().parts().partExportBus.stack( 1 ), 2 );
Upgrades.SPEED.registerItem( AEApi.instance().parts().partExportBus.stack( 1 ), 4 );
Upgrades.CRAFTING.registerItem( AEApi.instance().parts().partExportBus.stack( 1 ), 1 );
Upgrades.FUZZY.registerItem( parts.partExportBus, 1 );
Upgrades.REDSTONE.registerItem( parts.partExportBus, 1 );
Upgrades.CAPACITY.registerItem( parts.partExportBus, 2 );
Upgrades.SPEED.registerItem( parts.partExportBus, 4 );
Upgrades.CRAFTING.registerItem( parts.partExportBus, 1 );
// Storage Cells
Upgrades.FUZZY.registerItem( AEApi.instance().items().itemCell1k.stack( 1 ), 1 );
Upgrades.INVERTER.registerItem( AEApi.instance().items().itemCell1k.stack( 1 ), 1 );
Upgrades.FUZZY.registerItem( items.itemCell1k, 1 );
Upgrades.INVERTER.registerItem( items.itemCell1k, 1 );
Upgrades.FUZZY.registerItem( AEApi.instance().items().itemCell4k.stack( 1 ), 1 );
Upgrades.INVERTER.registerItem( AEApi.instance().items().itemCell4k.stack( 1 ), 1 );
Upgrades.FUZZY.registerItem( items.itemCell4k, 1 );
Upgrades.INVERTER.registerItem( items.itemCell4k, 1 );
Upgrades.FUZZY.registerItem( AEApi.instance().items().itemCell16k.stack( 1 ), 1 );
Upgrades.INVERTER.registerItem( AEApi.instance().items().itemCell16k.stack( 1 ), 1 );
Upgrades.FUZZY.registerItem( items.itemCell16k, 1 );
Upgrades.INVERTER.registerItem( items.itemCell16k, 1 );
Upgrades.FUZZY.registerItem( AEApi.instance().items().itemCell64k.stack( 1 ), 1 );
Upgrades.INVERTER.registerItem( AEApi.instance().items().itemCell64k.stack( 1 ), 1 );
Upgrades.FUZZY.registerItem( items.itemCell64k, 1 );
Upgrades.INVERTER.registerItem( items.itemCell64k, 1 );
Upgrades.FUZZY.registerItem( AEApi.instance().items().itemPortableCell.stack( 1 ), 1 );
Upgrades.INVERTER.registerItem( AEApi.instance().items().itemPortableCell.stack( 1 ), 1 );
Upgrades.FUZZY.registerItem( items.itemPortableCell, 1 );
Upgrades.INVERTER.registerItem( items.itemPortableCell, 1 );
Upgrades.FUZZY.registerItem( AEApi.instance().items().itemViewCell.stack( 1 ), 1 );
Upgrades.INVERTER.registerItem( AEApi.instance().items().itemViewCell.stack( 1 ), 1 );
Upgrades.FUZZY.registerItem( items.itemViewCell, 1 );
Upgrades.INVERTER.registerItem( items.itemViewCell, 1 );
// Storage Bus
Upgrades.FUZZY.registerItem( AEApi.instance().parts().partStorageBus.stack( 1 ), 1 );
Upgrades.INVERTER.registerItem( AEApi.instance().parts().partStorageBus.stack( 1 ), 1 );
Upgrades.CAPACITY.registerItem( AEApi.instance().parts().partStorageBus.stack( 1 ), 5 );
Upgrades.FUZZY.registerItem( parts.partStorageBus, 1 );
Upgrades.INVERTER.registerItem( parts.partStorageBus, 1 );
Upgrades.CAPACITY.registerItem( parts.partStorageBus, 5 );
// Formation Plane
Upgrades.FUZZY.registerItem( AEApi.instance().parts().partFormationPlane.stack( 1 ), 1 );
Upgrades.INVERTER.registerItem( AEApi.instance().parts().partFormationPlane.stack( 1 ), 1 );
Upgrades.CAPACITY.registerItem( AEApi.instance().parts().partFormationPlane.stack( 1 ), 5 );
Upgrades.FUZZY.registerItem( parts.partFormationPlane, 1 );
Upgrades.INVERTER.registerItem( parts.partFormationPlane, 1 );
Upgrades.CAPACITY.registerItem( parts.partFormationPlane, 5 );
// Matter Cannon
Upgrades.FUZZY.registerItem( AEApi.instance().items().itemMassCannon.stack( 1 ), 1 );
Upgrades.INVERTER.registerItem( AEApi.instance().items().itemMassCannon.stack( 1 ), 1 );
Upgrades.SPEED.registerItem( AEApi.instance().items().itemMassCannon.stack( 1 ), 4 );
Upgrades.FUZZY.registerItem( items.itemMassCannon, 1 );
Upgrades.INVERTER.registerItem( items.itemMassCannon, 1 );
Upgrades.SPEED.registerItem( items.itemMassCannon, 4 );
// Molecular Assembler
Upgrades.SPEED.registerItem( AEApi.instance().blocks().blockMolecularAssembler.stack( 1 ), 5 );
Upgrades.SPEED.registerItem( blocks.blockMolecularAssembler, 5 );
// Inscriber
Upgrades.SPEED.registerItem( AEApi.instance().blocks().blockInscriber.stack( 1 ), 3 );
Upgrades.SPEED.registerItem( blocks.blockInscriber, 3 );
AEApi.instance().registries().wireless().registerWirelessHandler( ( IWirelessTermHandler ) AEApi.instance().items().itemWirelessTerminal.item() );
if ( items.itemWirelessTerminal != null )
{
registries.wireless().registerWirelessHandler( ( IWirelessTermHandler ) items.itemWirelessTerminal.item() );
}
if ( AEConfig.instance.isFeatureEnabled( AEFeature.ChestLoot ) )
{
ChestGenHooks d = ChestGenHooks.getInfo( ChestGenHooks.MINESHAFT_CORRIDOR );
d.addItem( new WeightedRandomChestContent( AEApi.instance().materials().materialCertusQuartzCrystal.stack( 1 ), 1, 4, 2 ) );
d.addItem( new WeightedRandomChestContent( AEApi.instance().materials().materialCertusQuartzDust.stack( 1 ), 1, 4, 2 ) );
d.addItem( new WeightedRandomChestContent( api.materials().materialCertusQuartzCrystal.stack( 1 ), 1, 4, 2 ) );
d.addItem( new WeightedRandomChestContent( api.materials().materialCertusQuartzDust.stack( 1 ), 1, 4, 2 ) );
}
// add villager trading to black smiths for a few basic materials
@ -707,7 +719,7 @@ public class Registration
GameRegistry.registerWorldGenerator( new MeteoriteWorldGen(), 0 );
}
IMovableRegistry mr = AEApi.instance().registries().movable();
IMovableRegistry mr = registries.movable();
/**
* You can't move bed rock.
@ -747,19 +759,19 @@ public class Registration
*/
for ( WorldGenType type : WorldGenType.values() )
{
AEApi.instance().registries().worldgen().disableWorldGenForProviderID( type, StorageWorldProvider.class );
registries.worldgen().disableWorldGenForProviderID( type, StorageWorldProvider.class );
// nether
AEApi.instance().registries().worldgen().disableWorldGenForDimension( type, -1 );
registries.worldgen().disableWorldGenForDimension( type, -1 );
// end
AEApi.instance().registries().worldgen().disableWorldGenForDimension( type, 1 );
registries.worldgen().disableWorldGenForDimension( type, 1 );
}
// whitelist from config
for ( int dimension : AEConfig.instance.meteoriteDimensionWhitelist )
{
AEApi.instance().registries().worldgen().enableWorldGenForDimension( WorldGenType.Meteorites, dimension );
registries.worldgen().enableWorldGenForDimension( WorldGenType.Meteorites, dimension );
}
/**

View file

@ -53,7 +53,7 @@ public class StorageWorldProvider extends WorldProvider
@Override
protected void registerWorldChunkManager()
{
super.worldChunkMgr = new WorldChunkManagerHell( Registration.instance.storageBiome, 0.0F );
super.worldChunkMgr = new WorldChunkManagerHell( Registration.INSTANCE.storageBiome, 0.0F );
}
@Override

View file

@ -48,12 +48,12 @@ import appeng.util.Platform;
public class TileQuantumBridge extends AENetworkInvTile implements IAEMultiBlock
{
final private static ItemStack ring = AEApi.instance().blocks().blockQuantumRing.stack( 1 );
final private static ItemStack RING_STACK = ( AEApi.instance().blocks().blockQuantumRing != null ) ? AEApi.instance().blocks().blockQuantumRing.stack( 1 ) : null;
final int sidesRing[] = new int[] {};
final int sidesLink[] = new int[] { 0 };
final int[] sidesRing = new int[] { };
final int[] sidesLink = new int[] { 0 };
final AppEngInternalInventory inv = new AppEngInternalInventory( this, 1 );
final AppEngInternalInventory internalInventory = new AppEngInternalInventory( this, 1 );
public final byte corner = 16;
final byte hasSingularity = 32;
@ -68,7 +68,7 @@ public class TileQuantumBridge extends AENetworkInvTile implements IAEMultiBlock
private boolean updateStatus = false;
@TileEvent(TileEventType.TICK)
public void Tick_TileQuantumBridge()
public void onTickEvent()
{
if ( this.updateStatus )
{
@ -80,25 +80,25 @@ public class TileQuantumBridge extends AENetworkInvTile implements IAEMultiBlock
}
@TileEvent(TileEventType.NETWORK_WRITE)
public void writeToStream_TileQuantumBridge(ByteBuf data)
public void onNetworkWriteEvent( ByteBuf data )
{
int out = this.constructed;
if ( this.getStackInSlot( 0 ) != null && this.constructed != -1 )
out = out | this.hasSingularity;
out |= this.hasSingularity;
if ( this.gridProxy.isActive() && this.constructed != -1 )
out = out | this.powered;
out |= this.powered;
data.writeByte( (byte) out );
}
@TileEvent(TileEventType.NETWORK_READ)
public boolean readFromStream_TileQuantumBridge(ByteBuf data)
public boolean onNetworkReadEvent( ByteBuf data )
{
int oldValue = this.constructed;
this.constructed = data.readByte();
this.bridgePowered = (this.constructed | this.powered) == this.powered;
this.bridgePowered = ( this.constructed | this.powered ) == this.powered;
return this.constructed != oldValue;
}
@ -106,17 +106,17 @@ public class TileQuantumBridge extends AENetworkInvTile implements IAEMultiBlock
this.gridProxy.setValidSides( EnumSet.noneOf( ForgeDirection.class ) );
this.gridProxy.setFlags( GridFlags.DENSE_CAPACITY );
this.gridProxy.setIdlePowerUsage( 22 );
this.inv.setMaxStackSize( 1 );
this.internalInventory.setMaxStackSize( 1 );
}
@Override
public IInventory getInternalInventory()
{
return this.inv;
return this.internalInventory;
}
@MENetworkEventSubscribe
public void PowerSwitch(MENetworkPowerStatusChange c)
public void onPowerStatusChange( MENetworkPowerStatusChange c )
{
this.updateStatus = true;
}
@ -170,7 +170,7 @@ public class TileQuantumBridge extends AENetworkInvTile implements IAEMultiBlock
{
super.onReady();
if ( this.worldObj.getBlock( this.xCoord, this.yCoord, this.zCoord ) == AEApi.instance().blocks().blockQuantumRing.block() )
this.gridProxy.setVisualRepresentation( ring );
this.gridProxy.setVisualRepresentation( RING_STACK );
}
@Override
@ -210,7 +210,7 @@ public class TileQuantumBridge extends AENetworkInvTile implements IAEMultiBlock
public long getQEFrequency()
{
ItemStack is = this.inv.getStackInSlot( 0 );
ItemStack is = this.internalInventory.getStackInSlot( 0 );
if ( is != null )
{
NBTTagCompound c = is.getTagCompound();
@ -227,13 +227,13 @@ public class TileQuantumBridge extends AENetworkInvTile implements IAEMultiBlock
public boolean isCorner()
{
return (this.constructed & this.corner) == this.corner && this.constructed != -1;
return ( this.constructed & this.corner ) == this.corner && this.constructed != -1;
}
public boolean isPowered()
{
if ( Platform.isClient() )
return (this.constructed & this.powered) == this.powered && this.constructed != -1;
return ( this.constructed & this.powered ) == this.powered && this.constructed != -1;
try
{
@ -287,7 +287,7 @@ public class TileQuantumBridge extends AENetworkInvTile implements IAEMultiBlock
{
if ( this.constructed == -1 )
return false;
return (this.constructed & this.hasSingularity) == this.hasSingularity;
return ( this.constructed & this.hasSingularity ) == this.hasSingularity;
}
public void breakCluster()