diff --git a/build.properties b/build.properties index d86c6ca..cccb02e 100644 --- a/build.properties +++ b/build.properties @@ -1,3 +1,3 @@ minecraft_version=1.7.10 forge_version=10.13.1.1225 -mod_version=0.573 \ No newline at end of file +mod_version=0.574 \ No newline at end of file diff --git a/src/api/java/vazkii/botania/api/BotaniaAPI.java b/src/api/java/vazkii/botania/api/BotaniaAPI.java index f0e0866..96acba8 100644 --- a/src/api/java/vazkii/botania/api/BotaniaAPI.java +++ b/src/api/java/vazkii/botania/api/BotaniaAPI.java @@ -19,8 +19,10 @@ import java.util.Map; import java.util.Set; import net.minecraft.block.Block; +import net.minecraft.entity.Entity; import net.minecraft.init.Blocks; import net.minecraft.init.Items; +import net.minecraft.item.EnumRarity; import net.minecraft.item.Item; import net.minecraft.item.Item.ToolMaterial; import net.minecraft.item.ItemArmor.ArmorMaterial; @@ -29,6 +31,7 @@ import net.minecraft.item.crafting.CraftingManager; import net.minecraft.item.crafting.IRecipe; import net.minecraft.util.EnumChatFormatting; import net.minecraftforge.common.util.EnumHelper; +import net.minecraftforge.oredict.OreDictionary; import vazkii.botania.api.brew.Brew; import vazkii.botania.api.internal.DummyMethodHandler; import vazkii.botania.api.internal.DummySubTile; @@ -39,7 +42,9 @@ import vazkii.botania.api.lexicon.LexiconEntry; import vazkii.botania.api.recipe.RecipeBrew; import vazkii.botania.api.recipe.RecipeElvenTrade; import vazkii.botania.api.recipe.RecipeManaInfusion; +import vazkii.botania.api.recipe.RecipeMiniFlower; import vazkii.botania.api.recipe.RecipePetals; +import vazkii.botania.api.recipe.RecipePureDaisy; import vazkii.botania.api.recipe.RecipeRuneAltar; import vazkii.botania.api.subtile.SubTileEntity; import vazkii.botania.api.subtile.signature.BasicSignature; @@ -51,6 +56,8 @@ import vazkii.botania.api.wiki.WikiHooks; import com.google.common.collect.BiMap; import com.google.common.collect.HashBiMap; +import cpw.mods.fml.common.Loader; + public final class BotaniaAPI { private static List categories = new ArrayList(); @@ -59,20 +66,31 @@ public final class BotaniaAPI { public static Map knowledgeTypes = new HashMap(); public static Map brewMap = new LinkedHashMap(); + + public static List disposableBlocks = new ArrayList(); + public static List semiDisposableBlocks = new ArrayList(); public static List petalRecipes = new ArrayList(); - public static List runeAltarRecipes = new ArrayList(); + public static List pureDaisyRecipes = new ArrayList(); public static List manaInfusionRecipes = new ArrayList(); + public static List runeAltarRecipes = new ArrayList(); public static List elvenTradeRecipes = new ArrayList(); public static List brewRecipes = new ArrayList(); + public static List miniFlowerRecipes = new ArrayList(); private static BiMap> subTiles = HashBiMap.> create(); private static Map, SubTileSignature> subTileSignatures = new HashMap, SubTileSignature>(); public static Set subtilesForCreativeMenu = new LinkedHashSet(); + public static Map subTileMods = new HashMap(); + public static BiMap miniFlowers = HashBiMap. create(); public static Map oreWeights = new HashMap(); - + public static Map oreWeightsNether = new HashMap(); public static Map seeds = new HashMap(); + public static Set looniumBlacklist = new LinkedHashSet(); + public static Set paintableBlocks = new LinkedHashSet(); + public static Set magnetBlacklist = new LinkedHashSet(); + public static Set> gravityRodBlacklist = new LinkedHashSet>(); public static ArmorMaterial manasteelArmorMaterial = EnumHelper.addArmorMaterial("MANASTEEL", 16, new int[] { 2, 6, 5, 2 }, 18); public static ToolMaterial manasteelToolMaterial = EnumHelper.addToolMaterial("MANASTEEL", 3, 300, 6.2F, 2F, 20); @@ -83,7 +101,15 @@ public final class BotaniaAPI { public static ArmorMaterial terrasteelArmorMaterial = EnumHelper.addArmorMaterial("TERRASTEEL", 34, new int[] {3, 8, 6, 3}, 26); public static ToolMaterial terrasteelToolMaterial = EnumHelper.addToolMaterial("TERRASTEEL", 4, 2300, 9F, 3F, 26); - public static KnowledgeType basicKnowledge, elvenKnowledge; + public static ArmorMaterial manaweaveArmorMaterial = EnumHelper.addArmorMaterial("MANAWEAVE", 5, new int[] { 1, 2, 2, 1 }, 18); + + public static EnumRarity rarityRelic = EnumHelper.addRarity("RELIC", EnumChatFormatting.GOLD, "Relic"); + + public static KnowledgeType basicKnowledge; + public static KnowledgeType elvenKnowledge; + + // This is here for completeness sake, but you shouldn't use it + public static KnowledgeType relicKnowledge; // All of these categories are initialized during botania's PreInit stage. public static LexiconCategory categoryBasics; @@ -104,23 +130,22 @@ public final class BotaniaAPI { basicKnowledge = registerKnowledgeType("minecraft", EnumChatFormatting.RESET, true); elvenKnowledge = registerKnowledgeType("alfheim", EnumChatFormatting.DARK_GREEN, false); + relicKnowledge = registerKnowledgeType("relic", EnumChatFormatting.DARK_PURPLE, false); addOreWeight("oreAluminum", 3940); // Tinkers' Construct addOreWeight("oreAmber", 2075); // Thaumcraft addOreWeight("oreApatite", 1595); // Forestry addOreWeight("oreBlueTopaz", 3195); // Ars Magica - addOreWeight("oreCassiterite", 1634); // GregTech addOreWeight("oreCertusQuartz", 3975); // Applied Energistics addOreWeight("oreChimerite", 3970); // Ars Magica addOreWeight("oreCinnabar", 2585); // Thaumcraft addOreWeight("oreCoal", 46525); // Vanilla - addOreWeight("oreCooperite", 5); // GregTech addOreWeight("oreCopper", 8325); // IC2, Thermal Expansion, Tinkers' Construct, etc. addOreWeight("oreDark", 1350); // EvilCraft - addOreWeight("oreDarkIron", 1700); // Factorization + addOreWeight("oreDarkIron", 1700); // Factorization (older versions) + addOreWeight("oreFzDarkIron", 1700); // Factorization (newer versions) addOreWeight("oreDiamond", 1265); // Vanilla addOreWeight("oreEmerald", 780); // Vanilla - addOreWeight("oreEmery", 415); // GregTech addOreWeight("oreGalena", 1000); // Factorization addOreWeight("oreGold", 2970); // Vanilla addOreWeight("oreInfusedAir", 925); // Thaumcraft @@ -129,26 +154,52 @@ public final class BotaniaAPI { addOreWeight("oreInfusedFire", 925); // Thaumcraft addOreWeight("oreInfusedOrder", 925); // Thaumcraft addOreWeight("oreInfusedWater", 925); // Thaumcraft - addOreWeight("oreIridium", 30); // GregTech addOreWeight("oreIron", 20665); // Vanilla addOreWeight("oreLapis", 1285); // Vanilla addOreWeight("oreLead", 7985); // IC2, Thermal Expansion, Factorization, etc. addOreWeight("oreMCropsEssence", 3085); // Magical Crops + addOreWeight("oreMithril", 8); // Thermal Expansion addOreWeight("oreNickel", 2275); // Thermal Expansion addOreWeight("oreOlivine", 1100); // Project RED + addOreWeight("orePlatinum", 365); // Thermal Expansion addOreWeight("oreRedstone", 6885); // Vanilla addOreWeight("oreRuby", 1100); // Project RED addOreWeight("oreSapphire", 1100); // Project RED addOreWeight("oreSilver", 6300); // Thermal Expansion, Factorization, etc. - addOreWeight("oreSphalerite", 25); // GregTech addOreWeight("oreSulfur", 1105); // Railcraft - addOreWeight("oreTetrahedrite", 4040); // GregTech addOreWeight("oreTin", 9450); // IC2, Thermal Expansion, etc. - addOreWeight("oreTungstate", 20); // GregTech addOreWeight("oreUranium", 1337); // IC2 addOreWeight("oreVinteum", 5925); // Ars Magica addOreWeight("oreYellorite", 3520); // Big Reactors addOreWeight("oreZinc", 6485); // Flaxbeard's Steam Power + addOreWeight("oreMythril", 6485); // Simple Ores2 + addOreWeight("oreAdamantium", 2275); // Simple Ores2 + addOreWeight("oreTungsten", 3520); // Simple Tungsten + + addOreWeightNether("oreQuartz", 19600); // Vanilla + addOreWeightNether("oreCobalt", 500); // Tinker's Construct + addOreWeightNether("oreArdite", 500); // Tinker's Construct + addOreWeightNether("oreFirestone", 5); // Railcraft + addOreWeightNether("oreNetherCoal", 17000); // Nether Ores + addOreWeightNether("oreNetherCopper", 4700); // Nether Ores + addOreWeightNether("oreNetherDiamond", 175); // Nether Ores + addOreWeightNether("oreNetherEssence", 2460); // Magical Crops + addOreWeightNether("oreNetherGold", 3635); // Nether Ores + addOreWeightNether("oreNetherIron", 5790); // Nether Ores + addOreWeightNether("oreNetherLapis", 3250); // Nether Ores + addOreWeightNether("oreNetherLead", 2790); // Nether Ores + addOreWeightNether("oreNetherNickel", 1790); // Nether Ores + addOreWeightNether("oreNetherPlatinum", 170); // Nether Ores + addOreWeightNether("oreNetherRedstone", 5600); // Nether Ores + addOreWeightNether("oreNetherSilver", 1550); // Nether Ores + addOreWeightNether("oreNetherSteel", 1690); // Nether Ores + addOreWeightNether("oreNetherTin", 3750); // Nether Ores + addOreWeightNether("oreFyrite", 1000); // Netherrocks + addOreWeightNether("oreAshstone", 1000); // Netherrocks + addOreWeightNether("oreDragonstone", 175); // Netherrocks + addOreWeightNether("oreArgonite", 1000); // Netherrocks + addOreWeightNether("oreOnyx", 500); // SimpleOres 2 + addOreWeightNether("oreHaditeCoal", 500); // Hadite addSeed(Items.wheat_seeds, Blocks.wheat); addSeed(Items.potato, Blocks.potatoes); @@ -169,7 +220,7 @@ public final class BotaniaAPI { registerModWiki("EnderIO", new SimpleWikiProvider("EnderIO Wiki", "http://wiki.enderio.com/%s")); registerModWiki("TropiCraft", new SimpleWikiProvider("Tropicraft Wiki", "http://wiki.tropicraft.net/wiki/%s")); registerModWiki("RandomThings", new SimpleWikiProvider("Random Things Wiki", "http://randomthingsminecraftmod.wikispaces.com/%s")); - registerModWiki("Witchery", new SimpleWikiProvider("Witchery Wiki", "https://sites.google.com/site/witcherymod/%s", "-")); + registerModWiki("Witchery", new SimpleWikiProvider("Witchery Wiki", "https://sites.google.com/site/witcherymod/%s", "-", true)); registerModWiki("AppliedEnergistics2", new SimpleWikiProvider("AE2 Wiki", "http://ae-mod.info/%s")); registerModWiki("BigReactors", technicWiki); registerModWiki("BuildCraft|Core", buildcraftWiki); @@ -184,15 +235,32 @@ public final class BotaniaAPI { registerModWiki("GanysSurface", new SimpleWikiProvider("Gany's Surface Wiki", "http://ganys-surface.wikia.com/wiki/%s")); registerModWiki("GanysNether", new SimpleWikiProvider("Gany's Nether Wiki", "http://ganys-nether.wikia.com/wiki/%s")); registerModWiki("GanysEnd", new SimpleWikiProvider("Gany's End Wiki", "http://ganys-end.wikia.com/wiki/%s")); + + registerPaintableBlock(Blocks.stained_glass); + registerPaintableBlock(Blocks.stained_glass_pane); + registerPaintableBlock(Blocks.stained_hardened_clay); + registerPaintableBlock(Blocks.wool); + registerPaintableBlock(Blocks.carpet); + + registerDisposableBlock("dirt"); // Vanilla + registerDisposableBlock("sand"); // Vanilla + registerDisposableBlock("gravel"); // Vanilla + registerDisposableBlock("cobblestone"); // Vanilla + registerDisposableBlock("netherrack"); // Vanilla + registerSemiDisposableBlock("stoneAndesite"); // Botania + registerSemiDisposableBlock("stoneBasalt"); // Botania + registerSemiDisposableBlock("stoneDiorite"); // Botania + registerSemiDisposableBlock("stoneGranite"); // Botania } /** - * The internal method handler in use. Do not overwrite. + * The internal method handler in use. + * DO NOT OVERWRITE THIS OR YOU'RE GOING TO FEEL MY WRATH WHEN I UPDATE THE API. + * The fact I have to write that means some moron already tried, don't be that moron. * @see IInternalMethodHandler */ public static IInternalMethodHandler internalHandler = new DummyMethodHandler(); - /** * Registers a new Knowledge Type. * @param id The ID for this knowledge type. @@ -222,6 +290,100 @@ public final class BotaniaAPI { return fallbackBrew; } + /* + * Registers a Block as disposable using its Ore Dictionary Name. + */ + public static void registerDisposableBlock(String oreDictName) { + disposableBlocks.add(oreDictName); + } + + /* + * Registers a Block as semi disposable using its Ore Dictionary Name. + * This means it will not be trashed when sneaking. + */ + public static void registerSemiDisposableBlock(String oreDictName) { + semiDisposableBlocks.add(oreDictName); + } + + /** + * Registers a paintableBlock and returns it. + */ + public static Block registerPaintableBlock(Block paintable){ + paintableBlocks.add(paintable); + return paintable; + } + + /* + * Blacklists an Entity from being affected by the Rod of the Shaded Mesa. + * Pass in the class for the Entity, e.g. EntityCow.class + */ + public static void blacklistEntityFromGravityRod(Class entity) { + gravityRodBlacklist.add(entity); + } + + /* + * Checks if the provided Entity is contained in the Blacklist. + * Pass in the class for the Entity, e.g. entity.getClass() + */ + public static boolean isEntityBlacklistedFromGravityRod(Class entity) { + return gravityRodBlacklist.contains(entity); + } + + /** + * Blacklists an item from being pulled by the Ring of Magnetization. + * Short.MAX_VALUE can be used as the stack's damage for a wildcard. + */ + public static void blacklistItemFromMagnet(ItemStack stack) { + String key = getMagnetKey(stack); + magnetBlacklist.add(key); + } + + /** + * Blacklists a block from having items on top of it being pulled by the Ring of Magnetization. + * Short.MAX_VALUE can be used as meta for a wildcard. + */ + public static void blacklistBlockFromMagnet(Block block, int meta) { + String key = getMagnetKey(block, meta); + magnetBlacklist.add(key); + } + + public static boolean isItemBlacklistedFromMagnet(ItemStack stack) { + return isItemBlacklistedFromMagnet(stack, 0); + } + + public static boolean isItemBlacklistedFromMagnet(ItemStack stack, int recursion) { + if(recursion > 5) + return false; + + if(stack.getItemDamage() != Short.MAX_VALUE) { + ItemStack copy = new ItemStack(stack.getItem(), 0, Short.MAX_VALUE); + boolean general = isItemBlacklistedFromMagnet(copy, recursion + 1); + if(general) + return true; + } + + String key = getMagnetKey(stack); + return magnetBlacklist.contains(key); + } + + public static boolean isBlockBlacklistedFromMagnet(Block block, int meta) { + return isBlockBlacklistedFromMagnet(block, meta, 0); + } + + public static boolean isBlockBlacklistedFromMagnet(Block block, int meta, int recursion) { + if(recursion >= 5) + return false; + + if(meta != Short.MAX_VALUE) { + boolean general = isBlockBlacklistedFromMagnet(block, Short.MAX_VALUE, recursion + 1); + if(general) + return true; + } + + String key = getMagnetKey(block, meta); + return magnetBlacklist.contains(key); + } + /** * Registers a Petal Recipe. * @param output The ItemStack to craft. @@ -236,7 +398,20 @@ public final class BotaniaAPI { } /** - * Registers a Rune Altar + * Registers a Pure Daisy Recipe. + * @param input The block that works as an input for the recipe. Can be a Block or an oredict String. + * @param output The block to be placed upon recipe completion. + * @param outputMeta The metadata to be placed upon recipe completion. + * @return The recipe created. + */ + public static RecipePureDaisy registerPureDaisyRecipe(Object input, Block output, int outputMeta) { + RecipePureDaisy recipe = new RecipePureDaisy(input, output, outputMeta); + pureDaisyRecipes.add(recipe); + return recipe; + } + + /** + * Registers a Rune Altar Recipe. * @param output The ItemStack to craft. * @param mana The amount of mana required. Don't go over 100000! * @param inputs The objects for crafting. Can be ItemStack, MappableStackWrapper @@ -309,9 +484,25 @@ public final class BotaniaAPI { /** * Registers a SubTileEntity, a new special flower. Look in the subtile package of the API. + * If you call this after PostInit you're a failiure and we are very disappointed in you. */ public static void registerSubTile(String key, Class subtileClass) { subTiles.put(key, subtileClass); + subTileMods.put(key, Loader.instance().activeModContainer().getModId()); + } + + /** + * Register a SubTileEntity and makes it a mini flower. Also adds the recipe and returns it. + * @see BotaniaAPI#registerSubTile + */ + public static RecipeManaInfusion registerMiniSubTile(String key, Class subtileClass, String original) { + registerSubTile(key, subtileClass); + miniFlowers.put(original, key); + + RecipeMiniFlower recipe = new RecipeMiniFlower(key, original, 2500); + manaInfusionRecipes.add(recipe); + miniFlowerRecipes.add(recipe); + return recipe; } /** @@ -344,7 +535,8 @@ public final class BotaniaAPI { /** * Adds the key for a SubTileEntity into the creative menu. This goes into the - * subtilesForCreativeMenu Set. + * subtilesForCreativeMenu Set. This does not need to be called for mini flowers, + * those will just use the mini flower map to add themselves next to the source. */ public static void addSubTileToCreativeMenu(String key) { subtilesForCreativeMenu.add(key); @@ -390,10 +582,28 @@ public final class BotaniaAPI { oreWeights.put(ore, weight); } + /** + * Maps an ore (ore dictionary key) to it's weight on the nether world generation. This + * is used for the Orechid Ignem flower. Check the static block in the BotaniaAPI class + * to get the weights for the vanilla blocks.
+ * Alternatively get the values with the OreDetector mod:
+ * https://gist.github.com/Vazkii/9493322 + */ + public static void addOreWeightNether(String ore, int weight) { + if(ore.contains("Nether") && OreDictionary.getOres(ore.replace("Nether", "")).size() == 0) + return; + + oreWeightsNether.put(ore, weight); + } + public static int getOreWeight(String ore) { return oreWeights.get(ore); } + public static int getOreWeightNether(String ore) { + return oreWeightsNether.get(ore); + } + /** * Allows an item to be counted as a seed. Any item in this list can be * dispensed by a dispenser, the block is the block to be placed. @@ -402,6 +612,13 @@ public final class BotaniaAPI { seeds.put(item, block); } + /** + * Blacklists an item from the Loonium drop table. + */ + public static void blackListItemFromLoonium(Item item) { + looniumBlacklist.add(item); + } + /** * Gets the last recipe to have been added to the recipe list. */ @@ -440,4 +657,20 @@ public final class BotaniaAPI { public static String getSubTileStringMapping(Class clazz) { return subTiles.inverse().get(clazz); } + + public static Set getAllSubTiles() { + return subTiles.keySet(); + } + + private static String getMagnetKey(ItemStack stack) { + if(stack == null) + return ""; + + return "i_" + stack.getItem().getUnlocalizedName() + "@" + stack.getItemDamage(); + } + + private static String getMagnetKey(Block block, int meta) { + return "bm_" + block.getUnlocalizedName() + "@" + meta; + } + } diff --git a/src/api/java/vazkii/botania/api/boss/IBotaniaBoss.java b/src/api/java/vazkii/botania/api/boss/IBotaniaBoss.java index bc218f6..d337e6a 100644 --- a/src/api/java/vazkii/botania/api/boss/IBotaniaBoss.java +++ b/src/api/java/vazkii/botania/api/boss/IBotaniaBoss.java @@ -12,6 +12,7 @@ package vazkii.botania.api.boss; import java.awt.Rectangle; +import net.minecraft.client.gui.ScaledResolution; import net.minecraft.entity.boss.IBossDisplayData; import net.minecraft.util.ResourceLocation; import cpw.mods.fml.relauncher.Side; @@ -57,5 +58,5 @@ public interface IBotaniaBoss extends IBossDisplayData { * here if needed. */ @SideOnly(Side.CLIENT) - public void bossBarRenderCallback(); + public void bossBarRenderCallback(ScaledResolution res, int x, int y); } diff --git a/src/api/java/vazkii/botania/api/brew/Brew.java b/src/api/java/vazkii/botania/api/brew/Brew.java index 5b1948d..d0dd6ba 100644 --- a/src/api/java/vazkii/botania/api/brew/Brew.java +++ b/src/api/java/vazkii/botania/api/brew/Brew.java @@ -28,6 +28,7 @@ public class Brew { int cost; List effects; boolean canInfuseBloodPendant = true; + boolean canInfuseIncense = true; /** * @param name The unlocalized name of this potion. @@ -52,10 +53,22 @@ public class Brew { return this; } + /** + * Sets this brew to not be able to be infused onto Incense Sticks. + */ + public Brew setNotIncenseInfusable() { + canInfuseIncense = false; + return this; + } + public boolean canInfuseBloodPendant() { return canInfuseBloodPendant; } + public boolean canInfuseIncense() { + return canInfuseIncense; + } + /** * Returns the key for this brew, for it to be found in the map in the API. * This should ALWAYS return the same result. diff --git a/src/api/java/vazkii/botania/api/corporea/CorporeaHelper.java b/src/api/java/vazkii/botania/api/corporea/CorporeaHelper.java index 87e4862..d4934d7 100644 --- a/src/api/java/vazkii/botania/api/corporea/CorporeaHelper.java +++ b/src/api/java/vazkii/botania/api/corporea/CorporeaHelper.java @@ -15,6 +15,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.WeakHashMap; +import java.util.regex.Pattern; import net.minecraft.inventory.IInventory; import net.minecraft.inventory.ISidedInventory; @@ -22,12 +23,21 @@ import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.AxisAlignedBB; import net.minecraft.world.World; +import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.util.ForgeDirection; +import vazkii.botania.api.BotaniaAPI; public final class CorporeaHelper { private static final List empty = Collections.unmodifiableList(new ArrayList()); private static final WeakHashMap, List> cachedNetworks = new WeakHashMap(); + private static final List autoCompleteControllers = new ArrayList(); + + private static final Pattern patternControlCode = Pattern.compile("(?i)\\u00A7[0-9A-FK-OR]"); + + public static final String[] WILDCARD_STRINGS = new String[] { + "...", "~", "+", "?" , "*" + }; /** * How many items were matched in the last request. If java had "out" params like C# this wouldn't be needed :V @@ -114,22 +124,15 @@ public final class CorporeaHelper { * The deeper level function that use a List< IInventory > should be * called instead if the context for this exists to avoid having to get the value again. */ - public static Map getInventoriesWithItemInNetwork(ItemStack stack, List inventories, boolean checkNBT) { - Map countMap = new HashMap(); - - for(IInventory inv : inventories) { - int count = 0; - for(int i = 0; i < inv.getSizeInventory(); i++) { - if(!isValidSlot(inv, i)) - continue; - - ItemStack stackAt = inv.getStackInSlot(i); - if(stacksMatch(stack, stackAt, checkNBT)) - count += stackAt.stackSize; + public static Map getInventoriesWithItemInNetwork(ItemStack stack,List inventories, boolean checkNBT) { + Map countMap = new HashMap(); + List wrappedInventories = BotaniaAPI.internalHandler.wrapInventory(inventories); + for (IWrappedInventory inv : wrappedInventories) { + CorporeaRequest request = new CorporeaRequest(stack, checkNBT, -1); + inv.countItems(request); + if (request.foundItems > 0) { + countMap.put(inv.getWrappedObject(), request.foundItems); } - - if(count > 0) - countMap.put(inv, count); } return countMap; @@ -153,50 +156,49 @@ public final class CorporeaHelper { * Requests list of ItemStacks of the type passed in from the network, or tries to, checking NBT or not. * This will remove the items from the adequate inventories unless the "doit" parameter is false. * Returns a new list of ItemStacks of the items acquired or an empty list if none was found. + * Case itemCount is -1 it'll find EVERY item it can. *

* The "matcher" parameter has to be an ItemStack or a String, if the first it'll check if the * two stacks are similar using the "checkNBT" parameter, else it'll check if the name of the item * equals or matches (case a regex is passed in) the matcher string. + *

+ * When requesting counting of items, individual stacks may exceed maxStackSize for + * purposes of counting huge amounts. */ public static List requestItem(Object matcher, int itemCount, ICorporeaSpark spark, boolean checkNBT, boolean doit) { + List stacks = new ArrayList(); + CorporeaRequestEvent event = new CorporeaRequestEvent(matcher, itemCount, spark, checkNBT, doit); + if(MinecraftForge.EVENT_BUS.post(event)) + return stacks; + List inventories = getInventoriesOnNetwork(spark); - List stacks = new ArrayList(); + List inventoriesW = BotaniaAPI.internalHandler.wrapInventory(inventories); + Map interceptors = new HashMap(); - lastRequestMatches = 0; - lastRequestExtractions = 0; + CorporeaRequest request = new CorporeaRequest(matcher, checkNBT, itemCount); + for(IWrappedInventory inv : inventoriesW) { + ICorporeaSpark invSpark = inv.getSpark(); - int count = itemCount; - for(IInventory inv : inventories) { - ICorporeaSpark invSpark = getSparkForInventory(inv); - for(int i = inv.getSizeInventory() - 1; i >= 0; i--) { - if(!isValidSlot(inv, i)) - continue; + Object originalInventory = inv.getWrappedObject(); + if(originalInventory instanceof ICorporeaInterceptor) { + ICorporeaInterceptor interceptor = (ICorporeaInterceptor) originalInventory; + interceptor.interceptRequest(matcher, itemCount, invSpark, spark, stacks, inventories, doit); + interceptors.put(interceptor, invSpark); + } - ItemStack stackAt = inv.getStackInSlot(i); - if(matcher instanceof ItemStack ? stacksMatch((ItemStack) matcher, stackAt, checkNBT) : matcher instanceof String ? stacksMatch(stackAt, (String) matcher) : false) { - int rem = Math.min(stackAt.stackSize, count); - - if(rem > 0) { - ItemStack copy = stackAt.copy(); - if(rem < copy.stackSize) - copy.stackSize = rem; - stacks.add(copy); - } - - lastRequestMatches += stackAt.stackSize; - lastRequestExtractions += rem; - if(doit && rem > 0) { - stackAt.stackSize -= rem; - if(stackAt.stackSize == 0) - inv.setInventorySlotContents(i, null); - if(invSpark != null) - invSpark.onItemExtracted(stackAt); - } - count -= rem; - } + if(doit) { + stacks.addAll(inv.extractItems(request)); + } else { + stacks.addAll(inv.countItems(request)); } } + lastRequestMatches = request.foundItems; + lastRequestExtractions = request.extractedItems; + + for(ICorporeaInterceptor interceptor : interceptors.keySet()) + interceptor.interceptRequestLast(matcher, itemCount, interceptors.get(interceptor), spark, stacks, inventories, doit); + return stacks; } @@ -232,7 +234,7 @@ public final class CorporeaHelper { * Gets if the slot passed in can be extracted from by a spark. */ public static boolean isValidSlot(IInventory inv, int slot) { - return !(inv instanceof ISidedInventory) || arrayHas(((ISidedInventory) inv).getAccessibleSlotsFromSide(ForgeDirection.UP.ordinal()), slot); + return !(inv instanceof ISidedInventory) || arrayHas(((ISidedInventory) inv).getAccessibleSlotsFromSide(ForgeDirection.UP.ordinal()), slot) && ((ISidedInventory) inv).canExtractItem(slot, inv.getStackInSlot(slot), ForgeDirection.UP.ordinal()); } /** @@ -250,16 +252,22 @@ public final class CorporeaHelper { return false; boolean contains = false; - if(s.endsWith("...")) { - contains = true; - s = s.substring(0, s.length() - 3); - } - if(s.startsWith("...")) { - contains = true; - s = s.substring(3); + for(String wc : WILDCARD_STRINGS) { + if(s.endsWith(wc)) { + contains = true; + s = s.substring(0, s.length() - wc.length()); + } + else if(s.startsWith(wc)) { + contains = true; + s = s.substring(wc.length()); + } + + if(contains) + break; } - String name = stack.getDisplayName().toLowerCase().trim(); + + String name = stripControlCodes(stack.getDisplayName().toLowerCase().trim()); return equalOrContain(name, s, contains) || equalOrContain(name + "s", s, contains) || equalOrContain(name + "es", s, contains) || name.endsWith("y") && equalOrContain(name.substring(0, name.length() - 1) + "ies", s, contains); } @@ -288,4 +296,26 @@ public final class CorporeaHelper { public static boolean equalOrContain(String s1, String s2, boolean contain) { return contain ? s1.contains(s2) : s1.equals(s2); } + + /** + * Registers a ICorporeaAutoCompleteController + */ + public static void registerAutoCompleteController(ICorporeaAutoCompleteController controller) { + autoCompleteControllers.add(controller); + } + + /** + * Returns if the auto complete helper should run + */ + public static boolean shouldAutoComplete() { + for(ICorporeaAutoCompleteController controller : autoCompleteControllers) + if(controller.shouldAutoComplete()) + return true; + return false; + } + + // Copy from StringUtils + public static String stripControlCodes(String str) { + return patternControlCode.matcher(str).replaceAll(""); + } } diff --git a/src/api/java/vazkii/botania/api/corporea/CorporeaRequest.java b/src/api/java/vazkii/botania/api/corporea/CorporeaRequest.java new file mode 100644 index 0000000..b3e0bd9 --- /dev/null +++ b/src/api/java/vazkii/botania/api/corporea/CorporeaRequest.java @@ -0,0 +1,26 @@ +/** + * This class was created by . It's distributed as + * part of the Botania Mod. Get the Source Code in github: + * https://github.com/Vazkii/Botania + * + * Botania is Open Source and distributed under the + * Botania License: http://botaniamod.net/license.php + * + */ +package vazkii.botania.api.corporea; + +public class CorporeaRequest { + public Object matcher; + public boolean checkNBT; + public int count; + public int foundItems = 0; + public int extractedItems = 0; + + public CorporeaRequest(Object matcher, boolean checkNBT, int count) { + super(); + this.matcher = matcher; + this.checkNBT = checkNBT; + this.count = count; + } + +} diff --git a/src/api/java/vazkii/botania/api/corporea/CorporeaRequestEvent.java b/src/api/java/vazkii/botania/api/corporea/CorporeaRequestEvent.java new file mode 100644 index 0000000..a55ef7b --- /dev/null +++ b/src/api/java/vazkii/botania/api/corporea/CorporeaRequestEvent.java @@ -0,0 +1,40 @@ +/** + * This class was created by . It's distributed as + * part of the Botania Mod. Get the Source Code in github: + * https://github.com/Vazkii/Botania + * + * Botania is Open Source and distributed under the + * Botania License: http://botaniamod.net/license.php + * + * File Created @ [Apr 30, 2015, 2:55:57 PM (GMT)] + */ +package vazkii.botania.api.corporea; + +import cpw.mods.fml.common.eventhandler.Cancelable; +import cpw.mods.fml.common.eventhandler.Event; + +/** + * Fired when a corporea request is initiated. Can be cancelled. + */ +@Cancelable +public class CorporeaRequestEvent extends Event { + + public final Object request; + public final int count; + public final ICorporeaSpark spark; + public final boolean checkNBT; + /** + * If false then items won't be pulled. + */ + public final boolean realRequest; + + public CorporeaRequestEvent(Object request, int count, ICorporeaSpark spark, boolean nbt, boolean real) { + this.request = request; + this.count = count; + this.spark = spark; + checkNBT = nbt; + realRequest = real; + } + + +} diff --git a/src/api/java/vazkii/botania/api/corporea/ICorporeaAutoCompleteController.java b/src/api/java/vazkii/botania/api/corporea/ICorporeaAutoCompleteController.java new file mode 100644 index 0000000..fc0a3e9 --- /dev/null +++ b/src/api/java/vazkii/botania/api/corporea/ICorporeaAutoCompleteController.java @@ -0,0 +1,27 @@ +/** + * This class was created by . It's distributed as + * part of the Botania Mod. Get the Source Code in github: + * https://github.com/Vazkii/Botania + * + * Botania is Open Source and distributed under the + * Botania License: http://botaniamod.net/license.php + * + * File Created @ [June 8, 2015, 1:04:05 PM (GMT)] + */ +package vazkii.botania.api.corporea; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + +/** + * An interface for systems which may control if the item auto complete system should be active + */ +public interface ICorporeaAutoCompleteController { + + /** + * Return true if auto completion should be enabled. + */ + @SideOnly(Side.CLIENT) + public boolean shouldAutoComplete(); + +} diff --git a/src/api/java/vazkii/botania/api/corporea/ICorporeaInterceptor.java b/src/api/java/vazkii/botania/api/corporea/ICorporeaInterceptor.java new file mode 100644 index 0000000..eeea16a --- /dev/null +++ b/src/api/java/vazkii/botania/api/corporea/ICorporeaInterceptor.java @@ -0,0 +1,38 @@ +/** + * This class was created by . It's distributed as + * part of the Botania Mod. Get the Source Code in github: + * https://github.com/Vazkii/Botania + * + * Botania is Open Source and distributed under the + * Botania License: http://botaniamod.net/license.php + * + * File Created @ [Apr 19, 2015, 6:23:31 PM (GMT)] + */ +package vazkii.botania.api.corporea; + +import java.util.List; + +import net.minecraft.inventory.IInventory; +import net.minecraft.item.ItemStack; + +/** + * A TileEntity that implements this will be able to intercept corporea + * requests case there is a Corporea Spark on top. + */ +public interface ICorporeaInterceptor { + + /** + * Intercepts a request as it goes. The list of inventories has all the inventories + * at this point, but the list of stacks is not complete. The request parameter can + * be either a String or ItemStack. + */ + public void interceptRequest(Object request, int count, ICorporeaSpark spark, ICorporeaSpark source, List stacks, List inventories, boolean doit); + + /** + * Intercepts a request after all the stacks have been found and processed. Both the + * list of inventories and stacks is complete at this point. The request parameter can + * be either a String or ItemStack. + */ + public void interceptRequestLast(Object request, int count, ICorporeaSpark spark, ICorporeaSpark source, List stacks, List inventories, boolean doit); + +} diff --git a/src/api/java/vazkii/botania/api/corporea/ICorporeaRequestor.java b/src/api/java/vazkii/botania/api/corporea/ICorporeaRequestor.java new file mode 100644 index 0000000..66881b5 --- /dev/null +++ b/src/api/java/vazkii/botania/api/corporea/ICorporeaRequestor.java @@ -0,0 +1,25 @@ +/** + * This class was created by . It's distributed as + * part of the Botania Mod. Get the Source Code in github: + * https://github.com/Vazkii/Botania + * + * Botania is Open Source and distributed under the + * Botania License: http://botaniamod.net/license.php + * + * File Created @ [Sep 28, 2015, 11:25:48 AM (GMT)] + */ +package vazkii.botania.api.corporea; + +/** + * A TileEntity that implements this be called by other TileEntities + * to allow for it to do any request at any time. This is used by the + * Corporea Retainer for example. + */ +public interface ICorporeaRequestor { + + /* + * Executes the passed in request. + */ + public void doCorporeaRequest(Object request, int count, ICorporeaSpark spark); + +} diff --git a/src/api/java/vazkii/botania/api/corporea/IWrappedInventory.java b/src/api/java/vazkii/botania/api/corporea/IWrappedInventory.java new file mode 100644 index 0000000..1faf366 --- /dev/null +++ b/src/api/java/vazkii/botania/api/corporea/IWrappedInventory.java @@ -0,0 +1,57 @@ +/** + * This class was created by . It's distributed as + * part of the Botania Mod. Get the Source Code in github: + * https://github.com/Vazkii/Botania + * + * Botania is Open Source and distributed under the + * Botania License: http://botaniamod.net/license.php + * + */ +package vazkii.botania.api.corporea; + +import java.util.List; + +import net.minecraft.inventory.IInventory; +import net.minecraft.item.ItemStack; + +/** + * This interface wraps IInventory corporea works with in order to provide + * compatibility with different storage mods. + * + */ +public interface IWrappedInventory { + + /** + * Break encapsulation and exposes original inventory. + */ + IInventory getWrappedObject(); + + /** + * Counts items in the inventory matching the request + * + * @param request + * - specifies what should be found + * @return List of ItemStack, individual stacks may exceed maxStackSize for + * purposes of counting huge amounts. To get final count requestor + * should sum stackSize of all stacks. + */ + List countItems(CorporeaRequest request); + + /** + * Convenience method for accessing spark over inventory + */ + ICorporeaSpark getSpark(); + + /** + * Extracts items matching request from the inventory.
+ * {@link CorporeaRequest#count} is updated to reflect how many items are + * yet to be extracted.
+ * {@link CorporeaRequest#foundItems} and + * {@link CorporeaRequest#extractedItems} are updated to reflect how many + * items were found and extracted. + * + * @param request + * @return List of ItemStacks to be delivered to the destination. + */ + List extractItems(CorporeaRequest request); +} diff --git a/src/api/java/vazkii/botania/api/internal/DummyMethodHandler.java b/src/api/java/vazkii/botania/api/internal/DummyMethodHandler.java index b5bc59f..88ddf47 100644 --- a/src/api/java/vazkii/botania/api/internal/DummyMethodHandler.java +++ b/src/api/java/vazkii/botania/api/internal/DummyMethodHandler.java @@ -14,9 +14,11 @@ import java.util.List; import net.minecraft.client.gui.ScaledResolution; import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Blocks; import net.minecraft.inventory.IInventory; +import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.IRecipe; import net.minecraft.tileentity.TileEntity; @@ -24,12 +26,15 @@ import net.minecraft.util.IIcon; import net.minecraft.util.ResourceLocation; import net.minecraft.world.World; import vazkii.botania.api.boss.IBotaniaBoss; +import vazkii.botania.api.corporea.IWrappedInventory; import vazkii.botania.api.lexicon.LexiconPage; +import vazkii.botania.api.lexicon.multiblock.MultiblockSet; import vazkii.botania.api.recipe.RecipeBrew; import vazkii.botania.api.recipe.RecipeElvenTrade; import vazkii.botania.api.recipe.RecipeManaInfusion; import vazkii.botania.api.recipe.RecipePetals; import vazkii.botania.api.recipe.RecipeRuneAltar; +import vazkii.botania.api.subtile.SubTileEntity; public class DummyMethodHandler implements IInternalMethodHandler { @@ -103,6 +108,11 @@ public class DummyMethodHandler implements IInternalMethodHandler { return dummyPage(key); } + @Override + public LexiconPage multiblockPage(String key, MultiblockSet mb) { + return dummyPage(key); + } + private LexiconPage dummyPage(String key) { return new DummyPage(key); } @@ -117,6 +127,11 @@ public class DummyMethodHandler implements IInternalMethodHandler { return getSubTileAsStack(subTile); } + @Override + public String getStackSubTileKey(ItemStack stack) { + return null; + } + @Override public IIcon getSubTileIconForName(String name) { return Blocks.red_flower.getIcon(0, 0); @@ -137,6 +152,16 @@ public class DummyMethodHandler implements IInternalMethodHandler { // NO-OP } + @Override + public void drawComplexManaHUD(int color, int mana, int maxMana, String name, ScaledResolution res, ItemStack bindDisplay, boolean properlyBound) { + // NO-OP + } + + @Override + public ItemStack getBindDisplayForFlowerType(SubTileEntity e) { + return new ItemStack(Blocks.stone, 0, 0); + } + @Override public void renderLexiconText(int x, int y, int width, int height, String unlocalizedText) { // NO-OP @@ -177,4 +202,34 @@ public class DummyMethodHandler implements IInternalMethodHandler { return false; } + @Override + public void breakOnAllCursors(EntityPlayer player, Item item, ItemStack stack, int x, int y, int z, int side) { + // NO-OP + } + + @Override + public boolean hasSolegnoliaAround(Entity e) { + return false; + } + + @Override + public long getWorldElapsedTicks() { + return 0; + } + + @Override + public boolean isBotaniaFlower(World world, int x, int y, int z) { + return false; + } + + @Override + public void sendBaubleUpdatePacket(EntityPlayer player, int slot) { + // NO-OP + } + + @Override + public List wrapInventory(List inventories) { + return null; + } + } diff --git a/src/api/java/vazkii/botania/api/internal/IInternalMethodHandler.java b/src/api/java/vazkii/botania/api/internal/IInternalMethodHandler.java index a5892b6..b0e3d10 100644 --- a/src/api/java/vazkii/botania/api/internal/IInternalMethodHandler.java +++ b/src/api/java/vazkii/botania/api/internal/IInternalMethodHandler.java @@ -14,8 +14,10 @@ import java.util.List; import net.minecraft.client.gui.ScaledResolution; import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; +import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.IRecipe; import net.minecraft.tileentity.TileEntity; @@ -23,12 +25,15 @@ import net.minecraft.util.IIcon; import net.minecraft.util.ResourceLocation; import net.minecraft.world.World; import vazkii.botania.api.boss.IBotaniaBoss; +import vazkii.botania.api.corporea.IWrappedInventory; import vazkii.botania.api.lexicon.LexiconPage; +import vazkii.botania.api.lexicon.multiblock.MultiblockSet; import vazkii.botania.api.recipe.RecipeBrew; import vazkii.botania.api.recipe.RecipeElvenTrade; import vazkii.botania.api.recipe.RecipeManaInfusion; import vazkii.botania.api.recipe.RecipePetals; import vazkii.botania.api.recipe.RecipeRuneAltar; +import vazkii.botania.api.subtile.SubTileEntity; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; @@ -69,12 +74,16 @@ public interface IInternalMethodHandler { public LexiconPage brewPage(String key, String bottomText, RecipeBrew recipe); + public LexiconPage multiblockPage(String key, MultiblockSet mb); + public IManaNetwork getManaNetworkInstance(); public ItemStack getSubTileAsStack(String subTile); public ItemStack getSubTileAsFloatingFlowerStack(String subTile); + public String getStackSubTileKey(ItemStack stack); + public IIcon getSubTileIconForName(String name); public void registerBasicSignatureIcons(String name, IIconRegister register); @@ -85,9 +94,19 @@ public interface IInternalMethodHandler { public IInventory getBaublesInventory(EntityPlayer player); + public void breakOnAllCursors(EntityPlayer player, Item item, ItemStack stack, int x, int y, int z, int side); + + public boolean hasSolegnoliaAround(Entity e); + @SideOnly(Side.CLIENT) public void drawSimpleManaHUD(int color, int mana, int maxMana, String name, ScaledResolution res); + @SideOnly(Side.CLIENT) + public void drawComplexManaHUD(int color, int mana, int maxMana, String name, ScaledResolution res, ItemStack bindDisplay, boolean properlyBound); + + @SideOnly(Side.CLIENT) + public ItemStack getBindDisplayForFlowerType(SubTileEntity e); + @SideOnly(Side.CLIENT) public void renderLexiconText(int x, int y, int width, int height, String unlocalizedText); @@ -101,4 +120,15 @@ public interface IInternalMethodHandler { public void sparkleFX(World world, double x, double y, double z, float r, float g, float b, float size, int m); + public long getWorldElapsedTicks(); + + public boolean isBotaniaFlower(World world, int x, int y, int z); + + public void sendBaubleUpdatePacket(EntityPlayer player, int slot); + + /** + * Wrap inventories in the network into wrappers providing compatibility for storage mods. + */ + List wrapInventory(List inventories); + } diff --git a/src/api/java/vazkii/botania/api/internal/IManaBurst.java b/src/api/java/vazkii/botania/api/internal/IManaBurst.java index 343c7a0..945aa99 100644 --- a/src/api/java/vazkii/botania/api/internal/IManaBurst.java +++ b/src/api/java/vazkii/botania/api/internal/IManaBurst.java @@ -10,6 +10,8 @@ */ package vazkii.botania.api.internal; +import java.util.UUID; + import net.minecraft.item.ItemStack; import net.minecraft.util.ChunkCoordinates; @@ -60,4 +62,12 @@ public interface IManaBurst { public int getTicksExisted(); + public void setFake(boolean fake); + + public void setShooterUUID(UUID uuid); + + public UUID getShooterUIID(); + + public void ping(); + } diff --git a/src/api/java/vazkii/botania/api/internal/VanillaPacketDispatcher.java b/src/api/java/vazkii/botania/api/internal/VanillaPacketDispatcher.java new file mode 100644 index 0000000..dff8b96 --- /dev/null +++ b/src/api/java/vazkii/botania/api/internal/VanillaPacketDispatcher.java @@ -0,0 +1,42 @@ +/** + * This class was created by . It's distributed as + * part of the Botania Mod. Get the Source Code in github: + * https://github.com/Vazkii/Botania + * + * Botania is Open Source and distributed under the + * Botania License: http://botaniamod.net/license.php + * + * File Created @ [Apr 9, 2015, 9:38:44 PM (GMT)] + */ +package vazkii.botania.api.internal; + +import java.util.List; + +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; + +public final class VanillaPacketDispatcher { + + public static void dispatchTEToNearbyPlayers(TileEntity tile) { + World world = tile.getWorldObj(); + List players = world.playerEntities; + for(Object player : players) + if(player instanceof EntityPlayerMP) { + EntityPlayerMP mp = (EntityPlayerMP) player; + if(pointDistancePlane(mp.posX, mp.posZ, tile.xCoord + 0.5, tile.zCoord + 0.5) < 64) + ((EntityPlayerMP) player).playerNetServerHandler.sendPacket(tile.getDescriptionPacket()); + } + } + + public static void dispatchTEToNearbyPlayers(World world, int x, int y, int z) { + TileEntity tile = world.getTileEntity(x, y, z); + if(tile != null) + dispatchTEToNearbyPlayers(tile); + } + + public static float pointDistancePlane(double x1, double y1, double x2, double y2) { + return (float) Math.hypot(x1 - x2, y1 - y2); + } + +} diff --git a/src/api/java/vazkii/botania/api/item/IAvatarTile.java b/src/api/java/vazkii/botania/api/item/IAvatarTile.java new file mode 100644 index 0000000..c89f903 --- /dev/null +++ b/src/api/java/vazkii/botania/api/item/IAvatarTile.java @@ -0,0 +1,32 @@ +/** + * This class was created by . It's distributed as + * part of the Botania Mod. Get the Source Code in github: + * https://github.com/Vazkii/Botania + * + * Botania is Open Source and distributed under the + * Botania License: http://botaniamod.net/license.php + * + * File Created @ [Oct 24, 2015, 7:00:21 PM (GMT)] + */ +package vazkii.botania.api.item; + +import net.minecraft.inventory.IInventory; +import vazkii.botania.api.mana.IManaReceiver; + +/** + * A TileEntity that implements this is considered an Avatar. + */ +public interface IAvatarTile extends IInventory, IManaReceiver { + + /** + * Gets the amount of ticks that have elapsed on this avatar while it's functional + * (has redstone signal). + */ + public int getElapsedFunctionalTicks(); + + /** + * Gets if this avatar is enabled (isn't powered by a redstone signal). + */ + public boolean isEnabled(); + +} diff --git a/src/api/java/vazkii/botania/api/item/IAvatarWieldable.java b/src/api/java/vazkii/botania/api/item/IAvatarWieldable.java new file mode 100644 index 0000000..9691009 --- /dev/null +++ b/src/api/java/vazkii/botania/api/item/IAvatarWieldable.java @@ -0,0 +1,31 @@ +/** + * This class was created by . It's distributed as + * part of the Botania Mod. Get the Source Code in github: + * https://github.com/Vazkii/Botania + * + * Botania is Open Source and distributed under the + * Botania License: http://botaniamod.net/license.php + * + * File Created @ [Oct 24, 2015, 6:45:50 PM (GMT)] + */ +package vazkii.botania.api.item; + +import net.minecraft.item.ItemStack; +import net.minecraft.util.ResourceLocation; + +/** + * An Item that implements this can be wielded by an Avatar. + */ +public interface IAvatarWieldable { + + /** + * Called on update of the avatar tile. + */ + public void onAvatarUpdate(IAvatarTile tile, ItemStack stack); + + /** + * Gets the overlay resource to render on top of the avatar tile. + */ + public ResourceLocation getOverlayResource(IAvatarTile tile, ItemStack stack); + +} diff --git a/src/api/java/vazkii/botania/api/item/IBaubleRender.java b/src/api/java/vazkii/botania/api/item/IBaubleRender.java index 7cc492a..d98a294 100644 --- a/src/api/java/vazkii/botania/api/item/IBaubleRender.java +++ b/src/api/java/vazkii/botania/api/item/IBaubleRender.java @@ -53,7 +53,7 @@ public interface IBaubleRender { } public static void translateToHeadLevel(EntityPlayer player) { - GL11.glTranslated(0, (player != Minecraft.getMinecraft().thePlayer ? 1.62F : 0F) - player.getDefaultEyeHeight() + (player.isSneaking() ? 0.0625 : 0), 0); + GL11.glTranslated(0, (player != Minecraft.getMinecraft().thePlayer ? 1.68F : 0F) - player.getDefaultEyeHeight() + (player.isSneaking() ? 0.0625 : 0), 0); } } diff --git a/src/api/java/vazkii/botania/api/item/IBlockProvider.java b/src/api/java/vazkii/botania/api/item/IBlockProvider.java new file mode 100644 index 0000000..42f2e3f --- /dev/null +++ b/src/api/java/vazkii/botania/api/item/IBlockProvider.java @@ -0,0 +1,40 @@ +/** + * This class was created by . It's distributed as + * part of the Botania Mod. Get the Source Code in github: + * https://github.com/Vazkii/Botania + * + * Botania is Open Source and distributed under the + * Botania License: http://botaniamod.net/license.php + * + * File Created @ [Aug 20, 2015, 10:31:54 PM (GMT)] + */ +package vazkii.botania.api.item; + +import net.minecraft.block.Block; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; + +/** + * An Item that implements this can provide blocks to other items that use them. + * For example, the Black Hole Talisman implements this in order to allow for + * the Rod of the Shifting Crust to pull blocks from it. + */ +public interface IBlockProvider { + + /** + * Provides the requested item. The doit paremeter specifies whether this is + * just a test (false) or if the item should actually be removed (true). + * If you need to use calls to ManaItemHandler.requestMana[Exact], use + * the requestor as the ItemStack passed in. + */ + public boolean provideBlock(EntityPlayer player, ItemStack requestor, ItemStack stack, Block block, int meta, boolean doit); + + /** + * Gets the amount of blocks of the type passed stored in this item. You must + * check for the block passed in to not give the counter for a wrong block. Returning + * -1 states that the item can provide infinite of the item passed in (for example, + * the Rod of the Lands would return -1 if the block is dirt). + */ + public int getBlockCount(EntityPlayer player, ItemStack requestor, ItemStack stack, Block block, int meta); + +} diff --git a/src/api/java/vazkii/botania/api/item/IBurstViewerBauble.java b/src/api/java/vazkii/botania/api/item/IBurstViewerBauble.java index 7e37c84..4402a71 100644 --- a/src/api/java/vazkii/botania/api/item/IBurstViewerBauble.java +++ b/src/api/java/vazkii/botania/api/item/IBurstViewerBauble.java @@ -13,7 +13,7 @@ package vazkii.botania.api.item; /** * Base Interface for the Manaseer Monocle and items of the sort. * Having a IBauble of this type equipped on the 0th slot (amulet) - * will draw bursts without depth testing. + * will draw bursts without depth testing and to see sub tile radiuses. */ public interface IBurstViewerBauble { diff --git a/src/api/java/vazkii/botania/api/item/IExtendedWireframeCoordinateListProvider.java b/src/api/java/vazkii/botania/api/item/IExtendedWireframeCoordinateListProvider.java new file mode 100644 index 0000000..7713eaa --- /dev/null +++ b/src/api/java/vazkii/botania/api/item/IExtendedWireframeCoordinateListProvider.java @@ -0,0 +1,28 @@ +/** + * This class was created by . It's distributed as + * part of the Botania Mod. Get the Source Code in github: + * https://github.com/Vazkii/Botania + * + * Botania is Open Source and distributed under the + * Botania License: http://botaniamod.net/license.php + * + * File Created @ [Apr 30, 2015, 1:43:17 PM (GMT)] + */ +package vazkii.botania.api.item; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.util.ChunkCoordinates; + +/** + * An extension of IWireframeCoordinateListProvider that allows for + * rendering a single thicker wireframe. + */ +public interface IExtendedWireframeCoordinateListProvider extends IWireframeCoordinateListProvider { + + /** + * Gets the source wireframe to draw, this one will be drawn thicker. + */ + public ChunkCoordinates getSourceWireframe(EntityPlayer player, ItemStack stack); + +} diff --git a/src/api/java/vazkii/botania/api/item/IFlowerPlaceable.java b/src/api/java/vazkii/botania/api/item/IFlowerPlaceable.java new file mode 100644 index 0000000..05f1f1f --- /dev/null +++ b/src/api/java/vazkii/botania/api/item/IFlowerPlaceable.java @@ -0,0 +1,27 @@ +/** + * This class was created by . It's distributed as + * part of the Botania Mod. Get the Source Code in github: + * https://github.com/Vazkii/Botania + * + * Botania is Open Source and distributed under the + * Botania License: http://botaniamod.net/license.php + * + * File Created @ [17/11/2015, 20:10:53 (GMT)] + */ +package vazkii.botania.api.item; +import net.minecraft.block.Block; +import net.minecraft.item.ItemStack; +import vazkii.botania.api.subtile.SubTileEntity; + +/** + * An Item that implements this can be placed by a Rannuncarpus. + */ +public interface IFlowerPlaceable { + + /** + * Gets the block to be placed, return null to not place anything. + */ + public Block getBlockToPlaceByFlower(ItemStack stack, SubTileEntity flower, int x, int y, int z); + + public void onBlockPlacedByFlower(ItemStack stack, SubTileEntity flower, int x, int y, int z); +} diff --git a/src/api/java/vazkii/botania/api/item/IGrassHornExcempt.java b/src/api/java/vazkii/botania/api/item/IGrassHornExcempt.java index b23774c..601ad91 100644 --- a/src/api/java/vazkii/botania/api/item/IGrassHornExcempt.java +++ b/src/api/java/vazkii/botania/api/item/IGrassHornExcempt.java @@ -15,7 +15,9 @@ import net.minecraft.world.World; /** * A BlockBush can implement this to check if it can be broken * by a Horn/Drum of the Wild or not. + * @Deprecated Use IHornHarvestable instead */ +@Deprecated public interface IGrassHornExcempt { public boolean canUproot(World world, int x, int y, int z); diff --git a/src/api/java/vazkii/botania/api/item/IHornHarvestable.java b/src/api/java/vazkii/botania/api/item/IHornHarvestable.java new file mode 100644 index 0000000..a74af38 --- /dev/null +++ b/src/api/java/vazkii/botania/api/item/IHornHarvestable.java @@ -0,0 +1,64 @@ +/** + * This class was created by . It's distributed as + * part of the Botania Mod. Get the Source Code in github: + * https://github.com/Vazkii/Botania + * + * Botania is Open Source and distributed under the + * Botania License: http://botaniamod.net/license.php + * + * File Created @ [Oct 24, 2015, 11:16:00 PM (GMT)] + */ +package vazkii.botania.api.item; + +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; + +/** + * A Block that implements this can be uprooted by the various horns in Botania. + */ +public interface IHornHarvestable { + + /** + * Returns true if this block can be uprooted. + * Note that the stack param can be null if it's a drum breaking it. + */ + public boolean canHornHarvest(World world, int x, int y, int z, ItemStack stack, EnumHornType hornType); + + /** + * Returns true if harvestByHorn() should be called. If false it just uses the normal + * block breaking method. + * Note that the stack param can be null if it's a drum breaking it. + */ + public boolean hasSpecialHornHarvest(World world, int x, int y, int z, ItemStack stack, EnumHornType hornType); + + /** + * Called to harvest by a horn. + * Note that the stack param can be null if it's a drum breaking it. + */ + public void harvestByHorn(World world, int x, int y, int z, ItemStack stack, EnumHornType hornType); + + public static enum EnumHornType { + + /** + * Horn of the Wild, for grass and crops + */ + WILD, + + /** + * Horn of the Canopy, for leaves + */ + CANOPY, + + /** + * Horn of the Covering, for snow + */ + COVERING; + + public static EnumHornType getTypeForMeta(int meta) { + EnumHornType[] values = EnumHornType.values(); + return values[Math.min(values.length - 1, meta)]; + } + + }; + +} diff --git a/src/api/java/vazkii/botania/api/item/IManaProficiencyArmor.java b/src/api/java/vazkii/botania/api/item/IManaProficiencyArmor.java new file mode 100644 index 0000000..595e800 --- /dev/null +++ b/src/api/java/vazkii/botania/api/item/IManaProficiencyArmor.java @@ -0,0 +1,44 @@ +/** + * This class was created by . It's distributed as + * part of the Botania Mod. Get the Source Code in github: + * https://github.com/Vazkii/Botania + * + * Botania is Open Source and distributed under the + * Botania License: http://botaniamod.net/license.php + * + * File Created @ [Aug 28, 2015, 9:04:53 PM (GMT)] + */ +package vazkii.botania.api.item; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; + +/** + * An armor item that implements this gives the player wearing it mana proficiency, by + * which it makes Rods the player use have a stronger effect. This is a boolean, and only + * one armor piece with this returning true is required for the player to be considered + * to be having proficiency, by which it's suggested that this is used alongside an + * armor set, where only one piece implements it. + */ +public interface IManaProficiencyArmor { + + public boolean shouldGiveProficiency(ItemStack stack, int slot, EntityPlayer player); + + public final static class Helper { + + public static boolean hasProficiency(EntityPlayer player) { + for(int i = 0; i < 4; i++) { + ItemStack armor = player.getCurrentArmor(i); + if(armor != null) { + Item item = armor.getItem(); + if(item instanceof IManaProficiencyArmor && ((IManaProficiencyArmor) item).shouldGiveProficiency(armor, i, player)) + return true; + } + } + return false; + } + + } + +} diff --git a/src/api/java/vazkii/botania/api/item/IPhantomInkable.java b/src/api/java/vazkii/botania/api/item/IPhantomInkable.java new file mode 100644 index 0000000..dc2f397 --- /dev/null +++ b/src/api/java/vazkii/botania/api/item/IPhantomInkable.java @@ -0,0 +1,24 @@ +/** + * This class was created by . It's distributed as + * part of the Botania Mod. Get the Source Code in github: + * https://github.com/Vazkii/Botania + * + * Botania is Open Source and distributed under the + * Botania License: http://botaniamod.net/license.php + * + * File Created @ [Mar 17, 2015, 4:57:44 PM (GMT)] + */ +package vazkii.botania.api.item; + +import net.minecraft.item.ItemStack; + +/** + * An Item that implements this can be crafted with Phantom Ink. + */ +public interface IPhantomInkable { + + public boolean hasPhantomInk(ItemStack stack); + + public void setPhantomInk(ItemStack stack, boolean ink); + +} diff --git a/src/api/java/vazkii/botania/api/item/IRelic.java b/src/api/java/vazkii/botania/api/item/IRelic.java new file mode 100644 index 0000000..aecd1cd --- /dev/null +++ b/src/api/java/vazkii/botania/api/item/IRelic.java @@ -0,0 +1,42 @@ +/** + * This class was created by . It's distributed as + * part of the Botania Mod. Get the Source Code in github: + * https://github.com/Vazkii/Botania + * + * Botania is Open Source and distributed under the + * Botania License: http://botaniamod.net/license.php + * + * File Created @ [Mar 29, 2015, 7:17:41 PM (GMT)] + */ +package vazkii.botania.api.item; + +import net.minecraft.item.ItemStack; +import net.minecraft.stats.Achievement; + +/** + * An item that implements this counts as a Relic item. This is purely for interaction + * and other mod items should not implement this interface. + */ +public interface IRelic { + + /** + * Binds to the player name passed in. + */ + public void bindToUsername(String playerName, ItemStack stack); + + /** + * Gets the username of the person this relic is bound to. + */ + public String getSoulbindUsername(ItemStack stack); + + /** + * Sets the achievement that this relic binds to. + */ + public void setBindAchievement(Achievement achievement); + + /** + * Gets the achievement that this relic binds to. + */ + public Achievement getBindAchievement(); + +} diff --git a/src/api/java/vazkii/botania/api/item/ISequentialBreaker.java b/src/api/java/vazkii/botania/api/item/ISequentialBreaker.java new file mode 100644 index 0000000..87af2d0 --- /dev/null +++ b/src/api/java/vazkii/botania/api/item/ISequentialBreaker.java @@ -0,0 +1,27 @@ +/** + * This class was created by . It's distributed as + * part of the Botania Mod. Get the Source Code in github: + * https://github.com/Vazkii/Botania + * + * Botania is Open Source and distributed under the + * Botania License: http://botaniamod.net/license.php + * + * File Created @ [Mar 30, 2015, 2:46:05 PM (GMT)] + */ +package vazkii.botania.api.item; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; + +/** + * An item that implements this can break multiple blocks at once + * with a Ring of Loki. Usage of this interface requires an implementation + * (see ItemTerraPick). + */ +public interface ISequentialBreaker { + + public void breakOtherBlock(EntityPlayer player, ItemStack stack, int x, int y, int z, int originX, int originY, int originZ, int side); + + public boolean disposeOfTrashBlocks(ItemStack stack); + +} diff --git a/src/api/java/vazkii/botania/api/item/IWireframeCoordinateListProvider.java b/src/api/java/vazkii/botania/api/item/IWireframeCoordinateListProvider.java new file mode 100644 index 0000000..ae0863c --- /dev/null +++ b/src/api/java/vazkii/botania/api/item/IWireframeCoordinateListProvider.java @@ -0,0 +1,35 @@ +/** + * This class was created by . It's distributed as + * part of the Botania Mod. Get the Source Code in github: + * https://github.com/Vazkii/Botania + * + * Botania is Open Source and distributed under the + * Botania License: http://botaniamod.net/license.php + * + * File Created @ [Mar 29, 2015, 11:30:41 PM (GMT)] + */ +package vazkii.botania.api.item; + +import java.util.List; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.util.ChunkCoordinates; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + +/** + * An item that implements this will allow for various wireframes to be drawn + * around the player. This will be called while the item is in the inventory, + * armor slot or bauble slots. + */ +public interface IWireframeCoordinateListProvider { + + /** + * Returns a list of ChunkCoordinates for the wireframes to draw. + * Can be null. + */ + @SideOnly(Side.CLIENT) + public List getWireframesToDraw(EntityPlayer player, ItemStack stack); + +} diff --git a/src/api/java/vazkii/botania/api/item/TinyPotatoRenderEvent.java b/src/api/java/vazkii/botania/api/item/TinyPotatoRenderEvent.java new file mode 100644 index 0000000..8b51c26 --- /dev/null +++ b/src/api/java/vazkii/botania/api/item/TinyPotatoRenderEvent.java @@ -0,0 +1,38 @@ +/** + * This class was created by . It's distributed as + * part of the Botania Mod. Get the Source Code in github: + * https://github.com/Vazkii/Botania + * + * Botania is Open Source and distributed under the + * Botania License: http://botaniamod.net/license.php + * + * File Created @ [Jul 25, 2015, 8:02:41 PM (GMT)] + */ +package vazkii.botania.api.item; + +import net.minecraft.tileentity.TileEntity; +import cpw.mods.fml.common.eventhandler.Event; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + +/** + * Why would you ever want this ._. + */ +@SideOnly(Side.CLIENT) +public class TinyPotatoRenderEvent extends Event { + + public final TileEntity tile; + public final String name; + public final double x, y, z; + public final float partTicks; + + public TinyPotatoRenderEvent(TileEntity tile, String name, double x, double y, double z, float partTicks) { + this.tile = tile; + this.name = name; + this.x = x; + this.y = y; + this.z = z; + this.partTicks = partTicks; + } + +} diff --git a/src/api/java/vazkii/botania/api/lexicon/BotaniaTutorialStartEvent.java b/src/api/java/vazkii/botania/api/lexicon/BotaniaTutorialStartEvent.java new file mode 100644 index 0000000..c082572 --- /dev/null +++ b/src/api/java/vazkii/botania/api/lexicon/BotaniaTutorialStartEvent.java @@ -0,0 +1,29 @@ +/** + * This class was created by . It's distributed as + * part of the Botania Mod. Get the Source Code in github: + * https://github.com/Vazkii/Botania + * + * Botania is Open Source and distributed under the + * Botania License: http://botaniamod.net/license.php + * + * File Created @ [04/12/2015, 18:29:56 (GMT)] + */ +package vazkii.botania.api.lexicon; + +import java.util.Queue; + +import cpw.mods.fml.common.eventhandler.Event; + +/** + * Fired when the Lexica Botania's tutorial is started. You can add your + * own entries to the tutorial here. Please use this responsibly. + */ +public class BotaniaTutorialStartEvent extends Event { + + public final Queue tutorial; + + public BotaniaTutorialStartEvent(Queue tutorial) { + this.tutorial = tutorial; + } + +} diff --git a/src/api/java/vazkii/botania/api/lexicon/LexiconEntry.java b/src/api/java/vazkii/botania/api/lexicon/LexiconEntry.java index 3151e62..2bc0250 100644 --- a/src/api/java/vazkii/botania/api/lexicon/LexiconEntry.java +++ b/src/api/java/vazkii/botania/api/lexicon/LexiconEntry.java @@ -17,6 +17,8 @@ import java.util.List; import net.minecraft.item.ItemStack; import net.minecraft.util.StatCollector; import vazkii.botania.api.BotaniaAPI; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; public class LexiconEntry implements Comparable { @@ -28,6 +30,8 @@ public class LexiconEntry implements Comparable { public List pages = new ArrayList(); private boolean priority = false; private ItemStack icon = null; + + private List extraDisplayedRecipes = new ArrayList(); /** * @param unlocalizedName The unlocalized name of this entry. This will be localized by the client display. @@ -77,6 +81,15 @@ public class LexiconEntry implements Comparable { return unlocalizedName; } + public String getTagline() { + return null; // Override this if you want a tagline. You probably do + } + + @SideOnly(Side.CLIENT) + public boolean isVisible() { + return true; + } + /** * Sets what pages you want this entry to have. */ @@ -92,6 +105,15 @@ public class LexiconEntry implements Comparable { return this; } + /** + * Returns the web link for this entry. If this isn't null, looking at this entry will + * show a "View Online" button in the book. The String returned should be the URL to + * open when the button is clicked. + */ + public String getWebLink() { + return null; + } + /** * Adds a page to the list of pages. */ @@ -103,8 +125,42 @@ public class LexiconEntry implements Comparable { return (priority ? 0 : 1) + StatCollector.translateToLocal(getUnlocalizedName()); } + public List getDisplayedRecipes() { + ArrayList list = new ArrayList(); + for(LexiconPage page : pages) { + List l = page.getDisplayedRecipes(); + + if(l != null) { + ArrayList itemsAddedThisPage = new ArrayList(); + + for(ItemStack s : l) { + addItem: { + for(ItemStack s1 : itemsAddedThisPage) + if(s1.getItem() == s.getItem()) + break addItem; + for(ItemStack s1 : list) + if(s1.isItemEqual(s) && ItemStack.areItemStackTagsEqual(s1, s)) + break addItem; + + itemsAddedThisPage.add(s); + list.add(s); + } + } + } + } + + list.addAll(extraDisplayedRecipes); + + return list; + } + + public void addExtraDisplayedRecipe(ItemStack stack) { + extraDisplayedRecipes.add(stack); + } + @Override public int compareTo(LexiconEntry o) { return getNameForSorting().compareTo(o.getNameForSorting()); } + } \ No newline at end of file diff --git a/src/api/java/vazkii/botania/api/lexicon/LexiconPage.java b/src/api/java/vazkii/botania/api/lexicon/LexiconPage.java index e0982e7..9880b9e 100644 --- a/src/api/java/vazkii/botania/api/lexicon/LexiconPage.java +++ b/src/api/java/vazkii/botania/api/lexicon/LexiconPage.java @@ -10,7 +10,10 @@ */ package vazkii.botania.api.lexicon; +import java.util.List; + import net.minecraft.client.gui.GuiButton; +import net.minecraft.item.ItemStack; import vazkii.botania.api.internal.IGuiLexiconEntry; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; @@ -91,6 +94,14 @@ public abstract class LexiconPage { // NO-OP } + /** + * Shows the list of recipes present in this page for display in the category + * page. Can return null for an entry with no recipes. + */ + public List getDisplayedRecipes() { + return null; + } + public String getUnlocalizedName() { return unlocalizedName; } diff --git a/src/api/java/vazkii/botania/api/lexicon/LexiconRecipeMappings.java b/src/api/java/vazkii/botania/api/lexicon/LexiconRecipeMappings.java index f4456b9..8202a40 100644 --- a/src/api/java/vazkii/botania/api/lexicon/LexiconRecipeMappings.java +++ b/src/api/java/vazkii/botania/api/lexicon/LexiconRecipeMappings.java @@ -14,6 +14,7 @@ import java.util.HashMap; import java.util.Map; import net.minecraft.item.ItemStack; +import vazkii.botania.api.mana.IManaItem; /** * This class contains mappings for which entry and page correspond to each @@ -48,12 +49,19 @@ public final class LexiconRecipeMappings { public static EntryData getDataForStack(ItemStack stack) { return mappings.get(stackToString(stack)); } - + public static String stackToString(ItemStack stack) { + if(stack == null || stack.getItem() == null) + return "NULL"; + if(stack.hasTagCompound() && stack.getItem() instanceof IRecipeKeyProvider) return ((IRecipeKeyProvider) stack.getItem()).getKey(stack); - return stack.getUnlocalizedName() + "~" + stack.getItemDamage(); + return stack.getUnlocalizedName() + (ignoreMeta(stack) ? "" : "~" + stack.getItemDamage()); + } + + public static boolean ignoreMeta(ItemStack stack) { + return stack.isItemStackDamageable() || stack.getItem() instanceof IManaItem; } public static class EntryData { diff --git a/src/api/java/vazkii/botania/api/lexicon/multiblock/IMultiblockRenderHook.java b/src/api/java/vazkii/botania/api/lexicon/multiblock/IMultiblockRenderHook.java new file mode 100644 index 0000000..9d05c40 --- /dev/null +++ b/src/api/java/vazkii/botania/api/lexicon/multiblock/IMultiblockRenderHook.java @@ -0,0 +1,32 @@ +/** + * This class was created by . It's distributed as + * part of the Botania Mod. Get the Source Code in github: + * https://github.com/Vazkii/Botania + * + * Botania is Open Source and distributed under the + * Botania License: http://botaniamod.net/license.php + * + * File Created @ [Jun 27, 2015, 7:48:47 PM (GMT)] + */ +package vazkii.botania.api.lexicon.multiblock; + +import java.util.HashMap; +import java.util.Map; + +import net.minecraft.block.Block; +import net.minecraft.client.renderer.RenderBlocks; +import net.minecraft.world.IBlockAccess; +import vazkii.botania.api.lexicon.multiblock.component.MultiblockComponent; + +/** + * A hook for rendering blocks in the multiblock display. + */ +public interface IMultiblockRenderHook { + + public static Map renderHooks = new HashMap(); + + public void renderBlockForMultiblock(IBlockAccess world, Multiblock mb, Block block, int meta, RenderBlocks renderBlocks, MultiblockComponent comp, float alpha); + + public boolean needsTranslate(Block block); + +} diff --git a/src/api/java/vazkii/botania/api/lexicon/multiblock/Multiblock.java b/src/api/java/vazkii/botania/api/lexicon/multiblock/Multiblock.java new file mode 100644 index 0000000..4cf34b8 --- /dev/null +++ b/src/api/java/vazkii/botania/api/lexicon/multiblock/Multiblock.java @@ -0,0 +1,188 @@ +/** + * This class was created by . It's distributed as + * part of the Botania Mod. Get the Source Code in github: + * https://github.com/Vazkii/Botania + * + * Botania is Open Source and distributed under the + * Botania License: http://botaniamod.net/license.php + * + * File Created @ [Jun 27, 2015, 2:37:22 PM (GMT)] + */ +package vazkii.botania.api.lexicon.multiblock; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; + +import net.minecraft.block.Block; +import net.minecraft.item.ItemStack; +import net.minecraft.util.ChunkCoordinates; +import vazkii.botania.api.lexicon.multiblock.component.MultiblockComponent; + +/** + * This class describes a Mutiblock object. It's used to display a + * multiblock in the lexicon and to show the player in a ghost-like + * look in the world. + */ +public class Multiblock { + + public List components = new ArrayList(); + public List materials = new ArrayList(); + + public int minX, minY, minZ, maxX, maxY, maxZ, offX, offY, offZ; + + public HashMap, MultiblockComponent> locationCache = new HashMap, MultiblockComponent>(); + + /** + * Adds a multiblock component to this multiblock. The component's x y z + * coords should be pivoted to the center of the structure. + */ + public void addComponent(MultiblockComponent component) { + if(getComponentForLocation(component.relPos.posX, component.relPos.posY, component.relPos.posZ) != null) + throw new IllegalArgumentException("Location in multiblock already occupied"); + components.add(component); + changeAxisForNewComponent(component.relPos.posX, component.relPos.posY, component.relPos.posZ); + calculateCostForNewComponent(component); + addComponentToLocationCache(component); + } + + /** + * Constructs and adds a multiblock component to this multiblock. The x y z + * coords should be pivoted to the center of the structure. + */ + public void addComponent(int x, int y, int z, Block block, int meta) { + addComponent(new MultiblockComponent(new ChunkCoordinates(x, y, z), block, meta)); + } + + private void changeAxisForNewComponent(int x, int y, int z) { + if(x < minX) + minX = x; + else if(x > maxX) + maxX = x; + + if(y < minY) + minY = y; + else if(y > maxY) + maxY = y; + + if(z < minZ) + minZ = z; + else if(z > maxZ) + maxZ = z; + } + + private void calculateCostForNewComponent(MultiblockComponent comp) { + ItemStack[] materials = comp.getMaterials(); + if(materials != null) + for(ItemStack stack : materials) + addStack(stack); + } + + private void addStack(ItemStack stack) { + if(stack == null) + return; + + for(ItemStack oStack : materials) + if(oStack.isItemEqual(stack) && ItemStack.areItemStackTagsEqual(oStack, stack)) { + oStack.stackSize += stack.stackSize; + return; + } + + materials.add(stack); + } + + public void setRenderOffset(int x, int y, int z) { + offX = x; + offY = y; + offZ = z; + } + + public List getComponents() { + return components; + } + + /** + * Rotates this multiblock by the angle passed in. For the best results, use + * only multiples of pi/2. + */ + public void rotate(double angle) { + for(MultiblockComponent comp : getComponents()) + comp.rotate(angle); + updateLocationCache(); + } + + public Multiblock copy() { + Multiblock mb = new Multiblock(); + for(MultiblockComponent comp : getComponents()) + mb.addComponent(comp.copy()); + + return mb; + } + + /** + * Creates a length 4 array of all the rotations multiple of pi/2 required + * to render this multiblock in the world relevant to the 4 cardinal + * orientations. + */ + public Multiblock[] createRotations() { + Multiblock[] blocks = new Multiblock[4]; + blocks[0] = this; + blocks[1] = blocks[0].copy(); + blocks[1].rotate(Math.PI / 2); + blocks[2] = blocks[1].copy(); + blocks[2].rotate(Math.PI / 2); + blocks[3] = blocks[2].copy(); + blocks[3].rotate(Math.PI / 2); + + return blocks; + } + + /** + * Makes a MultiblockSet from this Multiblock and its rotations using + * createRotations(). + */ + public MultiblockSet makeSet() { + return new MultiblockSet(this); + } + + public int getXSize() { + return Math.abs(minX) + Math.abs(maxX) + 1; + } + + public int getYSize() { + return Math.abs(minY) + Math.abs(maxY) + 1; + } + + public int getZSize() { + return Math.abs(minZ) + Math.abs(maxZ) + 1; + } + + /** + * Rebuilds the location cache + */ + public void updateLocationCache() { + locationCache.clear(); + for(MultiblockComponent comp : components) + addComponentToLocationCache(comp); + } + + /** + * Adds a single component to the location cache + */ + private void addComponentToLocationCache(MultiblockComponent comp) { + ChunkCoordinates pos = comp.getRelativePosition(); + locationCache.put(Arrays.asList( + pos.posX, + pos.posY, + pos.posZ + ), comp); + } + + /** + * Gets the component for a given location + */ + public MultiblockComponent getComponentForLocation(int x, int y, int z) { + return locationCache.get(Arrays.asList(x, y, z)); + } +} diff --git a/src/api/java/vazkii/botania/api/lexicon/multiblock/MultiblockSet.java b/src/api/java/vazkii/botania/api/lexicon/multiblock/MultiblockSet.java new file mode 100644 index 0000000..c0435f8 --- /dev/null +++ b/src/api/java/vazkii/botania/api/lexicon/multiblock/MultiblockSet.java @@ -0,0 +1,43 @@ +/** + * This class was created by . It's distributed as + * part of the Botania Mod. Get the Source Code in github: + * https://github.com/Vazkii/Botania + * + * Botania is Open Source and distributed under the + * Botania License: http://botaniamod.net/license.php + * + * File Created @ [Jun 27, 2015, 7:31:58 PM (GMT)] + */ +package vazkii.botania.api.lexicon.multiblock; + +import net.minecraft.entity.Entity; +import net.minecraft.util.MathHelper; + +/** + * A set of Multiblock objects for various rotations. + */ +public class MultiblockSet { + + private final Multiblock[] mbs; + + public MultiblockSet(Multiblock[] mbs) { + this.mbs = mbs; + } + + public MultiblockSet(Multiblock mb) { + this(mb.createRotations()); + } + + public Multiblock getForEntity(Entity e) { + return getForRotation(e.rotationYaw); + } + + public Multiblock getForRotation(double rotation) { + int facing = MathHelper.floor_double(rotation * 4.0 / 360.0 + 0.5) & 3; + return getForIndex(facing); + } + + public Multiblock getForIndex(int index) { + return mbs[Math.min(mbs.length - 1, index)]; + } +} diff --git a/src/api/java/vazkii/botania/api/lexicon/multiblock/component/AnyComponent.java b/src/api/java/vazkii/botania/api/lexicon/multiblock/component/AnyComponent.java new file mode 100644 index 0000000..f7a159b --- /dev/null +++ b/src/api/java/vazkii/botania/api/lexicon/multiblock/component/AnyComponent.java @@ -0,0 +1,32 @@ +/** + * This class was created by . It's distributed as + * part of the Botania Mod. Get the Source Code in github: + * https://github.com/Vazkii/Botania + * + * Botania is Open Source and distributed under the + * Botania License: http://botaniamod.net/license.php + * + * File Created @ [01/11/2015, 19:05:57 (GMT)] + */ +package vazkii.botania.api.lexicon.multiblock.component; + +import net.minecraft.block.Block; +import net.minecraft.util.ChunkCoordinates; +import net.minecraft.world.World; + +/** + * A multiblock component that matches any non air blocks that have a collision box. + */ +public class AnyComponent extends MultiblockComponent { + + public AnyComponent(ChunkCoordinates relPos, Block block, int meta) { + super(relPos, block, meta); + } + + @Override + public boolean matches(World world, int x, int y, int z) { + Block block = world.getBlock(x, y, z); + return !block.isAir(world, x, y, z) && block.getCollisionBoundingBoxFromPool(world, x, y, z) != null; + } + +} diff --git a/src/api/java/vazkii/botania/api/lexicon/multiblock/component/ColorSwitchingComponent.java b/src/api/java/vazkii/botania/api/lexicon/multiblock/component/ColorSwitchingComponent.java new file mode 100644 index 0000000..27eb32a --- /dev/null +++ b/src/api/java/vazkii/botania/api/lexicon/multiblock/component/ColorSwitchingComponent.java @@ -0,0 +1,43 @@ +/** + * This class was created by . It's distributed as + * part of the Botania Mod. Get the Source Code in github: + * https://github.com/Vazkii/Botania + * + * Botania is Open Source and distributed under the + * Botania License: http://botaniamod.net/license.php + * + * File Created @ [Jun 27, 2015, 7:20:09 PM (GMT)] + */ +package vazkii.botania.api.lexicon.multiblock.component; + +import net.minecraft.block.Block; +import net.minecraft.util.ChunkCoordinates; +import net.minecraft.world.World; +import vazkii.botania.api.BotaniaAPI; + +/** + * A multiblock component that switches through the 16 colors of the + * minecraft spectrum. This can be used for flowers, for example. + */ +public class ColorSwitchingComponent extends MultiblockComponent { + + public ColorSwitchingComponent(ChunkCoordinates relPos, Block block) { + super(relPos, block, -1); + } + + @Override + public int getMeta() { + return (int) (BotaniaAPI.internalHandler.getWorldElapsedTicks() / 20) % 16; + } + + @Override + public boolean matches(World world, int x, int y, int z) { + return world.getBlock(x, y, z) == getBlock(); + } + + @Override + public MultiblockComponent copy() { + return new ColorSwitchingComponent(relPos, block); + } + +} diff --git a/src/api/java/vazkii/botania/api/lexicon/multiblock/component/FlowerComponent.java b/src/api/java/vazkii/botania/api/lexicon/multiblock/component/FlowerComponent.java new file mode 100644 index 0000000..8a4f0ad --- /dev/null +++ b/src/api/java/vazkii/botania/api/lexicon/multiblock/component/FlowerComponent.java @@ -0,0 +1,37 @@ +/** + * This class was created by . It's distributed as + * part of the Botania Mod. Get the Source Code in github: + * https://github.com/Vazkii/Botania + * + * Botania is Open Source and distributed under the + * Botania License: http://botaniamod.net/license.php + * + * File Created @ [Jun 28, 2015, 3:23:15 PM (GMT)] + */ +package vazkii.botania.api.lexicon.multiblock.component; + +import net.minecraft.block.Block; +import net.minecraft.util.ChunkCoordinates; +import net.minecraft.world.World; +import vazkii.botania.api.BotaniaAPI; + +/** + * A multiblock component that matches any botania flower. + */ +public class FlowerComponent extends ColorSwitchingComponent { + + public FlowerComponent(ChunkCoordinates relPos, Block block) { + super(relPos, block); + } + + @Override + public boolean matches(World world, int x, int y, int z) { + return BotaniaAPI.internalHandler.isBotaniaFlower(world, x, y, z); + } + + @Override + public MultiblockComponent copy() { + return new FlowerComponent(relPos, block); + } + +} diff --git a/src/api/java/vazkii/botania/api/lexicon/multiblock/component/MultiblockComponent.java b/src/api/java/vazkii/botania/api/lexicon/multiblock/component/MultiblockComponent.java new file mode 100644 index 0000000..b1a7d89 --- /dev/null +++ b/src/api/java/vazkii/botania/api/lexicon/multiblock/component/MultiblockComponent.java @@ -0,0 +1,96 @@ +/** + * This class was created by . It's distributed as + * part of the Botania Mod. Get the Source Code in github: + * https://github.com/Vazkii/Botania + * + * Botania is Open Source and distributed under the + * Botania License: http://botaniamod.net/license.php + * + * File Created @ [Jun 27, 2015, 2:42:32 PM (GMT)] + */ +package vazkii.botania.api.lexicon.multiblock.component; + +import net.minecraft.block.Block; +import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.ChunkCoordinates; +import net.minecraft.world.World; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + +/** + * A component of a multiblock, the normal one + * is just a block. + */ +public class MultiblockComponent { + + public ChunkCoordinates relPos; + public final Block block; + public final int meta; + public final TileEntity tileEntity; + public boolean doFancyRender; + + public MultiblockComponent(ChunkCoordinates relPos, Block block, int meta) { + this(relPos, block, meta, null); + } + + public MultiblockComponent(ChunkCoordinates relPos, Block block, int meta, boolean doFancyRender) { + this(relPos, block, meta, doFancyRender, null); + } + + public MultiblockComponent(ChunkCoordinates relPos, Block block, int meta, TileEntity tileEntity) { + this(relPos, block, meta, block.hasTileEntity() == (tileEntity != null), tileEntity); + } + + public MultiblockComponent(ChunkCoordinates relPos, Block block, int meta, boolean doFancyRender, TileEntity tileEntity) { + this.relPos = relPos; + this.block = block; + this.meta = meta; + this.tileEntity = tileEntity; + this.doFancyRender = doFancyRender; + } + + public ChunkCoordinates getRelativePosition() { + return relPos; + } + + public Block getBlock() { + return block; + } + + public int getMeta() { + return meta; + } + + public boolean matches(World world, int x, int y, int z) { + return world.getBlock(x, y, z) == getBlock() && (meta == -1 || world.getBlockMetadata(x, y, z) == meta); + } + + public ItemStack[] getMaterials() { + return new ItemStack[] { new ItemStack(block, 1, meta) }; + } + + public void rotate(double angle) { + double x = relPos.posX; + double z = relPos.posZ; + double sin = Math.sin(angle); + double cos = Math.cos(angle); + + double xn = x * cos - z * sin; + double zn = x * sin + z * cos; + relPos = new ChunkCoordinates((int) Math.round(xn), relPos.posY, (int) Math.round(zn)); + } + + public MultiblockComponent copy() { + return new MultiblockComponent(relPos, block, meta, tileEntity); + } + + public TileEntity getTileEntity() { + return tileEntity; + } + + @SideOnly(Side.CLIENT) + public boolean shouldDoFancyRender() { + return doFancyRender; + } +} diff --git a/src/api/java/vazkii/botania/api/mana/ICompositableLens.java b/src/api/java/vazkii/botania/api/mana/ICompositableLens.java new file mode 100644 index 0000000..775719d --- /dev/null +++ b/src/api/java/vazkii/botania/api/mana/ICompositableLens.java @@ -0,0 +1,32 @@ +/** + * This class was created by . It's distributed as + * part of the Botania Mod. Get the Source Code in github: + * https://github.com/Vazkii/Botania + * + * Botania is Open Source and distributed under the + * Botania License: http://botaniamod.net/license.php + * + * File Created @ [Nov 23, 2015, 10:30:34 AM (GMT)] + */ +package vazkii.botania.api.mana; + +import net.minecraft.item.ItemStack; + +/** + * Have an Item implement this to be counted as a lens that can be combined with an ItemLens. + */ +public interface ICompositableLens extends ILens { + + /** + * Returns the properties of the itemstack, used to check if two lenses can combine. + */ + public int getProps(ItemStack stack); + + /** + * Checks if the lens is combinable. + */ + public boolean isCombinable(ItemStack stack); + +} + + diff --git a/src/api/java/vazkii/botania/api/mana/IDirectioned.java b/src/api/java/vazkii/botania/api/mana/IDirectioned.java new file mode 100644 index 0000000..ff856f7 --- /dev/null +++ b/src/api/java/vazkii/botania/api/mana/IDirectioned.java @@ -0,0 +1,24 @@ +/** + * This class was created by . It's distributed as + * part of the Botania Mod. Get the Source Code in github: + * https://github.com/Vazkii/Botania + * + * Botania is Open Source and distributed under the + * Botania License: http://botaniamod.net/license.php + * + * File Created @ [15/11/2015, 19:27:07 (GMT)] + */ +package vazkii.botania.api.mana; + +/** + * Any TileEntity that implements this is defined as having a direction, + * and has two rotations (X and Y). + * An example of this is the Mana Spreader. + */ +public interface IDirectioned { + + public float getRotationX(); + + public float getRotationY(); + +} diff --git a/src/api/java/vazkii/botania/api/mana/IIdentifiable.java b/src/api/java/vazkii/botania/api/mana/IIdentifiable.java new file mode 100644 index 0000000..65f2edc --- /dev/null +++ b/src/api/java/vazkii/botania/api/mana/IIdentifiable.java @@ -0,0 +1,23 @@ +/** + * This class was created by . It's distributed as + * part of the Botania Mod. Get the Source Code in github: + * https://github.com/Vazkii/Botania + * + * Botania is Open Source and distributed under the + * Botania License: http://botaniamod.net/license.php + * + * File Created @ [Jun 19, 2015, 10:05:24 PM (GMT)] + */ +package vazkii.botania.api.mana; + +import java.util.UUID; + +/** + * This interface marks a TileEntity that can be identified through + * an UUID. This UUID must presist between sessions. + */ +public interface IIdentifiable { + + public UUID getIdentifier(); + +} diff --git a/src/api/java/vazkii/botania/api/mana/ILensControl.java b/src/api/java/vazkii/botania/api/mana/ILensControl.java new file mode 100644 index 0000000..ad0cc6c --- /dev/null +++ b/src/api/java/vazkii/botania/api/mana/ILensControl.java @@ -0,0 +1,35 @@ +/** + * This class was created by . It's distributed as + * part of the Botania Mod. Get the Source Code in github: + * https://github.com/Vazkii/Botania + * + * Botania is Open Source and distributed under the + * Botania License: http://botaniamod.net/license.php + * + * File Created @ [15/11/2015, 21:00:32 (GMT)] + */ +package vazkii.botania.api.mana; + +import net.minecraft.item.ItemStack; + +/** + * An extension of ILens that allows for the lens item to control the + * spreader's behaviour. + */ +public interface ILensControl extends ILens { + + public boolean isControlLens(ItemStack stack); + + public boolean allowBurstShooting(ItemStack stack, IManaSpreader spreader, boolean redstone); + + /** + * Used for the tick of a non-redstone spreader. + */ + public void onControlledSpreaderTick(ItemStack stack, IManaSpreader spreader, boolean redstone); + + /** + * Used for when a redstone spreader gets a pulse. + */ + public void onControlledSpreaderPulse(ItemStack stack, IManaSpreader spreader, boolean redstone); + +} diff --git a/src/api/java/vazkii/botania/api/mana/IManaDiscountArmor.java b/src/api/java/vazkii/botania/api/mana/IManaDiscountArmor.java index e580939..56a9683 100644 --- a/src/api/java/vazkii/botania/api/mana/IManaDiscountArmor.java +++ b/src/api/java/vazkii/botania/api/mana/IManaDiscountArmor.java @@ -15,7 +15,8 @@ import net.minecraft.item.ItemStack; /** * An armor item that implements this can provide a mana discount for mana tools. - * Mana tools are the ones on the main toolset (Pick, Shovel, Axe, Sword and Shovel). + * Mana tools are the ones on the main toolset (Pick, Shovel, Axe, Sword and Shovel) + * as well as Rods. */ public interface IManaDiscountArmor { diff --git a/src/api/java/vazkii/botania/api/mana/IManaGivingItem.java b/src/api/java/vazkii/botania/api/mana/IManaGivingItem.java new file mode 100644 index 0000000..a1d7f04 --- /dev/null +++ b/src/api/java/vazkii/botania/api/mana/IManaGivingItem.java @@ -0,0 +1,20 @@ +/** + * This class was created by . It's distributed as + * part of the Botania Mod. Get the Source Code in github: + * https://github.com/Vazkii/Botania + * + * Botania is Open Source and distributed under the + * Botania License: http://botaniamod.net/license.php + * + * File Created @ [08/12/2015, 18:10:29 (GMT)] + */ +package vazkii.botania.api.mana; + +/** + * An item that implements this is an item that can give mana to other items. + * This is used in botania for the terra shatterer to not be constantly + * receiving mana from these items.. + */ +public interface IManaGivingItem { + +} diff --git a/src/api/java/vazkii/botania/api/mana/IManaSpreader.java b/src/api/java/vazkii/botania/api/mana/IManaSpreader.java new file mode 100644 index 0000000..61b9f8e --- /dev/null +++ b/src/api/java/vazkii/botania/api/mana/IManaSpreader.java @@ -0,0 +1,30 @@ +/** + * This class was created by . It's distributed as + * part of the Botania Mod. Get the Source Code in github: + * https://github.com/Vazkii/Botania + * + * Botania is Open Source and distributed under the + * Botania License: http://botaniamod.net/license.php + * + * File Created @ [Apr 18, 2015, 7:30:00 PM (GMT)] + */ +package vazkii.botania.api.mana; + + +/** + * Any TileEntity that implements this is considered a Mana Spreader, + * by which can fire mana bursts as a spreader. + */ +public interface IManaSpreader extends IManaBlock, IPingable, IDirectioned { + + public void setCanShoot(boolean canShoot); + + public int getBurstParticleTick(); + + public void setBurstParticleTick(int i); + + public int getLastBurstDeathTick(); + + public void setLastBurstDeathTick(int ticksExisted); + +} diff --git a/src/api/java/vazkii/botania/api/mana/IManaTooltipDisplay.java b/src/api/java/vazkii/botania/api/mana/IManaTooltipDisplay.java new file mode 100644 index 0000000..21de474 --- /dev/null +++ b/src/api/java/vazkii/botania/api/mana/IManaTooltipDisplay.java @@ -0,0 +1,26 @@ +/** + * This class was created by . It's distributed as + * part of the Botania Mod. Get the Source Code in github: + * https://github.com/Vazkii/Botania + * + * Botania is Open Source and distributed under the + * Botania License: http://botaniamod.net/license.php + * + * File Created @ [Oct 23, 2015, 3:54:03 PM (GMT)] + */ +package vazkii.botania.api.mana; + +import net.minecraft.item.ItemStack; + +/** + * An Item that implements this has a mana tooltip display (like how the Mana Tablet + * and Mana Mirror) do. + */ +public interface IManaTooltipDisplay { + + /** + * Returns the fraction of mana in this item for display. From 0 to 1 (exclusive). + */ + public float getManaFractionForDisplay(ItemStack stack); + +} diff --git a/src/api/java/vazkii/botania/api/mana/IPingable.java b/src/api/java/vazkii/botania/api/mana/IPingable.java new file mode 100644 index 0000000..1605b42 --- /dev/null +++ b/src/api/java/vazkii/botania/api/mana/IPingable.java @@ -0,0 +1,31 @@ +/** + * This class was created by . It's distributed as + * part of the Botania Mod. Get the Source Code in github: + * https://github.com/Vazkii/Botania + * + * Botania is Open Source and distributed under the + * Botania License: http://botaniamod.net/license.php + * + * File Created @ [Jun 19, 2015, 9:52:05 PM (GMT)] + */ +package vazkii.botania.api.mana; + +import java.util.UUID; + +import vazkii.botania.api.internal.IManaBurst; + +/** + * This describes an interface of a Mana Sender block that should be able to pingbackable + * by a burst to tell it that the burst is still alive. + */ +public interface IPingable extends IIdentifiable { + + /** + * Pings this object back, telling it that the burst passed in is still alive + * in the world. The UUID parameter should be the UUID with which the burst + * was created, this is used to let the object handle the check for if it's the + * correct ID internally. IManaBurst implementations should do this every tick. + */ + public void pingback(IManaBurst burst, UUID expectedIdentity); + +} diff --git a/src/api/java/vazkii/botania/api/mana/IRedirectable.java b/src/api/java/vazkii/botania/api/mana/IRedirectable.java new file mode 100644 index 0000000..00a1b6a --- /dev/null +++ b/src/api/java/vazkii/botania/api/mana/IRedirectable.java @@ -0,0 +1,29 @@ +/** + * This class was created by . It's distributed as + * part of the Botania Mod. Get the Source Code in github: + * https://github.com/Vazkii/Botania + * + * Botania is Open Source and distributed under the + * Botania License: http://botaniamod.net/license.php + * + * File Created @ [15/11/2015, 19:28:18 (GMT)] + */ +package vazkii.botania.api.mana; + +/** + * This is an extension of IDirectioned for TileEntities + * that allow for their rotation to be public and modifiable outside. + * This is used in botania for the Redirective mana lens. + */ +public interface IRedirectable extends IDirectioned { + + public void setRotationX(float rot); + + public void setRotationY(float rot); + + /** + * This should be called after rotation setting is done to allow + * for the block to re-calculate. + */ + public void commitRedirection(); +} diff --git a/src/api/java/vazkii/botania/api/mana/IThrottledPacket.java b/src/api/java/vazkii/botania/api/mana/IThrottledPacket.java new file mode 100644 index 0000000..ff760be --- /dev/null +++ b/src/api/java/vazkii/botania/api/mana/IThrottledPacket.java @@ -0,0 +1,22 @@ +/** + * This class was created by . It's distributed as + * part of the Botania Mod. Get the Source Code in github: + * https://github.com/Vazkii/Botania + * + * Botania is Open Source and distributed under the + * Botania License: http://botaniamod.net/license.php + * + * File Created @ [Apr 12, 2015, 3:08:09 PM (GMT)] + */ +package vazkii.botania.api.mana; + +/** + * A TileEntity that will only send a few packets rather than one per every entity collision. + * markDispatchable marks that this TE needs to send a packet. Further handling is to be done + * in the TE itself. + */ +public interface IThrottledPacket { + + public void markDispatchable(); + +} diff --git a/src/api/java/vazkii/botania/api/mana/ManaItemHandler.java b/src/api/java/vazkii/botania/api/mana/ManaItemHandler.java index e05be50..d261d55 100644 --- a/src/api/java/vazkii/botania/api/mana/ManaItemHandler.java +++ b/src/api/java/vazkii/botania/api/mana/ManaItemHandler.java @@ -39,7 +39,8 @@ public final class ManaItemHandler { for(int i = 0; i < size; i++) { boolean useBaubles = i >= invSize; IInventory inv = useBaubles ? baublesInv : mainInv; - ItemStack stackInSlot = inv.getStackInSlot(i - (useBaubles ? invSize : 0)); + int slot = i - (useBaubles ? invSize : 0); + ItemStack stackInSlot = inv.getStackInSlot(slot); if(stackInSlot == stack) continue; @@ -53,6 +54,8 @@ public final class ManaItemHandler { if(remove) manaItem.addMana(stackInSlot, -mana); + if(useBaubles) + BotaniaAPI.internalHandler.sendBaubleUpdatePacket(player, slot); return mana; } @@ -84,7 +87,8 @@ public final class ManaItemHandler { for(int i = 0; i < size; i++) { boolean useBaubles = i >= invSize; IInventory inv = useBaubles ? baublesInv : mainInv; - ItemStack stackInSlot = inv.getStackInSlot(i - (useBaubles ? invSize : 0)); + int slot = i - (useBaubles ? invSize : 0); + ItemStack stackInSlot = inv.getStackInSlot(slot); if(stackInSlot == stack) continue; @@ -96,6 +100,8 @@ public final class ManaItemHandler { if(remove) manaItemSlot.addMana(stackInSlot, -manaToGet); + if(useBaubles) + BotaniaAPI.internalHandler.sendBaubleUpdatePacket(player, slot); return true; } @@ -127,7 +133,8 @@ public final class ManaItemHandler { for(int i = 0; i < size; i++) { boolean useBaubles = i >= invSize; IInventory inv = useBaubles ? baublesInv : mainInv; - ItemStack stackInSlot = inv.getStackInSlot(i - (useBaubles ? invSize : 0)); + int slot = i - (useBaubles ? invSize : 0); + ItemStack stackInSlot = inv.getStackInSlot(slot); if(stackInSlot == stack) continue; @@ -146,6 +153,8 @@ public final class ManaItemHandler { if(add) manaItemSlot.addMana(stackInSlot, manaToSend); + if(useBaubles) + BotaniaAPI.internalHandler.sendBaubleUpdatePacket(player, slot); return received; } @@ -177,7 +186,8 @@ public final class ManaItemHandler { for(int i = 0; i < size; i++) { boolean useBaubles = i >= invSize; IInventory inv = useBaubles ? baublesInv : mainInv; - ItemStack stackInSlot = inv.getStackInSlot(i - (useBaubles ? invSize : 0)); + int slot = i - (useBaubles ? invSize : 0); + ItemStack stackInSlot = inv.getStackInSlot(slot); if(stackInSlot == stack) continue; @@ -189,6 +199,8 @@ public final class ManaItemHandler { if(add) manaItemSlot.addMana(stackInSlot, manaToSend); + if(useBaubles) + BotaniaAPI.internalHandler.sendBaubleUpdatePacket(player, slot); return true; } diff --git a/src/api/java/vazkii/botania/api/package-info.java b/src/api/java/vazkii/botania/api/package-info.java index 9424a03..f5ba9c0 100644 --- a/src/api/java/vazkii/botania/api/package-info.java +++ b/src/api/java/vazkii/botania/api/package-info.java @@ -1,4 +1,4 @@ -@API(owner = "Botania", apiVersion = "35", provides = "BotaniaAPI") +@API(owner = "Botania", apiVersion = "76", provides = "BotaniaAPI") package vazkii.botania.api; import cpw.mods.fml.common.API; diff --git a/src/api/java/vazkii/botania/api/recipe/ElvenPortalUpdateEvent.java b/src/api/java/vazkii/botania/api/recipe/ElvenPortalUpdateEvent.java new file mode 100644 index 0000000..40d9713 --- /dev/null +++ b/src/api/java/vazkii/botania/api/recipe/ElvenPortalUpdateEvent.java @@ -0,0 +1,42 @@ +/** + * This class was created by . It's distributed as + * part of the Botania Mod. Get the Source Code in github: + * https://github.com/Vazkii/Botania + * + * Botania is Open Source and distributed under the + * Botania License: http://botaniamod.net/license.php + * + * File Created @ [Apr 17, 2015, 4:58:30 PM (GMT)] + */ +package vazkii.botania.api.recipe; + +import java.util.List; + +import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.AxisAlignedBB; +import cpw.mods.fml.common.eventhandler.Event; + +/** + * An event fired when an Elven Portal TE updates. The portal's + * relevant AABB and other stuff is passed in for convenience. This + * is fired in MinecraftForge.EVENT_BUS. + */ +public class ElvenPortalUpdateEvent extends Event { + + /** + * May be casted to TileAlfPortal if you have botania code access aside from the API. + */ + public final TileEntity portalTile; + public final AxisAlignedBB aabb; + public boolean open; + public final List stacksInside; + + public ElvenPortalUpdateEvent(TileEntity te, AxisAlignedBB aabb, boolean open, List stacks) { + portalTile = te; + this.aabb = aabb; + this.open = open; + stacksInside = stacks; + } + +} diff --git a/src/api/java/vazkii/botania/api/recipe/RecipeManaInfusion.java b/src/api/java/vazkii/botania/api/recipe/RecipeManaInfusion.java index 1f88c82..368c8d4 100644 --- a/src/api/java/vazkii/botania/api/recipe/RecipeManaInfusion.java +++ b/src/api/java/vazkii/botania/api/recipe/RecipeManaInfusion.java @@ -30,7 +30,6 @@ public class RecipeManaInfusion { } public boolean matches(ItemStack stack) { - if(input instanceof ItemStack) { ItemStack inputCopy = ((ItemStack) input).copy(); if(inputCopy.getItemDamage() == Short.MAX_VALUE) diff --git a/src/api/java/vazkii/botania/api/recipe/RecipeMiniFlower.java b/src/api/java/vazkii/botania/api/recipe/RecipeMiniFlower.java new file mode 100644 index 0000000..92908c0 --- /dev/null +++ b/src/api/java/vazkii/botania/api/recipe/RecipeMiniFlower.java @@ -0,0 +1,30 @@ +/** + * This class was created by . It's distributed as + * part of the Botania Mod. Get the Source Code in github: + * https://github.com/Vazkii/Botania + * + * Botania is Open Source and distributed under the + * Botania License: http://botaniamod.net/license.php + * + * File Created @ [Apr 22, 2015, 5:57:59 PM (GMT)] + */ +package vazkii.botania.api.recipe; + +import net.minecraft.item.ItemStack; +import vazkii.botania.api.BotaniaAPI; + +public class RecipeMiniFlower extends RecipeManaInfusion { + + public RecipeMiniFlower(String flower, String mini, int mana) { + super(BotaniaAPI.internalHandler.getSubTileAsStack(flower), BotaniaAPI.internalHandler.getSubTileAsStack(mini), mana); + setAlchemy(true); + } + + @Override + public boolean matches(ItemStack stack) { + String key = BotaniaAPI.internalHandler.getStackSubTileKey(stack); + String input = this.input instanceof String ? (String) this.input : BotaniaAPI.internalHandler.getStackSubTileKey((ItemStack) this.input); + return key != null && key.equals(input); + } + +} diff --git a/src/api/java/vazkii/botania/api/recipe/RecipePureDaisy.java b/src/api/java/vazkii/botania/api/recipe/RecipePureDaisy.java new file mode 100644 index 0000000..19248e6 --- /dev/null +++ b/src/api/java/vazkii/botania/api/recipe/RecipePureDaisy.java @@ -0,0 +1,99 @@ +/** + * This class was created by . It's distributed as + * part of the Botania Mod. Get the Source Code in github: + * https://github.com/Vazkii/Botania + * + * Botania is Open Source and distributed under the + * Botania License: http://botaniamod.net/license.php + * + * File Created @ [Apr 17, 2015, 5:07:25 PM (GMT)] + */ +package vazkii.botania.api.recipe; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import net.minecraft.block.Block; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; +import net.minecraftforge.oredict.OreDictionary; +import vazkii.botania.api.subtile.SubTileEntity; + +public class RecipePureDaisy { + + private static final Map> oreMap = new HashMap(); + + Object input; + Block output; + int outputMeta; + + public RecipePureDaisy(Object input, Block output, int outputMeta) { + this.input = input; + this.output = output; + this.outputMeta = outputMeta; + + if(input != null && !(input instanceof String || input instanceof Block)) + throw new IllegalArgumentException("input must be an oredict String or a Block."); + } + + /** + * This gets called every tick, please be careful with your checks. + */ + public boolean matches(World world, int x, int y, int z, SubTileEntity pureDaisy, Block block, int meta) { + if(input instanceof Block) + return block == input; + + ItemStack stack = new ItemStack(block, 1, meta); + String oredict = (String) input; + return isOreDict(stack, oredict); + } + + public boolean isOreDict(ItemStack stack, String entry) { + if(stack == null || stack.getItem() == null) + return false; + + List ores; + if(oreMap.containsKey(entry)) + ores = oreMap.get(entry); + else { + ores = OreDictionary.getOres(entry); + oreMap.put(entry, ores); + } + + for(ItemStack ostack : ores) { + ItemStack cstack = ostack.copy(); + if(cstack.getItemDamage() == Short.MAX_VALUE) + cstack.setItemDamage(stack.getItemDamage()); + + if(stack.isItemEqual(cstack)) + return true; + } + + return false; + } + + /** + * Returns true if the block was placed (and if the Pure Daisy should do particles and stuffs). + * Should only place the block if !world.isRemote, but should return true if it would've placed + * it otherwise. You may return false to cancel the normal particles and do your own. + */ + public boolean set(World world, int x, int y, int z, SubTileEntity pureDaisy) { + if(!world.isRemote) + world.setBlock(x, y, z, output, outputMeta, 1 | 2); + return true; + } + + public Object getInput() { + return input; + } + + public Block getOutput() { + return output; + } + + public int getOutputMeta() { + return outputMeta; + } + +} diff --git a/src/api/java/vazkii/botania/api/subtile/ISubTileSlowableContainer.java b/src/api/java/vazkii/botania/api/subtile/ISubTileSlowableContainer.java new file mode 100644 index 0000000..6092cd6 --- /dev/null +++ b/src/api/java/vazkii/botania/api/subtile/ISubTileSlowableContainer.java @@ -0,0 +1,26 @@ +/** + * This class was created by . It's distributed as + * part of the Botania Mod. Get the Source Code in github: + * https://github.com/Vazkii/Botania + * + * Botania is Open Source and distributed under the + * Botania License: http://botaniamod.net/license.php + * + * File Created @ [29/12/2015, 23:00:06 (GMT)] + */ +package vazkii.botania.api.subtile; + +/** + * An extension of ISubTileContainer that allows for the SubTile to be "slowed down". + * Slowing down is the action that happens when a flower is planted in Podzol or Mycellium. + * Any flowers that pick up items from the ground should have a delay on the time the item + * needs to be on the floor equal to the value of getSlowDownFactor(). + */ +public interface ISubTileSlowableContainer extends ISubTileContainer { + + public static final int SLOWDOWN_FACTOR_PODZOL = 5; + public static final int SLOWDOWN_FACTOR_MYCEL = 10; + + public int getSlowdownFactor(); + +} diff --git a/src/api/java/vazkii/botania/api/subtile/RadiusDescriptor.java b/src/api/java/vazkii/botania/api/subtile/RadiusDescriptor.java new file mode 100644 index 0000000..f57b6fa --- /dev/null +++ b/src/api/java/vazkii/botania/api/subtile/RadiusDescriptor.java @@ -0,0 +1,89 @@ +/** + * This class was created by . It's distributed as + * part of the Botania Mod. Get the Source Code in github: + * https://github.com/Vazkii/Botania + * + * Botania is Open Source and distributed under the + * Botania License: http://botaniamod.net/license.php + * + * File Created @ [Mar 31, 2015, 2:59:19 PM (GMT)] + */ +package vazkii.botania.api.subtile; + +import net.minecraft.util.AxisAlignedBB; +import net.minecraft.util.ChunkCoordinates; + +/** + * This object describes the Radius of a SubTileEntity. It can either be + * a circle or rectangle, it's to note that the + */ +public class RadiusDescriptor { + + final ChunkCoordinates subtileCoords; + + public RadiusDescriptor(ChunkCoordinates subtileCoords) { + this.subtileCoords = subtileCoords; + } + + public ChunkCoordinates getSubtileCoords() { + return subtileCoords; + } + + public boolean isCircle() { + return false; + } + + public double getCircleRadius() { + return 0; + } + + public AxisAlignedBB getAABB() { + return null; + } + + public static class Circle extends RadiusDescriptor { + + final double radius; + + public Circle(ChunkCoordinates subtileCoords, double radius) { + super(subtileCoords); + this.radius = radius; + } + + @Override + public boolean isCircle() { + return true; + } + + @Override + public double getCircleRadius() { + return radius; + } + + } + + public static class Rectangle extends RadiusDescriptor { + + final AxisAlignedBB aabb; + + public Rectangle(ChunkCoordinates subtileCoords, AxisAlignedBB aabb) { + super(subtileCoords); + this.aabb = aabb; + } + + @Override + public AxisAlignedBB getAABB() { + return aabb; + } + + } + + public static class Square extends Rectangle { + + public Square(ChunkCoordinates subtileCoords, int expand) { + super(subtileCoords, AxisAlignedBB.getBoundingBox(subtileCoords.posX - expand, subtileCoords.posY, subtileCoords.posZ - expand, subtileCoords.posX + 1 + expand, subtileCoords.posY, subtileCoords.posZ + 1 + expand)); + } + + } + +} diff --git a/src/api/java/vazkii/botania/api/subtile/SubTileEntity.java b/src/api/java/vazkii/botania/api/subtile/SubTileEntity.java index 23a4a5c..2b98121 100644 --- a/src/api/java/vazkii/botania/api/subtile/SubTileEntity.java +++ b/src/api/java/vazkii/botania/api/subtile/SubTileEntity.java @@ -23,6 +23,7 @@ import net.minecraft.util.ChunkCoordinates; import net.minecraft.util.IIcon; import net.minecraft.world.World; import vazkii.botania.api.BotaniaAPI; +import vazkii.botania.api.internal.VanillaPacketDispatcher; import vazkii.botania.api.lexicon.LexiconEntry; import vazkii.botania.api.wand.IWandBindable; import cpw.mods.fml.relauncher.Side; @@ -39,6 +40,11 @@ public class SubTileEntity { public int ticksExisted = 0; + /** true if this flower is working on Enchanted Soil **/ + public boolean overgrowth = false; + /** true if this flower is working on Enchanted Soil and this is the second tick **/ + public boolean overgrowthBoost = false; + /** The Tag items should use to store which sub tile they are. **/ public static final String TAG_TYPE = "type"; public static final String TAG_TICKS_EXISTED = "ticksExisted"; @@ -81,7 +87,7 @@ public class SubTileEntity { public void readFromPacketNBT(NBTTagCompound cmp) { } public void sync() { - supertile.getWorldObj().markBlockForUpdate(supertile.xCoord, supertile.yCoord, supertile.zCoord); + VanillaPacketDispatcher.dispatchTEToNearbyPlayers(supertile); } public String getUnlocalizedName() { @@ -153,6 +159,22 @@ public class SubTileEntity { return null; } + /** + * Returns a descriptor for the radius of this sub tile. This is called while a player + * is looking at the block with a Manaseer Monocle (IBurstViewerBauble). + */ + @SideOnly(Side.CLIENT) + public RadiusDescriptor getRadius() { + return null; + } + + /** + * Gets a ChunkCoordinates instance with the position of this sub tile. + */ + public ChunkCoordinates toChunkCoordinates() { + return new ChunkCoordinates(supertile.xCoord, supertile.yCoord, supertile.zCoord); + } + /** * @see IWandBindable#canSelect(EntityPlayer, ItemStack, int, int, int, int) */ @@ -175,4 +197,47 @@ public class SubTileEntity { public void renderHUD(Minecraft mc, ScaledResolution res) { // NO-OP } + + /** + * Gets the light value for this SubTileEntity, this is a int (-1 to default to the flower) + */ + public int getLightValue() { + return -1; + } + + /** + * Gets the comparator input value for this SubTileEntity + */ + public int getComparatorInputOverride(int side) { + return 0; + } + + /** + * Gets the redstone power level for this SubTileEntity + */ + public int getPowerLevel(int side) { + return 0; + } + + /** + * Gets if this SubTileEntity is affected by Enchanted Soil's speed boost. + */ + public boolean isOvergrowthAffected() { + return true; + } + + /** + * Gets ths slowdown factor of this SubTile. + * @see ISubTileSlowableContainer + */ + public int getSlowdownFactor() { + if(supertile instanceof ISubTileSlowableContainer) { + ISubTileSlowableContainer slowable = (ISubTileSlowableContainer) supertile; + return slowable.getSlowdownFactor(); + } + + return 0; + } + + } diff --git a/src/api/java/vazkii/botania/api/subtile/SubTileFunctional.java b/src/api/java/vazkii/botania/api/subtile/SubTileFunctional.java index c1f0698..d6156ea 100644 --- a/src/api/java/vazkii/botania/api/subtile/SubTileFunctional.java +++ b/src/api/java/vazkii/botania/api/subtile/SubTileFunctional.java @@ -30,6 +30,8 @@ import vazkii.botania.api.mana.IManaPool; */ public class SubTileFunctional extends SubTileEntity { + public static final int RANGE = 10; + private static final String TAG_MANA = "mana"; private static final String TAG_POOL_X = "poolX"; @@ -59,7 +61,7 @@ public class SubTileFunctional extends SubTileEntity { linkPool(); - if(linkedPool != null) { + if(linkedPool != null && isValidBinding()) { IManaPool pool = (IManaPool) linkedPool; int manaInPool = pool.getCurrentMana(); int manaMissing = getMaxMana() - mana; @@ -85,41 +87,43 @@ public class SubTileFunctional extends SubTileEntity { } public void linkPool() { - final int range = 10; - boolean needsNew = false; if(linkedPool == null) { needsNew = true; - if(cachedPoolCoordinates != null && supertile.getWorldObj().blockExists(cachedPoolCoordinates.posX, cachedPoolCoordinates.posY, cachedPoolCoordinates.posZ)) { - TileEntity tileAt = supertile.getWorldObj().getTileEntity(cachedPoolCoordinates.posX, cachedPoolCoordinates.posY, cachedPoolCoordinates.posZ); - if(tileAt != null && tileAt instanceof IManaPool) { - linkedPool = tileAt; - needsNew = false; + if(cachedPoolCoordinates != null) { + needsNew = false; + if(supertile.getWorldObj().blockExists(cachedPoolCoordinates.posX, cachedPoolCoordinates.posY, cachedPoolCoordinates.posZ)) { + needsNew = true; + TileEntity tileAt = supertile.getWorldObj().getTileEntity(cachedPoolCoordinates.posX, cachedPoolCoordinates.posY, cachedPoolCoordinates.posZ); + if(tileAt != null && tileAt instanceof IManaPool && !tileAt.isInvalid()) { + linkedPool = tileAt; + needsNew = false; + } + cachedPoolCoordinates = null; } - cachedPoolCoordinates = null; } - } - - if(!needsNew) { + } else { TileEntity tileAt = supertile.getWorldObj().getTileEntity(linkedPool.xCoord, linkedPool.yCoord, linkedPool.zCoord); - if(!(tileAt instanceof IManaPool)) { - linkedPool = null; - needsNew = true; - } else linkedPool = tileAt; + if(tileAt != null && tileAt instanceof IManaPool) + linkedPool = tileAt; } - if(needsNew) { + if(needsNew && ticksExisted == 1) { // Only for new flowers IManaNetwork network = BotaniaAPI.internalHandler.getManaNetworkInstance(); int size = network.getAllPoolsInWorld(supertile.getWorldObj()).size(); if(BotaniaAPI.internalHandler.shouldForceCheck() || size != sizeLastCheck) { ChunkCoordinates coords = new ChunkCoordinates(supertile.xCoord, supertile.yCoord, supertile.zCoord); - linkedPool = network.getClosestPool(coords, supertile.getWorldObj(), range); + linkedPool = network.getClosestPool(coords, supertile.getWorldObj(), RANGE); sizeLastCheck = size; } } } + public void linkToForcefully(TileEntity pool) { + linkedPool = pool; + } + public void addMana(int mana) { this.mana = Math.min(getMaxMana(), this.mana + mana); } @@ -151,20 +155,26 @@ public class SubTileFunctional extends SubTileEntity { int y = cmp.getInteger(TAG_POOL_Y); int z = cmp.getInteger(TAG_POOL_Z); - cachedPoolCoordinates = new ChunkCoordinates(x, y, z); + cachedPoolCoordinates = y < 0 ? null : new ChunkCoordinates(x, y, z); } @Override public void writeToPacketNBT(NBTTagCompound cmp) { cmp.setInteger(TAG_MANA, mana); - int x = linkedPool == null ? 0 : linkedPool.xCoord; - int y = linkedPool == null ? -1 : linkedPool.yCoord; - int z = linkedPool == null ? 0 : linkedPool.zCoord; + if(cachedPoolCoordinates != null) { + cmp.setInteger(TAG_POOL_X, cachedPoolCoordinates.posX); + cmp.setInteger(TAG_POOL_Y, cachedPoolCoordinates.posY); + cmp.setInteger(TAG_POOL_Z, cachedPoolCoordinates.posZ); + } else { + int x = linkedPool == null ? 0 : linkedPool.xCoord; + int y = linkedPool == null ? -1 : linkedPool.yCoord; + int z = linkedPool == null ? 0 : linkedPool.zCoord; - cmp.setInteger(TAG_POOL_X, x); - cmp.setInteger(TAG_POOL_Y, y); - cmp.setInteger(TAG_POOL_Z, z); + cmp.setInteger(TAG_POOL_X, x); + cmp.setInteger(TAG_POOL_Y, y); + cmp.setInteger(TAG_POOL_Z, z); + } } @Override @@ -196,11 +206,15 @@ public class SubTileFunctional extends SubTileEntity { return false; } + public boolean isValidBinding() { + return linkedPool != null && !linkedPool.isInvalid() && supertile.getWorldObj().getTileEntity(linkedPool.xCoord, linkedPool.yCoord, linkedPool.zCoord) == linkedPool; + } + @Override public void renderHUD(Minecraft mc, ScaledResolution res) { String name = StatCollector.translateToLocal("tile.botania:flower." + getUnlocalizedName() + ".name"); int color = getColor(); - BotaniaAPI.internalHandler.drawSimpleManaHUD(color, knownMana, getMaxMana(), name, res); + BotaniaAPI.internalHandler.drawComplexManaHUD(color, knownMana, getMaxMana(), name, res, BotaniaAPI.internalHandler.getBindDisplayForFlowerType(this), isValidBinding()); } } diff --git a/src/api/java/vazkii/botania/api/subtile/SubTileGenerating.java b/src/api/java/vazkii/botania/api/subtile/SubTileGenerating.java index 913c221..02f7a23 100644 --- a/src/api/java/vazkii/botania/api/subtile/SubTileGenerating.java +++ b/src/api/java/vazkii/botania/api/subtile/SubTileGenerating.java @@ -11,16 +11,22 @@ package vazkii.botania.api.subtile; import java.awt.Color; +import java.util.ArrayList; +import java.util.List; import net.minecraft.block.Block; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.ScaledResolution; +import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Blocks; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.ChunkCoordinates; import net.minecraft.util.StatCollector; +import net.minecraft.world.World; +import net.minecraftforge.common.util.ForgeDirection; import vazkii.botania.api.BotaniaAPI; import vazkii.botania.api.internal.IManaNetwork; import vazkii.botania.api.mana.IManaCollector; @@ -30,20 +36,33 @@ import vazkii.botania.api.mana.IManaCollector; */ public class SubTileGenerating extends SubTileEntity { + public static final int RANGE = 6; + private static final String TAG_MANA = "mana"; private static final String TAG_COLLECTOR_X = "collectorX"; private static final String TAG_COLLECTOR_Y = "collectorY"; private static final String TAG_COLLECTOR_Z = "collectorZ"; + private static final String TAG_PASSIVE_DECAY_TICKS = "passiveDecayTicks"; protected int mana; + public int redstoneSignal = 0; + int sizeLastCheck = -1; protected TileEntity linkedCollector = null; public int knownMana = -1; + public int passiveDecayTicks; ChunkCoordinates cachedCollectorCoordinates = null; + /** + * If set to true, redstoneSignal will be updated every tick. + */ + public boolean acceptsRedstone() { + return false; + } + @Override public void onUpdate() { super.onUpdate(); @@ -60,6 +79,14 @@ public class SubTileGenerating extends SubTileEntity { } emptyManaIntoCollector(); + if(acceptsRedstone()) { + redstoneSignal = 0; + for(ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) { + int redstoneSide = supertile.getWorldObj().getIndirectPowerLevelTo(supertile.xCoord + dir.offsetX, supertile.yCoord + dir.offsetY, supertile.zCoord + dir.offsetZ, dir.ordinal()); + redstoneSignal = Math.max(redstoneSignal, redstoneSide); + } + } + if(supertile.getWorldObj().isRemote) { double particleChance = 1F - (double) mana / (double) getMaxMana() / 3.5F; Color color = new Color(getColor()); @@ -67,58 +94,66 @@ public class SubTileGenerating extends SubTileEntity { BotaniaAPI.internalHandler.sparkleFX(supertile.getWorldObj(), supertile.xCoord + 0.3 + Math.random() * 0.5, supertile.yCoord + 0.5 + Math.random() * 0.5, supertile.zCoord + 0.3 + Math.random() * 0.5, color.getRed() / 255F, color.getGreen() / 255F, color.getBlue() / 255F, (float) Math.random(), 5); } + boolean passive = isPassiveFlower(); if(!supertile.getWorldObj().isRemote) { int muhBalance = BotaniaAPI.internalHandler.getPassiveFlowerDecay(); - if(isPassiveFlower() && muhBalance > 0 && ticksExisted > muhBalance) { + if(passive && muhBalance > 0 && passiveDecayTicks > muhBalance) { supertile.getWorldObj().playAuxSFX(2001, supertile.xCoord, supertile.yCoord, supertile.zCoord, Block.getIdFromBlock(supertile.getBlockType())); - supertile.getWorldObj().setBlockToAir(supertile.xCoord, supertile.yCoord, supertile.zCoord); + if(supertile.getWorldObj().getBlock(supertile.xCoord, supertile.yCoord - 1, supertile.zCoord).isSideSolid(supertile.getWorldObj(), supertile.xCoord, supertile.yCoord - 1, supertile.zCoord, ForgeDirection.UP)) + supertile.getWorldObj().setBlock(supertile.xCoord, supertile.yCoord, supertile.zCoord, Blocks.deadbush); + else supertile.getWorldObj().setBlockToAir(supertile.xCoord, supertile.yCoord, supertile.zCoord); } } + + if(!overgrowth && passive) + passiveDecayTicks++; } public void linkCollector() { - final int range = 6; - boolean needsNew = false; if(linkedCollector == null) { needsNew = true; - if(cachedCollectorCoordinates != null && supertile.getWorldObj().blockExists(cachedCollectorCoordinates.posX, cachedCollectorCoordinates.posY, cachedCollectorCoordinates.posZ)) { - TileEntity tileAt = supertile.getWorldObj().getTileEntity(cachedCollectorCoordinates.posX, cachedCollectorCoordinates.posY, cachedCollectorCoordinates.posZ); - if(tileAt != null && tileAt instanceof IManaCollector) { - linkedCollector = tileAt; - needsNew = false; + if(cachedCollectorCoordinates != null) { + needsNew = false; + if(supertile.getWorldObj().blockExists(cachedCollectorCoordinates.posX, cachedCollectorCoordinates.posY, cachedCollectorCoordinates.posZ)) { + needsNew = true; + TileEntity tileAt = supertile.getWorldObj().getTileEntity(cachedCollectorCoordinates.posX, cachedCollectorCoordinates.posY, cachedCollectorCoordinates.posZ); + if(tileAt != null && tileAt instanceof IManaCollector && !tileAt.isInvalid()) { + linkedCollector = tileAt; + needsNew = false; + } + cachedCollectorCoordinates = null; } - cachedCollectorCoordinates = null; } - } - - if(!needsNew) { + } else { TileEntity tileAt = supertile.getWorldObj().getTileEntity(linkedCollector.xCoord, linkedCollector.yCoord, linkedCollector.zCoord); - if(!(tileAt instanceof IManaCollector)) { - linkedCollector = null; - needsNew = true; - } else linkedCollector = tileAt; + if(tileAt != null && tileAt instanceof IManaCollector) + linkedCollector = tileAt; } - if(needsNew) { + if(needsNew && ticksExisted == 1) { // New flowers only IManaNetwork network = BotaniaAPI.internalHandler.getManaNetworkInstance(); int size = network.getAllCollectorsInWorld(supertile.getWorldObj()).size(); if(BotaniaAPI.internalHandler.shouldForceCheck() || size != sizeLastCheck) { ChunkCoordinates coords = new ChunkCoordinates(supertile.xCoord, supertile.yCoord, supertile.zCoord); - linkedCollector = network.getClosestCollector(coords, supertile.getWorldObj(), range); + linkedCollector = network.getClosestCollector(coords, supertile.getWorldObj(), RANGE); sizeLastCheck = size; } } } + public void linkToForcefully(TileEntity collector) { + linkedCollector = collector; + } + public void addMana(int mana) { this.mana = Math.min(getMaxMana(), this.mana + mana); } public void emptyManaIntoCollector() { - if(linkedCollector != null) { + if(linkedCollector != null && isValidBinding()) { IManaCollector collector = (IManaCollector) linkedCollector; if(!collector.isFull() && mana > 0) { int manaval = Math.min(mana, collector.getMaxMana() - collector.getCurrentMana()); @@ -148,6 +183,34 @@ public class SubTileGenerating extends SubTileEntity { return 1; } + @Override + public ArrayList getDrops(ArrayList list) { + ArrayList drops = super.getDrops(list); + populateDropStackNBTs(drops); + return drops; + } + + public void populateDropStackNBTs(List drops) { + if(isPassiveFlower() && ticksExisted > 0 && BotaniaAPI.internalHandler.getPassiveFlowerDecay() > 0) { + ItemStack drop = drops.get(0); + if(drop != null) { + if(!drop.hasTagCompound()) + drop.setTagCompound(new NBTTagCompound()); + NBTTagCompound cmp = drop.getTagCompound(); + cmp.setInteger(TAG_PASSIVE_DECAY_TICKS, passiveDecayTicks); + } + } + } + + @Override + public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entity, ItemStack stack) { + super.onBlockPlacedBy(world, x, y, z, entity, stack); + if(isPassiveFlower()) { + NBTTagCompound cmp = stack.getTagCompound(); + passiveDecayTicks = cmp.getInteger(TAG_PASSIVE_DECAY_TICKS); + } + } + @Override public boolean onWanded(EntityPlayer player, ItemStack wand) { if(player == null) @@ -173,28 +236,34 @@ public class SubTileGenerating extends SubTileEntity { @Override public void readFromPacketNBT(NBTTagCompound cmp) { mana = cmp.getInteger(TAG_MANA); - if(!cmp.hasKey(TAG_TICKS_EXISTED)) - ticksExisted = cmp.getInteger(TAG_TICKS_EXISTED); + passiveDecayTicks = cmp.getInteger(TAG_PASSIVE_DECAY_TICKS); int x = cmp.getInteger(TAG_COLLECTOR_X); int y = cmp.getInteger(TAG_COLLECTOR_Y); int z = cmp.getInteger(TAG_COLLECTOR_Z); - cachedCollectorCoordinates = new ChunkCoordinates(x, y, z); + cachedCollectorCoordinates = y < 0 ? null : new ChunkCoordinates(x, y, z); } @Override public void writeToPacketNBT(NBTTagCompound cmp) { cmp.setInteger(TAG_MANA, mana); cmp.setInteger(TAG_TICKS_EXISTED, ticksExisted); + cmp.setInteger(TAG_PASSIVE_DECAY_TICKS, passiveDecayTicks); - int x = linkedCollector == null ? 0 : linkedCollector.xCoord; - int y = linkedCollector == null ? -1 : linkedCollector.yCoord; - int z = linkedCollector == null ? 0 : linkedCollector.zCoord; + if(cachedCollectorCoordinates != null) { + cmp.setInteger(TAG_COLLECTOR_X, cachedCollectorCoordinates.posX); + cmp.setInteger(TAG_COLLECTOR_Y, cachedCollectorCoordinates.posY); + cmp.setInteger(TAG_COLLECTOR_Z, cachedCollectorCoordinates.posZ); + } else { + int x = linkedCollector == null ? 0 : linkedCollector.xCoord; + int y = linkedCollector == null ? -1 : linkedCollector.yCoord; + int z = linkedCollector == null ? 0 : linkedCollector.zCoord; - cmp.setInteger(TAG_COLLECTOR_X, x); - cmp.setInteger(TAG_COLLECTOR_Y, y); - cmp.setInteger(TAG_COLLECTOR_Z, z); + cmp.setInteger(TAG_COLLECTOR_X, x); + cmp.setInteger(TAG_COLLECTOR_Y, y); + cmp.setInteger(TAG_COLLECTOR_Z, z); + } } @Override @@ -226,11 +295,21 @@ public class SubTileGenerating extends SubTileEntity { return false; } + + public boolean isValidBinding() { + return linkedCollector != null && !linkedCollector.isInvalid() && supertile.getWorldObj().getTileEntity(linkedCollector.xCoord, linkedCollector.yCoord, linkedCollector.zCoord) == linkedCollector; + } + @Override public void renderHUD(Minecraft mc, ScaledResolution res) { String name = StatCollector.translateToLocal("tile.botania:flower." + getUnlocalizedName() + ".name"); int color = getColor(); - BotaniaAPI.internalHandler.drawSimpleManaHUD(color, knownMana, getMaxMana(), name, res); + BotaniaAPI.internalHandler.drawComplexManaHUD(color, knownMana, getMaxMana(), name, res, BotaniaAPI.internalHandler.getBindDisplayForFlowerType(this), isValidBinding()); + } + + @Override + public boolean isOvergrowthAffected() { + return !isPassiveFlower(); } } diff --git a/src/api/java/vazkii/botania/api/subtile/signature/BasicSignature.java b/src/api/java/vazkii/botania/api/subtile/signature/BasicSignature.java index a179387..b3f5e47 100644 --- a/src/api/java/vazkii/botania/api/subtile/signature/BasicSignature.java +++ b/src/api/java/vazkii/botania/api/subtile/signature/BasicSignature.java @@ -10,10 +10,18 @@ */ package vazkii.botania.api.subtile.signature; +import java.util.List; + import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; +import net.minecraft.util.EnumChatFormatting; import net.minecraft.util.IIcon; +import net.minecraft.util.StatCollector; import vazkii.botania.api.BotaniaAPI; +import vazkii.botania.api.subtile.SubTileEntity; +import vazkii.botania.api.subtile.SubTileFunctional; +import vazkii.botania.api.subtile.SubTileGenerating; /** * A basic (and fallback) implementation of SubTileSignature. @@ -50,6 +58,29 @@ public class BasicSignature extends SubTileSignature { return name; } + public String getType() { + Class clazz = BotaniaAPI.getSubTileMapping(name); + + if(clazz == null) + return "uwotm8"; + + if(clazz.getAnnotation(PassiveFlower.class) != null) + return "botania.flowerType.passiveGenerating"; + + if(SubTileGenerating.class.isAssignableFrom(clazz)) + return "botania.flowerType.generating"; + + if(SubTileFunctional.class.isAssignableFrom(clazz)) + return "botania.flowerType.functional"; + + return "botania.flowerType.misc"; + } + + @Override + public void addTooltip(ItemStack stack, EntityPlayer player, List tooltip) { + tooltip.add(EnumChatFormatting.BLUE + StatCollector.translateToLocal(getType())); + } + private String unlocalizedName(String end) { return "tile.botania:" + SubTileSignature.SPECIAL_FLOWER_PREFIX + name + end; } diff --git a/src/api/java/vazkii/botania/api/subtile/signature/PassiveFlower.java b/src/api/java/vazkii/botania/api/subtile/signature/PassiveFlower.java new file mode 100644 index 0000000..008fa83 --- /dev/null +++ b/src/api/java/vazkii/botania/api/subtile/signature/PassiveFlower.java @@ -0,0 +1,28 @@ +/** + * This class was created by . It's distributed as + * part of the Botania Mod. Get the Source Code in github: + * https://github.com/Vazkii/Botania + * + * Botania is Open Source and distributed under the + * Botania License: http://botaniamod.net/license.php + * + * File Created @ [04/12/2015, 16:47:01 (GMT)] + */ +package vazkii.botania.api.subtile.signature; + +import static java.lang.annotation.ElementType.TYPE; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +/** + * This annotation used for detecting whether a SubTileEntity + * is a passive flower without having to instantiate it. This + * is used for the flowers' tooltips. + */ +@Retention(value = RUNTIME) +@Target(value = TYPE) +public @interface PassiveFlower { + +} diff --git a/src/api/java/vazkii/botania/api/subtile/signature/SubTileSignature.java b/src/api/java/vazkii/botania/api/subtile/signature/SubTileSignature.java index c0834da..65fac22 100644 --- a/src/api/java/vazkii/botania/api/subtile/signature/SubTileSignature.java +++ b/src/api/java/vazkii/botania/api/subtile/signature/SubTileSignature.java @@ -10,7 +10,10 @@ */ package vazkii.botania.api.subtile.signature; +import java.util.List; + import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.util.IIcon; @@ -43,4 +46,11 @@ public abstract class SubTileSignature { */ public abstract String getUnlocalizedLoreTextForStack(ItemStack stack); + /** + * Adds additional text to the tooltip. This text is added after getUnlocalizedLoreTextForStack. + */ + public void addTooltip(ItemStack stack, EntityPlayer player, List tooltip) { + // NO-OP + } + } diff --git a/src/api/java/vazkii/botania/api/wiki/SimpleWikiProvider.java b/src/api/java/vazkii/botania/api/wiki/SimpleWikiProvider.java index 9e0fa81..f03e07c 100644 --- a/src/api/java/vazkii/botania/api/wiki/SimpleWikiProvider.java +++ b/src/api/java/vazkii/botania/api/wiki/SimpleWikiProvider.java @@ -20,15 +20,28 @@ import org.apache.commons.lang3.text.WordUtils; public class SimpleWikiProvider implements IWikiProvider { final String name, urlBase, replacement; + final boolean lowercase; public SimpleWikiProvider(String name, String urlBase) { this(name, urlBase, "%20"); } + public SimpleWikiProvider(String name, String urlBase, boolean lowercase) { + this(name, urlBase, "%20", lowercase); + } + public SimpleWikiProvider(String name, String urlBase, String replacement) { this.name = name; this.urlBase = urlBase; this.replacement = replacement; + lowercase = false; + } + + public SimpleWikiProvider(String name, String urlBase, String replacement, boolean lowercase) { + this.name = name; + this.urlBase = urlBase; + this.replacement = replacement; + this.lowercase = lowercase; } @Override @@ -61,7 +74,12 @@ public class SimpleWikiProvider implements IWikiProvider { String name = getBlockName(world, pos); if(name == null) return null; - return String.format(urlBase, WordUtils.capitalizeFully(name).replaceAll(" ", replacement)); + + if(lowercase) { + return String.format(urlBase, name.toLowerCase().replaceAll(" ", replacement)); + } else { + return String.format(urlBase, WordUtils.capitalizeFully(name).replaceAll(" ", replacement)); + } } @Override diff --git a/src/api/java/vazkii/botania/api/wiki/WikiHooks.java b/src/api/java/vazkii/botania/api/wiki/WikiHooks.java index 9ab7c49..ae42fd8 100644 --- a/src/api/java/vazkii/botania/api/wiki/WikiHooks.java +++ b/src/api/java/vazkii/botania/api/wiki/WikiHooks.java @@ -19,7 +19,7 @@ import cpw.mods.fml.common.registry.GameRegistry.UniqueIdentifier; public class WikiHooks { - private static final IWikiProvider FALLBACK_PROVIDER = new SimpleWikiProvider("FTB Wiki", "http://wiki.feed-the-beast.com/%s"); + private static final IWikiProvider FALLBACK_PROVIDER = new SimpleWikiProvider("FTB Wiki", "http://ftb.gamepedia.com/%s"); private static final Map modWikis = new HashMap(); diff --git a/src/main/java/fox/spiteful/forbidden/Config.java b/src/main/java/fox/spiteful/forbidden/Config.java index b0a556a..e48c42f 100644 --- a/src/main/java/fox/spiteful/forbidden/Config.java +++ b/src/main/java/fox/spiteful/forbidden/Config.java @@ -60,7 +60,6 @@ public class Config { public static boolean special = true; public static boolean twilight = true; public static boolean emc = true; - public static boolean dargon = true; //public static boolean eewand = true; public static int bloodvis = 5; @@ -127,7 +126,6 @@ public class Config { tc = conf.get("compatibility", "Tinkers Construct Interaction", tc).getBoolean(true); special = conf.get("compatibility", "Special Mobs Interaction", special).getBoolean(true); twilight = conf.get("compatibility", "Twilight Forest Interaction", twilight).getBoolean(true); - dargon = conf.get("compatibility", "Draconic Evolution Interaction", dargon).getBoolean(true); emc = conf.get("compatibility", "Equivalent Exchange 3 EMC", emc, "Disable if you don't want Forbidden Magic to add EMC values to items.").getBoolean(true); //eewand = conf.get("compatibility", "Equivalent Exchange 3 Wand", eewand, "Disable to specifically disable the EMC to Vis wand.").getBoolean(true); diff --git a/src/main/java/fox/spiteful/forbidden/FMEventHandler.java b/src/main/java/fox/spiteful/forbidden/FMEventHandler.java index f52056d..9150ad2 100644 --- a/src/main/java/fox/spiteful/forbidden/FMEventHandler.java +++ b/src/main/java/fox/spiteful/forbidden/FMEventHandler.java @@ -267,7 +267,7 @@ public class FMEventHandler { learning -= xp; event.entityLiving.worldObj.spawnEntityInWorld(new EntityXPOrb(event.entityLiving.worldObj, event.entityLiving.posX, event.entityLiving.posY, event.entityLiving.posZ, xp)); } - } catch (Exception e) { + } catch (Throwable e) { LogHandler.log(Level.ERROR, "Failed to educate!"); } } diff --git a/src/main/java/fox/spiteful/forbidden/Forbidden.java b/src/main/java/fox/spiteful/forbidden/Forbidden.java index d80f9d7..352aa9e 100644 --- a/src/main/java/fox/spiteful/forbidden/Forbidden.java +++ b/src/main/java/fox/spiteful/forbidden/Forbidden.java @@ -58,7 +58,7 @@ public class Forbidden { ForbiddenItems.addItems(); ForbiddenBlocks.addBlocks(); DarkEnchantments.hex(); - if(Compat.bm || Compat.dargon) + if(Compat.bm) DarkPotions.alchemize(); proxy.registerRenderInfo(); } diff --git a/src/main/java/fox/spiteful/forbidden/XPReflectionHelper.java b/src/main/java/fox/spiteful/forbidden/XPReflectionHelper.java index 9320158..cbf0a4d 100644 --- a/src/main/java/fox/spiteful/forbidden/XPReflectionHelper.java +++ b/src/main/java/fox/spiteful/forbidden/XPReflectionHelper.java @@ -2,35 +2,27 @@ package fox.spiteful.forbidden; import java.lang.reflect.Field; +import cpw.mods.fml.relauncher.ReflectionHelper; import net.minecraft.entity.EntityLiving; +import org.apache.logging.log4j.Level; public class XPReflectionHelper { - private static Field getField(Class clazz, String field) throws NoSuchFieldException { + public static Field stupidMojangProtectedVariable; + + static { try { - return clazz.getDeclaredField(field); - } catch (NoSuchFieldException e) { - Class superClass = clazz.getSuperclass(); - if (superClass == null) { - throw e; - } else { - return getField(superClass, field); - } + stupidMojangProtectedVariable = ReflectionHelper.findField(EntityLiving.class, "experienceValue", "field_70728_aV"); + stupidMojangProtectedVariable.setAccessible(true); + } + catch(Exception e){ + LogHandler.log(Level.ERROR, e.toString()); + e.printStackTrace(); } } public static int getXP(EntityLiving entityLiving) { try { - Field f = getField(entityLiving.getClass(), "experienceValue"); - f.setAccessible(true); - return (Integer) f.get(entityLiving); - } catch (NoSuchFieldException e) { - try { - Field f = getField(entityLiving.getClass(), "field_70728_aV"); - f.setAccessible(true); - return (Integer) f.get(entityLiving); - } catch (Exception e2) { - return 0; - } + return stupidMojangProtectedVariable.getInt(entityLiving); } catch (Exception e) { e.printStackTrace(); } diff --git a/src/main/java/fox/spiteful/forbidden/compat/Compat.java b/src/main/java/fox/spiteful/forbidden/compat/Compat.java index d0fd763..bc88a3d 100644 --- a/src/main/java/fox/spiteful/forbidden/compat/Compat.java +++ b/src/main/java/fox/spiteful/forbidden/compat/Compat.java @@ -3,9 +3,7 @@ package fox.spiteful.forbidden.compat; import com.pahimar.ee3.api.exchange.EnergyValueRegistryProxy; import fox.spiteful.forbidden.*; import fox.spiteful.forbidden.blocks.ForbiddenBlocks; -import fox.spiteful.forbidden.items.tools.ItemDragonslayer; import net.minecraft.block.Block; -import net.minecraft.init.Items; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraftforge.oredict.OreDictionary; @@ -34,7 +32,6 @@ public class Compat { public static boolean special = false; public static boolean twilight = false; public static boolean ee3 = false; - public static boolean dargon = false; public static void initiate() { if(!Config.crossMod) @@ -48,7 +45,6 @@ public class Compat { special = Config.wrathCage && Config.special && Loader.isModLoaded("SpecialMobs"); twilight = Config.wrathCage && Config.twilight && Loader.isModLoaded("TwilightForest"); ee3 = (Config.emc /* || Config.eewand*/) && Loader.isModLoaded("EE3"); - dargon = Config.dargon && Loader.isModLoaded("DraconicEvolution"); } public static void compatify() { @@ -384,29 +380,6 @@ public class Compat { Config.spawnerMobs.put("TwilightForest.WinterWolf", Aspect.COLD); } - if(dargon){ - try { - - Item ingot = Items.iron_ingot; - Item sword = Items.iron_sword; - if(twilight){ - try { - ingot = getItem("TwilightForest", "item.knightMetal"); - sword = getItem("TwilightForest", "item.knightlySword"); - }catch (Exception e){ - LogHandler.log(Level.INFO, e, "Forbidden Magic couldn't figure out Twilight Forest's progression."); - twilight = false; - } - } - ((ItemDragonslayer)ForbiddenItems.dragonslayer).repair = ingot; - InfusionRecipe dragonslayer_recipe = ThaumcraftApi.addInfusionCraftingRecipe("DRAGONSLAYER", new ItemStack(ForbiddenItems.dragonslayer, 1), 6, (new AspectList()).add(Aspect.LIGHT, 16).add(Aspect.ORDER, 8).add(Aspect.MAN, 16).add(Aspect.METAL, 32), new ItemStack(sword), new ItemStack[]{new ItemStack(Items.nether_star, 1), new ItemStack(Items.golden_helmet, 1, 0), new ItemStack(Items.writable_book, 1), new ItemStack(Items.ender_pearl, 1, 2)}); - (new DarkResearchItem("DRAGONSLAYER", "FORBIDDEN", "[DE]", (new AspectList()).add(Aspect.WEAPON, 16).add(Aspect.ARMOR, 8).add(Aspect.MIND, 4), 2, -6, 3, new ItemStack(ForbiddenItems.dragonslayer, 1))).setPages(new ResearchPage[]{new ResearchPage("forbidden.research_page.DRAGONSLAYER.1"), new ResearchPage(dragonslayer_recipe)}).setParents("INFUSION").setConcealed().registerResearchItem(); - - } catch (Exception e) { - LogHandler.log(Level.INFO, e, "Forbidden Magic wasn't unbalanced enough for Draconic Evolution."); - dargon = false; - } - } } public static Item getItem(String mod, String item) throws ItemNotFoundException { diff --git a/src/main/java/fox/spiteful/forbidden/compat/DarkSignature.java b/src/main/java/fox/spiteful/forbidden/compat/DarkSignature.java index 38fcc1b..2598b48 100644 --- a/src/main/java/fox/spiteful/forbidden/compat/DarkSignature.java +++ b/src/main/java/fox/spiteful/forbidden/compat/DarkSignature.java @@ -1,21 +1,30 @@ package fox.spiteful.forbidden.compat; import net.minecraft.client.renderer.texture.IIconRegister; + import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; + import net.minecraft.util.EnumChatFormatting; import net.minecraft.util.IIcon; + import net.minecraft.util.StatCollector; + import vazkii.botania.api.BotaniaAPI; + import vazkii.botania.api.subtile.SubTileEntity; + import vazkii.botania.api.subtile.SubTileFunctional; + import vazkii.botania.api.subtile.SubTileGenerating; + import vazkii.botania.api.subtile.signature.BasicSignature; import vazkii.botania.api.subtile.signature.SubTileSignature; -public class DarkSignature extends SubTileSignature { - String name; + import java.util.List; + +public class DarkSignature extends BasicSignature { IIcon icon; - public DarkSignature(String nombre){ - name = nombre; + public DarkSignature(String name){ + super(name); } @Override public void registerIcons(IIconRegister reg){ - icon = reg.registerIcon("forbidden:" + name); + icon = reg.registerIcon("forbidden:" + getName()); } @Override @@ -25,11 +34,12 @@ public class DarkSignature extends SubTileSignature { @Override public String getUnlocalizedNameForStack(ItemStack item){ - return "darkflower." + name; + return "darkflower." + getName(); } @Override public String getUnlocalizedLoreTextForStack(ItemStack item){ - return "tile.darkflower." + name + ".lore"; + return "tile.darkflower." + getName() + ".lore"; } + } \ No newline at end of file diff --git a/src/main/java/fox/spiteful/forbidden/items/ForbiddenItems.java b/src/main/java/fox/spiteful/forbidden/items/ForbiddenItems.java index 192f123..9d6a119 100644 --- a/src/main/java/fox/spiteful/forbidden/items/ForbiddenItems.java +++ b/src/main/java/fox/spiteful/forbidden/items/ForbiddenItems.java @@ -171,16 +171,6 @@ public class ForbiddenItems { } } - if(Compat.dargon){ - try { - dragonslayer = new ItemDragonslayer().setUnlocalizedName("Sword_Dragonslayer"); - GameRegistry.registerItem(dragonslayer, "Dragonslayer"); - } - catch (Throwable e){ - Compat.dargon = false; - } - } - crystalwell = new ItemCrystalwell().setUnlocalizedName("Crystalwell"); GameRegistry.registerItem(crystalwell, "Crystalwell"); diff --git a/src/main/java/fox/spiteful/forbidden/items/baubles/ItemRingNutrition.java b/src/main/java/fox/spiteful/forbidden/items/baubles/ItemRingNutrition.java index 09025be..b6f736c 100644 --- a/src/main/java/fox/spiteful/forbidden/items/baubles/ItemRingNutrition.java +++ b/src/main/java/fox/spiteful/forbidden/items/baubles/ItemRingNutrition.java @@ -78,10 +78,11 @@ public class ItemRingNutrition extends Item implements IRunicArmor, IBauble, ICo @Override public void setCosmeticItem(ItemStack stack, ItemStack cosmetic) { - if(cosmetic == null || stack == null) + if(stack == null) return; NBTTagCompound cmp = new NBTTagCompound(); - cosmetic.writeToNBT(cmp); + if(cosmetic != null) + cosmetic.writeToNBT(cmp); NBTTagCompound tag = stack.getTagCompound(); if(tag == null){ tag = new NBTTagCompound(); diff --git a/src/main/java/fox/spiteful/forbidden/items/baubles/ItemSubCollar.java b/src/main/java/fox/spiteful/forbidden/items/baubles/ItemSubCollar.java index 379f271..38296a3 100644 --- a/src/main/java/fox/spiteful/forbidden/items/baubles/ItemSubCollar.java +++ b/src/main/java/fox/spiteful/forbidden/items/baubles/ItemSubCollar.java @@ -145,10 +145,11 @@ public class ItemSubCollar extends ItemAmuletVis implements ICosmeticAttachable @Override public void setCosmeticItem(ItemStack stack, ItemStack cosmetic) { - if(cosmetic == null || stack == null) + if(stack == null) return; NBTTagCompound cmp = new NBTTagCompound(); - cosmetic.writeToNBT(cmp); + if(cosmetic != null) + cosmetic.writeToNBT(cmp); NBTTagCompound tag = stack.getTagCompound(); if(tag == null){ tag = new NBTTagCompound(); diff --git a/src/main/java/fox/spiteful/forbidden/items/tools/ItemDragonslayer.java b/src/main/java/fox/spiteful/forbidden/items/tools/ItemDragonslayer.java deleted file mode 100644 index a6e9eb5..0000000 --- a/src/main/java/fox/spiteful/forbidden/items/tools/ItemDragonslayer.java +++ /dev/null @@ -1,152 +0,0 @@ -package fox.spiteful.forbidden.items.tools; - -import cofh.api.energy.IEnergyContainerItem; -import cpw.mods.fml.common.eventhandler.EventPriority; -import cpw.mods.fml.common.eventhandler.SubscribeEvent; -import cpw.mods.fml.common.registry.GameRegistry; -import cpw.mods.fml.common.registry.GameRegistry.UniqueIdentifier; -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; -import fox.spiteful.forbidden.Config; -import fox.spiteful.forbidden.Forbidden; -import fox.spiteful.forbidden.LogHandler; -import fox.spiteful.forbidden.compat.Compat; -import fox.spiteful.forbidden.potions.DarkPotions; -import net.minecraft.client.renderer.texture.IIconRegister; -import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityLivingBase; -import net.minecraft.entity.boss.EntityDragon; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.EnumRarity; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.item.ItemSword; -import net.minecraft.potion.PotionEffect; -import net.minecraft.util.DamageSource; -import net.minecraft.util.EntityDamageSource; -import net.minecraft.util.IIcon; -import net.minecraftforge.common.MinecraftForge; -import net.minecraftforge.event.entity.living.LivingAttackEvent; -import net.minecraftforge.event.entity.living.LivingHurtEvent; -import org.apache.logging.log4j.Level; -import thaumcraft.api.IRepairable; - -public class ItemDragonslayer extends ItemSword implements IRepairable { - public IIcon icon; - public Item repair; - - public ItemDragonslayer() { - super(ToolMaterial.EMERALD); - this.setCreativeTab(Forbidden.tab); - MinecraftForge.EVENT_BUS.register(this); - } - - @SideOnly(Side.CLIENT) - @Override - public void registerIcons(IIconRegister ir) { - this.icon = ir.registerIcon("forbidden:dragonslayer"); - } - - @SideOnly(Side.CLIENT) - @Override - public IIcon getIconFromDamage(int par1) { - return this.icon; - } - - @Override - public EnumRarity getRarity(ItemStack itemstack) { - return EnumRarity.epic; - } - - @Override - public boolean getIsRepairable(ItemStack stack, ItemStack stack2) { - return stack2.getItem() == repair || super.getIsRepairable(stack, stack2); - } - - @Override - public boolean hitEntity(ItemStack stack, EntityLivingBase victim, EntityLivingBase player) { - stack.damageItem(1, player); - if (!victim.worldObj.isRemote && Compat.dargon & isDragon(victim)) { - absoluteDamage(victim, new EntityDamageSource("dragonslayer", player).setDamageBypassesArmor(), Math.max(4F, victim.getMaxHealth() / 5F)); - if(victim instanceof EntityPlayer) { - EntityPlayer target = (EntityPlayer)victim; - for(int x = 0;x < 5;x++){ - if(target.getEquipmentInSlot(x) != null){ - ItemStack equip = target.getEquipmentInSlot(x); - if(equip.getItem() instanceof IEnergyContainerItem){ - IEnergyContainerItem battery = (IEnergyContainerItem)equip.getItem(); - battery.extractEnergy(equip, battery.getMaxEnergyStored(equip) / 20, false); - } - } - } - } - victim.addPotionEffect(new PotionEffect(DarkPotions.dragonwrack.getId(), 300)); - } - return true; - } - - public static boolean isDragon(Entity target){ - if(target == null) - return false; - if(target instanceof EntityPlayer){ - EntityPlayer player = (EntityPlayer)target; - for(int x = 1;x < 5;x++){ - if(player.getEquipmentInSlot(x) != null){ - UniqueIdentifier id = GameRegistry.findUniqueIdentifierFor(player.getEquipmentInSlot(x).getItem()); - if(id != null && id.modId.equals("DraconicEvolution")) - return true; - } - } - } - else if(target instanceof EntityDragon || - target.getCommandSenderName().toLowerCase().contains("dragon") || - target.getCommandSenderName().toLowerCase().contains("drake") || - target.getCommandSenderName().toLowerCase().contains("dracon")) - return true; - return false; - } - - public static void absoluteDamage(EntityLivingBase target, DamageSource src, float damage){ - target.func_110142_aN().func_94547_a(src, target.getHealth(), damage); - target.setHealth(target.getHealth() - damage); - if(target.getHealth() < 1){ - target.onDeath(src); - } - } - - @SubscribeEvent(priority = EventPriority.LOWEST) - public void onGetHurt(LivingHurtEvent event) { - if(event.entityLiving instanceof EntityPlayer && event.source.getEntity() != null){ - EntityPlayer player = (EntityPlayer)event.entityLiving; - ItemStack equip = player.getCurrentEquippedItem(); - if(equip != null && equip.getItem() == this && isDragon(event.source.getEntity())){ - event.ammount = Math.min(event.ammount, 3F); - } - } - } - - @SubscribeEvent - public void onAttacked(LivingAttackEvent event) { - if(event.entityLiving instanceof EntityPlayer && event.source.getEntity() != null){ - EntityPlayer player = (EntityPlayer)event.entityLiving; - ItemStack equip = player.getCurrentEquippedItem(); - if(equip != null && player.isUsingItem() && equip.getItem() == this && isDragon(event.source.getEntity())){ - event.setCanceled(true); - if(event.source.getEntity() instanceof EntityPlayer) { - EntityPlayer other = (EntityPlayer)event.source.getEntity(); - other.addPotionEffect(new PotionEffect(DarkPotions.dragonwrack.getId(), 300)); - for(int x = 0;x < 5;x++){ - if(other.getEquipmentInSlot(x) != null){ - ItemStack gear = other.getEquipmentInSlot(x); - if(gear.getItem() instanceof IEnergyContainerItem){ - IEnergyContainerItem battery = (IEnergyContainerItem)gear.getItem(); - battery.extractEnergy(gear, battery.getMaxEnergyStored(gear) / 50, false); - } - } - } - } - } - } - } - -} diff --git a/src/main/java/fox/spiteful/forbidden/potions/DarkPotions.java b/src/main/java/fox/spiteful/forbidden/potions/DarkPotions.java index 92ad151..0d032bd 100644 --- a/src/main/java/fox/spiteful/forbidden/potions/DarkPotions.java +++ b/src/main/java/fox/spiteful/forbidden/potions/DarkPotions.java @@ -37,13 +37,5 @@ public class DarkPotions { if(Compat.bm) bloodSeal = new PotionBloodSeal(Config.bloodSealPotionID); - if(Compat.dargon) { - try { - dragonwrack = new PotionDragonwrack(Config.dragonwrackPotionID); - } - catch (Exception e){ - Compat.dargon = false; - } - } } } diff --git a/src/main/java/fox/spiteful/forbidden/potions/PotionDragonwrack.java b/src/main/java/fox/spiteful/forbidden/potions/PotionDragonwrack.java deleted file mode 100644 index e2423a9..0000000 --- a/src/main/java/fox/spiteful/forbidden/potions/PotionDragonwrack.java +++ /dev/null @@ -1,60 +0,0 @@ -package fox.spiteful.forbidden.potions; - -import cofh.api.energy.IEnergyContainerItem; -import cpw.mods.fml.common.registry.GameRegistry; -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; -import fox.spiteful.forbidden.items.tools.ItemDragonslayer; -import net.minecraft.client.Minecraft; -import net.minecraft.entity.EntityLivingBase; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.ItemStack; -import net.minecraft.potion.Potion; -import net.minecraft.util.DamageSource; - -public class PotionDragonwrack extends Potion { - - DamageSource wrack; - - public PotionDragonwrack(int id){ - super(id, false, 0xFFFFAA); - this.setPotionName("potion.dragonwrack"); - this.setIconIndex(4, 1); - wrack = new DamageSource("dragonwrack").setDamageBypassesArmor(); - } - - @Override - @SideOnly(Side.CLIENT) - public int getStatusIconIndex() { - Minecraft.getMinecraft().renderEngine.bindTexture(DarkPotions.icons); - return super.getStatusIconIndex(); - } - - @Override - public void performEffect(EntityLivingBase victim, int level) - { - if(!ItemDragonslayer.isDragon(victim) || victim.worldObj.isRemote) - return; - ItemDragonslayer.absoluteDamage(victim, wrack, Math.max(1F, victim.getMaxHealth() / 20F)); - if(victim instanceof EntityPlayer){ - EntityPlayer player = (EntityPlayer)victim; - for(int x = 0;x < 5;x++){ - if(player.getEquipmentInSlot(x) != null){ - ItemStack equip = player.getEquipmentInSlot(x); - if(equip.getItem() instanceof IEnergyContainerItem){ - IEnergyContainerItem battery = (IEnergyContainerItem)equip.getItem(); - battery.extractEnergy(equip, battery.getMaxEnergyStored(equip) / 50, false); - } - } - } - } - } - - public boolean isReady(int tick, int level) - { - int k; - - k = 40 >> level; - return k <= 0 || tick % k == 0; - } -} diff --git a/src/main/resources/assets/forbidden/lang/en_US.lang b/src/main/resources/assets/forbidden/lang/en_US.lang index f736dfd..521d39e 100644 --- a/src/main/resources/assets/forbidden/lang/en_US.lang +++ b/src/main/resources/assets/forbidden/lang/en_US.lang @@ -376,10 +376,6 @@ forbidden.research_name.SUBCOLLAR=Collar of Pain forbidden.research_text.SUBCOLLAR=Pain and Magic forbidden.research_page.SUBCOLLAR.1=Sometimes, people just want to get hurt. Especially if there's a benefit...

The Collar of Pain has all the capabilities of an Amulet of Vis Storage with the added bonus that it will generate vis whenever you take damage. The more you get hurt, the more vis it generates. # -forbidden.research_name.DRAGONSLAYER=Sword of the Dragonslayer -forbidden.research_text.DRAGONSLAYER=JOOR-ZAH-FRUL -forbidden.research_page.DRAGONSLAYER.1=Myths and legends abound of valiant heroes battling against great and terrifying beasts. Dragons are some of the most terrifying creatures, and the slaying of one is spoken of in legends for generations afterwards.

By infusing a sword with such mythical importance, you create a blade capable of felling such terrifying opponents. The Sword of the Dragonslayer exists to slay dragons, dealing them mortal wounds and deflecting their attacks with ease.

Not all dragons are born as dragons. Any human using the power of dragons will find themselves reminded of their mortality. -# # Lexicon forbidden.lexicon.euclidaisy=Euclidaisy forbidden.lexicon.euclidaisy.0=The eerie, pink &1Euclidaisy&0 is an oddity. It uses large amounts of mana to conjure some sort of ethereal substance that only seems useful to thaumaturges.
&oIt doesn't combustion bend.&r