Fixes #675 No disabled feature should log spam or crash anymore.

Deprecates the old usage of the AEItemDefinitions via the direct method access of

* blocks()
* parts()
* items()
* materials()

and thus use the new re-direct via definitions().

All definitions are now initialized, no matter what. But SubItems, Items and Blocks are not registered, if by chance are disabled.
This commit is contained in:
thatsIch
2015-01-03 02:53:14 +01:00
parent 3dd81433ac
commit 9986ffc458
385 changed files with 12477 additions and 8292 deletions
+52 -40
View File
@@ -28,7 +28,12 @@ import net.minecraft.village.MerchantRecipeList;
import cpw.mods.fml.common.registry.VillagerRegistry.IVillageTradeHandler;
import com.google.common.base.Optional;
import appeng.api.AEApi;
import appeng.api.definitions.IItemDefinition;
import appeng.api.definitions.IMaterials;
public class AETrading implements IVillageTradeHandler
{
@@ -48,60 +53,67 @@ public class AETrading implements IVillageTradeHandler
l.add( new MerchantRecipe( a, b ) );
}
private void addTrade(MerchantRecipeList list, ItemStack a, ItemStack b, Random rand, int conversion_Variance)
private void addTrade(MerchantRecipeList list, IItemDefinition inputDefinition, IItemDefinition outputDefinition, Random rand, int conversionVariance)
{
// Sell
ItemStack From = a.copy();
ItemStack To = b.copy();
final Optional<ItemStack> maybeInputStack = inputDefinition.maybeStack( 1 );
final Optional<ItemStack> maybeOutputStack = outputDefinition.maybeStack( 1 );
From.stackSize = 1 + (Math.abs( rand.nextInt() ) % (1 + conversion_Variance));
To.stackSize = 1;
if ( maybeInputStack.isPresent() && maybeOutputStack.isPresent() )
{
// Sell
ItemStack inputStack = maybeInputStack.get().copy();
ItemStack outputStack = maybeOutputStack.get().copy();
this.addToList( list, From, To );
inputStack.stackSize = 1 + (Math.abs( rand.nextInt() ) % (1 + conversionVariance));
outputStack.stackSize = 1;
this.addToList( list, inputStack, outputStack );
}
}
private void addMerchant(MerchantRecipeList list, ItemStack item, int emera, Random rand, int greed)
private void addMerchant(MerchantRecipeList list, IItemDefinition item, int emera, Random rand, int greed)
{
if ( item == null )
return;
// Sell
ItemStack From = item.copy();
ItemStack To = new ItemStack( Items.emerald );
int multiplier = (Math.abs( rand.nextInt() ) % 6);
emera += (Math.abs( rand.nextInt() ) % greed) - multiplier;
int mood = rand.nextInt() % 2;
From.stackSize = multiplier + mood;
To.stackSize = multiplier * emera - mood;
if ( To.stackSize < 0 )
for ( ItemStack itemStack : item.maybeStack( 1 ).asSet() )
{
From.stackSize -= To.stackSize;
To.stackSize -= To.stackSize;
// Sell
ItemStack from = itemStack.copy();
ItemStack to = new ItemStack( Items.emerald );
int multiplier = (Math.abs( rand.nextInt() ) % 6);
final int emeraldCost = emera + (Math.abs( rand.nextInt() ) % greed) - multiplier;
int mood = rand.nextInt() % 2;
from.stackSize = multiplier + mood;
to.stackSize = multiplier * emeraldCost - mood;
if ( to.stackSize < 0 )
{
from.stackSize -= to.stackSize;
to.stackSize -= to.stackSize;
}
this.addToList( list, from, to );
// Buy
ItemStack reverseTo = from.copy();
ItemStack reverseFrom = to.copy();
reverseFrom.stackSize *= rand.nextFloat() * 3.0f + 1.0f;
this.addToList( list, reverseFrom, reverseTo );
}
this.addToList( list, From, To );
// Buy
ItemStack reverseTo = From.copy();
ItemStack reverseFrom = To.copy();
reverseFrom.stackSize *= rand.nextFloat() * 3.0f + 1.0f;
this.addToList( list, reverseFrom, reverseTo );
}
@Override
public void manipulateTradesForVillager(EntityVillager villager, MerchantRecipeList recipeList, Random random)
{
this.addMerchant( recipeList, AEApi.instance().materials().materialSilicon.stack( 1 ), 1, random, 2 );
this.addMerchant( recipeList, AEApi.instance().materials().materialCertusQuartzCrystal.stack( 1 ), 2, random, 4 );
this.addMerchant( recipeList, AEApi.instance().materials().materialCertusQuartzDust.stack( 1 ), 1, random, 3 );
final IMaterials materials = AEApi.instance().definitions().materials();
this.addTrade( recipeList, AEApi.instance().materials().materialCertusQuartzDust.stack( 1 ),
AEApi.instance().materials().materialCertusQuartzCrystal.stack( 1 ), random, 2 );
this.addMerchant( recipeList, materials.silicon(), 1, random, 2 );
this.addMerchant( recipeList, materials.certusQuartzCrystal(), 2, random, 4 );
this.addMerchant( recipeList, materials.certusQuartzDust(), 1, random, 3 );
this.addTrade( recipeList, materials.certusQuartzDust(), materials.certusQuartzCrystal(), random, 2 );
}
}
@@ -1,166 +0,0 @@
/*
* 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.hooks;
import java.util.Collection;
import java.util.Random;
import java.util.concurrent.Callable;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
import net.minecraft.world.chunk.IChunkProvider;
import cpw.mods.fml.common.IWorldGenerator;
import appeng.api.features.IWorldGen.WorldGenType;
import appeng.core.AEConfig;
import appeng.core.WorldSettings;
import appeng.core.features.registries.WorldGenRegistry;
import appeng.helpers.MeteoritePlacer;
import appeng.services.compass.ICompassCallback;
import appeng.util.Platform;
final public class MeteoriteWorldGen implements IWorldGenerator
{
static class MyGen implements ICompassCallback
{
double distance = 0;
@Override
public void calculatedDirection(boolean hasResult, boolean spin, double radians, double dist)
{
if ( hasResult )
this.distance = dist;
else
this.distance = Double.MAX_VALUE;
}
}
@Override
public void generate(Random r, int chunkX, int chunkZ, World w, IChunkProvider chunkGenerator, IChunkProvider chunkProvider)
{
if ( WorldGenRegistry.INSTANCE.isWorldGenEnabled( WorldGenType.Meteorites, w ) )
{
// add new meteorites?
if ( r.nextFloat() < AEConfig.instance.meteoriteSpawnChance )
{
int x = r.nextInt( 16 ) + (chunkX << 4);
int z = r.nextInt( 16 ) + (chunkZ << 4);
int depth = 180 + r.nextInt( 20 );
TickHandler.INSTANCE.addCallable( w, new MeteoriteSpawn( x, depth, z, w ) );
}
else
TickHandler.INSTANCE.addCallable( w, new MeteoriteSpawn( chunkX << 4, 128, chunkZ << 4, w ) );
}
else
WorldSettings.getInstance().getCompass().updateArea( w, chunkX, chunkZ );
}
class MeteoriteSpawn implements Callable
{
final int x;
final int z;
final World w;
final int depth;
public MeteoriteSpawn(int x, int depth, int z, World w) {
this.x = x;
this.z = z;
this.w = w;
this.depth = depth;
}
@Override
public Object call() throws Exception
{
int chunkX = this.x >> 4;
int chunkZ = this.z >> 4;
double minSqDist = Double.MAX_VALUE;
// near by meteorites!
for (NBTTagCompound data : MeteoriteWorldGen.this.getNearByMeteorites( this.w, chunkX, chunkZ ))
{
MeteoritePlacer mp = new MeteoritePlacer();
mp.spawnMeteorite( new MeteoritePlacer.ChunkOnly( this.w, chunkX, chunkZ ), data );
minSqDist = Math.min( minSqDist, mp.getSqDistance( this.x, this.z ) );
}
boolean isCluster = (minSqDist < 30 * 30) && Platform.getRandomFloat() < AEConfig.instance.meteoriteClusterChance;
if ( minSqDist > AEConfig.instance.minMeteoriteDistanceSq || isCluster )
MeteoriteWorldGen.this.tryMeteorite( this.w, this.depth, this.x, this.z );
WorldSettings.getInstance().setGenerated( this.w.provider.dimensionId, chunkX, chunkZ );
WorldSettings.getInstance().getCompass().updateArea( this.w, chunkX, chunkZ );
return null;
}
}
private boolean tryMeteorite(World w, int depth, int x, int z)
{
for (int tries = 0; tries < 20; tries++)
{
MeteoritePlacer mp = new MeteoritePlacer();
if ( mp.spawnMeteorite( new MeteoritePlacer.ChunkOnly( w, x >> 4, z >> 4 ), x, depth, z ) )
{
int px = x >> 4;
int pz = z >> 4;
for (int cx = px - 6; cx < px + 6; cx++)
for (int cz = pz - 6; cz < pz + 6; cz++)
{
if ( w.getChunkProvider().chunkExists( cx, cz ) )
{
if ( px == cx && pz == cz )
continue;
if ( WorldSettings.getInstance().hasGenerated( w.provider.dimensionId, cx, cz ) )
{
MeteoritePlacer mp2 = new MeteoritePlacer();
mp2.spawnMeteorite( new MeteoritePlacer.ChunkOnly( w, cx, cz ), mp.getSettings() );
}
}
}
return true;
}
depth -= 15;
if ( depth < 40 )
return false;
}
return false;
}
private Collection<NBTTagCompound> getNearByMeteorites(World w, int chunkX, int chunkZ)
{
return WorldSettings.getInstance().getNearByMeteorites( w.provider.dimensionId, chunkX, chunkZ );
}
}
@@ -1,88 +0,0 @@
/*
* 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.hooks;
import java.util.Random;
import net.minecraft.block.Block;
import net.minecraft.init.Blocks;
import net.minecraft.world.World;
import net.minecraft.world.chunk.IChunkProvider;
import net.minecraft.world.gen.feature.WorldGenMinable;
import cpw.mods.fml.common.IWorldGenerator;
import appeng.api.AEApi;
import appeng.api.features.IWorldGen.WorldGenType;
import appeng.core.AEConfig;
import appeng.core.features.registries.WorldGenRegistry;
final public class QuartzWorldGen implements IWorldGenerator
{
final WorldGenMinable oreNormal;
final WorldGenMinable oreCharged;
public QuartzWorldGen() {
Block normal = AEApi.instance().blocks().blockQuartzOre.block();
Block charged = AEApi.instance().blocks().blockQuartzOreCharged.block();
if ( normal != null && charged != null )
{
this.oreNormal = new WorldGenMinable( normal, 0, AEConfig.instance.quartzOresPerCluster, Blocks.stone );
this.oreCharged = new WorldGenMinable( charged, 0, AEConfig.instance.quartzOresPerCluster, Blocks.stone );
}
else
this.oreNormal = this.oreCharged = null;
}
@Override
public void generate(Random r, int chunkX, int chunkZ, World w, IChunkProvider chunkGenerator, IChunkProvider chunkProvider)
{
int seaLevel = w.provider.getAverageGroundLevel() + 1;
if ( seaLevel < 20 )
{
int x = (chunkX << 4) + 8;
int z = (chunkZ << 4) + 8;
seaLevel = w.getHeightValue( x, z );
}
if ( this.oreNormal == null || this.oreCharged == null )
return;
double oreDepthMultiplier = AEConfig.instance.quartzOresClusterAmount * seaLevel / 64;
int scale = (int) Math.round( r.nextGaussian() * Math.sqrt( oreDepthMultiplier ) + oreDepthMultiplier );
for (int x = 0; x < (r.nextBoolean() ? scale * 2 : scale) / 2; ++x)
{
boolean isCharged = r.nextFloat() > AEConfig.instance.spawnChargedChance;
WorldGenMinable whichOre = isCharged ? this.oreCharged : this.oreNormal;
if ( WorldGenRegistry.INSTANCE.isWorldGenEnabled( isCharged ? WorldGenType.ChargedCertusQuartz : WorldGenType.CertusQuartz, w ) )
{
int cx = chunkX * 16 + r.nextInt( 22 );
int cy = r.nextInt( 40 * seaLevel / 64 ) + r.nextInt( 22 * seaLevel / 64 ) + 12 * seaLevel / 64;
int cz = chunkZ * 16 + r.nextInt( 22 );
whichOre.generate( w, r, cx, cy, cz );
}
}
}
}