Refactoring Transmutation effect somewhat to allow for greater flexibitily.

This commit is contained in:
MysteriousAges committed 2015-04-22 21:22:54 -07:00
1 parent 99c40a99a9
commit a6c235aa5a
5 files changed
+35 -28

No files matched your search

+11 -1
View File
@@ -1,5 +1,7 @@
package magicbees.bees;
import magicbees.api.MagicBeesAPI;
import magicbees.api.bees.ITransmutationEffectLogic;
import magicbees.bees.allele.effect.AlleleEffectCrumbling;
import magicbees.bees.allele.effect.AlleleEffectCure;
import magicbees.bees.allele.effect.AlleleEffectPotion;
@@ -7,6 +9,9 @@ import magicbees.bees.allele.effect.AlleleEffectSpawnMob;
import magicbees.bees.allele.effect.AlleleEffectSpawnMobWeighted;
import magicbees.bees.allele.effect.AlleleEffectSpawnWisp;
import magicbees.bees.allele.effect.AlleleEffectTransmuting;
import magicbees.bees.allele.effect.TransmutationEffectController;
import magicbees.bees.allele.effect.TransmutationEffectRailcraft;
import magicbees.bees.allele.effect.TransmutationEffectVanilla;
import magicbees.bees.allele.flowerProvider.FlowerProviderArsMagicaFlower;
import magicbees.bees.allele.flowerProvider.FlowerProviderAuraNode;
import magicbees.bees.allele.flowerProvider.FlowerProviderBookshelf;
@@ -122,7 +127,12 @@ public class Allele implements IAllele {
Allele.effectSlowSpeed = new AlleleEffectPotion("SlowSpeed", Potion.moveSlowdown, 3, false).setMalicious();
Allele.effectWithering = new AlleleEffectPotion("Withering", Potion.wither, 10, false).setMalicious();
Allele.effectTransmuting = new AlleleEffectTransmuting("Transmuting", true);
TransmutationEffectController controller = new TransmutationEffectController(new ITransmutationEffectLogic[] {
new TransmutationEffectRailcraft(),
new TransmutationEffectVanilla()
});
MagicBeesAPI.transmutationEffectController = controller;
Allele.effectTransmuting = new AlleleEffectTransmuting("Transmuting", true, controller);
Allele.effectCrumbling = new AlleleEffectCrumbling("Crumbling", true);
Allele.effectInvisibility = new AlleleEffectPotion("Invisibility", Potion.invisibility, 10, false);
@@ -1348,6 +1348,7 @@ public class BeeGenomeManager {
genome[EnumBeeChromosome.NOCTURNAL.ordinal()] = Allele.getBaseAllele("boolTrue");
genome[EnumBeeChromosome.CAVE_DWELLING.ordinal()] = Allele.getBaseAllele("boolTrue");
genome[EnumBeeChromosome.SPEED.ordinal()] = Allele.getBaseAllele("speedSlowest");
genome[EnumBeeChromosome.EFFECT.ordinal()] = Allele.effectSlowSpeed;
return genome;
}
@@ -9,8 +9,12 @@ import forestry.api.apiculture.IBeeHousing;
import forestry.api.genetics.IEffectData;
public class AlleleEffectTransmuting extends AlleleEffect {
public AlleleEffectTransmuting(String id, boolean isDominant) {
private TransmutationEffectController transmutationController;
public AlleleEffectTransmuting(String id, boolean isDominant, TransmutationEffectController effectController) {
super(id, isDominant, 200);
this.transmutationController = effectController;
}
@Override
@@ -34,7 +38,7 @@ public class AlleleEffectTransmuting extends AlleleEffect {
int zCoord = housing.getZCoord() + world.rand.nextInt(zRange) - zRange / 2;
BiomeGenBase biome = world.getBiomeGenForCoords(xCoord, zCoord);
TransmutationEffectController.instance.attemptTransmutations(world, biome,
transmutationController.attemptTransmutations(world, biome,
new ItemStack(world.getBlock(xCoord, yCoord, zCoord), 1, world.getBlockMetadata(xCoord, yCoord, zCoord)), xCoord, yCoord, zCoord);
storedData.setInteger(0, 0);
@@ -1,44 +1,37 @@
package magicbees.bees.allele.effect;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import cpw.mods.fml.common.FMLLog;
import magicbees.api.MagicBeesAPI;
import magicbees.api.bees.ITransmutationEffectController;
import magicbees.api.bees.ITransmutationEffectLogic;
import magicbees.main.utils.LogHelper;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.minecraft.world.biome.BiomeGenBase;
public class TransmutationEffectController implements ITransmutationEffectController {
private ArrayList<ITransmutationEffectLogic> logicObjects;
static TransmutationEffectController instance;
private List<ITransmutationEffectLogic> logicObjects;
public TransmutationEffectController() {
public TransmutationEffectController(ITransmutationEffectLogic[] effectLogic) {
logicObjects = new ArrayList<ITransmutationEffectLogic>();
logicObjects.add(new TransmutationEffectRailcraft());
logicObjects.add(new TransmutationEffectVanilla());
MagicBeesAPI.transmutationEffectController = instance = this;
for (ITransmutationEffectLogic logic : effectLogic) {
logicObjects.add(logic);
}
}
public void attemptTransmutations(World world, BiomeGenBase biome, ItemStack sourceBlock, int x, int y, int z) {
boolean done;
ITransmutationEffectLogic logic;
for (int i = 0; i < logicObjects.size(); i++) {
logic = logicObjects.get(i);
Collections.shuffle(logicObjects);
for (ITransmutationEffectLogic logic : logicObjects) {
try {
done = logic.tryTransmutation(world, biome, sourceBlock, x, y, z);
if (logic.tryTransmutation(world, biome, sourceBlock, x, y, z)) {
break;
}
} catch (Exception e) {
done = false;
FMLLog.warning("Magic Bees encountered an issue with an ITransmutationEffectLogic provider %s. Debug information follows.", logic.getClass()
.getName());
FMLLog.info(e.getMessage());
}
if (done) {
logicObjects.remove(i);
logicObjects.add(logic);
break;
LogHelper.warn(String.format("Magic Bees encountered an issue with an ITransmutationEffectLogic provider %s. Debug information follows.",
logic.getClass().getName()));
LogHelper.info(e.getMessage());
}
}
}
+1 -2
View File
@@ -52,8 +52,7 @@ public class MagicBees
this.modConfig.setupItems();
// LocalizationManager.setupLocalizationInfo();
new TransmutationEffectController();
LogHelper.info("Preinit completed");
}