From 4c93eb6bf479691d8800d816290f10eeb46dcecd Mon Sep 17 00:00:00 2001 From: MysteriousAges Date: Thu, 3 Sep 2015 16:17:05 -0700 Subject: [PATCH] Update to forestry 3.6 API. Adds Aura node Recharge effect. --- build.gradle | 5 + gradle.properties | 1 + src/main/java/magicbees/bees/Allele.java | 4 + .../java/magicbees/bees/BeeGenomeManager.java | 2 +- src/main/java/magicbees/bees/BeeMutation.java | 12 +- .../java/magicbees/bees/BeeProductHelper.java | 8 +- src/main/java/magicbees/bees/BeeSpecies.java | 22 ++-- .../allele/effect/AlleleEffectRecharge.java | 45 +++++++ .../FlowerProviderAuraNode.java | 14 ++- .../FlowerProviderThaumcraftFlower.java | 11 +- src/main/java/magicbees/item/ItemGrafter.java | 4 +- src/main/java/magicbees/main/Config.java | 24 +--- .../java/magicbees/main/utils/BlockUtil.java | 21 ++++ .../magicbees/main/utils/CraftingManager.java | 4 +- .../main/utils/compat/ThaumcraftHelper.java | 109 ++++++++++++----- .../utils/compat/thaumcraft/NodeHelper.java | 114 ++++++++++++++++++ 16 files changed, 317 insertions(+), 83 deletions(-) create mode 100644 src/main/java/magicbees/bees/allele/effect/AlleleEffectRecharge.java create mode 100644 src/main/java/magicbees/main/utils/compat/thaumcraft/NodeHelper.java diff --git a/build.gradle b/build.gradle index 51f5fbf..cd8de5d 100644 --- a/build.gradle +++ b/build.gradle @@ -20,6 +20,10 @@ repositories { name = "forestry" url = "http://maven.ic2.player.to/" } + ivy { + name = "Baubles" + artifactPattern "http://addons-origin.cursecdn.com/files/2224/857/[module]-1.7.10-[revision].[ext]" + } } apply plugin: 'forge' @@ -40,6 +44,7 @@ minecraft { dependencies { compile "net.sengir.forestry:forestry_${project.version_mc}:${project.version_forestry}:api" runtime "net.sengir.forestry:forestry_${project.version_mc}:${project.version_forestry}:dev" + compile name: "Baubles", version: "${version_baubles}", ext: "jar" compile files("/libs/BloodMagic-${project.version_mc}-${project.version_bloodmagic}.jar") compile files("/libs/Botania ${project.version_botania}-deobf.jar") } diff --git a/gradle.properties b/gradle.properties index 07384a2..153afba 100644 --- a/gradle.properties +++ b/gradle.properties @@ -5,6 +5,7 @@ version_rev=4 version_forestry=3.6.3.20 version_bloodmagic=1.3.3-4 version_botania=r1.6-197 +version_baubles=1.0.1.10 version_mc=1.7.10 version_forge=10.13.2.1291 diff --git a/src/main/java/magicbees/bees/Allele.java b/src/main/java/magicbees/bees/Allele.java index d9c3401..5c5b074 100644 --- a/src/main/java/magicbees/bees/Allele.java +++ b/src/main/java/magicbees/bees/Allele.java @@ -4,6 +4,7 @@ import magicbees.api.MagicBeesAPI; import magicbees.bees.allele.effect.AlleleEffectCrumbling; import magicbees.bees.allele.effect.AlleleEffectCure; import magicbees.bees.allele.effect.AlleleEffectPotion; +import magicbees.bees.allele.effect.AlleleEffectRecharge; import magicbees.bees.allele.effect.AlleleEffectSpawnMob; import magicbees.bees.allele.effect.AlleleEffectSpawnMobWeighted; import magicbees.bees.allele.effect.AlleleEffectSpawnWisp; @@ -47,6 +48,7 @@ public class Allele implements IAllele { public static IAlleleEffect effectMoveSpeed; public static IAlleleEffect effectSlowSpeed; public static IAlleleEffect effectWithering; + public static IAlleleEffect effectVisRecharge; public static IAlleleEffect effectTransmuting; public static IAlleleEffect effectCrumbling; public static IAlleleEffect effectInvisibility; @@ -73,6 +75,8 @@ public class Allele implements IAllele { if (ThaumcraftHelper.isActive()) { Allele.flowerThaumcraft = new AlleleFlower("ThaumcraftPlant", new FlowerProviderThaumcraftFlower(), false); Allele.flowerAuraNode = new AlleleFlower("AuraNode", new FlowerProviderAuraNode(), true); + + Allele.effectVisRecharge = new AlleleEffectRecharge("VisRecharge", false); Allele.spawnBrainyZombie = new AlleleEffectSpawnMob("Brainy", false, ThaumcraftHelper.Entity.BRAINY_ZOMBIE.entityID) .setAggrosPlayerOnSpawn() diff --git a/src/main/java/magicbees/bees/BeeGenomeManager.java b/src/main/java/magicbees/bees/BeeGenomeManager.java index 39ea409..623d526 100644 --- a/src/main/java/magicbees/bees/BeeGenomeManager.java +++ b/src/main/java/magicbees/bees/BeeGenomeManager.java @@ -894,7 +894,7 @@ public class BeeGenomeManager { IAllele[] genome = getTemplateTCBaseVis(); genome[EnumBeeChromosome.SPECIES.ordinal()] = BeeSpecies.TC_REJUVENATING; - //genome[EnumBeeChromosome.EFFECT.ordinal()] = Allele.effectNodeCharge; + genome[EnumBeeChromosome.EFFECT.ordinal()] = Allele.effectVisRecharge; genome[EnumBeeChromosome.FLOWER_PROVIDER.ordinal()] = Allele.flowerAuraNode; genome[EnumBeeChromosome.HUMIDITY_TOLERANCE.ordinal()] = Allele.getBaseAllele("toleranceNone"); diff --git a/src/main/java/magicbees/bees/BeeMutation.java b/src/main/java/magicbees/bees/BeeMutation.java index 8261193..8777450 100644 --- a/src/main/java/magicbees/bees/BeeMutation.java +++ b/src/main/java/magicbees/bees/BeeMutation.java @@ -231,17 +231,17 @@ public class BeeMutation implements IBeeMutation { if (ThaumcraftHelper.isActive()) { new BeeMutation(BeeSpecies.WINDY, BeeSpecies.WINDY, BeeSpecies.TC_AIR, 8) - .setBlockAndMetaRequired(Config.tcCrystal, ThaumcraftHelper.ShardType.AIR.ordinal()); + .setBlockAndMetaRequired(ThaumcraftHelper.crystal, ThaumcraftHelper.ShardType.AIR.ordinal()); new BeeMutation(BeeSpecies.FIREY, BeeSpecies.FIREY, BeeSpecies.TC_FIRE, 8) - .setBlockAndMetaRequired(Config.tcCrystal, ThaumcraftHelper.ShardType.FIRE.ordinal()); + .setBlockAndMetaRequired(ThaumcraftHelper.crystal, ThaumcraftHelper.ShardType.FIRE.ordinal()); new BeeMutation(BeeSpecies.WATERY, BeeSpecies.WATERY, BeeSpecies.TC_WATER, 8) - .setBlockAndMetaRequired(Config.tcCrystal, ThaumcraftHelper.ShardType.WATER.ordinal()); + .setBlockAndMetaRequired(ThaumcraftHelper.crystal, ThaumcraftHelper.ShardType.WATER.ordinal()); new BeeMutation(BeeSpecies.EARTHY, BeeSpecies.EARTHY, BeeSpecies.TC_EARTH, 8) - .setBlockAndMetaRequired(Config.tcCrystal, ThaumcraftHelper.ShardType.EARTH.ordinal()); + .setBlockAndMetaRequired(ThaumcraftHelper.crystal, ThaumcraftHelper.ShardType.EARTH.ordinal()); new BeeMutation(BeeSpecies.ETHEREAL, BeeSpecies.ARCANE, BeeSpecies.TC_ORDER, 8) - .setBlockAndMetaRequired(Config.tcCrystal, ThaumcraftHelper.ShardType.ORDER.ordinal()); + .setBlockAndMetaRequired(ThaumcraftHelper.crystal, ThaumcraftHelper.ShardType.ORDER.ordinal()); new BeeMutation(BeeSpecies.ETHEREAL, BeeSpecies.SUPERNATURAL, BeeSpecies.TC_CHAOS, 8) - .setBlockAndMetaRequired(Config.tcCrystal, ThaumcraftHelper.ShardType.CHAOS.ordinal()); + .setBlockAndMetaRequired(ThaumcraftHelper.crystal, ThaumcraftHelper.ShardType.CHAOS.ordinal()); new BeeMutation(BeeSpecies.SKULKING, BeeSpecies.WINDY, BeeSpecies.TC_BATTY, 9); new BeeMutation(BeeSpecies.SKULKING, BeeSpecies.PUPIL, BeeSpecies.TC_BRAINY, 9); diff --git a/src/main/java/magicbees/bees/BeeProductHelper.java b/src/main/java/magicbees/bees/BeeProductHelper.java index 3f824d1..95cc89b 100644 --- a/src/main/java/magicbees/bees/BeeProductHelper.java +++ b/src/main/java/magicbees/bees/BeeProductHelper.java @@ -273,10 +273,10 @@ public class BeeProductHelper { TC_ORDER.addSpecialty(Config.propolis.getStackForType(PropolisType.ORDER), 0.18f); TC_CHAOS.addSpecialty(Config.propolis.getStackForType(PropolisType.CHAOS), 0.18f); - TC_BRAINY.addSpecialty(new ItemStack(Config.tcMiscResource, 1, ThaumcraftHelper.MiscResource.ZOMBIE_BRAIN.ordinal()), 0.2f); - TC_CHICKEN.addSpecialty(new ItemStack(Config.tcNuggetChicken, 1), 0.9f); - TC_BEEF.addSpecialty(new ItemStack(Config.tcNuggetBeef, 1), 0.9f); - TC_PORK.addSpecialty(new ItemStack(Config.tcNuggetPork, 1), 0.9f); + TC_BRAINY.addSpecialty(new ItemStack(ThaumcraftHelper.miscResource, 1, ThaumcraftHelper.MiscResource.ZOMBIE_BRAIN.ordinal()), 0.2f); + TC_CHICKEN.addSpecialty(new ItemStack(ThaumcraftHelper.nuggetChicken, 1), 0.9f); + TC_BEEF.addSpecialty(new ItemStack(ThaumcraftHelper.nuggetBeef, 1), 0.9f); + TC_PORK.addSpecialty(new ItemStack(ThaumcraftHelper.nuggetPork, 1), 0.9f); } } diff --git a/src/main/java/magicbees/bees/BeeSpecies.java b/src/main/java/magicbees/bees/BeeSpecies.java index e988821..a7fbd79 100644 --- a/src/main/java/magicbees/bees/BeeSpecies.java +++ b/src/main/java/magicbees/bees/BeeSpecies.java @@ -478,7 +478,7 @@ public enum BeeSpecies implements IAlleleBeeSpecies, IIconProvider // These species should be fixed. ¯\_(ツ)_/¯ TC_TAINT.setInactive(); TC_ATTRACT.setInactive(); - TC_REJUVENATING.setInactive(); + //TC_REJUVENATING.setInactive(); BeeProductHelper.initEquivalentExchange3Species(); if (!EquivalentExchangeHelper.isActive()) { @@ -556,7 +556,11 @@ public enum BeeSpecies implements IAlleleBeeSpecies, IIconProvider private boolean isNocturnal; private IClassification branch; private HashMap products; + @Deprecated + private HashMap oldProducts; private HashMap specialties; + @Deprecated + private HashMap oldSpecialties; private IAllele genomeTemplate[]; private String uid; private boolean dominant; @@ -604,7 +608,9 @@ public enum BeeSpecies implements IAlleleBeeSpecies, IIconProvider isSecret = isSpeciesSecret; isCounted = isSpeciesCounted; products = new HashMap(); + oldProducts = new HashMap(); specialties = new HashMap(); + oldSpecialties = new HashMap(); this.branch = classification; this.branch.addMemberSpecies(this); this.isNocturnal = isSpeciesNocturnal; @@ -617,23 +623,25 @@ public enum BeeSpecies implements IAlleleBeeSpecies, IIconProvider @Deprecated public BeeSpecies addProduct(ItemStack produce, int percentChance) { - products.put(produce, percentChance / 100f); - return this; + // Don't use this plz. + return null; } public BeeSpecies addProduct(ItemStack produce, float chance) { products.put(produce, chance); + oldProducts.put(produce, (int)(chance * 100)); return this; } @Deprecated public BeeSpecies addSpecialty(ItemStack produce, int percentChance) { - specialties.put(produce, percentChance / 100f); - return this; + // Don't use this plz. + return null; } public BeeSpecies addSpecialty(ItemStack produce, float chance) { specialties.put(produce, chance); + oldSpecialties.put(produce, (int)(chance * 100)); return this; } @@ -719,13 +727,13 @@ public enum BeeSpecies implements IAlleleBeeSpecies, IIconProvider @Override @Deprecated public HashMap getProducts() { - return null; + return oldProducts; } @Override @Deprecated public HashMap getSpecialty() { - return null; + return oldSpecialties; } @Override diff --git a/src/main/java/magicbees/bees/allele/effect/AlleleEffectRecharge.java b/src/main/java/magicbees/bees/allele/effect/AlleleEffectRecharge.java new file mode 100644 index 0000000..acc48b9 --- /dev/null +++ b/src/main/java/magicbees/bees/allele/effect/AlleleEffectRecharge.java @@ -0,0 +1,45 @@ +package magicbees.bees.allele.effect; + +import java.util.List; + +import magicbees.bees.AlleleEffect; +import magicbees.main.utils.BlockUtil; +import magicbees.main.utils.compat.thaumcraft.NodeHelper; +import net.minecraft.world.World; +import net.minecraft.world.chunk.Chunk; +import forestry.api.apiculture.IBeeGenome; +import forestry.api.apiculture.IBeeHousing; +import forestry.api.genetics.IEffectData; + +public class AlleleEffectRecharge extends AlleleEffect { + + private int range; + + public AlleleEffectRecharge(String id, boolean isDominant) { + super(id, isDominant, 10); + range = 20; + } + + @Override + public IEffectData validateStorage(IEffectData storedData) { + if (storedData == null || !(storedData instanceof magicbees.bees.EffectData)) { + storedData = new magicbees.bees.EffectData(1, 0, 0); + } + return storedData; + } + + @Override + protected IEffectData doEffectThrottled(IBeeGenome genome, IEffectData storedData, IBeeHousing housing) { + World world = housing.getWorld(); + int xCoord = housing.getXCoord(); + int yCoord = housing.getYCoord(); + int zCoord = housing.getZCoord(); + List chunks = BlockUtil.getChunksInSearchRange(world, xCoord, zCoord, range); + + if (NodeHelper.rechargeNodeInRange(chunks, world, xCoord, yCoord, zCoord, range)) { + storedData.setInteger(0, storedData.getInteger(0) - throttle); + } + + return storedData; + } +} diff --git a/src/main/java/magicbees/bees/allele/flowerProvider/FlowerProviderAuraNode.java b/src/main/java/magicbees/bees/allele/flowerProvider/FlowerProviderAuraNode.java index 5d39782..4aa86e3 100644 --- a/src/main/java/magicbees/bees/allele/flowerProvider/FlowerProviderAuraNode.java +++ b/src/main/java/magicbees/bees/allele/flowerProvider/FlowerProviderAuraNode.java @@ -4,8 +4,11 @@ import java.util.ArrayList; import java.util.List; import magicbees.main.utils.LocalizationManager; +import magicbees.main.utils.compat.ThaumcraftHelper; +import net.minecraft.block.Block; import net.minecraft.item.ItemStack; import net.minecraft.world.World; +import net.minecraftforge.oredict.OreDictionary; import forestry.api.genetics.IFlower; import forestry.api.genetics.IIndividual; import forestry.api.genetics.IPollinatable; @@ -13,11 +16,20 @@ import forestry.api.genetics.IPollinatable; public class FlowerProviderAuraNode extends FlowerProvider { public FlowerProviderAuraNode() { - super(0); + super(2); + flowers.add(new FlowerImpl(ThaumcraftHelper.airy, ThaumcraftHelper.AiryBlockType.NODE.ordinal(), 1, false)); + flowers.add(new FlowerImpl(ThaumcraftHelper.airy, ThaumcraftHelper.AiryBlockType.ENERGIZED_NODE.ordinal(), 1, false)); } @Override public boolean isAcceptedFlower(World world, IIndividual genome, int x, int y, int z) { + Block block = world.getBlock(x, y, z); + int meta = world.getBlockMetadata(x, y, z); + for (IFlower flower : flowers) { + if (flower.getBlock() == block && (flower.getMeta() == OreDictionary.WILDCARD_VALUE || flower.getMeta() == meta)) { + return true; + } + } return false; } diff --git a/src/main/java/magicbees/bees/allele/flowerProvider/FlowerProviderThaumcraftFlower.java b/src/main/java/magicbees/bees/allele/flowerProvider/FlowerProviderThaumcraftFlower.java index 05bd357..863fc00 100644 --- a/src/main/java/magicbees/bees/allele/flowerProvider/FlowerProviderThaumcraftFlower.java +++ b/src/main/java/magicbees/bees/allele/flowerProvider/FlowerProviderThaumcraftFlower.java @@ -1,6 +1,5 @@ package magicbees.bees.allele.flowerProvider; -import magicbees.main.Config; import magicbees.main.utils.LocalizationManager; import magicbees.main.utils.compat.ThaumcraftHelper; import net.minecraft.block.Block; @@ -14,13 +13,13 @@ public class FlowerProviderThaumcraftFlower extends FlowerProvider { public FlowerProviderThaumcraftFlower() { super(2); - flowers.add(new FlowerImpl(Config.tcPlant, ThaumcraftHelper.BlockPlant.SHIMMERLEAF.ordinal(), 1, true)); - flowers.add(new FlowerImpl(Config.tcPlant, ThaumcraftHelper.BlockPlant.CINDERPEARL.ordinal(), 1, true)); + flowers.add(new FlowerImpl(ThaumcraftHelper.plant, ThaumcraftHelper.BlockPlant.SHIMMERLEAF.ordinal(), 1, true)); + flowers.add(new FlowerImpl(ThaumcraftHelper.plant, ThaumcraftHelper.BlockPlant.CINDERPEARL.ordinal(), 1, true)); } @Override public boolean isAcceptedFlower(World world, IIndividual genome, int x, int y, int z) { - if (world.getBlock(x, y, z) == Config.tcPlant) { + if (world.getBlock(x, y, z) == ThaumcraftHelper.plant) { int meta = world.getBlockMetadata(x, y, z); if (meta == ThaumcraftHelper.BlockPlant.SHIMMERLEAF.ordinal() || meta == ThaumcraftHelper.BlockPlant.CINDERPEARL.ordinal()) { @@ -36,10 +35,10 @@ public class FlowerProviderThaumcraftFlower extends FlowerProvider { Block blockDown = world.getBlock(x, y - 1, z); if (world.getBlock(x, y, z).isAir(world, x, y, z)) { if (blockDown == Blocks.dirt || blockDown == Blocks.grass) { - world.setBlock(x, y, z, Config.tcPlant, ThaumcraftHelper.BlockPlant.SHIMMERLEAF.ordinal(), 2); + world.setBlock(x, y, z, ThaumcraftHelper.plant, ThaumcraftHelper.BlockPlant.SHIMMERLEAF.ordinal(), 2); flag = true; } else if (blockDown == Blocks.sand) { - world.setBlock(x, y, z, Config.tcPlant, ThaumcraftHelper.BlockPlant.CINDERPEARL.ordinal(), 2); + world.setBlock(x, y, z, ThaumcraftHelper.plant, ThaumcraftHelper.BlockPlant.CINDERPEARL.ordinal(), 2); flag = true; } } diff --git a/src/main/java/magicbees/item/ItemGrafter.java b/src/main/java/magicbees/item/ItemGrafter.java index b934c65..f47c218 100644 --- a/src/main/java/magicbees/item/ItemGrafter.java +++ b/src/main/java/magicbees/item/ItemGrafter.java @@ -29,7 +29,7 @@ public class ItemGrafter extends Item implements IToolGrafter { public boolean onBlockDestroyed(ItemStack itemstack, World world, Block block, int x, int y, int z, EntityLivingBase entityLiving) { int damage = 1; if (ThaumcraftHelper.isActive()) { - if (block == Config.tcLeaf) + if (block == ThaumcraftHelper.leaf) { int meta = world.getBlockMetadata(x, y, z) & 1; if (meta == 0 || meta == 1) @@ -37,7 +37,7 @@ public class ItemGrafter extends Item implements IToolGrafter { double chance = Math.random(); if (chance <= Config.thaumcraftSaplingDroprate) { - this.dropItem(world, x, y, z, new ItemStack(Config.tcPlant, 1, meta)); + this.dropItem(world, x, y, z, new ItemStack(ThaumcraftHelper.plant, 1, meta)); } } } diff --git a/src/main/java/magicbees/main/Config.java b/src/main/java/magicbees/main/Config.java index e1a2408..6841e6a 100644 --- a/src/main/java/magicbees/main/Config.java +++ b/src/main/java/magicbees/main/Config.java @@ -157,29 +157,6 @@ public class Config public static Item fHoneydew; public static Item fHoneyDrop; public static Item fPollen; - public static Item fCraftingResource; - //----- Thaumcraft Blocks ---------------------------------- - public static Block tcPlant; - public static Block tcCandle; - public static Block tcCrystal; - public static Block tcMarker; - public static Block tcJar; - public static Block tcLog; - public static Block tcLeaf; - public static Block tcWarded; - public static Block tcWooden; - public static Block tcMetal; - //----- Thaumcraft Items ----------------------------------- - public static Item tcFilledJar; - public static Item tcMiscResource; - //public static Item tcEssentiaBottle; - public static Item tcShard; - public static Item tcGolem; - //public static Item tcWispEssence; - public static Item tcNuggets; - public static Item tcNuggetChicken; - public static Item tcNuggetBeef; - public static Item tcNuggetPork; //----- Equivalent Exchange Blocks ------------------------- //----- Equivalent Exchange Items -------------------------- public static Item eeMinuimShard; @@ -217,6 +194,7 @@ public class Config //----- Config State info ---------------------------------- public static Configuration configuration; + public static Item fCraftingResource; public Config(File configFile) { diff --git a/src/main/java/magicbees/main/utils/BlockUtil.java b/src/main/java/magicbees/main/utils/BlockUtil.java index 3fca28e..2c0de1d 100644 --- a/src/main/java/magicbees/main/utils/BlockUtil.java +++ b/src/main/java/magicbees/main/utils/BlockUtil.java @@ -1,7 +1,11 @@ package magicbees.main.utils; +import java.util.ArrayList; +import java.util.List; + import net.minecraft.block.Block; import net.minecraft.world.World; +import net.minecraft.world.chunk.Chunk; public class BlockUtil { @@ -52,4 +56,21 @@ public class BlockUtil { Block block = world.getBlock(x, y, z); return block.isReplaceableOreGen(world, x, y, z, target); } + + public static List getChunksInSearchRange(World world, int xCoord, int zCoord, int searchRadius) { + List searchChunks = new ArrayList(); + int chunkRange = (int)Math.ceil(searchRadius / 16.0); + int minChunkX = xCoord / 16 - chunkRange; + int maxChunkX = xCoord / 16 + chunkRange; + int minChunkZ = zCoord / 16 - chunkRange; + int maxChunkZ = zCoord / 16 + chunkRange; + + for (int chunkX = minChunkX; chunkX <= maxChunkX; ++chunkX) { + for (int chunkZ = minChunkZ; chunkZ <= maxChunkZ; ++chunkZ) { + searchChunks.add(world.getChunkFromChunkCoords(chunkX, chunkZ)); + } + } + + return searchChunks; + } } diff --git a/src/main/java/magicbees/main/utils/CraftingManager.java b/src/main/java/magicbees/main/utils/CraftingManager.java index 776a271..3375c23 100644 --- a/src/main/java/magicbees/main/utils/CraftingManager.java +++ b/src/main/java/magicbees/main/utils/CraftingManager.java @@ -373,7 +373,7 @@ public class CraftingManager { if (ThaumcraftHelper.isActive()) { input = Config.miscResources.getStackForType(ResourceType.LORE_FRAGMENT); - output = new ItemStack(Config.tcMiscResource, 1, ThaumcraftHelper.MiscResource.KNOWLEDGE_FRAGMENT.ordinal()); + output = new ItemStack(ThaumcraftHelper.miscResource, 1, ThaumcraftHelper.MiscResource.KNOWLEDGE_FRAGMENT.ordinal()); GameRegistry.addShapelessRecipe(output, input, input, input, input ); @@ -384,7 +384,7 @@ public class CraftingManager { "SWS", "NCN", "SWS", 'S', Items.string, 'W', Blocks.wool, - 'N', new ItemStack(Config.tcMiscResource, 1, ThaumcraftHelper.MiscResource.AMBER.ordinal()), + 'N', new ItemStack(ThaumcraftHelper.miscResource, 1, ThaumcraftHelper.MiscResource.AMBER.ordinal()), 'C', Blocks.chest ); } diff --git a/src/main/java/magicbees/main/utils/compat/ThaumcraftHelper.java b/src/main/java/magicbees/main/utils/compat/ThaumcraftHelper.java index 06dc66e..1000c4d 100644 --- a/src/main/java/magicbees/main/utils/compat/ThaumcraftHelper.java +++ b/src/main/java/magicbees/main/utils/compat/ThaumcraftHelper.java @@ -14,11 +14,14 @@ import magicbees.main.Config; import magicbees.main.utils.BlockInterface; import magicbees.main.utils.ItemInterface; import magicbees.main.utils.LocalizationManager; +import net.minecraft.block.Block; import net.minecraft.init.Blocks; import net.minecraft.init.Items; +import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.IRecipe; import net.minecraft.item.crafting.ShapelessRecipes; +import net.minecraft.tileentity.TileEntity; import net.minecraft.util.ResourceLocation; import thaumcraft.api.ThaumcraftApi; import thaumcraft.api.aspects.Aspect; @@ -106,6 +109,16 @@ public class ThaumcraftHelper { BANNER, ; } + + public enum AiryBlockType { + NODE, + NITOR, + _2, + _3, + WARDING_STONE_FENCE, + ENERGIZED_NODE, + ; + } public enum Entity { BRAINY_ZOMBIE("entBrainyZombie", "EntityBrainyZombie"), @@ -145,6 +158,33 @@ public class ThaumcraftHelper { ; } + public static Block plant; + public static Block candle; + public static Block crystal; + public static Block marker; + public static Block jar; + public static Block log; + public static Block leaf; + public static Block warded; + public static Block wooden; + public static Block metal; + public static Block airy; + public static Block fluxGas; + public static Block fluxGoo; + + public static Item filledJar; + public static Item miscResource; + //public static Item tcEssentiaBottle; + public static Item shard; + public static Item golem; + //public static Item tcWispEssence; + public static Item nuggetMetal; + public static Item nuggetChicken; + public static Item nuggetBeef; + public static Item nuggetPork; + + public static Class nodeClass; + public static final String Name = "Thaumcraft"; private static boolean isThaumcraftPresent = false; @@ -184,6 +224,12 @@ public class ThaumcraftHelper { setupItemAspects(); setupCrafting(); setupResearch(); + + try { + nodeClass = (Class) Class.forName("thaumcraft.common.tiles.TileNode"); + } catch (Throwable e) { + e.printStackTrace(); + } } } @@ -204,64 +250,65 @@ public class ThaumcraftHelper { private static Object visAuraProvider; private static void getBlocks() { - Config.tcPlant = BlockInterface.getBlock(Name, "blockCustomPlant"); - Config.tcCandle = BlockInterface.getBlock(Name, "blockCandle"); - Config.tcCrystal = BlockInterface.getBlock(Name, "blockCrystal"); - Config.tcMarker = BlockInterface.getBlock(Name, "blockMarker"); - Config.tcJar = BlockInterface.getBlock(Name, "blockJar"); - Config.tcLog = BlockInterface.getBlock(Name, "blockMagicalLog"); - Config.tcLeaf = BlockInterface.getBlock(Name, "blockMagicalLeaves"); - Config.tcWarded = BlockInterface.getBlock(Name, "blockWarded"); - Config.tcWooden = BlockInterface.getBlock(Name, "blockWoodenDevice"); - Config.tcMetal = BlockInterface.getBlock(Name, "blockMetalDevice"); + plant = BlockInterface.getBlock(Name, "blockCustomPlant"); + candle = BlockInterface.getBlock(Name, "blockCandle"); + crystal = BlockInterface.getBlock(Name, "blockCrystal"); + marker = BlockInterface.getBlock(Name, "blockMarker"); + jar = BlockInterface.getBlock(Name, "blockJar"); + log = BlockInterface.getBlock(Name, "blockMagicalLog"); + leaf = BlockInterface.getBlock(Name, "blockMagicalLeaves"); + warded = BlockInterface.getBlock(Name, "blockWarded"); + wooden = BlockInterface.getBlock(Name, "blockWoodenDevice"); + metal = BlockInterface.getBlock(Name, "blockMetalDevice"); + airy = BlockInterface.getBlock(Name, "blockAiry"); } private static void getItems() { - Config.tcFilledJar = ItemInterface.getItem(Name, "BlockJarFilledItem"); - Config.tcMiscResource = ItemInterface.getItem(Name, "ItemResource"); + filledJar = ItemInterface.getItem(Name, "BlockJarFilledItem"); + miscResource = ItemInterface.getItem(Name, "ItemResource"); // Config.tcEssentiaBottle = ItemInterface.getItem(Name, // "BlockJarFilledItem"); - Config.tcShard = ItemInterface.getItem(Name, "ItemShard"); - Config.tcGolem = ItemInterface.getItem(Name, "ItemGolemPlacer"); + shard = ItemInterface.getItem(Name, "ItemShard"); + golem = ItemInterface.getItem(Name, "ItemGolemPlacer"); // Config.tcWispEssence = ItemApi.getItem("itemWispEssence", // 0).getItem(); - Config.tcNuggets = ItemInterface.getItem(Name, "ItemNugget"); - Config.tcShard = ItemInterface.getItem(Name, "ItemShard"); - Config.tcNuggetChicken = ItemInterface.getItem(Name, + nuggetMetal = ItemInterface.getItem(Name, "ItemNugget"); + shard = ItemInterface.getItem(Name, "ItemShard"); + nuggetChicken = ItemInterface.getItem(Name, "ItemNuggetChicken"); - Config.tcNuggetBeef = ItemInterface.getItem(Name, "ItemNuggetBeef"); - Config.tcNuggetPork = ItemInterface.getItem(Name, "ItemNuggetPork"); + nuggetBeef = ItemInterface.getItem(Name, "ItemNuggetBeef"); + nuggetPork = ItemInterface.getItem(Name, "ItemNuggetPork"); } private static void setupCrafting() { ItemStack input, output; input = Config.miscResources.getStackForType(ResourceType.TC_DUST_AIR); - output = new ItemStack(Config.tcShard, 1, ShardType.AIR.ordinal()); + output = new ItemStack(shard, 1, ShardType.AIR.ordinal()); GameRegistry.addShapelessRecipe(output, input, input, input, input); input = Config.miscResources .getStackForType(ResourceType.TC_DUST_WATER); - output = new ItemStack(Config.tcShard, 1, ShardType.WATER.ordinal()); + output = new ItemStack(shard, 1, ShardType.WATER.ordinal()); GameRegistry.addShapelessRecipe(output, input, input, input, input); input = Config.miscResources.getStackForType(ResourceType.TC_DUST_FIRE); - output = new ItemStack(Config.tcShard, 1, ShardType.FIRE.ordinal()); + output = new ItemStack(shard, 1, ShardType.FIRE.ordinal()); GameRegistry.addShapelessRecipe(output, input, input, input, input); input = Config.miscResources .getStackForType(ResourceType.TC_DUST_EARTH); - output = new ItemStack(Config.tcShard, 1, ShardType.EARTH.ordinal()); + output = new ItemStack(shard, 1, ShardType.EARTH.ordinal()); GameRegistry.addShapelessRecipe(output, input, input, input, input); input = Config.miscResources .getStackForType(ResourceType.TC_DUST_ORDER); - output = new ItemStack(Config.tcShard, 1, ShardType.ORDER.ordinal()); + output = new ItemStack(shard, 1, ShardType.ORDER.ordinal()); GameRegistry.addShapelessRecipe(output, input, input, input, input); input = Config.miscResources .getStackForType(ResourceType.TC_DUST_CHAOS); - output = new ItemStack(Config.tcShard, 1, ShardType.CHAOS.ordinal()); + output = new ItemStack(shard, 1, ShardType.CHAOS.ordinal()); GameRegistry.addShapelessRecipe(output, input, input, input, input); thaumScoop = ThaumcraftApi.addArcaneCraftingRecipe("MB_Scoop", new ItemStack(Config.thaumiumScoop), @@ -269,28 +316,28 @@ public class ThaumcraftHelper { "sWs", "sTs", " T ", 's', Items.stick, 'W', Blocks.wool, - 'T', new ItemStack(Config.tcMiscResource, 1, MiscResource.THAUMIUM.ordinal()) }); + 'T', new ItemStack(miscResource, 1, MiscResource.THAUMIUM.ordinal()) }); thaumGrafter = ThaumcraftApi.addArcaneCraftingRecipe("MB_Grafter", new ItemStack(Config.thaumiumGrafter), new AspectList().add(Aspect.ORDER, 5), new Object[] { " T", " s ", "s ", 's', Items.stick, - 'T', new ItemStack(Config.tcMiscResource, 1, MiscResource.THAUMIUM.ordinal()) }); + 'T', new ItemStack(miscResource, 1, MiscResource.THAUMIUM.ordinal()) }); frameMagic = ThaumcraftApi.addArcaneCraftingRecipe("MB_FrameMagic", new ItemStack(Config.hiveFrameMagic), new AspectList().add(Aspect.ORDER, 5).add(Aspect.AIR, 2).add(Aspect.EARTH, 2), new Object[] { "sss", "sCs", "sss", 's', Items.stick, - 'C', new ItemStack(Config.tcMiscResource, 1, MiscResource.ENCHANTED_FABRIC.ordinal()) }); + 'C', new ItemStack(miscResource, 1, MiscResource.ENCHANTED_FABRIC.ordinal()) }); visAuraProvider = ThaumcraftApi.addArcaneCraftingRecipe("MB_VisAuraProvider", new ItemStack(Config.visAuraProvider), new AspectList().add(Aspect.ORDER, 60).add(Aspect.AIR, 60).add(Aspect.ENTROPY, 60).add(Aspect.WATER, 60), new Object[] { "ngn", "gvg", "npn", 'n', Items.gold_nugget, - 'g', new ItemStack(Config.tcWooden, 1, ThaumcraftHelper.WoodenDeviceType.PLANKS_GREATWOOD.ordinal()), - 'v', new ItemStack(Config.tcMetal, 1, ThaumcraftHelper.MetalDeviceType.VIS_RELAY.ordinal()), + 'g', new ItemStack(wooden, 1, WoodenDeviceType.PLANKS_GREATWOOD.ordinal()), + 'v', new ItemStack(metal, 1, MetalDeviceType.VIS_RELAY.ordinal()), 'p', Config.pollen.getStackForType(PollenType.UNUSUAL)}); essenceLife = ThaumcraftApi.addCrucibleRecipe("MB_EssenceLife", Config.miscResources.getStackForType(ResourceType.ESSENCE_FALSE_LIFE), @@ -368,7 +415,7 @@ public class ThaumcraftHelper { list.add(Config.miscResources.getStackForType(ResourceType.LORE_FRAGMENT)); list.add(Config.miscResources.getStackForType(ResourceType.LORE_FRAGMENT)); list.add(Config.miscResources.getStackForType(ResourceType.LORE_FRAGMENT)); - recipe = new ShapelessRecipes(new ItemStack(Config.tcMiscResource, 1, + recipe = new ShapelessRecipes(new ItemStack(miscResource, 1, MiscResource.KNOWLEDGE_FRAGMENT.ordinal()), list); new ResearchItem("MB_LoreFragment", category, diff --git a/src/main/java/magicbees/main/utils/compat/thaumcraft/NodeHelper.java b/src/main/java/magicbees/main/utils/compat/thaumcraft/NodeHelper.java new file mode 100644 index 0000000..f8fd280 --- /dev/null +++ b/src/main/java/magicbees/main/utils/compat/thaumcraft/NodeHelper.java @@ -0,0 +1,114 @@ +package magicbees.main.utils.compat.thaumcraft; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Map; + +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.Vec3; +import net.minecraft.world.ChunkPosition; +import net.minecraft.world.World; +import net.minecraft.world.chunk.Chunk; +import thaumcraft.api.aspects.Aspect; +import thaumcraft.api.aspects.AspectList; +import thaumcraft.api.nodes.INode; + +public class NodeHelper { + + @SuppressWarnings("unchecked") + public static INode findNode(Chunk chunk, int x, int y, int z, int range) { + Vec3 apiaryPos = Vec3.createVectorHelper(x, y, z); + List tileEntities = new ArrayList(((Map)chunk.chunkTileEntityMap).values()); + Collections.shuffle(tileEntities); + for (TileEntity entity : tileEntities) { + if (entity instanceof INode) { + Vec3 tePos = Vec3.createVectorHelper(entity.xCoord, entity.yCoord, entity.zCoord); + Vec3 result = apiaryPos.subtract(tePos); + if (result.lengthVector() <= range) { + return (INode)entity; + } + } + } + + return null; + } + + public static boolean rechargeNodeInRange(List chunks, World world, int xCoord, int yCoord, int zCoord, int range) { + Collections.shuffle(chunks); + for (Chunk chunk : chunks) { + INode nearestNode = findNode(chunk, xCoord, yCoord, zCoord, range); + boolean nodeChanged = false; + if (nearestNode != null) { + AspectList baseAspects = nearestNode.getAspectsBase().copy(); + AspectList currentAspects = nearestNode.getAspects().copy(); + for (Aspect aspect : nearestNode.getAspects().getAspects()) { + int diff = baseAspects.getAmount(aspect) - currentAspects.getAmount(aspect); + if (1 < diff) { + nearestNode.addToContainer(aspect, world.rand.nextInt(diff - 1) + 1); + nodeChanged = true; + } + else if (diff == 1) { + nearestNode.addToContainer(aspect, 1); + nodeChanged = true; + } + } + if (nodeChanged) { + updateNode(nearestNode, world); + } + return true; + } + } + return false; + } + + public static boolean growNodeInRange(List chunks, World world, int xCoord, int yCoord, int zCoord, int range) { + Collections.shuffle(chunks); + for (Chunk chunk : chunks) { + INode nearestNode = findNode(chunk, xCoord, yCoord, zCoord, range); + if (nearestNode != null) { + Aspect aspectToAdd; + if (0.55f <= world.rand.nextFloat()) { + List aspects = new ArrayList(Aspect.aspects.values()); + aspectToAdd = aspects.get(world.rand.nextInt(aspects.size())); + } + else { + switch (world.rand.nextInt(6)) { + default: + case 0: + aspectToAdd = Aspect.EARTH; + break; + case 1: + aspectToAdd = Aspect.WATER; + break; + case 2: + aspectToAdd = Aspect.FIRE; + break; + case 3: + aspectToAdd = Aspect.AIR; + break; + case 4: + aspectToAdd = Aspect.ORDER; + break; + case 5: + aspectToAdd = Aspect.ENTROPY; + break; + } + } + + nearestNode.setNodeVisBase(aspectToAdd, (short)(1 + world.rand.nextInt(2))); + updateNode(nearestNode, world); + return true; + } + } + return false; + } + + private static void updateNode(INode nearestNode, World world) { + if (nearestNode instanceof TileEntity) { + TileEntity tile = (TileEntity)nearestNode; + tile.markDirty(); + world.markBlockForUpdate(tile.xCoord, tile.yCoord, tile.zCoord); + } + } +}