Step 1: File Standardization

This commit is contained in:
Cayde Dixon committed 2014-11-07 02:12:37 +11:00
1 parent 69c287f828
commit 3f6fa103dc
1177 files changed
+2 -2

No files matched your search

@@ -0,0 +1,431 @@
/**
* This class was created by <Vazkii>. 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 a
* Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License
* (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB)
*
* File Created @ [Jan 14, 2014, 6:15:28 PM (GMT)]
*/
package vazkii.botania.api;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import net.minecraft.block.Block;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.Item.ToolMaterial;
import net.minecraft.item.ItemArmor.ArmorMaterial;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.CraftingManager;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.util.EnumChatFormatting;
import net.minecraftforge.common.util.EnumHelper;
import vazkii.botania.api.brew.Brew;
import vazkii.botania.api.internal.DummyMethodHandler;
import vazkii.botania.api.internal.DummySubTile;
import vazkii.botania.api.internal.IInternalMethodHandler;
import vazkii.botania.api.lexicon.KnowledgeType;
import vazkii.botania.api.lexicon.LexiconCategory;
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.RecipePetals;
import vazkii.botania.api.recipe.RecipeRuneAltar;
import vazkii.botania.api.subtile.SubTileEntity;
import vazkii.botania.api.subtile.signature.BasicSignature;
import vazkii.botania.api.subtile.signature.SubTileSignature;
import vazkii.botania.api.wiki.IWikiProvider;
import vazkii.botania.api.wiki.SimpleWikiProvider;
import vazkii.botania.api.wiki.WikiHooks;
import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
public final class BotaniaAPI {
private static List<LexiconCategory> categories = new ArrayList<LexiconCategory>();
private static List<LexiconEntry> allEntries = new ArrayList<LexiconEntry>();
public static Map<String, KnowledgeType> knowledgeTypes = new HashMap<String, KnowledgeType>();
public static Map<String, Brew> brewMap = new LinkedHashMap<String, Brew>();
public static List<RecipePetals> petalRecipes = new ArrayList<RecipePetals>();
public static List<RecipeRuneAltar> runeAltarRecipes = new ArrayList<RecipeRuneAltar>();
public static List<RecipeManaInfusion> manaInfusionRecipes = new ArrayList<RecipeManaInfusion>();
public static List<RecipeElvenTrade> elvenTradeRecipes = new ArrayList<RecipeElvenTrade>();
public static List<RecipeBrew> brewRecipes = new ArrayList<RecipeBrew>();
private static BiMap<String, Class<? extends SubTileEntity>> subTiles = HashBiMap.<String, Class<? extends SubTileEntity>> create();
private static Map<Class<? extends SubTileEntity>, SubTileSignature> subTileSignatures = new HashMap<Class<? extends SubTileEntity>, SubTileSignature>();
public static Set<String> subtilesForCreativeMenu = new LinkedHashSet();
public static Map<String, Integer> oreWeights = new HashMap<String, Integer>();
public static Map<Item, Block> seeds = new HashMap();
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);
public static ArmorMaterial elementiumArmorMaterial = EnumHelper.addArmorMaterial("B_ELEMENTIUM", 18, new int[] { 2, 6, 5, 2 }, 18);
public static ToolMaterial elementiumToolMaterial = EnumHelper.addToolMaterial("B_ELEMENTIUM", 3, 720, 6.2F, 2F, 20);
public static ArmorMaterial terrasteelArmorMaterial = EnumHelper.addArmorMaterial("TERRASTEEL", 34, new int[] {3, 8, 6, 3}, 26);
public static ToolMaterial terrasteelToolMaterial = EnumHelper.addToolMaterial("TERRASTEEL", 3, 2300, 9F, 3F, 26);
public static KnowledgeType basicKnowledge, elvenKnowledge;
public static Brew fallbackBrew = new Brew("fallback", "botania.brew.fallback", 0, 0);
static {
registerSubTile("", DummySubTile.class);
basicKnowledge = registerKnowledgeType("minecraft", EnumChatFormatting.RESET, true);
elvenKnowledge = registerKnowledgeType("alfheim", EnumChatFormatting.DARK_GREEN, 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("oreDarkIron", 1700); // Factorization
addOreWeight("oreDiamond", 1265); // Vanilla
addOreWeight("oreEmerald", 780); // Vanilla
addOreWeight("oreEmery", 415); // GregTech
addOreWeight("oreGalena", 1000); // Factorization
addOreWeight("oreGold", 2970); // Vanilla
addOreWeight("oreInfusedAir", 925); // Thaumcraft
addOreWeight("oreInfusedEarth", 925); // Thaumcraft
addOreWeight("oreInfusedEntropy", 925); // Thaumcraft
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("oreNickel", 2275); // Thermal Expansion
addOreWeight("oreOlivine", 1100); // Project RED
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
addSeed(Items.wheat_seeds, Blocks.wheat);
addSeed(Items.potato, Blocks.potatoes);
addSeed(Items.carrot, Blocks.carrots);
addSeed(Items.nether_wart, Blocks.nether_wart);
addSeed(Items.pumpkin_seeds, Blocks.pumpkin_stem);
addSeed(Items.melon_seeds, Blocks.melon_stem);
registerModWiki("Minecraft", new SimpleWikiProvider("Minecraft Wiki", "http://minecraft.gamepedia.com/%s"));
IWikiProvider technicWiki = new SimpleWikiProvider("Technic Wiki", "http://wiki.technicpack.net/%s");
IWikiProvider mekanismWiki = new SimpleWikiProvider("Mekanism Wiki", "http://wiki.aidancbrady.com/wiki/%s");
IWikiProvider buildcraftWiki = new SimpleWikiProvider("BuildCraft Wiki", "http://www.mod-buildcraft.com/wiki/doku.php?id=%s");
registerModWiki("Mekanism", mekanismWiki);
registerModWiki("MekanismGenerators", mekanismWiki);
registerModWiki("MekanismTools", mekanismWiki);
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("AppliedEnergistics2", new SimpleWikiProvider("AE2 Wiki", "http://ae-mod.info/%s"));
registerModWiki("BigReactors", technicWiki);
registerModWiki("BuildCraft|Core", buildcraftWiki);
registerModWiki("BuildCraft|Builders", buildcraftWiki);
registerModWiki("BuildCraft|Energy", buildcraftWiki);
registerModWiki("BuildCraft|Factory", buildcraftWiki);
registerModWiki("BuildCraft|Silicon", buildcraftWiki);
registerModWiki("BuildCraft|Transport", buildcraftWiki);
registerModWiki("ArsMagica2", new SimpleWikiProvider("ArsMagica2 Wiki", "http://wiki.arsmagicamod.com/wiki/%s"));
registerModWiki("PneumaticCraft", new SimpleWikiProvider("PneumaticCraft Wiki", "http://www.minemaarten.com/wikis/pneumaticcraft-wiki/pneumaticcraft-wiki-%s"));
registerModWiki("StevesCarts2", new SimpleWikiProvider("Steve's Carts Wiki", "http://stevescarts2.wikispaces.com/%s"));
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"));
}
/**
* The internal method handler in use. Do not overwrite.
* @see IInternalMethodHandler
*/
public static IInternalMethodHandler internalHandler = new DummyMethodHandler();
/**
* Registers a new Knowledge Type.
* @param id The ID for this knowledge type.
* @param color The color to display this knowledge type as.
*/
public static KnowledgeType registerKnowledgeType(String id, EnumChatFormatting color, boolean autoUnlock) {
KnowledgeType type = new KnowledgeType(id, color, autoUnlock);
knowledgeTypes.put(id, type);
return type;
}
/**
* Registers a Brew and returns it.
*/
public static Brew registerBrew(Brew brew) {
brewMap.put(brew.getKey(), brew);
return brew;
}
/**
* Gets a brew from the key passed in, returns the fallback if
* it's not in the map.
*/
public static Brew getBrewFromKey(String key) {
if(brewMap.containsKey(key))
return brewMap.get(key);
return fallbackBrew;
}
/**
* Registers a Petal Recipe.
* @param output The ItemStack to craft.
* @param inputs The objects for crafting. Can be ItemStack, MappableStackWrapper
* or String (case for Ore Dictionary). The array can't be larger than 16.
* @return The recipe created.
*/
public static RecipePetals registerPetalRecipe(ItemStack output, Object... inputs) {
RecipePetals recipe = new RecipePetals(output, inputs);
petalRecipes.add(recipe);
return recipe;
}
/**
* Registers a Rune Altar
* @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
* or String (case for Ore Dictionary). The array can't be larger than 16.
* @return The recipe created.
*/
public static RecipeRuneAltar registerRuneAltarRecipe(ItemStack output, int mana, Object... inputs) {
RecipeRuneAltar recipe = new RecipeRuneAltar(output, mana, inputs);
runeAltarRecipes.add(recipe);
return recipe;
}
/**
* Registers a Mana Infusion Recipe (throw an item in a mana pool)
* @param output The ItemStack to craft
* @param input The input item, be it an ItemStack or an ore dictionary entry String.
* @param mana The amount of mana required. Don't go over 100000!
* @return The recipe created.
*/
public static RecipeManaInfusion registerManaInfusionRecipe(ItemStack output, Object input, int mana) {
RecipeManaInfusion recipe = new RecipeManaInfusion(output, input, mana);
manaInfusionRecipes.add(recipe);
return recipe;
}
/**
* Register a Mana Infusion Recipe and flags it as an Alchemy recipe (requires an
* Alchemy Catalyst below the pool).
* @see BotaniaAPI#registerManaInfusionRecipe
*/
public static RecipeManaInfusion registerManaAlchemyRecipe(ItemStack output, Object input, int mana) {
RecipeManaInfusion recipe = registerManaInfusionRecipe(output, input, mana);
recipe.setAlchemy(true);
return recipe;
}
/**
* Register a Mana Infusion Recipe and flags it as an Conjuration recipe (requires a
* Conjuration Catalyst below the pool).
* @see BotaniaAPI#registerManaInfusionRecipe
*/
public static RecipeManaInfusion registerManaConjurationRecipe(ItemStack output, Object input, int mana) {
RecipeManaInfusion recipe = registerManaInfusionRecipe(output, input, mana);
recipe.setConjuration(true);
return recipe;
}
/**
* Registers a Elven Trade recipe (throw an item in an Alfheim Portal).
* @param output The ItemStack to return.
* @param inputs The items required, can be ItemStack or ore dictionary entry string.
* @return The recipe created.
*/
public static RecipeElvenTrade registerElvenTradeRecipe(ItemStack output, Object... inputs) {
RecipeElvenTrade recipe = new RecipeElvenTrade(output, inputs);
elvenTradeRecipes.add(recipe);
return recipe;
}
/**
* Registers a Brew Recipe (for the Botanical Brewery).
* @param brew The brew in to be set in this recipe.
* @inputs The items used in the recipe, no more than 6.
*/
public static RecipeBrew registerBrewRecipe(Brew brew, Object... inputs) {
RecipeBrew recipe = new RecipeBrew(brew, inputs);
brewRecipes.add(recipe);
return recipe;
}
/**
* Registers a SubTileEntity, a new special flower. Look in the subtile package of the API.
*/
public static void registerSubTile(String key, Class<? extends SubTileEntity> subtileClass) {
subTiles.put(key, subtileClass);
}
/**
* Registers a SubTileEntity's signature.
* @see SubTileSignature
*/
public static void registerSubTileSignature(Class<? extends SubTileEntity> subtileClass, SubTileSignature signature) {
subTileSignatures.put(subtileClass, signature);
}
/**
* Gets the singleton signature for a SubTileEntity class. Registers a fallback if one wasn't registered
* before the call.
*/
public static SubTileSignature getSignatureForClass(Class<? extends SubTileEntity> subtileClass) {
if(!subTileSignatures.containsKey(subtileClass))
registerSubTileSignature(subtileClass, new BasicSignature(subTiles.inverse().get(subtileClass)));
return subTileSignatures.get(subtileClass);
}
/**
* Gets the singleton signature for a SubTileEntity's name. Registers a fallback if one wasn't registered
* before the call.
*/
public static SubTileSignature getSignatureForName(String name) {
Class<? extends SubTileEntity> subtileClass = subTiles.get(name);
return getSignatureForClass(subtileClass);
}
/**
* Adds the key for a SubTileEntity into the creative menu. This goes into the
* subtilesForCreativeMenu Set.
*/
public static void addSubTileToCreativeMenu(String key) {
subtilesForCreativeMenu.add(key);
}
/**
* Adds a category to the list of registered categories to appear in the Lexicon.
*/
public static void addCategory(LexiconCategory category) {
categories.add(category);
}
/**
* Gets all registered categories.
*/
public static List<LexiconCategory> getAllCategories() {
return categories;
}
/**
* Gets all registered entries.
*/
public static List<LexiconEntry> getAllEntries() {
return allEntries;
}
/**
* Registers a Lexicon Entry and adds it to the category passed in.
*/
public static void addEntry(LexiconEntry entry, LexiconCategory category) {
allEntries.add(entry);
category.entries.add(entry);
}
/**
* Maps an ore (ore dictionary key) to it's weight on the world generation. This
* is used for the Orechid flower. Check the static block in the BotaniaAPI class
* to get the weights for the vanilla blocks.<br>
* Alternatively get the values with the OreDetector mod:<br>
* https://gist.github.com/Vazkii/9493322
*/
public static void addOreWeight(String ore, int weight) {
oreWeights.put(ore, weight);
}
public static int getOreWeight(String ore) {
return oreWeights.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.
*/
public static void addSeed(Item item, Block block) {
seeds.put(item, block);
}
/**
* Gets the last recipe to have been added to the recipe list.
*/
public static IRecipe getLatestAddedRecipe() {
List<IRecipe> list = CraftingManager.getInstance().getRecipeList();
return list.get(list.size() - 1);
}
/**
* Gets the last x recipes added to the recipe list.
*/
public static List<IRecipe> getLatestAddedRecipes(int x) {
List<IRecipe> list = CraftingManager.getInstance().getRecipeList();
List<IRecipe> newList = new ArrayList();
for(int i = x - 1; i >= 0; i--)
newList.add(list.get(list.size() - 1 - i));
return newList;
}
/**
* Registers a Wiki provider for a mod so it uses that instead of the fallback
* FTB wiki. Make sure to call this on PostInit only!
*/
public static void registerModWiki(String mod, IWikiProvider provider) {
WikiHooks.registerModWiki(mod, provider);
}
public static Class<? extends SubTileEntity> getSubTileMapping(String key) {
if(!subTiles.containsKey(key))
key = "";
return subTiles.get(key);
}
public static String getSubTileStringMapping(Class<? extends SubTileEntity> clazz) {
return subTiles.inverse().get(clazz);
}
}
@@ -0,0 +1,63 @@
/**
* This class was created by <Vazkii>. 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 a
* Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License
* (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB)
*
* File Created @ [Oct 29, 2014, 6:09:48 PM (GMT)]
*/
package vazkii.botania.api.boss;
import java.awt.Rectangle;
import net.minecraft.entity.boss.BossStatus;
import net.minecraft.entity.boss.IBossDisplayData;
import net.minecraft.util.ResourceLocation;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
/**
* An extension of IBossDisplayData. This counts as a botania boss and as a normal
* minecraft boss since it has IBossDisplayData. Instead of using the typical
* BossStatus.setBossStatus(entity, true) to set the health bar in the render use
* BotaniaAPI.internalMethodHandler.setBossStatus(entity);<br><br>
* Alternatively, you can check if botania is loaded and use the vanilla one
* if that's not the case.
*/
public interface IBotaniaBoss extends IBossDisplayData {
/**
* The ResourceLocation to bind for this boss's boss bar.
* You can use BotaniaAPI.internalMethodHandler.getDefaultBossBarTexture() to get
* the one used by botania bosses.
*/
@SideOnly(Side.CLIENT)
public ResourceLocation getBossBarTexture();
/**
* A Rectangle instance delimiting the uv, width and height of this boss's
* boss bar texture. This is for the background, not the bar that shows
* the HP.
*/
@SideOnly(Side.CLIENT)
public Rectangle getBossBarTextureRect();
/**
* A Rectangle instance delimiting the uv, width and height of this boss's
* boss bar HP texture. This is for the foreground that shows how much
* HP the boss has. The width of the rectangle will be multiplied by the
* faction of the boss's current HP by max HP.
*/
@SideOnly(Side.CLIENT)
public Rectangle getBossBarHPTextureRect();
/**
* A callback for when this boss's boss bar renders, you can do aditional rendering
* here if needed.
*/
@SideOnly(Side.CLIENT)
public void bossBarRenderCallback();
}
@@ -0,0 +1,43 @@
/**
* This class was created by <Vazkii>. 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 a
* Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License
* (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB)
*
* File Created @ [Oct 29, 2014, 6:13:21 PM (GMT)]
*/
package vazkii.botania.api.boss;
import vazkii.botania.api.internal.ShaderCallback;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
/**
* A Botania boss whose HP bar makes use of shaders. Shaders
* used through this have a few uniforms available:
* <li><b><i>int</i> time</b> - The amount of total ticks elapsed.</li>
* <li><b><i>int</i> startX</b> - The U coordinate passed in for the render of this bar's texture.</li>
* <li><b><i>int</i> startY</b> - The V coordinate passed in for the render of this bar's texture.</li>
*/
public interface IBotaniaBossWithShader extends IBotaniaBoss {
/**
* The Shader Program to use for this boss bar. Return 0 case
* you don't want a shader to be used. You can use separate shaders
* for the background and foreground.
* @param background True if rendering the background of the boss bar,
* false if rendering the bar itself that shows the HP.
*/
@SideOnly(Side.CLIENT)
public int getBossBarShaderProgram(boolean background);
/**
* A callback for the shader, used to pass in uniforms. Return null for no callback.
*/
@SideOnly(Side.CLIENT)
public ShaderCallback getBossBarShaderCallback(boolean background, int shader);
}
@@ -0,0 +1,101 @@
/**
* This class was created by <Vazkii>. 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 a
* Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License
* (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB)
*
* File Created @ [Nov 1, 2014, 6:22:54 PM (GMT)]
*/
package vazkii.botania.api.brew;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import net.minecraft.item.ItemStack;
import net.minecraft.potion.PotionEffect;
/**
* The class for a Brew definition, each one is a singleton.
*/
public class Brew {
String key;
String name;
int color;
int cost;
List<PotionEffect> effects;
/**
* @param name The unlocalized name of this potion.
* @param color The color for the potion to be rendered in the bottle, note that it will get
* changed a bit when it renders (for more or less brightness) to give a fancy effect.
* @param cost The cost, in Mana for this brew.
* @param effects A list of effects to apply to the player when they drink it.
*/
public Brew(String key, String name, int color, int cost, PotionEffect... effects) {
this.key = key;
this.name = name;
this.color = color;
this.cost = cost;
this.effects = new ArrayList(Arrays.asList(effects));
}
/**
* Returns the key for this brew, for it to be found in the map in the API.
* This should ALWAYS return the same result.
*/
public String getKey() {
return key;
}
/**
* Gets the insensitive unlocalized name. This is used for the lexicon.
*/
public String getUnlocalizedName() {
return name;
}
/**
* Gets the unlocalized name for the ItemStack passed in.
*/
public String getUnlocalizedName(ItemStack stack) {
return getUnlocalizedName();
}
/**
* Gets the display color for the ItemStack passed in. Note that for
* the lexicon, this passes in a botania Managlass Vial or an
* Alfglass Flask at all times.
*/
public int getColor(ItemStack stack) {
return color;
}
/**
* Gets the insensitive unlocalized mana cost. This is used for the lexicon.
*/
public int getManaCost() {
return cost;
}
/**
* Gets the mana cost for the ItemStack passed in.
*/
public int getManaCost(ItemStack stack) {
return getManaCost();
}
/**
* Gets the list of potion effects for the ItemStack passed in.
* Note that for the lexicon, this passes in a botania Managlass
* Vial or an Alfglass Flask at all times.
*/
public List<PotionEffect> getPotionEffects(ItemStack stack) {
return effects;
}
}
@@ -0,0 +1,36 @@
/**
* This class was created by <Vazkii>. 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 a
* Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License
* (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB)
*
* File Created @ [Nov 1, 2014, 6:26:40 PM (GMT)]
*/
package vazkii.botania.api.brew;
import net.minecraft.item.ItemStack;
/**
* An Item that implements this counts as a Brew Container, by which
* it can be used a center item for brew recipes and can contain
* a brew.
*/
public interface IBrewContainer {
/**
* Returs an ItemStack that should be an item that has the brew
* passed in.
*/
public ItemStack getItemForBrew(Brew brew, ItemStack stack);
/**
* Gets the cost to add this brew onto this container. Return -1
* to not allow for the brew to be added. Normally you'd
* use brew.getManaCost(stack);
*/
public int getManaCost(Brew brew, ItemStack stack);
}
@@ -0,0 +1,25 @@
/**
* This class was created by <Vazkii>. 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 a
* Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License
* (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB)
*
* File Created @ [Nov 1, 2014, 9:20:33 PM (GMT)]
*/
package vazkii.botania.api.brew;
import net.minecraft.item.ItemStack;
/**
* An Item that implements this is a Brew item, by which it contains
* a brew. This is only used in vanilla to prevent the brew item
* from going back into the brewery but other mods might use it for whatever.
*/
public interface IBrewItem {
public Brew getBrew(ItemStack brew);
}
@@ -0,0 +1,51 @@
/**
* This class was created by <Vazkii>. 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 a
* Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License
* (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB)
*
* File Created @ [Mar 7, 2014, 3:47:43 PM (GMT)]
*/
package vazkii.botania.api.internal;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ChunkCoordinates;
import net.minecraft.world.World;
import vazkii.botania.api.mana.TileSignature;
public class DummyManaNetwork implements IManaNetwork {
public static final DummyManaNetwork instance = new DummyManaNetwork();
@Override
public void clear() {
// NO-OP
}
@Override
public TileEntity getClosestPool(ChunkCoordinates pos, World world, int limit) {
return null;
}
@Override
public TileEntity getClosestCollector(ChunkCoordinates pos, World world, int limit) {
return null;
}
@Override
public List<TileSignature> getAllCollectorsInWorld(World world) {
return new ArrayList();
}
@Override
public List<TileSignature> getAllPoolsInWorld(World world) {
return new ArrayList();
}
}
@@ -0,0 +1,171 @@
/**
* This class was created by <Vazkii>. 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 a
* Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License
* (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB)
*
* File Created @ [Jan 14, 2014, 6:43:03 PM (GMT)]
*/
package vazkii.botania.api.internal;
import java.util.List;
import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.tileentity.TileEntity;
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.lexicon.LexiconPage;
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;
public class DummyMethodHandler implements IInternalMethodHandler {
@Override
public LexiconPage textPage(String key) {
return dummyPage(key);
}
@Override
public LexiconPage imagePage(String key, String resource) {
return dummyPage(key);
}
@Override
public LexiconPage craftingRecipesPage(String key, List<IRecipe> recipes) {
return dummyPage(key);
}
@Override
public LexiconPage craftingRecipePage(String key, IRecipe recipe) {
return dummyPage(key);
}
@Override
public LexiconPage petalRecipesPage(String key, List<RecipePetals> recipes) {
return dummyPage(key);
}
@Override
public LexiconPage petalRecipePage(String key, RecipePetals recipe) {
return dummyPage(key);
}
@Override
public LexiconPage runeRecipesPage(String key, List<RecipeRuneAltar> recipes) {
return dummyPage(key);
}
@Override
public LexiconPage runeRecipePage(String key, RecipeRuneAltar recipe) {
return dummyPage(key);
}
@Override
public LexiconPage manaInfusionRecipesPage(String key, List<RecipeManaInfusion> recipes) {
return dummyPage(key);
}
@Override
public LexiconPage manaInfusionRecipePage(String key, RecipeManaInfusion recipe) {
return dummyPage(key);
}
@Override
public LexiconPage elvenTradePage(String key, List<RecipeElvenTrade> recipes) {
return dummyPage(key);
}
@Override
public LexiconPage elvenTradesPage(String key, RecipeElvenTrade recipe) {
return dummyPage(key);
}
@Override
public LexiconPage brewPage(String key, String bottomText, RecipeBrew recipe) {
return dummyPage(key);
}
private LexiconPage dummyPage(String key) {
return new DummyPage(key);
}
@Override
public ItemStack getSubTileAsStack(String subTile) {
return new ItemStack(Blocks.stone, 0, 0);
}
@Override
public IIcon getSubTileIconForName(String name) {
return Blocks.red_flower.getIcon(0, 0);
}
@Override
public void registerBasicSignatureIcons(String name, IIconRegister register) {
// NO-OP
}
@Override
public IManaNetwork getManaNetworkInstance() {
return DummyManaNetwork.instance;
}
@Override
public void drawSimpleManaHUD(int color, int mana, int maxMana, String name, ScaledResolution res) {
// NO-OP
}
@Override
public void renderLexiconText(int x, int y, int width, int height, String unlocalizedText) {
// NO-OP
}
@Override
public void sparkleFX(World world, double x, double y, double z, float r, float g, float b, float size, int m) {
// NO-OP
}
@Override
public IInventory getBaublesInventory(EntityPlayer player) {
return null;
}
@Override
public boolean shouldForceCheck() {
return true;
}
@Override
public int getPassiveFlowerDecay() {
return 0;
}
@Override
public ResourceLocation getDefaultBossBarTexture() {
return null;
}
@Override
public void setBossStatus(IBotaniaBoss status) {
// NO-OP
}
@Override
public boolean isBuildcraftPipe(TileEntity tile) {
return false;
}
}
@@ -0,0 +1,35 @@
/**
* This class was created by <Vazkii>. 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 a
* Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License
* (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB)
*
* File Created @ [Jan 14, 2014, 6:41:23 PM (GMT)]
*/
package vazkii.botania.api.internal;
import vazkii.botania.api.lexicon.LexiconPage;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
/**
* A dummy page. It does absolutely nothing and is only
* existant to make sure everything goes right even if
* Botania isn't loaded.
*/
public class DummyPage extends LexiconPage {
public DummyPage(String unlocalizedName) {
super(unlocalizedName);
}
@Override
@SideOnly(Side.CLIENT)
public void renderScreen(IGuiLexiconEntry gui, int x, int y) {
// NO-OP
}
}
@@ -0,0 +1,18 @@
/**
* This class was created by <Vazkii>. 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 a
* Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License
* (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB)
*
* File Created @ [Jan 24, 2014, 4:17:33 PM (GMT)]
*/
package vazkii.botania.api.internal;
import vazkii.botania.api.subtile.SubTileEntity;
public class DummySubTile extends SubTileEntity {
}
@@ -0,0 +1,82 @@
/**
* This class was created by <Vazkii>. 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 a
* Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License
* (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB)
*
* File Created @ [Jan 14, 2014, 6:48:41 PM (GMT)]
*/
package vazkii.botania.api.internal;
import java.util.List;
import net.minecraft.client.gui.GuiButton;
import vazkii.botania.api.lexicon.LexiconEntry;
/**
* Internal interface for the Lexicon Entry GUI. This contains
* everything that can be accessed from it. It's safe to cast
* this type to GuiScreen.
*/
public interface IGuiLexiconEntry {
/**
* Gets the entry currently portrayed in this gui.
*/
public LexiconEntry getEntry();
/**
* Gets the current page the lexicon GUI is browsing.
*/
public int getPageOn();
/**
* Gets the leftmost part of the GUI.
*/
public int getLeft();
/**
* Gets the topmost part of the GUI.
*/
public int getTop();
/**
* Gets the GUI's width.
*/
public int getWidth();
/**
* Gets the GUI's height
*/
public int getHeight();
/**
* Gets the GUI's Z level for rendering.
*/
public float getZLevel();
/**
* Gets the list of buttons in this gui.
*/
public List<GuiButton> getButtonList();
/**
* Gets the total amount of ticks (+ partial ticks) the player
* has been in this gui.
*/
public float getElapsedTicks();
/**
* Gets the current partial ticks.
*/
public float getPartialTicks();
/**
* Gets the delta (1F = 1 tick) between this render call
* and the last one.
*/
public float getTickDelta();
}
@@ -0,0 +1,101 @@
/**
* This class was created by <Vazkii>. 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 a
* Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License
* (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB)
*
* File Created @ [Jan 14, 2014, 6:34:34 PM (GMT)]
*/
package vazkii.botania.api.internal;
import java.util.List;
import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.tileentity.TileEntity;
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.lexicon.LexiconPage;
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 cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
/**
* Any methods that refer to internal methods in Botania are here.
* This is defaulted to a dummy handler, whose methods do nothing.
* This handler is set to a proper one on PreInit. Make sure to
* make your mod load after Botania if you have any intention of
* doing anythign with this on PreInit.
*/
public interface IInternalMethodHandler {
public LexiconPage textPage(String key);
public LexiconPage imagePage(String key, String resource);
public LexiconPage craftingRecipesPage(String key, List<IRecipe> recipes);
public LexiconPage craftingRecipePage(String key, IRecipe recipe);
public LexiconPage petalRecipesPage(String key, List<RecipePetals> recipes);
public LexiconPage petalRecipePage(String key, RecipePetals recipe);
public LexiconPage runeRecipesPage(String key, List<RecipeRuneAltar> recipes);
public LexiconPage runeRecipePage(String key, RecipeRuneAltar recipe);
public LexiconPage manaInfusionRecipesPage(String key, List<RecipeManaInfusion> recipes);
public LexiconPage manaInfusionRecipePage(String key, RecipeManaInfusion recipe);
public LexiconPage elvenTradePage(String key, List<RecipeElvenTrade> recipes);
public LexiconPage elvenTradesPage(String key, RecipeElvenTrade recipe);
public LexiconPage brewPage(String key, String bottomText, RecipeBrew recipe);
public IManaNetwork getManaNetworkInstance();
public ItemStack getSubTileAsStack(String subTile);
public IIcon getSubTileIconForName(String name);
public void registerBasicSignatureIcons(String name, IIconRegister register);
public boolean shouldForceCheck();
public int getPassiveFlowerDecay();
public IInventory getBaublesInventory(EntityPlayer player);
@SideOnly(Side.CLIENT)
public void drawSimpleManaHUD(int color, int mana, int maxMana, String name, ScaledResolution res);
@SideOnly(Side.CLIENT)
public void renderLexiconText(int x, int y, int width, int height, String unlocalizedText);
@SideOnly(Side.CLIENT)
public ResourceLocation getDefaultBossBarTexture();
@SideOnly(Side.CLIENT)
public void setBossStatus(IBotaniaBoss status);
public boolean isBuildcraftPipe(TileEntity tile);
public void sparkleFX(World world, double x, double y, double z, float r, float g, float b, float size, int m);
}
@@ -0,0 +1,62 @@
/**
* This class was created by <Vazkii>. 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 a
* Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License
* (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB)
*
* File Created @ [Jan 31, 2014, 4:36:13 PM (GMT)]
*/
package vazkii.botania.api.internal;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ChunkCoordinates;
/**
* Interface for the Mana Burst entity. This can safely be casted to EntityThrowable.
*/
public interface IManaBurst {
public boolean isFake();
public void setMotion(double x, double y, double z);
public int getColor();
public void setColor(int color);
public int getMana();
public void setMana(int mana);
public int getStartingMana();
public void setStartingMana(int mana);
public int getMinManaLoss();
public void setMinManaLoss(int minManaLoss);
public float getManaLossPerTick();
public void setManaLossPerTick(float mana);
public float getGravity();
public void setGravity(float gravity);
public ChunkCoordinates getBurstSourceChunkCoordinates();
public void setBurstSourceCoords(int x, int y, int z);
public ItemStack getSourceLens();
public void setSourceLens(ItemStack lens);
public boolean hasAlreadyCollidedAt(int x, int y, int z);
public int getTicksExisted();
}
@@ -0,0 +1,68 @@
/**
* This class was created by <Vazkii>. 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 a
* Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License
* (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB)
*
* File Created @ [Mar 7, 2014, 3:39:48 PM (GMT)]
*/
package vazkii.botania.api.internal;
import java.util.List;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ChunkCoordinates;
import net.minecraft.world.World;
import vazkii.botania.api.mana.TileSignature;
/**
* A basic interface for a world's Mana Network.
* @see IInternalMethodHandler#getManaNetworkInstance()
*/
public interface IManaNetwork {
/**
* Clears the entire Mana Network of all it's contents, you probably
* don't want to call this unless you have a very good reason.
*/
public void clear();
/**
* Gets the closest Mana Collector (eg. Mana Spreader) in the network to the Chunk
* Coordinates passed in, in the given dimension.<br>
* A way of getting the dimension is via worldObj.provider.dimensionId<br>
* Note that this function *can* get performance intensive, it's reccomended you
* call it sparingly and take cache of the value returned.
* @param limit The maximum distance the closest block can be, if the closest block
* is farther away than that, null will be returned instead.
*/
public TileEntity getClosestCollector(ChunkCoordinates pos, World world, int limit);
/**
* Gets the closest Mana Pool in the network to the Chunk Coordinates passed in,
* in the given dimension.<br>
* A way of getting the dimension is via worldObj.provider.dimensionId<br>
* Note that this function *can* get performance intensive, it's reccomended you
* call it sparingly and take cache of the value returned.
* @param limit The maximum distance the closest block can be, if the closest block
* is farther away than that, null will be returned instead.
*/
public TileEntity getClosestPool(ChunkCoordinates pos, World world, int limit);
/**
* Gets the list of all Mana Collectors (eg. Mana Spreader) in the dimension
* passed in. Note that this is the actual list and not a copy, make sure to
* clone the list if you intend to change it in any way.
*/
public List<TileSignature> getAllCollectorsInWorld(World world);
/**
* Gets the list of all Mana Pools in the dimension passed in. Note that this
* is the actual list and not a copy, make sure to clone the list if you intend
* to change it in any way.
*/
public List<TileSignature> getAllPoolsInWorld(World world);
}
@@ -0,0 +1,21 @@
/**
* This class was created by <Vazkii>. 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 a
* Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License
* (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB)
*
* File Created @ [Oct 29, 2014, 6:31:35 PM (GMT)]
*/
package vazkii.botania.api.internal;
/**
* A Callback for when a shader is called. Used to define shader uniforms.
*/
public abstract class ShaderCallback {
public abstract void call(int shader);
}
@@ -0,0 +1,44 @@
/**
* This class was created by <Vazkii>. 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 a
* Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License
* (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB)
*
* File Created @ [Aug 30, 2014, 4:28:29 PM (GMT)]
*/
package vazkii.botania.api.item;
/**
* A TileEntity that implements this can be heated by an Exoflame flower.
*/
public interface IExoflameHeatable {
/**
* Can this TileEntity smelt its contents. If true, the Exoflame is allowed
* to fuel it.
*/
public boolean canSmelt();
/**
* Gets the amount of ticks left for the fuel. If below 2, the exoflame
* will call boostBurnTime.
*/
public int getBurnTime();
/**
* Called to increase the amount of time this furnace should be burning
* the fuel for. Even if it doesn't have any fuel.
*/
public void boostBurnTime();
/**
* Called once every two ticks to increase the speed of the furnace. Feel
* free to not do anything if all you want is to allow the exoflame to feed
* it, not make it faster.
*/
public void boostCookTime();
}
@@ -0,0 +1,29 @@
/**
* This class was created by <Vazkii>. 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 a
* Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License
* (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB)
*
* File Created @ [Aug 6, 2014, 6:02:29 PM (GMT)]
*/
package vazkii.botania.api.item;
/**
* An interface that defines an instance of PlayerControllerMP with
* the ability to modify reach. See vazkii.botania.client.core.handler.BotaniaPlayerController
*/
public interface IExtendedPlayerController {
/**
* Sets the extra reach the player should have.
*/
public void setReachDistanceExtension(float f);
/**
* Gets the current reach extension.
*/
public float getReachDistanceExtension();
}
@@ -0,0 +1,25 @@
/**
* This class was created by <TheLoneDevil>. 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 a
* Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License
* (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB)
*
* File Created @ [? (GMT)]
*/
package vazkii.botania.api.item;
import net.minecraft.world.World;
/**
* A WorldProvider that implements this will not have Botania flowers generated.
*/
public interface IFlowerlessWorld {
/**
* @return Should this world be allowed to generate flowers?
*/
public boolean generateFlowers(World world);
}
@@ -0,0 +1,24 @@
/**
* This class was created by <Vazkii>. 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 a
* Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License
* (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB)
*
* File Created @ [Oct 29, 2014, 4:52:04 PM (GMT)]
*/
package vazkii.botania.api.item;
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.
*/
public interface IGrassHornExcempt {
public boolean canUproot(World world, int x, int y, int z);
}
@@ -0,0 +1,30 @@
/**
* This class was created by <Vazkii>. 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 a
* Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License
* (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB)
*
* File Created @ [Aug 30, 2014, 4:22:15 PM (GMT)]
*/
package vazkii.botania.api.item;
/**
* Base Interface for the Petal Apothecary block. Can
* be safely casted to TileEntity.
*/
public interface IPetalApothecary {
/**
* Sets if the the apothecary has water or not.
*/
public void setWater(boolean water);
/**
* Does the apothecary have water in it?
*/
public boolean hasWater();
}
@@ -0,0 +1,30 @@
/**
* This class was created by <Vazkii>. 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 a
* Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License
* (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB)
*
* File Created @ [Aug 6, 2014, 6:06:27 PM (GMT)]
*/
package vazkii.botania.api.item;
import net.minecraft.item.ItemStack;
/**
* Any item that implements this allows for pixies to be spawned when the player takes damage when...<br>
* - Case the item is armor, having it equipped.<br>
* - Case the item is a bauble, having it worn.<br>
* - On any other case, having the item being the current held item.
*/
public interface IPixieSpawner {
/**
* The chance this item adds for pixies to be spawned. From 0.0 to 1.0. All values
* are put together when calculating.
*/
public float getPixieChance(ItemStack stack);
}
@@ -0,0 +1,29 @@
/**
* This class was created by <Vazkii>. 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 a
* Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License
* (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB)
*
* File Created @ [Jun 8, 2014, 7:02:48 PM (GMT)]
*/
package vazkii.botania.api.lexicon;
/**
* Have a LexiconEntry implement this to signify it's an "Addon entry", as
* in, one provided by an Addon. This allows it to draw a subtitle of
* sorts, to prevent the [Mod tag here] nonsense that happened with thaumcraft
* addons. It can also be used for other purposes, such as stating an
* entry is WIP.
*/
public interface IAddonEntry {
/**
* Returns the <b>unlocalized</b> subtitle to show below the title. Here you'd
* return something like "(This Entry is provided by the Botanic Tinkerer addon)".
*/
public String getSubtitle();
}
@@ -0,0 +1,21 @@
package vazkii.botania.api.lexicon;
import net.minecraft.item.ItemStack;
/**
* Basic interface for the Lexica Botania.
*/
public interface ILexicon {
/**
* Gets if a specific knowledge is unlocked. Check the knowledge types in
* BotaniaAPI.
*/
public boolean isKnowledgeUnlocked(ItemStack stack, KnowledgeType knowledge);
/**
* Unlocks a specfic type of knowledge.
*/
public void unlockKnowledge(ItemStack stack, KnowledgeType knowledge);
}
@@ -0,0 +1,29 @@
/**
* This class was created by <Vazkii>. 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 a
* Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License
* (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB)
*
* File Created @ [Jan 20, 2014, 7:05:44 PM (GMT)]
*/
package vazkii.botania.api.lexicon;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
/**
* Any block that implements this can be right clicked with
* a Lexica Botania to open a entry page.
*/
public interface ILexiconable {
/**
* Gets the lexicon entry to open at this location. null works too.
*/
public LexiconEntry getEntry(World world, int x, int y, int z, EntityPlayer player, ItemStack lexicon);
}
@@ -0,0 +1,24 @@
/**
* This class was created by <Vazkii>. 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 a
* Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License
* (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB)
*
* File Created @ [Mar 20, 2014, 6:08:48 PM (GMT)]
*/
package vazkii.botania.api.lexicon;
import net.minecraft.item.ItemStack;
/**
* Have an Item implement this so that the method used for mapping it into
* the lexicon recipe mappings isn't the typical id:meta key.
*/
public interface IRecipeKeyProvider {
public String getKey(ItemStack stack);
}
@@ -0,0 +1,24 @@
/**
* This class was created by <Vazkii>. 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 a
* Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License
* (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB)
*
* File Created @ [Nov 3, 2014, 2:59:55 PM (GMT)]
*/
package vazkii.botania.api.lexicon;
/**
* A LexiconPage that implements this has two unlocalized names
* rather than one. (See brew pages)
*/
public interface ITwoNamedPage {
public void setSecondUnlocalizedName(String name);
public String getSecondUnlocalizedName();
}
@@ -0,0 +1,20 @@
package vazkii.botania.api.lexicon;
import net.minecraft.util.EnumChatFormatting;
public class KnowledgeType {
public final String id;
public final EnumChatFormatting color;
public final boolean autoUnlock;
public KnowledgeType(String id, EnumChatFormatting color, boolean autoUnlock) {
this.id = id;
this.color = color;
this.autoUnlock = autoUnlock;
}
public String getUnlocalizedName() {
return "botania.knowledge." + id;
}
}
@@ -0,0 +1,44 @@
/**
* This class was created by <Vazkii>. 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 a
* Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License
* (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB)
*
* File Created @ [Jan 14, 2014, 6:23:47 PM (GMT)]
*/
package vazkii.botania.api.lexicon;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.util.ResourceLocation;
public class LexiconCategory {
public final String unlocalizedName;
public final List<LexiconEntry> entries = new ArrayList<LexiconEntry>();
private ResourceLocation icon;
/**
* @param unlocalizedName The unlocalized name of this category. This will be localized by the client display.
*/
public LexiconCategory(String unlocalizedName) {
this.unlocalizedName = unlocalizedName;
}
public String getUnlocalizedName() {
return unlocalizedName;
}
public LexiconCategory setIcon(ResourceLocation icon) {
this.icon = icon;
return this;
}
public ResourceLocation getIcon() {
return icon;
}
}
@@ -0,0 +1,97 @@
/**
* This class was created by <Vazkii>. 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 a
* Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License
* (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB)
*
* File Created @ [Jan 14, 2014, 6:17:06 PM (GMT)]
*/
package vazkii.botania.api.lexicon;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import net.minecraft.util.StatCollector;
import vazkii.botania.api.BotaniaAPI;
public class LexiconEntry implements Comparable<LexiconEntry> {
public final String unlocalizedName;
public final LexiconCategory category;
private KnowledgeType type = BotaniaAPI.basicKnowledge;
public List<LexiconPage> pages = new ArrayList<LexiconPage>();
private boolean priority = false;
/**
* @param unlocalizedName The unlocalized name of this entry. This will be localized by the client display.
*/
public LexiconEntry(String unlocalizedName, LexiconCategory category) {
this.unlocalizedName = unlocalizedName;
this.category = category;
}
/**
* Sets this page as prioritized, as in, will appear before others in the lexicon.
*/
public LexiconEntry setPriority() {
priority = true;
return this;
}
/**
* Sets the Knowledge type of this entry.
*/
public LexiconEntry setKnowledgeType(KnowledgeType type) {
this.type = type;
return this;
}
public KnowledgeType getKnowledgeType() {
return type;
}
public boolean isPriority() {
return priority;
}
public String getUnlocalizedName() {
return unlocalizedName;
}
/**
* Sets what pages you want this entry to have.
*/
public LexiconEntry setLexiconPages(LexiconPage... pages) {
this.pages.addAll(Arrays.asList(pages));
for(int i = 0; i < this.pages.size(); i++) {
LexiconPage page = this.pages.get(i);
if(!page.skipRegistry)
page.onPageAdded(this, i);
}
return this;
}
/**
* Adds a page to the list of pages.
*/
public void addPage(LexiconPage page) {
pages.add(page);
}
public final String getNameForSorting() {
return (priority ? 0 : 1) + StatCollector.translateToLocal(getUnlocalizedName());
}
@Override
public int compareTo(LexiconEntry o) {
return getNameForSorting().compareTo(o.getNameForSorting());
}
}
@@ -0,0 +1,103 @@
/**
* This class was created by <Vazkii>. 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 a
* Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License
* (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB)
*
* File Created @ [Jan 14, 2014, 6:17:24 PM (GMT)]
*/
package vazkii.botania.api.lexicon;
import net.minecraft.client.gui.GuiButton;
import vazkii.botania.api.internal.IGuiLexiconEntry;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public abstract class LexiconPage {
public String unlocalizedName;
public boolean skipRegistry;
public LexiconPage(String unlocalizedName) {
this.unlocalizedName = unlocalizedName;
}
/**
* Does the rendering for this page.
* @param gui The active GuiScreen
* @param mx The mouse's relative X position.
* @param my The mouse's relative Y position.
*/
@SideOnly(Side.CLIENT)
public abstract void renderScreen(IGuiLexiconEntry gui, int mx, int my);
/**
* Called per update tick. Non gui-sensitive version, kept for backwards compatibility only.
*/
@SideOnly(Side.CLIENT)
public void updateScreen() {
// NO-OP
}
/**
* Called per update tick. Feel free to override fully, the
* call to updateScreen() is for backwards compatibility.
*/
@SideOnly(Side.CLIENT)
public void updateScreen(IGuiLexiconEntry gui) {
updateScreen();
}
/**
* Called when this page is opened, be it via initGui() or when the player changes page.
* You can add buttons and whatever you'd do on initGui() here.
*/
@SideOnly(Side.CLIENT)
public void onOpened(IGuiLexiconEntry gui) {
// NO-OP
}
/**
* Called when this page is opened, be it via closing the gui or when the player changes page.
* Make sure to dispose of anything you don't use any more, such as buttons in the gui's buttonList.
*/
@SideOnly(Side.CLIENT)
public void onClosed(IGuiLexiconEntry gui) {
// NO-OP
}
/**
* Called when a button is pressed, equivalent to GuiScreen.actionPerformed.
*/
@SideOnly(Side.CLIENT)
public void onActionPerformed(IGuiLexiconEntry gui, GuiButton button) {
// NO-OP
}
/**
* Called when a key is pressed.
*/
@SideOnly(Side.CLIENT)
public void onKeyPressed(char c, int key) {
// NO-OP
}
/**
* Called when {@link LexiconEntry#setLexiconPages(LexiconPage...)} is called.
*/
public void onPageAdded(LexiconEntry entry, int index) {
// NO-OP
}
public String getUnlocalizedName() {
return unlocalizedName;
}
public LexiconPage setSkipRegistry() {
skipRegistry = true;
return this;
}
}
@@ -0,0 +1,66 @@
/**
* This class was created by <Vazkii>. 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 a
* Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License
* (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB)
*
* File Created @ [Mar 6, 2014, 3:54:12 PM (GMT)]
*/
package vazkii.botania.api.lexicon;
import java.util.HashMap;
import java.util.Map;
import net.minecraft.item.ItemStack;
/**
* This class contains mappings for which entry and page correspond to each
* craftable ItemStack. Use the map method to map an ItemStack to a page in
* an entry in the lexicon.
*/
public final class LexiconRecipeMappings {
private static Map<String, EntryData> mappings = new HashMap();
/**
* Maps the given stack to the given page of the entry.
*/
public static void map(ItemStack stack, LexiconEntry entry, int page, boolean force) {
EntryData data = new EntryData(entry, page);
String str = stackToString(stack);
if(force || !mappings.containsKey(str))
mappings.put(str, data);
}
public static void map(ItemStack stack, LexiconEntry entry, int page) {
map(stack, entry, page, false);
}
public static EntryData getDataForStack(ItemStack stack) {
return mappings.get(stackToString(stack));
}
public static String stackToString(ItemStack stack) {
if(stack.hasTagCompound() && stack.getItem() instanceof IRecipeKeyProvider)
return ((IRecipeKeyProvider) stack.getItem()).getKey(stack);
return stack.getUnlocalizedName() + "~" + stack.getItemDamage();
}
public static class EntryData {
public final LexiconEntry entry;
public final int page;
public EntryData(LexiconEntry entry, int page) {
this.entry = entry;
this.page = page;
}
}
}
@@ -0,0 +1,37 @@
/**
* This class was created by <Vazkii>. 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 a
* Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License
* (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB)
*
* File Created @ [Jan 31, 2014, 3:49:30 PM (GMT)]
*/
package vazkii.botania.api.mana;
/**
* The properties of a mana burst, when shot. This is passed to the lens
* currently on the mana spreader to apply changes.
*/
public final class BurstProperties {
public int maxMana;
public int ticksBeforeManaLoss;
public float manaLossPerTick;
public float gravity;
public float motionModifier;
public int color;
public BurstProperties(int maxMana, int ticksBeforeManaLoss, float manaLossPerTick, float gravity, float motionModifier, int color) {
this.maxMana = maxMana;
this.ticksBeforeManaLoss = ticksBeforeManaLoss;
this.manaLossPerTick = manaLossPerTick;
this.gravity = gravity;
this.motionModifier = motionModifier;
this.color = color;
}
}
@@ -0,0 +1,21 @@
/**
* This class was created by <Vazkii>. 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 a
* Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License
* (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB)
*
* File Created @ [Jul 2, 2014, 5:26:02 PM (GMT)]
*/
package vazkii.botania.api.mana;
/**
* A TileEntity that implements this will get it's recieveMana call
* called on both client and server. If this is not implemented
* the call will only occur on the server.
*/
public interface IClientManaHandler extends IManaReceiver {
}
@@ -0,0 +1,26 @@
/**
* This class was created by <Vazkii>. 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 a
* Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License
* (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB)
*
* File Created @ [May 25, 2014, 7:34:00 PM (GMT)]
*/
package vazkii.botania.api.mana;
import net.minecraft.item.ItemStack;
/**
* Have an item implement this to flag it as an infinite
* mana source for the purposes of the HUD rendered when
* an IManaUserItem implementing item is present.
*/
public interface ICreativeManaProvider {
public boolean isCreative(ItemStack stack);
}
@@ -0,0 +1,30 @@
/**
* This class was created by <Vazkii>. 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 a
* Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License
* (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB)
*
* File Created @ [Jul 11, 2014, 4:29:32 PM (GMT)]
*/
package vazkii.botania.api.mana;
/**
* A TileEntity that implements this interface has an IO key lock. This
* interface defines an input and output key.<br><br>
*
* A Spreader can only shoot mana into a IKeyLocked interfaced TE if the Input
* key of the TE is equal to the Output key of the Spreader.<br><br>
*
* A Spreader can only pull mana from a IKeyLocked interfaced IManaPool TE if the
* Output key of the IManaPool is equal to the Input key of the Spreader.
*/
public interface IKeyLocked {
public String getInputKey();
public String getOutputKey();
}
@@ -0,0 +1,23 @@
/**
* This class was created by <Vazkii>. 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 a
* Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License
* (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB)
*
* File Created @ [Jul 26, 2014, 9:51:58 PM (GMT)]
*/
package vazkii.botania.api.mana;
import net.minecraft.world.World;
/**
* A block that implements this has a flag for whether it can be moved by the Shard of Laputa.
*/
public interface ILaputaImmobile {
public boolean canMove(World world, int x, int y, int z);
}
@@ -0,0 +1,43 @@
/**
* This class was created by <Vazkii>. 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 a
* Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License
* (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB)
*
* File Created @ [Jan 31, 2014, 3:03:04 PM (GMT)]
*/
package vazkii.botania.api.mana;
import net.minecraft.item.ItemStack;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
/**
* Have an Item implement this to be counted as a lens for the mana spreader.
*/
public interface ILens extends ILensEffect {
@SideOnly(Side.CLIENT)
public int getLensColor(ItemStack stack);
/**
* Can the source lens be combined with the composite lens? This is called
* for both the ILens instance of ItemStack.getItem() of sourceLens and compositeLens.
*/
public boolean canCombineLenses(ItemStack sourceLens, ItemStack compositeLens);
/**
* Gets the composite lens in the stack passed in, return null for none.
*/
public ItemStack getCompositeLens(ItemStack stack);
/**
* Sets the composite lens for the sourceLens as the compositeLens, returns
* the ItemStack with the combination.
*/
public ItemStack setCompositeLens(ItemStack sourceLens, ItemStack compositeLens);
}
@@ -0,0 +1,49 @@
/**
* This class was created by <Vazkii>. 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 a
* Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License
* (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB)
*
* File Created @ [Apr 14, 2014, 7:30:00 PM (GMT)]
*/
package vazkii.botania.api.mana;
import net.minecraft.item.ItemStack;
import net.minecraft.util.MovingObjectPosition;
import vazkii.botania.api.internal.IManaBurst;
/**
* Have an item implement this for it to count as a lens effect and
* be able to change the properties of Mana Bursts.
*/
public interface ILensEffect {
/**
* Called when a mana spreader that has this focus shoots a burst. This is where
* you change the properties of the burst.
*/
public void apply(ItemStack stack, BurstProperties props);
/**
* Called when a mana burst fired from a mana spreader with this focus collides against
* any block. This is called after the collision is handled.
* @return True to kill the burst. False to keep it alive.
*/
public boolean collideBurst(IManaBurst burst, MovingObjectPosition pos, boolean isManaBlock, boolean dead, ItemStack stack);
/**
* Called when a mana burst fired from a mana spreader with this focus is updated.
* This is called before the update is handled.
*/
public void updateBurst(IManaBurst burst, ItemStack stack);
/**
* Called when the mana burst should do it's particles. Return false to not
* do any particles.
*/
public boolean doParticles(IManaBurst burst, ItemStack stack);
}
@@ -0,0 +1,26 @@
/**
* This class was created by <Vazkii>. 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 a
* Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License
* (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB)
*
* File Created @ [Jan 22, 2014, 4:59:05 PM (GMT)]
*/
package vazkii.botania.api.mana;
/**
* A TileEntity that implements this is considered a Mana Block.
* Just being a Mana Block doesn't mean much, look at the other IMana
* interfaces.
*/
public interface IManaBlock {
/**
* Gets the amount of mana currently in this block.
*/
public int getCurrentMana();
}
@@ -0,0 +1,43 @@
/**
* This class was created by <Vazkii>. 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 a
* Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License
* (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB)
*
* File Created @ [Jan 22, 2014, 5:01:19 PM (GMT)]
*/
package vazkii.botania.api.mana;
import vazkii.botania.api.internal.IManaBurst;
/**
* Any TileEntity that implements this is considered a mana collector, by
* which nearby generating flowers will pump mana into it.<br><br>
*
* <b>Implementation Instructions:</b><br>
* - Override invalidate() and onChunkUnload(), calling <i>ManaNetworkEvent.removeCollector(this);</i> on both.<br>
* - On the first tick of onUpdate(), call </i>ManaNetworkEvent.addCollector(this);<i>
*/
public interface IManaCollector extends IManaReceiver {
/**
* Called every tick on the client case the player is holding a Wand of the Forest.
*/
public void onClientDisplayTick();
/**
* Get the multiplier of mana to input into the block, 1.0 is the original amount of mana
* in the burst. 0.9, for example, is 90%, so 10% of the mana in the burst will get
* dissipated.
*/
public float getManaYieldMultiplier(IManaBurst burst);
/**
* Gets the maximum amount of mana this collector can have.
*/
public int getMaxMana();
}
@@ -0,0 +1,22 @@
/**
* This class was created by <Vazkii>. 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 a
* Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License
* (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB)
*
* File Created @ [Mar 10, 2014, 7:49:19 PM (GMT)]
*/
package vazkii.botania.api.mana;
/**
* Any TileEntity that implements this can be counted as a "ghost" block of
* sorts, that won't call the collision code for the mana bursts.
*/
public interface IManaCollisionGhost {
public boolean isGhost();
}
@@ -0,0 +1,69 @@
/**
* This class was created by <Vazkii>. 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 a
* Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License
* (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB)
*
* File Created @ [Mar 6, 2014, 9:07:40 AM (GMT)]
*/
package vazkii.botania.api.mana;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
/**
* An item that implements this can be counted as an item that can
* contain mana.
*/
public interface IManaItem {
/**
* Gets the amount of mana this item contains
*/
public int getMana(ItemStack stack);
/**
* Gets the max amount of mana this item can hold.
*/
public int getMaxMana(ItemStack stack);
/**
* Adds mana to this item.
*/
public void addMana(ItemStack stack, int mana);
/**
* Can this item receive mana from a mana Pool?
* @param pool The pool it's receiving mana from, can be casted to IManaPool.
* @see IManaPool#isOutputtingPower()
*/
public boolean canReceiveManaFromPool(ItemStack stack, TileEntity pool);
/**
* Can this item recieve mana from another item?
*/
public boolean canReceiveManaFromItem(ItemStack stack, ItemStack otherStack);
/**
* Can this item export mana to a mana Pool?
* @param pool The pool it's exporting mana to, can be casted to IManaPool.
* @see IManaPool#isOutputtingPower()
*/
public boolean canExportManaToPool(ItemStack stack,TileEntity pool);
/**
* Can this item export mana to another item?
*/
public boolean canExportManaToItem(ItemStack stack, ItemStack otherStack);
/**
* If this item simply does not export mana at all, set this to true. This is
* used to skip items that contain mana but can't export it when drawing the
* mana bar above the XP bar.
*/
public boolean isNoExport(ItemStack stack);
}
@@ -0,0 +1,31 @@
/**
* This class was created by <Vazkii>. 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 a
* Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License
* (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB)
*
* File Created @ [Jan 22, 2014, 5:03:09 PM (GMT)]
*/
package vazkii.botania.api.mana;
/**
* Any TileEntity that implements this is considered a Mana Pool,
* by which nearby functional flowers will pull mana from it.<br>
* Mana Distributors will also accept it as valid output.<br><br>
*
* <b>Implementation Instructions:</b><br>
* - Override invalidate() and onChunkUnload(), calling <i>ManaNetworkEvent.removePool(this);</i> on both.<br>
* - On the first tick of onUpdate(), call <i>ManaNetworkEvent.addPool(this);</i>
*/
public interface IManaPool extends IManaReceiver {
/**
* Returns false if the mana pool is accepting power from other power items,
* true if it's sending power into them.
*/
public boolean isOutputtingPower();
}
@@ -0,0 +1,35 @@
/**
* This class was created by <Vazkii>. 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 a
* Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License
* (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB)
*
* File Created @ [Jan 22, 2014, 4:55:00 PM (GMT)]
*/
package vazkii.botania.api.mana;
/**
* Any TileEntity that implements this can receive mana from mana bursts.
*/
public interface IManaReceiver extends IManaBlock {
/**
* Is this Mana Receiver is full? Being full means no mana bursts will be sent.
*/
public boolean isFull();
/**
* Called when this receiver receives mana.
*/
public void recieveMana(int mana);
/**
* Can this tile receive mana from bursts? Generally set to false for
* implementations of IManaCollector.
*/
public boolean canRecieveManaFromBursts();
}
@@ -0,0 +1,24 @@
/**
* This class was created by <Vazkii>. 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 a
* Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License
* (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB)
*
* File Created @ [May 16, 2014, 7:52:53 PM (GMT)]
*/
package vazkii.botania.api.mana;
import net.minecraft.world.World;
import vazkii.botania.api.internal.IManaBurst;
/**
* Have a block implement this class to make it do something when a mana burst collides with it.
*/
public interface IManaTrigger {
public void onBurstCollision(IManaBurst burst, World world, int x, int y, int z);
}
@@ -0,0 +1,26 @@
/**
* This class was created by <Vazkii>. 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 a
* Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License
* (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB)
*
* File Created @ [May 25, 2014, 7:32:10 PM (GMT)]
*/
package vazkii.botania.api.mana;
import net.minecraft.item.ItemStack;
/**
* Any item that implements this interface is an item that would use mana
* from the player's inventory. If there's any items in the inventory or
* equipped in either the baubles or armor inventories that implement
* this interface, a mana bar will be rendered.
*/
public interface IManaUsingItem {
public boolean usesMana(ItemStack stack);
}
@@ -0,0 +1,26 @@
/**
* This class was created by <Vazkii>. 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 a
* Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License
* (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB)
*
* File Created @ [Jul 2, 2014, 6:36:54 PM (GMT)]
*/
package vazkii.botania.api.mana;
import net.minecraft.util.IIcon;
import net.minecraft.world.World;
/**
* A block that implements this can provide an IIcon (block icons only)
* to be used as an overlay for the mana pool, similarly to the mana void
* and catalysts.
*/
public interface IPoolOverlayProvider {
public IIcon getIcon(World world, int x, int y, int z);
}
@@ -0,0 +1,24 @@
/**
* This class was created by <Vazkii>. 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 a
* Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License
* (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB)
*
* File Created @ [Jul 22, 2014, 2:26:14 PM (GMT)]
*/
package vazkii.botania.api.mana;
import net.minecraft.item.ItemStack;
/**
* Any Item that implements ILensEffect and this will have
* a check before being pulled by the Tiny Planet.
*/
public interface ITinyPlanetExcempt {
public boolean shouldPull(ItemStack stack);
}
@@ -0,0 +1,201 @@
/**
* This class was created by <Vazkii>. 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 a
* Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License
* (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB)
*
* File Created @ [Mar 13, 2014, 5:32:24 PM (GMT)]
*/
package vazkii.botania.api.mana;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import vazkii.botania.api.BotaniaAPI;
public final class ManaItemHandler {
/**
* Requests mana from items in a given player's inventory.
* @param manaToGet How much mana is to be requested, if less mana exists than this amount,
* the amount of mana existent will be returned instead, if you want exact values use requestManaExact.
* @param remove If true, the mana will be removed from the target item. Set to false to just check.
* @return The amount of mana received from the request.
*/
public static int requestMana(ItemStack stack, EntityPlayer player, int manaToGet, boolean remove) {
if(stack == null)
return 0;
IInventory mainInv = player.inventory;
IInventory baublesInv = BotaniaAPI.internalHandler.getBaublesInventory(player);
int invSize = mainInv.getSizeInventory();
int size = invSize;
if(baublesInv != null)
size += baublesInv.getSizeInventory();
for(int i = 0; i < size; i++) {
boolean useBaubles = i >= invSize;
IInventory inv = useBaubles ? baublesInv : mainInv;
ItemStack stackInSlot = inv.getStackInSlot(i - (useBaubles ? invSize : 0));
if(stackInSlot == stack)
continue;
if(stackInSlot != null && stackInSlot.getItem() instanceof IManaItem) {
IManaItem manaItem = (IManaItem) stackInSlot.getItem();
if(manaItem.canExportManaToItem(stackInSlot, stack) && manaItem.getMana(stackInSlot) > 0) {
if(stack.getItem() instanceof IManaItem && !((IManaItem) stack.getItem()).canReceiveManaFromItem(stack, stackInSlot))
continue;
int mana = Math.min(manaToGet, manaItem.getMana(stackInSlot));
if(remove)
manaItem.addMana(stackInSlot, -mana);
return mana;
}
}
}
return 0;
}
/**
* Requests an exact amount of mana from items in a given player's inventory.
* @param manaToGet How much mana is to be requested, if less mana exists than this amount,
* false will be returned instead, and nothing will happen.
* @param remove If true, the mana will be removed from the target item. Set to false to just check.
* @return If the request was succesful.
*/
public static boolean requestManaExact(ItemStack stack, EntityPlayer player, int manaToGet, boolean remove) {
if(stack == null)
return false;
IInventory mainInv = player.inventory;
IInventory baublesInv = BotaniaAPI.internalHandler.getBaublesInventory(player);
int invSize = mainInv.getSizeInventory();
int size = invSize;
if(baublesInv != null)
size += baublesInv.getSizeInventory();
for(int i = 0; i < size; i++) {
boolean useBaubles = i >= invSize;
IInventory inv = useBaubles ? baublesInv : mainInv;
ItemStack stackInSlot = inv.getStackInSlot(i - (useBaubles ? invSize : 0));
if(stackInSlot == stack)
continue;
if(stackInSlot != null && stackInSlot.getItem() instanceof IManaItem) {
IManaItem manaItemSlot = (IManaItem) stackInSlot.getItem();
if(manaItemSlot.canExportManaToItem(stackInSlot, stack) && manaItemSlot.getMana(stackInSlot) > manaToGet) {
if(stack.getItem() instanceof IManaItem && !((IManaItem) stack.getItem()).canReceiveManaFromItem(stack, stackInSlot))
continue;
if(remove)
manaItemSlot.addMana(stackInSlot, -manaToGet);
return true;
}
}
}
return false;
}
/**
* Dispatches mana to items in a given player's inventory. Note that this method
* does not automatically remove mana from the item which is exporting.
* @param manaToSend How much mana is to be sent.
* @param remove If true, the mana will be added from the target item. Set to false to just check.
* @return The amount of mana actually sent.
*/
public static int dispatchMana(ItemStack stack, EntityPlayer player, int manaToSend, boolean add) {
if(stack == null)
return 0;
IInventory mainInv = player.inventory;
IInventory baublesInv = BotaniaAPI.internalHandler.getBaublesInventory(player);
int invSize = mainInv.getSizeInventory();
int size = invSize;
if(baublesInv != null)
size += baublesInv.getSizeInventory();
for(int i = 0; i < size; i++) {
boolean useBaubles = i >= invSize;
IInventory inv = useBaubles ? baublesInv : mainInv;
ItemStack stackInSlot = inv.getStackInSlot(i - (useBaubles ? invSize : 0));
if(stackInSlot == stack)
continue;
if(stackInSlot != null && stackInSlot.getItem() instanceof IManaItem) {
IManaItem manaItemSlot = (IManaItem) stackInSlot.getItem();
if(manaItemSlot.canReceiveManaFromItem(stackInSlot, stack)) {
if(stack.getItem() instanceof IManaItem && !((IManaItem) stack.getItem()).canExportManaToItem(stack, stackInSlot))
continue;
int received = 0;
if(manaItemSlot.getMana(stackInSlot) + manaToSend <= manaItemSlot.getMaxMana(stackInSlot))
received = manaToSend;
else received = manaToSend - (manaItemSlot.getMana(stackInSlot) + manaToSend - manaItemSlot.getMaxMana(stackInSlot));
if(add)
manaItemSlot.addMana(stackInSlot, manaToSend);
return received;
}
}
}
return 0;
}
/**
* Dispatches an exact amount of mana to items in a given player's inventory. Note that this method
* does not automatically remove mana from the item which is exporting.
* @param manaToSend How much mana is to be sent.
* @param remove If true, the mana will be added from the target item. Set to false to just check.
* @return If an item received the mana sent.
*/
public static boolean dispatchManaExact(ItemStack stack, EntityPlayer player, int manaToSend, boolean add) {
if(stack == null)
return false;
IInventory mainInv = player.inventory;
IInventory baublesInv = BotaniaAPI.internalHandler.getBaublesInventory(player);
int invSize = mainInv.getSizeInventory();
int size = invSize;
if(baublesInv != null)
size += baublesInv.getSizeInventory();
for(int i = 0; i < size; i++) {
boolean useBaubles = i >= invSize;
IInventory inv = useBaubles ? baublesInv : mainInv;
ItemStack stackInSlot = inv.getStackInSlot(i - (useBaubles ? invSize : 0));
if(stackInSlot == stack)
continue;
if(stackInSlot != null && stackInSlot.getItem() instanceof IManaItem) {
IManaItem manaItemSlot = (IManaItem) stackInSlot.getItem();
if(manaItemSlot.getMana(stackInSlot) + manaToSend <= manaItemSlot.getMaxMana(stackInSlot) && manaItemSlot.canReceiveManaFromItem(stackInSlot, stack)) {
if(stack.getItem() instanceof IManaItem && !((IManaItem) stack.getItem()).canExportManaToItem(stack, stackInSlot))
continue;
if(add)
manaItemSlot.addMana(stackInSlot, manaToSend);
return true;
}
}
}
return false;
}
}
@@ -0,0 +1,57 @@
/**
* This class was created by <Vazkii>. 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 a
* Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License
* (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB)
*
* File Created @ [Jan 22, 2014, 5:04:30 PM (GMT)]
*/
package vazkii.botania.api.mana;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.MinecraftForge;
import cpw.mods.fml.common.eventhandler.Event;
public class ManaNetworkEvent extends Event {
public final TileEntity tile;
public final ManaBlockType type;
public final Action action;
public ManaNetworkEvent(TileEntity tile, ManaBlockType type, Action action) {
this.tile = tile;
this.type = type;
this.action = action;
}
public static void addCollector(TileEntity tile) {
ManaNetworkEvent event = new ManaNetworkEvent(tile, ManaBlockType.COLLECTOR, Action.ADD);
MinecraftForge.EVENT_BUS.post(event);
}
public static void removeCollector(TileEntity tile) {
ManaNetworkEvent event = new ManaNetworkEvent(tile, ManaBlockType.COLLECTOR, Action.REMOVE);
MinecraftForge.EVENT_BUS.post(event);
}
public static void addPool(TileEntity tile) {
ManaNetworkEvent event = new ManaNetworkEvent(tile, ManaBlockType.POOL, Action.ADD);
MinecraftForge.EVENT_BUS.post(event);
}
public static void removePool(TileEntity tile) {
ManaNetworkEvent event = new ManaNetworkEvent(tile, ManaBlockType.POOL, Action.REMOVE);
MinecraftForge.EVENT_BUS.post(event);
}
public enum ManaBlockType {
POOL, COLLECTOR
}
public enum Action {
REMOVE, ADD
}
}
@@ -0,0 +1,15 @@
package vazkii.botania.api.mana;
import net.minecraft.tileentity.TileEntity;
public class TileSignature {
public final TileEntity tile;
public final boolean remoteWorld;
public TileSignature(TileEntity tile, boolean remoteWorld) {
this.tile = tile;
this.remoteWorld = remoteWorld;
}
}
@@ -0,0 +1,54 @@
/**
* This class was created by <Vazkii>. 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 a
* Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License
* (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB)
*
* File Created @ [Aug 21, 2014, 5:44:13 PM (GMT)]
*/
package vazkii.botania.api.mana.spark;
import net.minecraft.item.ItemStack;
import vazkii.botania.api.mana.IManaReceiver;
/**
* A TileEntity that implements this can have a Spark attached to it.
* For the Spark to be allowed to have upgrades, it needs to be an IManaPool.
*/
public interface ISparkAttachable extends IManaReceiver {
/**
* Can this block have a Spark attached to it. Note that this will not
* unattach the Spark if it's changed later.
*/
public boolean canAttachSpark(ItemStack stack);
/**
* Called when the Spark is attached.
*/
public void attachSpark(ISparkEntity entity);
/**
* Gets the Spark that is attached to this block. A common implementation is
* to check for Spark entities above:
*
List<ISparkEntity> sparks = worldObj.getEntitiesWithinAABB(ISparkEntity.class, AxisAlignedBB.getBoundingBox(xCoord, yCoord + 1, zCoord, xCoord + 1, yCoord + 2, zCoord + 1));
if(sparks.size() == 1) {
Entity e = (Entity) sparks.get(0);
return (ISparkEntity) e;
}
return null;
*/
public ISparkEntity getAttachedSpark();
/**
* Return true if this Tile no longer requires mana and all Sparks
* transferring mana to it should cancel their transfer.
*/
public boolean areIncomingTranfersDone();
}
@@ -0,0 +1,65 @@
/**
* This class was created by <Vazkii>. 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 a
* Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License
* (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB)
*
* File Created @ [Aug 21, 2014, 5:44:07 PM (GMT)]
*/
package vazkii.botania.api.mana.spark;
import java.util.Collection;
/**
* An Entity that implements this is considered a Spark.
*/
public interface ISparkEntity {
/**
* Which TileEntity is this Spark attached to? A common implementation is checking the block below.
*
int x = MathHelper.floor_double(posX);
int y = MathHelper.floor_double(posY) - 1;
int z = MathHelper.floor_double(posZ);
TileEntity tile = worldObj.getTileEntity(x, y, z);
if(tile != null && tile instanceof ISparkAttachable)
return (ISparkAttachable) tile;
return null;
*/
public ISparkAttachable getAttachedTile();
/**
* Gets a collection of all Sparks this is tranfering to.
*/
public Collection<ISparkEntity> getTransfers();
/**
* Registers the Spark passed in as a Spark meant for mana to be transfered towards.
*/
public void registerTransfer(ISparkEntity entity);
/**
* Gets which upgrade is in this Spark.<br>
* 0: None<br>
* 1: Dispersive<br>
* 2: Dominant<br>
* 3: Recessive<br>
* 4: Isolated
*/
public int getUpgrade();
/**
* Sets the upgrade on this Spark. See {@link ISparkEntity#getUpgrade}
*/
public void setUpgrade(int upgrade);
/**
* See {@link ISparkAttachable#areIncomingTranfersDone()}
*/
public boolean areIncomingTransfersDone();
}
@@ -0,0 +1,33 @@
/**
* This class was created by <Vazkii>. 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 a
* Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License
* (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB)
*
* File Created @ [Aug 21, 2014, 7:16:11 PM (GMT)]
*/
package vazkii.botania.api.mana.spark;
import java.util.List;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.world.World;
public final class SparkHelper {
public static final int SPARK_SCAN_RANGE = 12;
public static List<ISparkEntity> getSparksAround(World world, double x, double y, double z) {
return SparkHelper.getEntitiesAround(ISparkEntity.class, world, x, y, z);
}
public static <T> List<T> getEntitiesAround(Class<? extends T> clazz, World world, double x, double y, double z) {
int r = SPARK_SCAN_RANGE;
List<T> entities = world.getEntitiesWithinAABB(clazz, AxisAlignedBB.getBoundingBox(x - r, y - r, z - r, x + r, y + r, z + r));
return entities;
}
}
@@ -0,0 +1,4 @@
@API(owner = "Botania", apiVersion = "23", provides = "BotaniaAPI")
package vazkii.botania.api;
import cpw.mods.fml.common.API;
@@ -0,0 +1,14 @@
package vazkii.botania.api.recipe;
import net.minecraft.item.ItemStack;
/**
* Any Item that implements this is classified as an "Elven Item", by which,
* it'll not go through the alfheim portal. Any item that comes out of it
* must implement this or it'll just go back in.
*/
public interface IElvenItem {
public boolean isElvenItem(ItemStack stack);
}
@@ -0,0 +1,26 @@
/**
* This class was created by <Vazkii>. 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 a
* Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License
* (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB)
*
* File Created @ [Feb 15, 2014, 2:36:35 PM (GMT)]
*/
package vazkii.botania.api.recipe;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
/**
* Have an Item implement this to allow it to be used in the Petal Apothecary.
*/
public interface IFlowerComponent {
public boolean canFit(ItemStack stack, IInventory apothecary);
public int getParticleColor(ItemStack stack);
}
@@ -0,0 +1,115 @@
/**
* This class was created by <Vazkii>. 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 a
* Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License
* (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB)
*
* File Created @ [Nov 1, 2014, 8:52:00 PM (GMT)]
*/
package vazkii.botania.api.recipe;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.init.Items;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraftforge.oredict.OreDictionary;
import vazkii.botania.api.brew.Brew;
import vazkii.botania.api.brew.IBrewContainer;
public class RecipeBrew {
Brew brew;
List<Object> inputs;
public RecipeBrew(Brew brew, Object... inputs) {
this.brew = brew;
List<Object> inputsToSet = new ArrayList();
for(Object obj : inputs) {
if(obj instanceof String || obj instanceof ItemStack)
inputsToSet.add(obj);
else throw new IllegalArgumentException("Invalid input");
}
this.inputs = inputsToSet;
}
public boolean matches(IInventory inv) {
List<Object> inputsMissing = new ArrayList(inputs);
for(int i = 0; i < inv.getSizeInventory(); i++) {
ItemStack stack = inv.getStackInSlot(i);
if(stack == null)
break;
if(stack.getItem() instanceof IBrewContainer)
continue;
int stackIndex = -1, oredictIndex = -1;
for(int j = 0; j < inputsMissing.size(); j++) {
Object input = inputsMissing.get(j);
if(input instanceof String) {
List<ItemStack> validStacks = OreDictionary.getOres((String) input);
boolean found = false;
for(ItemStack ostack : validStacks) {
ItemStack cstack = ostack.copy();
if(cstack.getItemDamage() == Short.MAX_VALUE)
cstack.setItemDamage(stack.getItemDamage());
if(stack.isItemEqual(cstack)) {
oredictIndex = j;
found = true;
break;
}
}
if(found)
break;
} else if(input instanceof ItemStack && simpleAreStacksEqual((ItemStack) input, stack)) {
stackIndex = j;
break;
}
}
if(stackIndex != -1)
inputsMissing.remove(stackIndex);
else if(oredictIndex != -1)
inputsMissing.remove(oredictIndex);
else return false;
}
return inputsMissing.isEmpty();
}
boolean simpleAreStacksEqual(ItemStack stack, ItemStack stack2) {
return stack.getItem() == stack2.getItem() && stack.getItemDamage() == stack2.getItemDamage();
}
public List<Object> getInputs() {
return new ArrayList(inputs);
}
public Brew getBrew() {
return brew;
}
public int getManaUsage() {
return brew.getManaCost();
}
public ItemStack getOutput(ItemStack stack) {
if(stack == null || !(stack.getItem() instanceof IBrewContainer))
return new ItemStack(Items.glass_bottle); // Fallback...
IBrewContainer container = (IBrewContainer) stack.getItem();
return container.getItemForBrew(brew, stack);
}
}
@@ -0,0 +1,94 @@
package vazkii.botania.api.recipe;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.item.ItemStack;
import net.minecraftforge.oredict.OreDictionary;
public class RecipeElvenTrade {
ItemStack output;
List<Object> inputs;
public RecipeElvenTrade(ItemStack output, Object... inputs) {
this.output = output;
List<Object> inputsToSet = new ArrayList();
for(Object obj : inputs) {
if(obj instanceof String || obj instanceof ItemStack)
inputsToSet.add(obj);
else throw new IllegalArgumentException("Invalid input");
}
this.inputs = inputsToSet;
}
public boolean matches(List<ItemStack> stacks, boolean remove) {
List<Object> inputsMissing = new ArrayList(inputs);
List<ItemStack> stacksToRemove = new ArrayList();
for(ItemStack stack : stacks) {
if(stack == null) {
continue;
}
if(inputsMissing.isEmpty())
break;
int stackIndex = -1, oredictIndex = -1;
for(int j = 0; j < inputsMissing.size(); j++) {
Object input = inputsMissing.get(j);
if(input instanceof String) {
List<ItemStack> validStacks = OreDictionary.getOres((String) input);
boolean found = false;
for(ItemStack ostack : validStacks) {
ItemStack cstack = ostack.copy();
if(cstack.getItemDamage() == Short.MAX_VALUE)
cstack.setItemDamage(stack.getItemDamage());
if(stack.isItemEqual(cstack)) {
if(!stacksToRemove.contains(stack))
stacksToRemove.add(stack);
oredictIndex = j;
found = true;
break;
}
}
if(found)
break;
} else if(input instanceof ItemStack && simpleAreStacksEqual((ItemStack) input, stack)) {
if(!stacksToRemove.contains(stack))
stacksToRemove.add(stack);
stackIndex = j;
break;
}
}
if(stackIndex != -1)
inputsMissing.remove(stackIndex);
else if(oredictIndex != -1)
inputsMissing.remove(oredictIndex);
}
if(remove)
for(ItemStack r : stacksToRemove)
stacks.remove(r);
return inputsMissing.isEmpty();
}
boolean simpleAreStacksEqual(ItemStack stack, ItemStack stack2) {
return stack.getItem() == stack2.getItem() && stack.getItemDamage() == stack2.getItemDamage();
}
public List<Object> getInputs() {
return new ArrayList(inputs);
}
public ItemStack getOutput() {
return output;
}
}
@@ -0,0 +1,87 @@
/**
* This class was created by <Vazkii>. 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 a
* Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License
* (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB)
*
* File Created @ [Jan 30, 2014, 5:57:07 PM (GMT)]
*/
package vazkii.botania.api.recipe;
import java.util.List;
import net.minecraft.item.ItemStack;
import net.minecraftforge.oredict.OreDictionary;
public class RecipeManaInfusion {
ItemStack output;
Object input;
int mana;
boolean isAlchemy = false;
boolean isConjuration = false;
public RecipeManaInfusion(ItemStack output, Object input, int mana) {
this.output = output;
this.input = input;
this.mana = mana;
}
public boolean matches(ItemStack stack) {
if(input instanceof ItemStack) {
ItemStack inputCopy = ((ItemStack) input).copy();
if(inputCopy.getItemDamage() == Short.MAX_VALUE)
inputCopy.setItemDamage(stack.getItemDamage());
return stack.isItemEqual((ItemStack) inputCopy);
}
if(input instanceof String) {
List<ItemStack> validStacks = OreDictionary.getOres((String) input);
for(ItemStack ostack : validStacks) {
ItemStack cstack = ostack.copy();
if(cstack.getItemDamage() == Short.MAX_VALUE)
cstack.setItemDamage(stack.getItemDamage());
if(stack.isItemEqual(cstack))
return true;
}
}
return false;
}
public void setAlchemy(boolean alchemy) {
isAlchemy = alchemy;
}
public boolean isAlchemy() {
return isAlchemy;
}
public void setConjuration(boolean conjuration) {
isConjuration = conjuration;
}
public boolean isConjuration() {
return isConjuration;
}
public Object getInput() {
return input;
}
public ItemStack getOutput() {
return output;
}
public int getManaToConsume() {
return mana;
}
}
@@ -0,0 +1,97 @@
/**
* This class was created by <Vazkii>. 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 a
* Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License
* (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB)
*
* File Created @ [Jan 22, 2014, 2:02:44 PM (GMT)]
*/
package vazkii.botania.api.recipe;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraftforge.oredict.OreDictionary;
public class RecipePetals {
ItemStack output;
List<Object> inputs;
public RecipePetals(ItemStack output, Object... inputs) {
this.output = output;
List<Object> inputsToSet = new ArrayList();
for(Object obj : inputs) {
if(obj instanceof String || obj instanceof ItemStack)
inputsToSet.add(obj);
else throw new IllegalArgumentException("Invalid input");
}
this.inputs = inputsToSet;
}
public boolean matches(IInventory inv) {
List<Object> inputsMissing = new ArrayList(inputs);
for(int i = 0; i < inv.getSizeInventory(); i++) {
ItemStack stack = inv.getStackInSlot(i);
if(stack == null)
break;
int stackIndex = -1, oredictIndex = -1;
for(int j = 0; j < inputsMissing.size(); j++) {
Object input = inputsMissing.get(j);
if(input instanceof String) {
List<ItemStack> validStacks = OreDictionary.getOres((String) input);
boolean found = false;
for(ItemStack ostack : validStacks) {
ItemStack cstack = ostack.copy();
if(cstack.getItemDamage() == Short.MAX_VALUE)
cstack.setItemDamage(stack.getItemDamage());
if(stack.isItemEqual(cstack)) {
oredictIndex = j;
found = true;
break;
}
}
if(found)
break;
} else if(input instanceof ItemStack && simpleAreStacksEqual((ItemStack) input, stack)) {
stackIndex = j;
break;
}
}
if(stackIndex != -1)
inputsMissing.remove(stackIndex);
else if(oredictIndex != -1)
inputsMissing.remove(oredictIndex);
else return false;
}
return inputsMissing.isEmpty();
}
boolean simpleAreStacksEqual(ItemStack stack, ItemStack stack2) {
return stack.getItem() == stack2.getItem() && stack.getItemDamage() == stack2.getItemDamage();
}
public List<Object> getInputs() {
return new ArrayList(inputs);
}
public ItemStack getOutput() {
return output;
}
}
@@ -0,0 +1,29 @@
/**
* This class was created by <Vazkii>. 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 a
* Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License
* (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB)
*
* File Created @ [Feb 5, 2014, 1:41:14 PM (GMT)]
*/
package vazkii.botania.api.recipe;
import net.minecraft.item.ItemStack;
public class RecipeRuneAltar extends RecipePetals {
int mana;
public RecipeRuneAltar(ItemStack output, int mana, Object... inputs) {
super(output, inputs);
this.mana = mana;
}
public int getManaUsage() {
return mana;
}
}
@@ -0,0 +1,21 @@
/**
* This class was created by <Vazkii>. 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 a
* Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License
* (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB)
*
* File Created @ [Jan 22, 2014, 7:12:28 PM (GMT)]
*/
package vazkii.botania.api.subtile;
/**
* The special flowers in botania implement this. Used for cases where
* BlockFlower would be checked against, but isn't convenient for
* the special flowers with effects. For Azanor and Lycaon.
*/
public interface ISpecialFlower {
}
@@ -0,0 +1,30 @@
/**
* This class was created by <Vazkii>. 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 a
* Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License
* (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB)
*
* File Created @ [Aug 26, 2014, 5:42:16 PM (GMT)]
*/
package vazkii.botania.api.subtile;
/**
* A TileEntity that implements this contains a SubTileEntity.
*/
public interface ISubTileContainer {
/**
* Gets the SubTile in this block. Generally shouldn't return null, but in that
* case use the fallback DummySubTile.
*/
public SubTileEntity getSubTile();
/**
* Sets the SubTile on this block from it's name.
*/
public void setSubTile(String name);
}
@@ -0,0 +1,126 @@
/**
* This class was created by <Vazkii>. 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 a
* Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License
* (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB)
*
* File Created @ [Jan 24, 2014, 3:59:06 PM (GMT)]
*/
package vazkii.botania.api.subtile;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ChunkCoordinates;
import net.minecraft.util.IIcon;
import vazkii.botania.api.BotaniaAPI;
import vazkii.botania.api.lexicon.LexiconEntry;
import vazkii.botania.api.wand.IWandBindable;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
/**
* A Sub-TileEntity, this is used for the flower system. Make sure to map subclasses
* of this using BotaniaAPI.mapSubTile(String, Class). Any subclass of this must have
* a no parameter constructor.
*/
public class SubTileEntity {
protected TileEntity supertile;
/** The Tag items should use to store which sub tile they are. **/
public static final String TAG_TYPE = "type";
public void setSupertile(TileEntity tile) {
supertile = tile;
}
public boolean canUpdate() {
return false;
}
public void onUpdate() { }
/**
* Writes some extra data to a network packet. This data is read
* by readFromPacketNBT on the client that receives the packet.
* Note: This method is also used to write to the world NBT.
*/
public void writeToPacketNBT(NBTTagCompound cmp) { }
/**
* Reads data from a network packet. This data is written by
* writeToPacketNBT in the server. Note: This method is also used
* to read from the world NBT.
*/
public void readFromPacketNBT(NBTTagCompound cmp) { }
public void sync() {
supertile.getWorldObj().markBlockForUpdate(supertile.xCoord, supertile.yCoord, supertile.zCoord);
}
public String getUnlocalizedName() {
return BotaniaAPI.getSubTileStringMapping(getClass());
}
/**
* Gets the icon for this SubTileEntity, this is a block icon.
*/
@SideOnly(Side.CLIENT)
public IIcon getIcon() {
return BotaniaAPI.internalHandler.getSubTileIconForName(getUnlocalizedName());
}
/**
* Called when a Wand of the Forest is used on this sub tile. Note that the
* player parameter can be null if this is called from a dispenser.
*/
public boolean onWanded(EntityPlayer player, ItemStack wand) {
return false;
}
/**
* Gets which Lexicon Entry to open when this sub tile is right clicked with a lexicon.
*/
public LexiconEntry getEntry() {
return null;
}
/**
* Gets the block coordinates this is bound to, for use with the wireframe render
* when the sub tile is being hovered with a wand of the forest.
*/
@SideOnly(Side.CLIENT)
public ChunkCoordinates getBinding() {
return null;
}
/**
* @see IWandBindable#canSelect(EntityPlayer, ItemStack, int, int, int, int)
*/
public boolean canSelect(EntityPlayer player, ItemStack wand, int x, int y, int z, int side) {
return false;
}
/**
* @see IWandBindable#bindTo(EntityPlayer, ItemStack, int, int, int, int)
*/
public boolean bindTo(EntityPlayer player, ItemStack wand, int x, int y, int z, int side) {
return false;
}
/**
* Called on the client when the block being pointed at is the one with this sub tile.
* Used to render a HUD portraying some data from this sub tile.
*/
@SideOnly(Side.CLIENT)
public void renderHUD(Minecraft mc, ScaledResolution res) {
// NO-OP
}
}
@@ -0,0 +1,212 @@
/**
* This class was created by <Vazkii>. 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 a
* Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License
* (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB)
*
* File Created @ [Jan 24, 2014, 8:03:44 PM (GMT)]
*/
package vazkii.botania.api.subtile;
import java.awt.Color;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.entity.player.EntityPlayer;
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.minecraftforge.common.util.ForgeDirection;
import vazkii.botania.api.BotaniaAPI;
import vazkii.botania.api.internal.IManaNetwork;
import vazkii.botania.api.mana.IManaPool;
/**
* The basic class for a Functional Flower.
*/
public class SubTileFunctional extends SubTileEntity {
private static final String TAG_MANA = "mana";
private static final String TAG_POOL_X = "poolX";
private static final String TAG_POOL_Y = "poolY";
private static final String TAG_POOL_Z = "poolZ";
public int mana;
public int redstoneSignal = 0;
int sizeLastCheck = -1;
TileEntity linkedPool = null;
public int knownMana = -1;
ChunkCoordinates cachedPoolCoordinates = null;
@Override
public boolean canUpdate() {
return true;
}
/**
* If set to true, redstoneSignal will be updated every tick.
*/
public boolean acceptsRedstone() {
return false;
}
@Override
public void onUpdate() {
super.onUpdate();
linkPool();
if(linkedPool != null) {
IManaPool pool = (IManaPool) linkedPool;
int manaInPool = pool.getCurrentMana();
int manaMissing = getMaxMana() - mana;
int manaToRemove = Math.min(manaMissing, manaInPool);
pool.recieveMana(-manaToRemove);
addMana(manaToRemove);
}
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());
if(Math.random() > particleChance)
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);
}
}
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;
}
cachedPoolCoordinates = null;
}
}
if(!needsNew) {
TileEntity tileAt = supertile.getWorldObj().getTileEntity(linkedPool.xCoord, linkedPool.yCoord, linkedPool.zCoord);
if(!(tileAt instanceof IManaPool)) {
linkedPool = null;
needsNew = true;
} else linkedPool = tileAt;
}
if(needsNew) {
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);
sizeLastCheck = size;
}
}
}
public void addMana(int mana) {
this.mana = Math.min(getMaxMana(), this.mana + mana);
}
@Override
public boolean onWanded(EntityPlayer player, ItemStack wand) {
if(player == null)
return false;
knownMana = mana;
player.worldObj.playSoundAtEntity(player, "botania:ding", 0.1F, 1F);
return super.onWanded(player, wand);
}
public int getMaxMana() {
return 20;
}
public int getColor() {
return 0xFFFFFF;
}
@Override
public void readFromPacketNBT(NBTTagCompound cmp) {
mana = cmp.getInteger(TAG_MANA);
int x = cmp.getInteger(TAG_POOL_X);
int y = cmp.getInteger(TAG_POOL_Y);
int z = cmp.getInteger(TAG_POOL_Z);
cachedPoolCoordinates = 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;
cmp.setInteger(TAG_POOL_X, x);
cmp.setInteger(TAG_POOL_Y, y);
cmp.setInteger(TAG_POOL_Z, z);
}
@Override
public ChunkCoordinates getBinding() {
if(linkedPool == null)
return null;
return new ChunkCoordinates(linkedPool.xCoord, linkedPool.yCoord, linkedPool.zCoord);
}
@Override
public boolean canSelect(EntityPlayer player, ItemStack wand, int x, int y, int z, int side) {
return true;
}
@Override
public boolean bindTo(EntityPlayer player, ItemStack wand, int x, int y, int z, int side) {
int range = 10;
range *= range;
double dist = (x - supertile.xCoord) * (x - supertile.xCoord) + (y - supertile.yCoord) * (y - supertile.yCoord) + (z - supertile.zCoord) * (z - supertile.zCoord);
if(range >= dist) {
TileEntity tile = player.worldObj.getTileEntity(x, y, z);
if(tile instanceof IManaPool) {
linkedPool = tile;
return true;
}
}
return false;
}
@Override
public void renderHUD(Minecraft mc, ScaledResolution res) {
String name = StatCollector.translateToLocal("tile.botania:flower." + getUnlocalizedName() + ".name");
int color = 0x66000000 | getColor();
BotaniaAPI.internalHandler.drawSimpleManaHUD(color, knownMana, getMaxMana(), name, res);
}
}
@@ -0,0 +1,245 @@
/**
* This class was created by <Vazkii>. 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 a
* Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License
* (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB)
*
* File Created @ [Jan 24, 2014, 8:03:36 PM (GMT)]
*/
package vazkii.botania.api.subtile;
import java.awt.Color;
import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.entity.player.EntityPlayer;
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 vazkii.botania.api.BotaniaAPI;
import vazkii.botania.api.internal.IManaNetwork;
import vazkii.botania.api.mana.IManaCollector;
/**
* The basic class for a Generating Flower.
*/
public class SubTileGenerating extends SubTileEntity {
private static final String TAG_MANA = "mana";
private static final String TAG_TICKS_EXISTED = "ticksExisted";
private static final String TAG_COLLECTOR_X = "collectorX";
private static final String TAG_COLLECTOR_Y = "collectorY";
private static final String TAG_COLLECTOR_Z = "collectorZ";
protected int mana;
int ticksExisted = 0;
int sizeLastCheck = -1;
protected TileEntity linkedCollector = null;
public int knownMana = -1;
ChunkCoordinates cachedCollectorCoordinates = null;
@Override
public boolean canUpdate() {
return true;
}
@Override
public void onUpdate() {
super.onUpdate();
linkCollector();
if(canGeneratePassively()) {
int delay = getDelayBetweenPassiveGeneration();
if(delay > 0 && supertile.getWorldObj().getWorldTime() % delay == 0) {
if(shouldSyncPassiveGeneration())
sync();
addMana(getValueForPassiveGeneration());
}
}
emptyManaIntoCollector();
if(supertile.getWorldObj().isRemote) {
double particleChance = 1F - (double) mana / (double) getMaxMana() / 3.5F;
Color color = new Color(getColor());
if(Math.random() > particleChance)
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);
}
if(!supertile.getWorldObj().isRemote) {
++ticksExisted;
int muhBalance = BotaniaAPI.internalHandler.getPassiveFlowerDecay();
if(isPassiveFlower() && muhBalance > 0 && ticksExisted > muhBalance) {
supertile.getWorldObj().playAuxSFX(2001, supertile.xCoord, supertile.yCoord, supertile.zCoord, Block.getIdFromBlock(supertile.getBlockType()));
supertile.getWorldObj().setBlockToAir(supertile.xCoord, supertile.yCoord, supertile.zCoord);
}
}
}
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;
}
cachedCollectorCoordinates = null;
}
}
if(!needsNew) {
TileEntity tileAt = supertile.getWorldObj().getTileEntity(linkedCollector.xCoord, linkedCollector.yCoord, linkedCollector.zCoord);
if(!(tileAt instanceof IManaCollector)) {
linkedCollector = null;
needsNew = true;
} else linkedCollector = tileAt;
}
if(needsNew) {
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);
sizeLastCheck = size;
}
}
}
public void addMana(int mana) {
this.mana = Math.min(getMaxMana(), this.mana + mana);
}
public void emptyManaIntoCollector() {
if(linkedCollector != null) {
IManaCollector collector = (IManaCollector) linkedCollector;
if(!collector.isFull() && mana > 0) {
int manaval = Math.min(mana, collector.getMaxMana() - collector.getCurrentMana());
mana -= manaval;
collector.recieveMana(manaval);
}
}
}
public boolean isPassiveFlower() {
return false;
}
public boolean shouldSyncPassiveGeneration() {
return false;
}
public boolean canGeneratePassively() {
return false;
}
public int getDelayBetweenPassiveGeneration() {
return 20;
}
public int getValueForPassiveGeneration() {
return 1;
}
@Override
public boolean onWanded(EntityPlayer player, ItemStack wand) {
if(player == null)
return false;
if(!player.worldObj.isRemote)
sync();
knownMana = mana;
player.worldObj.playSoundAtEntity(player, "botania:ding", 0.1F, 1F);
return super.onWanded(player, wand);
}
public int getMaxMana() {
return 20;
}
public int getColor() {
return 0xFFFFFF;
}
@Override
public void readFromPacketNBT(NBTTagCompound cmp) {
mana = cmp.getInteger(TAG_MANA);
if(!cmp.hasKey(TAG_TICKS_EXISTED))
ticksExisted = cmp.getInteger(TAG_TICKS_EXISTED);
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);
}
@Override
public void writeToPacketNBT(NBTTagCompound cmp) {
cmp.setInteger(TAG_MANA, mana);
cmp.setInteger(TAG_TICKS_EXISTED, ticksExisted);
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);
}
@Override
public ChunkCoordinates getBinding() {
if(linkedCollector == null)
return null;
return new ChunkCoordinates(linkedCollector.xCoord, linkedCollector.yCoord, linkedCollector.zCoord);
}
@Override
public boolean canSelect(EntityPlayer player, ItemStack wand, int x, int y, int z, int side) {
return true;
}
@Override
public boolean bindTo(EntityPlayer player, ItemStack wand, int x, int y, int z, int side) {
int range = 6;
range *= range;
double dist = (x - supertile.xCoord) * (x - supertile.xCoord) + (y - supertile.yCoord) * (y - supertile.yCoord) + (z - supertile.zCoord) * (z - supertile.zCoord);
if(range >= dist) {
TileEntity tile = player.worldObj.getTileEntity(x, y, z);
if(tile instanceof IManaCollector) {
linkedCollector = tile;
return true;
}
}
return false;
}
@Override
public void renderHUD(Minecraft mc, ScaledResolution res) {
String name = StatCollector.translateToLocal("tile.botania:flower." + getUnlocalizedName() + ".name");
int color = 0x66000000 | getColor();
BotaniaAPI.internalHandler.drawSimpleManaHUD(color, knownMana, getMaxMana(), name, res);
}
}
@@ -0,0 +1,58 @@
/**
* This class was created by <Vazkii>. 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 a
* Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License
* (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB)
*
* File Created @ [Oct 17, 2014, 5:34:35 PM (GMT)]
*/
package vazkii.botania.api.subtile.signature;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.item.ItemStack;
import net.minecraft.util.IIcon;
import vazkii.botania.api.BotaniaAPI;
/**
* A basic (and fallback) implementation of SubTileSignature.
*/
public class BasicSignature extends SubTileSignature {
final String name;
public BasicSignature(String name) {
this.name = name;
}
@Override
public void registerIcons(IIconRegister register) {
BotaniaAPI.internalHandler.registerBasicSignatureIcons(name, register);
}
@Override
public IIcon getIconForStack(ItemStack stack) {
return BotaniaAPI.internalHandler.getSubTileIconForName(name);
}
@Override
public String getUnlocalizedNameForStack(ItemStack stack) {
return unlocalizedName("");
}
@Override
public String getUnlocalizedLoreTextForStack(ItemStack stack) {
return unlocalizedName(".reference");
}
public String getName() {
return name;
}
private String unlocalizedName(String end) {
return "tile.botania:" + SubTileSignature.SPECIAL_FLOWER_PREFIX + name + end;
}
}
@@ -0,0 +1,47 @@
/**
* This class was created by <Vazkii>. 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 a
* Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License
* (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB)
*
* File Created @ [Oct 17, 2014, 5:29:26 PM (GMT)]
*/
package vazkii.botania.api.subtile.signature;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.item.ItemStack;
import net.minecraft.util.IIcon;
/**
* A singleton instance for a SubTileEntity, this is called for a few methods.
*/
public abstract class SubTileSignature {
public static final String SPECIAL_FLOWER_PREFIX = "flower.";
/**
* Equivalent to Block.registerBlockIcons.
*/
public abstract void registerIcons(IIconRegister register);
/**
* Gets the icon to display for the flower item.
*/
public abstract IIcon getIconForStack(ItemStack stack);
/**
* Gets the display name for the flower item.
*/
public abstract String getUnlocalizedNameForStack(ItemStack stack);
/**
* Gets the lore text for the flower item, displayed in the item's tooltip.
* If you do not want a reference return a key that does not have localization such
* as "botaniamisc.noloc".
*/
public abstract String getUnlocalizedLoreTextForStack(ItemStack stack);
}
@@ -0,0 +1,18 @@
package vazkii.botania.api.wand;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ChunkCoordinates;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
/**
* The item equivalent of ITileBound, renders when the
* item is in hand.
* @see ITileBound
*/
public interface ICoordBoundItem {
@SideOnly(Side.CLIENT)
public ChunkCoordinates getBinding(ItemStack stack);
}
@@ -0,0 +1,31 @@
/**
* This class was created by <Vazkii>. 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 a
* Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License
* (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB)
*
* File Created @ [Mar 24, 2014, 6:47:53 PM (GMT)]
*/
package vazkii.botania.api.wand;
import net.minecraft.util.ChunkCoordinates;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
/**
* Any TileEntity that implements this is technically bound
* to something, and the binding will be shown when hovering
* over with a Wand of the Forest.
*/
public interface ITileBound {
/**
* Gets where this block is bound to, can return null.
*/
@SideOnly(Side.CLIENT)
public ChunkCoordinates getBinding();
}
@@ -0,0 +1,35 @@
/**
* This class was created by <Vazkii>. 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 a
* Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License
* (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB)
*
* File Created @ [Oct 9, 2014, 3:01:58 PM (GMT)]
*/
package vazkii.botania.api.wand;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
/**
* A TileEntity that implements this can be bound to another block
* via the Wand of the Forest. Also see IWireframeAABBProvider to change
* the displayed bounding box.
*/
public interface IWandBindable extends ITileBound {
/**
* Return true if the Wand can select this tile.
*/
public boolean canSelect(EntityPlayer player, ItemStack wand, int x, int y, int z, int side);
/**
* Call to bind the TileEntity to where the player clicked. Return true to deselect
* the TileEntity for another bind or false case the TileEntity should stay selected.
*/
public boolean bindTo(EntityPlayer player, ItemStack wand, int x, int y, int z, int side);
}
@@ -0,0 +1,26 @@
/**
* This class was created by <Vazkii>. 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 a
* Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License
* (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB)
*
* File Created @ [Feb 5, 2014, 1:34:44 PM (GMT)]
*/
package vazkii.botania.api.wand;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.world.World;
/**
* Any block that implements this has a HUD rendered when being hovered
* with a Wand of the Forest.
*/
public interface IWandHUD {
public void renderHUD(Minecraft mc, ScaledResolution res, World world, int x, int y, int z);
}
@@ -0,0 +1,29 @@
/**
* This class was created by <Vazkii>. 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 a
* Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License
* (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB)
*
* File Created @ [Jan 22, 2014, 5:12:53 PM (GMT)]
*/
package vazkii.botania.api.wand;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
/**
* Any block that implements this can be used with the Wand for the Forest for some purpose.
*/
public interface IWandable {
/**
* Called when the block is used by a wand. Note that the player parameter can be null
* if this function is called from a dispenser.
*/
public boolean onUsedByWand(EntityPlayer player, ItemStack stack, World world, int x, int y, int z, int side);
}
@@ -0,0 +1,25 @@
/**
* This class was created by <Vazkii>. 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 a
* Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License
* (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB)
*
* File Created @ [Apr 19, 2014, 7:23:59 PM (GMT)]
*/
package vazkii.botania.api.wand;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.world.World;
/**
* A block that implements this can provide a custom AABB
* for rendering the wireframe with ITileBound.
*/
public interface IWireframeAABBProvider {
public AxisAlignedBB getWireframeAABB(World world, int x, int y, int z);
}
@@ -0,0 +1,39 @@
/**
* This class was created by <Vazkii>. 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 a
* Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License
* (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB)
*
* File Created @ [Sep 2, 2014, 5:57:35 PM (GMT)]
*/
package vazkii.botania.api.wiki;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.World;
/**
* An interface for a Wiki Provider, these are registered to allow a mod to provide a wiki
* for all the blocks in them, used for the world interaction with the Lexica Botania.
* A simple, mostly all-inclusive implementation can be found on SimpleWikiProvider.
*/
public interface IWikiProvider {
/**
* Gets the name of the block being looked at for display.
*/
public String getBlockName(World world, MovingObjectPosition pos);
/**
* Gets the URL to open when the block is clicked.
*/
public String getWikiURL(World world, MovingObjectPosition pos);
/**
* Gets the name of the wiki for display.
*/
public String getWikiName(World world, MovingObjectPosition pos);
}
@@ -0,0 +1,73 @@
/**
* This class was created by <Vazkii>. 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 a
* Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License
* (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB)
*
* File Created @ [Sep 2, 2014, 5:58:39 PM (GMT)]
*/
package vazkii.botania.api.wiki;
import net.minecraft.block.Block;
import net.minecraft.item.ItemStack;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.World;
import org.apache.commons.lang3.text.WordUtils;
public class SimpleWikiProvider implements IWikiProvider {
final String name, urlBase, replacement;
public SimpleWikiProvider(String name, String urlBase) {
this(name, urlBase, "%20");
}
public SimpleWikiProvider(String name, String urlBase, String replacement) {
this.name = name;
this.urlBase = urlBase;
this.replacement = replacement;
}
@Override
public String getBlockName(World world, MovingObjectPosition pos) {
int x = pos.blockX;
int y = pos.blockY;
int z = pos.blockZ;
Block block = world.getBlock(x, y, z);
if(block == null)
return null;
ItemStack stack = block.getPickBlock(pos, world, x, y, z);
if(stack == null || stack.getItem() == null)
stack = new ItemStack(block, 1, world.getBlockMetadata(x, y, z));
if(stack.getItem() == null)
return null;
String name = stack.getDisplayName();
if(name == null || name.isEmpty())
return null;
return name;
}
@Override
public String getWikiURL(World world, MovingObjectPosition pos) {
String name = getBlockName(world, pos);
if(name == null)
return null;
return String.format(urlBase, WordUtils.capitalizeFully(name).replaceAll(" ", replacement));
}
@Override
public String getWikiName(World world, MovingObjectPosition pos) {
return name;
}
}
@@ -0,0 +1,43 @@
/**
* This class was created by <Vazkii>. 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 a
* Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License
* (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB)
*
* File Created @ [Sep 2, 2014, 6:05:03 PM (GMT)]
*/
package vazkii.botania.api.wiki;
import java.util.HashMap;
import java.util.Map;
import net.minecraft.block.Block;
import cpw.mods.fml.common.registry.GameRegistry;
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 Map<String, IWikiProvider> modWikis = new HashMap();
public static IWikiProvider getWikiFor(Block block) {
UniqueIdentifier mod = GameRegistry.findUniqueIdentifierFor(block);
return getWikiFor(mod.modId.toLowerCase());
}
public static IWikiProvider getWikiFor(String mod) {
if(!modWikis.containsKey(mod))
modWikis.put(mod, FALLBACK_PROVIDER);
return modWikis.get(mod);
}
public static void registerModWiki(String mod, IWikiProvider provider) {
modWikis.put(mod.toLowerCase(), provider);
}
}
@@ -0,0 +1,117 @@
/**
* This class was created by <Vazkii>. 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 a
* Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License
* (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB)
*
* File Created @ [Oct 29, 2014, 6:46:10 PM (GMT)]
*/
package vazkii.botania.client.core.handler;
import java.awt.Rectangle;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.ResourceLocation;
import org.lwjgl.opengl.ARBShaderObjects;
import org.lwjgl.opengl.GL11;
import vazkii.botania.api.boss.IBotaniaBoss;
import vazkii.botania.api.boss.IBotaniaBossWithShader;
import vazkii.botania.api.internal.ShaderCallback;
import vazkii.botania.client.core.helper.RenderHelper;
import vazkii.botania.client.core.helper.ShaderHelper;
import vazkii.botania.client.lib.LibResources;
import vazkii.botania.common.core.helper.MathHelper;
public final class BossBarHandler {
public static final ResourceLocation defaultBossBar = new ResourceLocation(LibResources.GUI_BOSS_BAR);
static IBotaniaBoss currentBoss;
private static final BarCallback barUniformCallback = new BarCallback();
public static void setCurrentBoss(IBotaniaBoss status) {
currentBoss = status;
}
public static void render(ScaledResolution res) {
if(currentBoss == null)
return;
Minecraft mc = Minecraft.getMinecraft();
Rectangle bgRect = currentBoss.getBossBarTextureRect();
Rectangle fgRect = currentBoss.getBossBarHPTextureRect();
String name = currentBoss.func_145748_c_().getFormattedText();
int c = res.getScaledWidth() / 2;
int x = c - bgRect.width / 2;
int y = 20;
int xf = x + (bgRect.width - fgRect.width) / 2;
int yf = y + (bgRect.height - fgRect.height) / 2;
int fw = (int) ((double) fgRect.width * (currentBoss.getHealth() / currentBoss.getMaxHealth()));
int tx = c - mc.fontRenderer.getStringWidth(name) / 2;
GL11.glColor4f(1F, 1F, 1F, 1F);
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
currentBoss.bossBarRenderCallback();
mc.renderEngine.bindTexture(currentBoss.getBossBarTexture());
drawBar(x, y, bgRect.x, bgRect.y, bgRect.width, bgRect.height, true);
drawBar(xf, yf, fgRect.x, fgRect.y, fw, fgRect.height, false);
mc.fontRenderer.drawStringWithShadow(name, tx, y - 10, 0xA2018C);
GL11.glDisable(GL11.GL_BLEND);
Entity e = (Entity) currentBoss;
EntityPlayer p = mc.thePlayer;
if(e.isDead || !e.worldObj.loadedEntityList.contains(e) || MathHelper.pointDistanceSpace(e.posX, e.posY, e.posZ, p.posX, p.posY, p.posZ) > 32)
currentBoss = null;
}
public static void drawBar(int x, int y, int u, int v, int w, int h, boolean bg) {
boolean useShader = currentBoss instanceof IBotaniaBossWithShader;
if(useShader) {
IBotaniaBossWithShader shader = (IBotaniaBossWithShader) currentBoss;
int program = shader.getBossBarShaderProgram(bg);
ShaderCallback callback = program == 0 ? null : shader.getBossBarShaderCallback(bg, program);
barUniformCallback.set(u, v, callback);
ShaderHelper.useShader(program, barUniformCallback);
}
RenderHelper.drawTexturedModalRect(x, y, 0, u, v, w, h);
if(useShader)
ShaderHelper.releaseShader();
}
static class BarCallback extends ShaderCallback {
int x, y;
ShaderCallback callback;
@Override
public void call(int shader) {
int startXUniform = ARBShaderObjects.glGetUniformLocationARB(shader, "startX");
int startYUniform = ARBShaderObjects.glGetUniformLocationARB(shader, "startY");
ARBShaderObjects.glUniform1iARB(startXUniform, x);
ARBShaderObjects.glUniform1iARB(startYUniform, y);
if(callback != null)
callback.call(shader);
}
void set(int x, int y, ShaderCallback callback) {
this.x = x;
this.y = y;
this.callback = callback;
}
}
}
@@ -0,0 +1,45 @@
/**
* This class was created by <Vazkii>. 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 a
* Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License
* (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB)
*
* File Created @ [Jul 22, 2014, 3:33:25 PM (GMT)]
*/
package vazkii.botania.client.core.handler;
import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.PlayerControllerMP;
import net.minecraft.client.network.NetHandlerPlayClient;
import vazkii.botania.api.item.IExtendedPlayerController;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class BotaniaPlayerController extends PlayerControllerMP implements IExtendedPlayerController {
private float distance = 0F;
public BotaniaPlayerController(Minecraft p_i45062_1_, NetHandlerPlayClient p_i45062_2_) {
super(p_i45062_1_, p_i45062_2_);
}
@Override
public float getBlockReachDistance() {
return super.getBlockReachDistance() + distance;
}
@Override
public void setReachDistanceExtension(float f) {
distance = f;
}
@Override
public float getReachDistanceExtension() {
return distance;
}
}
@@ -0,0 +1,147 @@
/**
* This class was created by <Vazkii>. 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 a
* Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License
* (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB)
*
* File Created @ [Mar 24, 2014, 7:02:37 PM (GMT)]
*/
package vazkii.botania.client.core.handler;
import java.awt.Color;
import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.ChunkCoordinates;
import net.minecraft.world.World;
import net.minecraftforge.client.event.RenderWorldLastEvent;
import org.lwjgl.opengl.GL11;
import vazkii.botania.api.wand.ICoordBoundItem;
import vazkii.botania.api.wand.IWireframeAABBProvider;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
public final class BoundTileRenderer {
@SubscribeEvent
public void onWorldRenderLast(RenderWorldLastEvent event) {
GL11.glPushMatrix();
GL11.glDisable(GL11.GL_DEPTH_TEST);
GL11.glDisable(GL11.GL_TEXTURE_2D);
GL11.glEnable(GL11.GL_BLEND);
Tessellator.renderingWorldRenderer = false;
EntityPlayer player = Minecraft.getMinecraft().thePlayer;
ItemStack stack = player.getCurrentEquippedItem();
if(stack != null && stack.getItem() instanceof ICoordBoundItem) {
ChunkCoordinates coords = ((ICoordBoundItem) stack.getItem()).getBinding(stack);
if(coords != null)
renderBlockOutlineAt(coords, Color.HSBtoRGB(ClientTickHandler.ticksInGame % 200 / 200F, 0.6F, 1F));
}
GL11.glEnable(GL11.GL_DEPTH_TEST);
GL11.glEnable(GL11.GL_TEXTURE_2D);
GL11.glDisable(GL11.GL_BLEND);
GL11.glPopMatrix();
}
private void renderBlockOutlineAt(ChunkCoordinates pos, int color) {
GL11.glPushMatrix();
GL11.glTranslated(pos.posX - RenderManager.renderPosX, pos.posY - RenderManager.renderPosY, pos.posZ - RenderManager.renderPosZ + 1);
Color colorRGB = new Color(color);
GL11.glColor4ub((byte) colorRGB.getRed(), (byte) colorRGB.getGreen(), (byte) colorRGB.getBlue(), (byte) 255);
World world = Minecraft.getMinecraft().theWorld;
Block block = world.getBlock(pos.posX, pos.posY, pos.posZ);
drawWireframe : {
if(block != null) {
AxisAlignedBB axis;
if(block instanceof IWireframeAABBProvider)
axis = ((IWireframeAABBProvider) block).getWireframeAABB(world, pos.posX, pos.posY, pos.posZ);
else axis = block.getSelectedBoundingBoxFromPool(world, pos.posX, pos.posY, pos.posZ);
if(axis == null)
break drawWireframe;
axis.minX -= pos.posX;
axis.maxX -= pos.posX;
axis.minY -= pos.posY;
axis.maxY -= pos.posY;
axis.minZ -= pos.posZ + 1;
axis.maxZ -= pos.posZ + 1;
GL11.glScalef(1F, 1F, 1F);
GL11.glLineWidth(1F);
renderBlockOutline(axis);
GL11.glLineWidth(4F);
GL11.glColor4ub((byte) colorRGB.getRed(), (byte) colorRGB.getGreen(), (byte) colorRGB.getBlue(), (byte) 64);
renderBlockOutline(axis);
}
}
GL11.glPopMatrix();
}
private void renderBlockOutline(AxisAlignedBB aabb) {
Tessellator tessellator = Tessellator.instance;
double ix = aabb.minX;
double iy = aabb.minY;
double iz = aabb.minZ;
double ax = aabb.maxX;
double ay = aabb.maxY;
double az = aabb.maxZ;
tessellator.startDrawing(GL11.GL_LINES);
tessellator.addVertex(ix, iy, iz);
tessellator.addVertex(ix, ay, iz);
tessellator.addVertex(ix, ay, iz);
tessellator.addVertex(ax, ay, iz);
tessellator.addVertex(ax, ay, iz);
tessellator.addVertex(ax, iy, iz);
tessellator.addVertex(ax, iy, iz);
tessellator.addVertex(ix, iy, iz);
tessellator.addVertex(ix, iy, az);
tessellator.addVertex(ix, ay, az);
tessellator.addVertex(ix, iy, az);
tessellator.addVertex(ax, iy, az);
tessellator.addVertex(ax, iy, az);
tessellator.addVertex(ax, ay, az);
tessellator.addVertex(ix, ay, az);
tessellator.addVertex(ax, ay, az);
tessellator.addVertex(ix, iy, iz);
tessellator.addVertex(ix, iy, az);
tessellator.addVertex(ix, ay, iz);
tessellator.addVertex(ix, ay, az);
tessellator.addVertex(ax, iy, iz);
tessellator.addVertex(ax, iy, az);
tessellator.addVertex(ax, ay, iz);
tessellator.addVertex(ax, ay, az);
tessellator.draw();
}
}
@@ -0,0 +1,91 @@
/**
* This class was created by <Vazkii>. 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 a
* Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License
* (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB)
*
* File Created @ [Feb 3, 2014, 9:59:17 PM (GMT)]
*/
package vazkii.botania.client.core.handler;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import vazkii.botania.api.mana.IManaCollector;
import vazkii.botania.api.mana.TileSignature;
import vazkii.botania.client.core.handler.LightningHandler.LightningBolt;
import vazkii.botania.client.gui.lexicon.GuiLexicon;
import vazkii.botania.common.core.handler.ManaNetworkHandler;
import vazkii.botania.common.item.ItemTwigWand;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.TickEvent.ClientTickEvent;
import cpw.mods.fml.common.gameevent.TickEvent.Phase;
public class ClientTickHandler {
public static int ticksWithLexicaOpen = 0;
public static int pageFlipTicks = 0;
public static int ticksInGame = 0;
@SubscribeEvent
public void clientTickEnd(ClientTickEvent event) {
if(event.phase == Phase.END) {
LightningBolt.update();
if(Minecraft.getMinecraft().theWorld == null)
ManaNetworkHandler.instance.clear();
GuiScreen gui = Minecraft.getMinecraft().currentScreen;
if(gui == null || !gui.doesGuiPauseGame()) {
ticksInGame++;
EntityPlayer player = Minecraft.getMinecraft().thePlayer;
if(player != null) {
ItemStack stack = player.getCurrentEquippedItem();
if(stack != null && stack.getItem() instanceof ItemTwigWand) {
List<TileSignature> list = new ArrayList(ManaNetworkHandler.instance.getAllCollectorsInWorld(Minecraft.getMinecraft().theWorld));
for(TileSignature sig : list) {
if(!sig.remoteWorld)
continue;
TileEntity tile = sig.tile;
if(tile instanceof IManaCollector)
((IManaCollector) tile).onClientDisplayTick();
}
}
}
}
int ticksToOpen = 10;
if(gui instanceof GuiLexicon) {
if(ticksWithLexicaOpen < 0)
ticksWithLexicaOpen = 0;
if(ticksWithLexicaOpen < ticksToOpen)
ticksWithLexicaOpen++;
if(pageFlipTicks > 0)
pageFlipTicks--;
} else {
pageFlipTicks = 0;
if(ticksWithLexicaOpen > 0) {
if(ticksWithLexicaOpen > ticksToOpen)
ticksWithLexicaOpen = ticksToOpen;
ticksWithLexicaOpen--;
}
}
}
}
public static void notifyPageChange() {
if(pageFlipTicks == 0)
pageFlipTicks = 5;
}
}
@@ -0,0 +1,37 @@
/**
* This class was created by <Vazkii>. 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 a
* Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License
* (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB)
*
* File Created @ [Oct 21, 2014, 4:58:55 PM (GMT)]
*/
package vazkii.botania.client.core.handler;
import net.minecraft.client.Minecraft;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.world.World;
import net.minecraftforge.client.event.RenderGameOverlayEvent;
import vazkii.botania.client.fx.ParticleRenderDispatcher;
import vazkii.botania.common.core.handler.ManaNetworkHandler;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
public final class DebugHandler {
private static final String PREFIX = EnumChatFormatting.GREEN + "[Botania] " + EnumChatFormatting.RESET;
@SubscribeEvent
public void onDrawDebugText(RenderGameOverlayEvent.Text event) {
World world = Minecraft.getMinecraft().theWorld;
if(Minecraft.getMinecraft().gameSettings.showDebugInfo) {
event.left.add(null);
event.left.add(PREFIX + "pS: " + ParticleRenderDispatcher.sparkleFxCount + ", pFS: " + ParticleRenderDispatcher.fakeSparkleFxCount + ", pW: " + ParticleRenderDispatcher.wispFxCount + ", pDIW: " + ParticleRenderDispatcher.depthIgnoringWispFxCount + ", pLB: " + ParticleRenderDispatcher.lightningCount);
event.left.add(PREFIX + "netColl: " + ManaNetworkHandler.instance.getAllCollectorsInWorld(world).size() + ", netPool: " + ManaNetworkHandler.instance.getAllPoolsInWorld(world).size());
}
}
}
@@ -0,0 +1,323 @@
/**
* This class was created by <Vazkii>. 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 a
* Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License
* (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB)
*
* File Created @ [Jan 25, 2014, 6:11:10 PM (GMT)]
*/
package vazkii.botania.client.core.handler;
import java.awt.Color;
import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.GuiIngame;
import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.client.renderer.entity.RenderItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.profiler.Profiler;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.StatCollector;
import net.minecraftforge.client.event.RenderGameOverlayEvent;
import net.minecraftforge.client.event.RenderGameOverlayEvent.ElementType;
import org.lwjgl.opengl.GL11;
import vazkii.botania.api.BotaniaAPI;
import vazkii.botania.api.lexicon.ILexicon;
import vazkii.botania.api.lexicon.ILexiconable;
import vazkii.botania.api.lexicon.LexiconEntry;
import vazkii.botania.api.mana.ICreativeManaProvider;
import vazkii.botania.api.mana.IManaItem;
import vazkii.botania.api.mana.IManaUsingItem;
import vazkii.botania.api.recipe.RecipeManaInfusion;
import vazkii.botania.api.wand.IWandHUD;
import vazkii.botania.api.wiki.IWikiProvider;
import vazkii.botania.api.wiki.WikiHooks;
import vazkii.botania.client.core.helper.RenderHelper;
import vazkii.botania.client.lib.LibResources;
import vazkii.botania.common.block.tile.mana.TilePool;
import vazkii.botania.common.item.ItemTwigWand;
import vazkii.botania.common.item.ModItems;
import vazkii.botania.common.lib.LibObfuscation;
import baubles.common.lib.PlayerHandler;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.relauncher.ReflectionHelper;
public final class HUDHandler {
private static final ResourceLocation manaBar = new ResourceLocation(LibResources.GUI_MANA_HUD);
@SubscribeEvent
public void onDrawScreen(RenderGameOverlayEvent.Post event) {
Minecraft mc = Minecraft.getMinecraft();
Profiler profiler = mc.mcProfiler;
if(event.type == ElementType.ALL) {
profiler.startSection("botania-hud");
MovingObjectPosition pos = mc.objectMouseOver;
if(pos != null) {
Block block = mc.theWorld.getBlock(pos.blockX, pos.blockY, pos.blockZ);
TileEntity tile = mc.theWorld.getTileEntity(pos.blockX, pos.blockY, pos.blockZ);
ItemStack stack = mc.thePlayer.getCurrentEquippedItem();
if(stack != null) {
if(pos != null && stack.getItem() == ModItems.twigWand) {
renderWandModeDisplay(event.resolution);
if(block instanceof IWandHUD) {
profiler.startSection("wandItem");
((IWandHUD) block).renderHUD(mc, event.resolution, mc.theWorld, pos.blockX, pos.blockY, pos.blockZ);
profiler.endSection();
}
}
else if(pos != null && stack.getItem() instanceof ILexicon)
drawLexiconHUD(mc.thePlayer.getCurrentEquippedItem(), block, pos, event.resolution);
else if(tile != null && tile instanceof TilePool)
renderPoolRecipeHUD(event.resolution, (TilePool) tile, stack);
}
}
profiler.startSection("manaBar");
EntityPlayer player = Minecraft.getMinecraft().thePlayer;
int totalMana = 0;
int totalMaxMana = 0;
boolean anyRequest = false;
boolean creative = false;
IInventory mainInv = player.inventory;
IInventory baublesInv = PlayerHandler.getPlayerBaubles(player);
int invSize = mainInv.getSizeInventory();
int size = invSize;
if(baublesInv != null)
size += baublesInv.getSizeInventory();
for(int i = 0; i < size; i++) {
boolean useBaubles = i >= invSize;
IInventory inv = useBaubles ? baublesInv : mainInv;
ItemStack stack = inv.getStackInSlot(i - (useBaubles ? invSize : 0));
if(stack != null) {
Item item = stack.getItem();
if(item instanceof IManaUsingItem)
anyRequest = anyRequest || ((IManaUsingItem) item).usesMana(stack);
if(item instanceof IManaItem) {
if(!((IManaItem) item).isNoExport(stack)) {
totalMana += ((IManaItem) item).getMana(stack);
totalMaxMana += ((IManaItem) item).getMaxMana(stack);
}
}
if(item instanceof ICreativeManaProvider && ((ICreativeManaProvider) item).isCreative(stack))
creative = true;
}
}
if(anyRequest)
renderManaInvBar(event.resolution, creative, totalMana, totalMaxMana);
profiler.endStartSection("bossBar");
BossBarHandler.render(event.resolution);
profiler.endSection();
profiler.endSection();
}
}
private void renderWandModeDisplay(ScaledResolution res) {
Minecraft mc = Minecraft.getMinecraft();
Profiler profiler = mc.mcProfiler;
profiler.startSection("wandMode");
int ticks = ReflectionHelper.getPrivateValue(GuiIngame.class, mc.ingameGUI, LibObfuscation.REMAINING_HIGHLIGHT_TICKS);
ticks -= 15;
if(ticks > 0) {
int alpha = Math.min(255, (int) (ticks * 256.0F / 10.0F));
int color = 0x00CC00 + (alpha << 24);
String disp = StatCollector.translateToLocal(ItemTwigWand.getModeString(mc.thePlayer.getCurrentEquippedItem()));
int x = res.getScaledWidth() / 2 - mc.fontRenderer.getStringWidth(disp) / 2;
int y = res.getScaledHeight() - 70;
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
mc.fontRenderer.drawStringWithShadow(disp, x, y, color);
GL11.glDisable(GL11.GL_BLEND);
}
profiler.endSection();
}
private void renderManaInvBar(ScaledResolution res, boolean hasCreative, int totalMana, int totalMaxMana) {
Minecraft mc = Minecraft.getMinecraft();
int width = 182;
int x = res.getScaledWidth() / 2 - width / 2;
int y = res.getScaledHeight() - 29;
if(!hasCreative) {
if(totalMaxMana == 0)
width = 0;
else width *= (double) totalMana / (double) totalMaxMana;
}
if(width == 0) {
if(totalMana > 0)
width = 1;
else return;
}
Color color = new Color(Color.HSBtoRGB(0.55F, (float) Math.min(1F, Math.sin(System.currentTimeMillis() / 200D) * 0.5 + 1F), 1F));
GL11.glColor4ub((byte) color.getRed(), (byte) color.getGreen(), (byte) color.getBlue(), (byte) (255 - color.getRed()));
mc.renderEngine.bindTexture(manaBar);
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
RenderHelper.drawTexturedModalRect(x, y, 0, 0, 251, width, 5);
GL11.glDisable(GL11.GL_BLEND);
}
private void renderPoolRecipeHUD(ScaledResolution res, TilePool tile, ItemStack stack) {
Minecraft mc = Minecraft.getMinecraft();
Profiler profiler = mc.mcProfiler;
profiler.startSection("poolRecipe");
for(RecipeManaInfusion recipe : BotaniaAPI.manaInfusionRecipes) {
if(recipe.matches(stack)) {
if((!recipe.isAlchemy() || tile.alchemy) && (!recipe.isConjuration() || tile.conjuration)) {
int x = res.getScaledWidth() / 2 - 11;
int y = res.getScaledHeight() / 2 + 10;
int u = tile.getCurrentMana() >= recipe.getManaToConsume() ? 0 : 22;
int v = mc.thePlayer.getCommandSenderName().equals("haighyorkie") && mc.thePlayer.isSneaking() ? 23 : 8;
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
mc.renderEngine.bindTexture(manaBar);
RenderHelper.drawTexturedModalRect(x, y, 0, u, v, 22, 15);
GL11.glColor4f(1F, 1F, 1F, 1F);
net.minecraft.client.renderer.RenderHelper.enableGUIStandardItemLighting();
RenderItem.getInstance().renderItemAndEffectIntoGUI(mc.fontRenderer, mc.renderEngine, stack, x - 20, y);
RenderItem.getInstance().renderItemAndEffectIntoGUI(mc.fontRenderer, mc.renderEngine, recipe.getOutput(), x + 26, y);
RenderItem.getInstance().renderItemOverlayIntoGUI(mc.fontRenderer, mc.renderEngine, recipe.getOutput(), x + 26, y);
net.minecraft.client.renderer.RenderHelper.disableStandardItemLighting();
GL11.glDisable(GL11.GL_LIGHTING);
GL11.glDisable(GL11.GL_BLEND);
break;
}
}
}
profiler.endSection();
}
private void drawLexiconHUD(ItemStack stack, Block block, MovingObjectPosition pos, ScaledResolution res) {
Minecraft mc = Minecraft.getMinecraft();
Profiler profiler = mc.mcProfiler;
profiler.startSection("lexicon");
FontRenderer font = mc.fontRenderer;
boolean draw = false;
String drawStr = "";
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
int sx = res.getScaledWidth() / 2 - 17;
int sy = res.getScaledHeight() / 2 + 2;
if(block instanceof ILexiconable) {
LexiconEntry entry = ((ILexiconable) block).getEntry(mc.theWorld, pos.blockX, pos.blockY, pos.blockZ, mc.thePlayer, mc.thePlayer.getCurrentEquippedItem());
if(entry != null) {
if(!((ILexicon) stack.getItem()).isKnowledgeUnlocked(stack, entry.getKnowledgeType()))
font = mc.standardGalacticFontRenderer;
drawStr = StatCollector.translateToLocal(entry.getUnlocalizedName());
draw = true;
}
}
if(!draw && pos.entityHit == null) {
profiler.startSection("wikiLookup");
IWikiProvider provider = WikiHooks.getWikiFor(block);
String url = provider.getWikiURL(mc.theWorld, pos);
if(url != null && !url.isEmpty()) {
String name = provider.getBlockName(mc.theWorld, pos);
String wikiName = provider.getWikiName(mc.theWorld, pos);
drawStr = name + " @ " + EnumChatFormatting.AQUA + wikiName;
draw = true;
}
profiler.endSection();
}
if(draw) {
if(!mc.thePlayer.isSneaking()) {
drawStr = "?";
font = mc.fontRenderer;
}
RenderItem.getInstance().renderItemIntoGUI(mc.fontRenderer, mc.renderEngine, new ItemStack(ModItems.lexicon), sx, sy);
GL11.glDisable(GL11.GL_LIGHTING);
font.drawStringWithShadow(drawStr, sx + 10, sy + 8, 0xFFFFFFFF);
}
GL11.glDisable(GL11.GL_BLEND);
GL11.glColor4f(1F, 1F, 1F, 1F);
profiler.endSection();
}
public static void drawSimpleManaHUD(int color, int mana, int maxMana, String name, ScaledResolution res) {
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
Minecraft mc = Minecraft.getMinecraft();
int x = res.getScaledWidth() / 2 - mc.fontRenderer.getStringWidth(name) / 2;
int y = res.getScaledHeight() / 2 + 10;
mc.fontRenderer.drawStringWithShadow(name, x, y, color);
x = res.getScaledWidth() / 2 - 51;
y += 10;
renderManaBar(x, y, color, 0.5F, mana, maxMana);
if(mana < 0) {
String text = StatCollector.translateToLocal("botaniamisc.statusUnknown");
x = res.getScaledWidth() / 2 - mc.fontRenderer.getStringWidth(text) / 2;
y -= 1;
mc.fontRenderer.drawStringWithShadow(text, x, y, color);
}
GL11.glDisable(GL11.GL_BLEND);
}
public static void renderManaBar(int x, int y, int color, float alpha, int mana, int maxMana) {
Minecraft mc = Minecraft.getMinecraft();
GL11.glColor4f(1F, 1F, 1F, alpha);
mc.renderEngine.bindTexture(manaBar);
RenderHelper.drawTexturedModalRect(x, y, 0, 0, 0, 102, 5);
int manaPercentage = Math.max(0, (int) ((double) mana / (double) maxMana * 100));
if(manaPercentage == 0 && mana > 0)
manaPercentage = 1;
RenderHelper.drawTexturedModalRect(x + 1, y + 1, 0, 0, 5, 100, 3);
Color color_ = new Color(color);
GL11.glColor4ub((byte) color_.getRed(), (byte) color_.getGreen(),(byte) color_.getBlue(), (byte) (255F * alpha));
RenderHelper.drawTexturedModalRect(x + 1, y + 1, 0, 0, 5, manaPercentage, 3);
}
}
@@ -0,0 +1,495 @@
/**
* This class was created by <Vazkii/ChickenBones>. 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 a
* Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License
* (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB)
*
* File Created @ [Feb 3, 2014, 9:05:38 PM (GMT)]
*/
package vazkii.botania.client.core.handler;
import java.awt.Color;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Random;
import java.util.concurrent.ConcurrentLinkedQueue;
import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.ActiveRenderInfo;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.texture.TextureManager;
import net.minecraft.entity.Entity;
import net.minecraft.profiler.Profiler;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.ChunkCoordinates;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;
import net.minecraftforge.client.event.RenderWorldLastEvent;
import org.lwjgl.opengl.GL11;
import vazkii.botania.client.core.handler.LightningHandler.LightningBolt.Segment;
import vazkii.botania.client.fx.ParticleRenderDispatcher;
import vazkii.botania.client.lib.LibResources;
import vazkii.botania.common.core.helper.Vector3;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
public class LightningHandler {
private static final ResourceLocation outsideResource = new ResourceLocation(LibResources.MISC_WISP_LARGE);
private static final ResourceLocation insideResource = new ResourceLocation(LibResources.MISC_WISP_SMALL);
static double interpPosX;
static double interpPosY;
static double interpPosZ;
private static Vector3 getRelativeViewVector(Vector3 pos) {
Entity renderEntity = Minecraft.getMinecraft().renderViewEntity;
return new Vector3((float) renderEntity.posX - pos.x, (float) renderEntity.posY + renderEntity.getEyeHeight() - pos.y, (float) renderEntity.posZ - pos.z);
}
@SubscribeEvent
public void onRenderWorldLast(RenderWorldLastEvent event) {
Profiler profiler = Minecraft.getMinecraft().mcProfiler;
profiler.startSection("botania-particles");
ParticleRenderDispatcher.dispatch();
profiler.startSection("lightning");
float frame = event.partialTicks;
Entity entity = Minecraft.getMinecraft().thePlayer;
TextureManager render = Minecraft.getMinecraft().renderEngine;
interpPosX = entity.lastTickPosX + (entity.posX - entity.lastTickPosX) * frame;
interpPosY = entity.lastTickPosY + (entity.posY - entity.lastTickPosY) * frame;
interpPosZ = entity.lastTickPosZ + (entity.posZ - entity.lastTickPosZ) * frame;
GL11.glTranslated(-interpPosX, -interpPosY, -interpPosZ);
Tessellator tessellator = Tessellator.instance;
GL11.glDepthMask(false);
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
ParticleRenderDispatcher.lightningCount = 0;
render.bindTexture(outsideResource);
tessellator.startDrawingQuads();
tessellator.setBrightness(0xF000F0);
for(LightningBolt bolt : LightningBolt.boltlist)
renderBolt(bolt, tessellator, frame, ActiveRenderInfo.rotationX, ActiveRenderInfo.rotationXZ, ActiveRenderInfo.rotationZ, ActiveRenderInfo.rotationXY, 0, false);
tessellator.draw();
render.bindTexture(insideResource);
tessellator.startDrawingQuads();
tessellator.setBrightness(0xF000F0);
for(LightningBolt bolt : LightningBolt.boltlist)
renderBolt(bolt, tessellator, frame, ActiveRenderInfo.rotationX, ActiveRenderInfo.rotationXZ, ActiveRenderInfo.rotationZ, ActiveRenderInfo.rotationXY, 1, true);
tessellator.draw();
GL11.glDisable(GL11.GL_BLEND);
GL11.glDepthMask(true);
GL11.glTranslated(interpPosX, interpPosY, interpPosZ);
profiler.endSection();
profiler.endSection();
}
public static void spawnLightningBolt(World world, Vector3 vectorStart, Vector3 vectorEnd, float ticksPerMeter, long seed, int colorOuter, int colorInner) {
LightningBolt bolt = new LightningBolt(world, vectorStart, vectorEnd, ticksPerMeter, seed, colorOuter, colorInner);
bolt.defaultFractal();
bolt.finalizeBolt();
LightningBolt.boltlist.add(bolt);
}
private void renderBolt(LightningBolt bolt, Tessellator tessellator, float partialframe, float cosyaw, float cospitch, float sinyaw, float cossinpitch, int pass, boolean inner) {
ParticleRenderDispatcher.lightningCount++;
float boltage = bolt.particleAge < 0 ? 0 : (float) bolt.particleAge / (float) bolt.particleMaxAge;
float mainalpha = 1;
if(pass == 0)
mainalpha = (1 - boltage) * 0.4F;
else mainalpha = 1 - boltage * 0.5F;
int expandTime = (int) (bolt.length * bolt.speed);
int renderstart = (int) ((expandTime / 2 - bolt.particleMaxAge + bolt.particleAge) / (float) (expandTime / 2) * bolt.numsegments0);
int renderend = (int) ((bolt.particleAge + expandTime) / (float) expandTime * bolt.numsegments0);
for(Segment rendersegment : bolt.segments) {
if(rendersegment.segmentno < renderstart || rendersegment.segmentno > renderend)
continue;
Vector3 playervec = getRelativeViewVector(rendersegment.startpoint.point).multiply(-1);
double width = 0.025F * (playervec.mag() / 5 + 1) * (1 + rendersegment.light) * 0.5F;
Vector3 diff1 = playervec.copy().crossProduct(rendersegment.prevdiff).normalize().multiply(width / rendersegment.sinprev);
Vector3 diff2 = playervec.copy().crossProduct(rendersegment.nextdiff).normalize().multiply(width / rendersegment.sinnext);
Vector3 startvec = rendersegment.startpoint.point;
Vector3 endvec = rendersegment.endpoint.point;
int color = inner ? bolt.colorInner : bolt.colorOuter;
tessellator.setColorRGBA_I(color, (int) (mainalpha * rendersegment.light * new Color(color).getAlpha()));
tessellator.addVertexWithUV(endvec.x - diff2.x, endvec.y - diff2.y, endvec.z - diff2.z, 0.5, 0);
tessellator.addVertexWithUV(startvec.x - diff1.x, startvec.y - diff1.y, startvec.z - diff1.z, 0.5, 0);
tessellator.addVertexWithUV(startvec.x + diff1.x, startvec.y + diff1.y, startvec.z + diff1.z, 0.5, 1);
tessellator.addVertexWithUV(endvec.x + diff2.x, endvec.y + diff2.y, endvec.z + diff2.z, 0.5, 1);
if(rendersegment.next == null) {
Vector3 roundend = rendersegment.endpoint.point.copy().add(rendersegment.diff.copy().normalize().multiply(width));
tessellator.addVertexWithUV(roundend.x - diff2.x, roundend.y - diff2.y, roundend.z - diff2.z, 0, 0);
tessellator.addVertexWithUV(endvec.x - diff2.x, endvec.y - diff2.y, endvec.z - diff2.z, 0.5, 0);
tessellator.addVertexWithUV(endvec.x + diff2.x, endvec.y + diff2.y, endvec.z + diff2.z, 0.5, 1);
tessellator.addVertexWithUV(roundend.x + diff2.x, roundend.y + diff2.y, roundend.z + diff2.z, 0, 1);
}
if(rendersegment.prev == null) {
Vector3 roundend = rendersegment.startpoint.point.copy().subtract(rendersegment.diff.copy().normalize().multiply(width));
tessellator.addVertexWithUV(startvec.x - diff1.x, startvec.y - diff1.y, startvec.z - diff1.z, 0.5, 0);
tessellator.addVertexWithUV(roundend.x - diff1.x, roundend.y - diff1.y, roundend.z - diff1.z, 0, 0);
tessellator.addVertexWithUV(roundend.x + diff1.x, roundend.y + diff1.y, roundend.z + diff1.z, 0, 1);
tessellator.addVertexWithUV(startvec.x + diff1.x, startvec.y + diff1.y, startvec.z + diff1.z, 0.5, 1);
}
}
}
public static class LightningBolt {
public ArrayList<Segment> segments = new ArrayList<Segment>();
public Vector3 start;
public Vector3 end;
ChunkCoordinates target;
HashMap<Integer, Integer> splitparents = new HashMap<Integer, Integer>();
public double length;
public int numsegments0;
private int numsplits;
private boolean finalized;
private Random rand;
public long seed;
public int particleAge;
public int particleMaxAge;
public boolean isDead;
private AxisAlignedBB boundingBox;
private World world;
private Entity source;
public static ConcurrentLinkedQueue<LightningBolt> boltlist = new ConcurrentLinkedQueue<LightningBolt>();
public float speed = 1.5F;
public static final int fadetime = 20;
public static int playerdamage = 1;
public static int entitydamage = 1;
public int colorOuter;
public int colorInner;
public class BoltPoint {
public BoltPoint(Vector3 basepoint, Vector3 offsetvec) {
point = basepoint.copy().add(offsetvec);
this.basepoint = basepoint;
this.offsetvec = offsetvec;
}
public Vector3 point;
Vector3 basepoint;
Vector3 offsetvec;
}
public class SegmentSorter implements Comparator<Segment> {
@Override
public int compare(Segment o1, Segment o2) {
int comp = Integer.valueOf(o1.splitno).compareTo(o2.splitno);
if(comp == 0)
return Integer.valueOf(o1.segmentno).compareTo(o2.segmentno);
else return comp;
}
}
public class SegmentLightSorter implements Comparator<Segment> {
@Override
public int compare(Segment o1, Segment o2) {
return Float.compare(o2.light, o1.light);
}
}
public class Segment {
public Segment(BoltPoint start, BoltPoint end, float light, int segmentnumber, int splitnumber) {
startpoint = start;
endpoint = end;
this.light = light;
segmentno = segmentnumber;
splitno = splitnumber;
calcDiff();
}
public Segment(Vector3 start, Vector3 end) {
this(new BoltPoint(start, new Vector3(0, 0, 0)), new BoltPoint(end, new Vector3(0, 0, 0)), 1, 0, 0);
}
public void calcDiff() {
diff = endpoint.point.copy().subtract(startpoint.point);
}
public void calcEndDiffs() {
if(prev != null) {
Vector3 prevdiffnorm = prev.diff.copy().normalize();
Vector3 thisdiffnorm = diff.copy().normalize();
prevdiff = thisdiffnorm.copy().add(prevdiffnorm).normalize();
sinprev = (float) Math.sin(thisdiffnorm.angle(prevdiffnorm.multiply(-1)) / 2);
} else {
prevdiff = diff.copy().normalize();
sinprev = 1;
}
if(next != null) {
Vector3 nextdiffnorm = next.diff.copy().normalize();
Vector3 thisdiffnorm = diff.copy().normalize();
nextdiff = thisdiffnorm.add(nextdiffnorm).normalize();
sinnext = (float) Math.sin(thisdiffnorm.angle(nextdiffnorm.multiply(-1)) / 2);
} else {
nextdiff = diff.copy().normalize();
sinnext = 1;
}
}
@Override
public String toString() {
return startpoint.point.toString() + " " + endpoint.point.toString();
}
public BoltPoint startpoint;
public BoltPoint endpoint;
public Vector3 diff;
public Segment prev;
public Segment next;
public Vector3 nextdiff;
public Vector3 prevdiff;
public float sinprev;
public float sinnext;
public float light;
public int segmentno;
public int splitno;
}
public LightningBolt(World world, Vector3 sourcevec, Vector3 targetvec, float ticksPerMeter, long seed, int colorOuter, int colorInner) {
this.world = world;
this.seed = seed;
rand = new Random(seed);
start = sourcevec;
end = targetvec;
speed = ticksPerMeter;
this.colorOuter = colorOuter;
this.colorInner = colorInner;
numsegments0 = 1;
length = end.copy().subtract(start).mag();
particleMaxAge = fadetime + rand.nextInt(fadetime) - fadetime / 2;
particleAge = -(int) (length * speed);
boundingBox = AxisAlignedBB.getBoundingBox(0, 0, 0, 0, 0, 0);
boundingBox.setBB(AxisAlignedBB.getBoundingBox(Math.min(start.x, end.x), Math.min(start.y, end.y), Math.min(start.z, end.z), Math.max(start.x, end.x), Math.max(start.y, end.y), Math.max(start.z, end.z)).expand(length / 2, length / 2, length / 2));
segments.add(new Segment(start, end));
}
public static Vector3 getFocalPoint(TileEntity tile) {
return Vector3.fromTileEntityCenter(tile);
}
public LightningBolt(World world, Vector3 sourcevec, TileEntity target, float ticksPerMeter, long seed, int colorOuter, int colorInner) {
this(world, sourcevec, getFocalPoint(target), ticksPerMeter, seed, colorOuter, colorInner);
this.target = new ChunkCoordinates(target.xCoord, target.yCoord, target.zCoord);
}
public void setWrapper(Entity entity) {
source = entity;
}
public void fractal(int splits, double amount, double splitchance, double splitlength, double splitangle) {
if(finalized)
return;
ArrayList<Segment> oldsegments = segments;
segments = new ArrayList<Segment>();
Segment prev = null;
for(Segment segment : oldsegments) {
prev = segment.prev;
Vector3 subsegment = segment.diff.copy().multiply(1F / splits);
BoltPoint[] newpoints = new BoltPoint[splits + 1];
Vector3 startpoint = segment.startpoint.point;
newpoints[0] = segment.startpoint;
newpoints[splits] = segment.endpoint;
for(int i = 1; i < splits; i++) {
Vector3 randoff = segment.diff.copy().perpendicular().normalize().rotate(rand.nextFloat() * 360, segment.diff);
randoff.multiply((rand.nextFloat() - 0.5F) * amount * 2);
Vector3 basepoint = startpoint.copy().add(subsegment.copy().multiply(i));
newpoints[i] = new BoltPoint(basepoint, randoff);
}
for(int i = 0; i < splits; i++) {
Segment next = new Segment(newpoints[i], newpoints[i + 1], segment.light, segment.segmentno * splits + i, segment.splitno);
next.prev = prev;
if (prev != null)
prev.next = next;
if(i != 0 && rand.nextFloat() < splitchance) {
Vector3 splitrot = next.diff.copy().xCrossProduct().rotate(rand.nextFloat() * 360, next.diff);
Vector3 diff = next.diff.copy().rotate((rand.nextFloat() * 0.66F + 0.33F) * splitangle, splitrot).multiply(splitlength);
numsplits++;
splitparents.put(numsplits, next.splitno);
Segment split = new Segment(newpoints[i], new BoltPoint(newpoints[i + 1].basepoint, newpoints[i + 1].offsetvec.copy().add(diff)), segment.light / 2F, next.segmentno, numsplits);
split.prev = prev;
segments.add(split);
}
prev = next;
segments.add(next);
}
if(segment.next != null)
segment.next.prev = prev;
}
numsegments0 *= splits;
}
public void defaultFractal() {
fractal(2, length / 1.5, 0.7F, 0.7F, 45);
fractal(2, length / 4, 0.5F, 0.8F, 50);
fractal(2, length / 15, 0.5F, 0.9F, 55);
fractal(2, length / 30, 0.5F, 1.0F, 60);
fractal(2, length / 60, 0, 0, 0);
fractal(2, length / 100, 0, 0, 0);
fractal(2, length / 400, 0, 0, 0);
}
private float rayTraceResistance(Vector3 start, Vector3 end, float prevresistance) {
MovingObjectPosition mop = world.rayTraceBlocks(start.toVec3D(), end.toVec3D());
if(mop == null)
return prevresistance;
if(mop.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK) {
Block block = world.getBlock(mop.blockX, mop.blockY, mop.blockZ);
if(world.isAirBlock(mop.blockX, mop.blockY, mop.blockZ))
return prevresistance;
return prevresistance + block.getExplosionResistance(source) + 0.3F;
} else return prevresistance;
}
private void calculateCollisionAndDiffs() {
HashMap<Integer, Integer> lastactivesegment = new HashMap<Integer, Integer>();
Collections.sort(segments, new SegmentSorter());
int lastsplitcalc = 0;
int lastactiveseg = 0;// unterminated
float splitresistance = 0;
for(Segment segment : segments) {
if(segment.splitno > lastsplitcalc) {
lastactivesegment.put(lastsplitcalc, lastactiveseg);
lastsplitcalc = segment.splitno;
lastactiveseg = lastactivesegment.get(splitparents.get(segment.splitno));
splitresistance = lastactiveseg < segment.segmentno ? 50 : 0;
}
if(splitresistance >= 40 * segment.light)
continue;
splitresistance = rayTraceResistance(segment.startpoint.point, segment.endpoint.point, splitresistance);
lastactiveseg = segment.segmentno;
}
lastactivesegment.put(lastsplitcalc, lastactiveseg);
lastsplitcalc = 0;
lastactiveseg = lastactivesegment.get(0);
for(Iterator<Segment> iterator = segments.iterator(); iterator.hasNext();) {
Segment segment = iterator.next();
if(lastsplitcalc != segment.splitno) {
lastsplitcalc = segment.splitno;
lastactiveseg = lastactivesegment.get(segment.splitno);
}
if(segment.segmentno > lastactiveseg)
iterator.remove();
segment.calcEndDiffs();
}
}
public void finalizeBolt() {
if(finalized)
return;
finalized = true;
calculateCollisionAndDiffs();
Collections.sort(segments, new SegmentLightSorter());
boltlist.add(this);
}
public void onUpdate() {
particleAge++;
if (particleAge >= particleMaxAge)
isDead = true;
}
// Called in ClientTickHandler
public static void update() {
for(Iterator<LightningBolt> iterator = boltlist.iterator(); iterator.hasNext();) {
LightningBolt bolt = iterator.next();
bolt.onUpdate();
if(bolt.isDead)
iterator.remove();
}
}
}
}
@@ -0,0 +1,185 @@
/**
* This class was created by <Vazkii>. 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 a
* Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License
* (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB)
*
* File Created @ [Aug 27, 2014, 8:55:00 PM (GMT)]
*/
package vazkii.botania.client.core.handler;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.ItemRenderer;
import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.IIcon;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.event.RenderPlayerEvent;
import org.lwjgl.opengl.GL11;
import vazkii.botania.client.core.helper.ShaderHelper;
import vazkii.botania.client.lib.LibResources;
import vazkii.botania.common.item.equipment.bauble.ItemFlightTiara;
import baubles.common.container.InventoryBaubles;
import baubles.common.lib.PlayerHandler;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
public final class TiaraWingRenderHandler {
private static ResourceLocation textureHalo = new ResourceLocation(LibResources.MISC_HALO);
@SubscribeEvent
public void onPlayerRender(RenderPlayerEvent.Specials.Post event) {
InventoryBaubles inv = PlayerHandler.getPlayerBaubles(event.entityPlayer);
if(inv.getStackInSlot(0) != null && inv.getStackInSlot(0).getItem() instanceof ItemFlightTiara) {
int meta = inv.getStackInSlot(0).getItemDamage();
if(meta > 0 && meta <= ItemFlightTiara.wingIcons.length) {
IIcon icon = ItemFlightTiara.wingIcons[meta - 1];
Minecraft.getMinecraft().renderEngine.bindTexture(TextureMap.locationItemsTexture);
boolean flying = event.entityPlayer.capabilities.isFlying;
float rz = 120F;
float rx = 20F + (float) ((Math.sin((double) (event.entityPlayer.ticksExisted + event.partialRenderTick) * (flying ? 0.4F : 0.2F)) + 0.5F) * (flying ? 30F : 5F));
float ry = 0F;
float h = 0.2F;
float i = 0.15F;
float s = 1F;
GL11.glPushMatrix();
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
GL11.glColor4f(1F, 1F, 1F, 1F);
switch(meta) {
case 1 : { // Jibril
h = 0.4F;
break;
}
case 2 : { // Sephiroth
s = 1.3F;
break;
}
case 3 : { // Cirno
h = -0.1F;
rz = 0F;
rx = 0F;
i = 0.3F;
break;
}
case 4 : { // Fire
int light = 15728880;
int lightmapX = light % 65536;
int lightmapY = light / 65536;
OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, lightmapX, lightmapY);
break;
}
case 5 : { // Kuroyukihime
h = 0.8F;
rz = 180F;
ry = -rx;
rx = 0F;
s = 2F;
break;
}
case 6 : { // Random Devil
rz = 150F;
break;
}
case 7 : { // Lyfa
h = -0.1F;
rz = 0F;
ry = -rx;
rx = 0F;
GL11.glColor4f(1F, 1F, 1F, 0.5F + (float) Math.cos((double) (event.entityPlayer.ticksExisted + event.partialRenderTick) * 0.3F) * 0.2F);
break;
}
}
float f = icon.getMinU();
float f1 = icon.getMaxU();
float f2 = icon.getMinV();
float f3 = icon.getMaxV();
float sr = 1F / s;
if(event.entityPlayer.isSneaking())
GL11.glRotatef(28.64789F, 1.0F, 0.0F, 0.0F);
GL11.glTranslatef(0F, h, i);
GL11.glRotatef(rz, 0F, 0F, 1F);
GL11.glRotatef(rx, 1F, 0F, 0F);
GL11.glRotatef(ry, 0F, 1F, 0F);
GL11.glScalef(s, s, s);
ItemRenderer.renderItemIn2D(Tessellator.instance, f1, f2, f, f3, icon.getIconWidth(), icon.getIconHeight(), 1F / 32F);
GL11.glScalef(sr, sr, sr);
GL11.glRotatef(-ry, 0F, 1F, 0F);
GL11.glRotatef(-rx, 1F, 0F, 0F);
GL11.glRotatef(-rz, 0F, 0F, 1F);
if(meta != 2) { // Sephiroth
GL11.glScalef(-1F, 1F, 1F);
GL11.glRotatef(rz, 0F, 0F, 1F);
GL11.glRotatef(rx, 1F, 0F, 0F);
GL11.glRotatef(ry, 0F, 1F, 0F);
GL11.glScalef(s, s, s);
ItemRenderer.renderItemIn2D(Tessellator.instance, f1, f2, f, f3, icon.getIconWidth(), icon.getIconHeight(), 1F / 32F);
GL11.glScalef(sr, sr, sr);
GL11.glRotatef(-ry, 1F, 0F, 0F);
GL11.glRotatef(-rx, 1F, 0F, 0F);
GL11.glRotatef(-rz, 0F, 0F, 1F);
}
GL11.glColor3f(1F, 1F, 1F);
GL11.glPopMatrix();
// Jibril's Halo
if(meta == 1)
renderHalo(event.entityPlayer, event.partialRenderTick);
}
}
}
private void renderHalo(EntityPlayer player, float partialTicks) {
float yaw = player.prevRotationYawHead + (player.rotationYawHead - player.prevRotationYawHead) * partialTicks;
float yawOffset = player.prevRenderYawOffset + (player.renderYawOffset - player.prevRenderYawOffset) * partialTicks;
float pitch = player.prevRotationPitch + (player.rotationPitch - player.prevRotationPitch) * partialTicks;
GL11.glPushMatrix();
GL11.glRotatef(yawOffset, 0, -1, 0);
GL11.glRotatef(yaw - 270, 0, 1, 0);
GL11.glRotatef(pitch, 0, 0, 1);
GL11.glShadeModel(GL11.GL_SMOOTH);
OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, 240, 240);
GL11.glDisable(GL11.GL_LIGHTING);
GL11.glColor4f(1F, 1F, 1F, 1F);
Minecraft.getMinecraft().renderEngine.bindTexture(textureHalo);
GL11.glTranslated(0, -player.getDefaultEyeHeight() + (player.isSneaking() ? 0.0625 : 0), 0);
GL11.glRotated(30, 1, 0, -1);
GL11.glTranslatef(-0.1F, -0.5F, -0.1F);
GL11.glRotatef(player.ticksExisted + partialTicks, 0, 1, 0);
Tessellator tes = Tessellator.instance;
ShaderHelper.useShader(ShaderHelper.halo);
tes.startDrawingQuads();
tes.addVertexWithUV(-0.75, 0, -0.75, 0, 0);
tes.addVertexWithUV(-0.75, 0, 0.75, 0, 1);
tes.addVertexWithUV(0.75, 0, 0.75, 1, 1);
tes.addVertexWithUV(0.75, 0, -0.75, 1, 0);
tes.draw();
ShaderHelper.releaseShader();
GL11.glEnable(GL11.GL_LIGHTING);
GL11.glShadeModel(GL11.GL_FLAT);
GL11.glPopMatrix();
}
}
@@ -0,0 +1,37 @@
/**
* This class was created by <Vazkii>. 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 a
* Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License
* (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB)
*
* File Created @ [Jul 26, 2014, 2:33:04 AM (GMT)]
*/
package vazkii.botania.client.core.handler;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.util.StatCollector;
import net.minecraftforge.event.entity.player.ItemTooltipEvent;
import vazkii.botania.common.core.helper.ItemNBTHelper;
import vazkii.botania.common.item.ItemRegenIvy;
import cpw.mods.fml.common.eventhandler.EventPriority;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
public final class TooltipHandler {
@SubscribeEvent(priority = EventPriority.HIGHEST)
public void onTooltipEvent(ItemTooltipEvent event) {
if(event.itemStack.getItem() == Item.getItemFromBlock(Blocks.dirt) && event.itemStack.getItemDamage() == 1) {
event.toolTip.add(StatCollector.translateToLocal("botaniamisc.coarseDirt0"));
event.toolTip.add(StatCollector.translateToLocal("botaniamisc.coarseDirt1"));
} else if(event.itemStack.getItem() == Item.getItemFromBlock(Blocks.mob_spawner) && event.entityPlayer.capabilities.isCreativeMode)
event.toolTip.add(StatCollector.translateToLocal("botaniamisc.spawnerTip"));
if(ItemNBTHelper.detectNBT(event.itemStack) && ItemNBTHelper.getBoolean(event.itemStack, ItemRegenIvy.TAG_REGEN, false))
event.toolTip.add(StatCollector.translateToLocal("botaniamisc.hasIvy"));
}
}
@@ -0,0 +1,43 @@
/**
* This class was created by <Vazkii>. 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 a
* Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License
* (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB)
*
* File Created @ [Jan 16, 2014, 5:30:52 PM (GMT)]
*/
package vazkii.botania.client.core.helper;
public final class FontHelper {
public static boolean isFormatColor(char par0) {
return par0 >= 48 && par0 <= 57 || par0 >= 97 && par0 <= 102 || par0 >= 65 && par0 <= 70;
}
public static boolean isFormatSpecial(char par0) {
return par0 >= 107 && par0 <= 111 || par0 >= 75 && par0 <= 79 || par0 == 114 || par0 == 82;
}
public static String getFormatFromString(String par0Str) {
String s1 = "";
int i = -1;
int j = par0Str.length();
while ((i = par0Str.indexOf(167, i + 1)) != -1) {
if (i < j - 1) {
char c0 = par0Str.charAt(i + 1);
if (isFormatColor(c0))
s1 = "\u00a7" + c0;
else if (isFormatSpecial(c0))
s1 = s1 + "\u00a7" + c0;
}
}
return s1;
}
}
@@ -0,0 +1,59 @@
/**
* This class was created by <Vazkii>. 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 a
* Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License
* (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB)
*
* File Created @ [Jan 14, 2014, 5:28:21 PM (GMT)]
*/
package vazkii.botania.client.core.helper;
import net.minecraft.block.Block;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.item.Item;
import net.minecraft.util.IIcon;
import vazkii.botania.client.lib.LibResources;
public final class IconHelper {
public static IIcon forName(IIconRegister ir, String name) {
return ir.registerIcon(LibResources.PREFIX_MOD + name);
}
public static IIcon forBlock(IIconRegister ir, Block block) {
return forName(ir, block.getUnlocalizedName().replaceAll("tile\\.", ""));
}
public static IIcon forBlock(IIconRegister ir, Block block, int i) {
return forBlock(ir, block, Integer.toString(i));
}
public static IIcon forBlock(IIconRegister ir, Block block, int i, String dir) {
return forBlock(ir, block, Integer.toString(i), dir);
}
public static IIcon forBlock(IIconRegister ir, Block block, String s) {
return forName(ir, block.getUnlocalizedName().replaceAll("tile\\.", "") + s);
}
public static IIcon forBlock(IIconRegister ir, Block block, String s, String dir) {
return forName(ir, dir + "/" + block.getUnlocalizedName().replaceAll("tile\\.", "") + s);
}
public static IIcon forItem(IIconRegister ir, Item item) {
return forName(ir, item.getUnlocalizedName().replaceAll("item\\.", ""));
}
public static IIcon forItem(IIconRegister ir, Item item, int i) {
return forItem(ir, item, Integer.toString(i));
}
public static IIcon forItem(IIconRegister ir, Item item, String s) {
return forName(ir, item.getUnlocalizedName().replaceAll("item\\.", "") + s);
}
}
@@ -0,0 +1,205 @@
/**
* This class was created by <Vazkii>. 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 a
* Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License
* (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB)
*
* File Created @ [Jan 19, 2014, 5:40:38 PM (GMT)]
*/
package vazkii.botania.client.core.helper;
import java.util.List;
import java.util.Random;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.settings.KeyBinding;
import org.lwjgl.input.Keyboard;
import org.lwjgl.opengl.GL11;
import vazkii.botania.client.core.handler.ClientTickHandler;
public final class RenderHelper {
public static void renderTooltip(int x, int y, List<String> tooltipData) {
int color = 0x505000ff;
int color2 = 0xf0100010;
renderTooltip(x, y, tooltipData, color, color2);
}
public static void renderTooltipOrange(int x, int y, List<String> tooltipData) {
int color = 0x50a06600;
int color2 = 0xf01e1200;
renderTooltip(x, y, tooltipData, color, color2);
}
public static void renderTooltipGreen(int x, int y, List<String> tooltipData) {
int color = 0x5000a000;
int color2 = 0xf0001e00;
renderTooltip(x, y, tooltipData, color, color2);
}
public static void renderTooltip(int x, int y, List<String> tooltipData, int color, int color2) {
boolean lighting = GL11.glGetBoolean(GL11.GL_LIGHTING);
if(lighting)
net.minecraft.client.renderer.RenderHelper.disableStandardItemLighting();
if (!tooltipData.isEmpty()) {
int var5 = 0;
int var6;
int var7;
FontRenderer fontRenderer = Minecraft.getMinecraft().fontRenderer;
for (var6 = 0; var6 < tooltipData.size(); ++var6) {
var7 = fontRenderer.getStringWidth(tooltipData.get(var6));
if (var7 > var5)
var5 = var7;
}
var6 = x + 12;
var7 = y - 12;
int var9 = 8;
if (tooltipData.size() > 1)
var9 += 2 + (tooltipData.size() - 1) * 10;
float z = 300F;
drawGradientRect(var6 - 3, var7 - 4, z, var6 + var5 + 3, var7 - 3, color2, color2);
drawGradientRect(var6 - 3, var7 + var9 + 3, z, var6 + var5 + 3, var7 + var9 + 4, color2, color2);
drawGradientRect(var6 - 3, var7 - 3, z, var6 + var5 + 3, var7 + var9 + 3, color2, color2);
drawGradientRect(var6 - 4, var7 - 3, z, var6 - 3, var7 + var9 + 3, color2, color2);
drawGradientRect(var6 + var5 + 3, var7 - 3, z, var6 + var5 + 4, var7 + var9 + 3, color2, color2);
int var12 = (color & 0xFFFFFF) >> 1 | color & -16777216;
drawGradientRect(var6 - 3, var7 - 3 + 1, z, var6 - 3 + 1, var7 + var9 + 3 - 1, color, var12);
drawGradientRect(var6 + var5 + 2, var7 - 3 + 1, z, var6 + var5 + 3, var7 + var9 + 3 - 1, color, var12);
drawGradientRect(var6 - 3, var7 - 3, z, var6 + var5 + 3, var7 - 3 + 1, color, color);
drawGradientRect(var6 - 3, var7 + var9 + 2, z, var6 + var5 + 3, var7 + var9 + 3, var12, var12);
GL11.glDisable(GL11.GL_DEPTH_TEST);
for (int var13 = 0; var13 < tooltipData.size(); ++var13) {
String var14 = tooltipData.get(var13);
fontRenderer.drawStringWithShadow(var14, var6, var7, -1);
if (var13 == 0)
var7 += 2;
var7 += 10;
}
GL11.glEnable(GL11.GL_DEPTH_TEST);
}
if(!lighting)
net.minecraft.client.renderer.RenderHelper.disableStandardItemLighting();
GL11.glColor4f(1F, 1F, 1F, 1F);
}
public static void drawGradientRect(int par1, int par2, float z, int par3, int par4, int par5, int par6) {
float var7 = (par5 >> 24 & 255) / 255F;
float var8 = (par5 >> 16 & 255) / 255F;
float var9 = (par5 >> 8 & 255) / 255F;
float var10 = (par5 & 255) / 255F;
float var11 = (par6 >> 24 & 255) / 255F;
float var12 = (par6 >> 16 & 255) / 255F;
float var13 = (par6 >> 8 & 255) / 255F;
float var14 = (par6 & 255) / 255F;
GL11.glDisable(GL11.GL_TEXTURE_2D);
GL11.glEnable(GL11.GL_BLEND);
GL11.glDisable(GL11.GL_ALPHA_TEST);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
GL11.glShadeModel(GL11.GL_SMOOTH);
Tessellator var15 = Tessellator.instance;
var15.startDrawingQuads();
var15.setColorRGBA_F(var8, var9, var10, var7);
var15.addVertex(par3, par2, z);
var15.addVertex(par1, par2, z);
var15.setColorRGBA_F(var12, var13, var14, var11);
var15.addVertex(par1, par4, z);
var15.addVertex(par3, par4, z);
var15.draw();
GL11.glShadeModel(GL11.GL_FLAT);
GL11.glDisable(GL11.GL_BLEND);
GL11.glEnable(GL11.GL_ALPHA_TEST);
GL11.glEnable(GL11.GL_TEXTURE_2D);
}
public static void drawTexturedModalRect(int par1, int par2, float z, int par3, int par4, int par5, int par6) {
drawTexturedModalRect(par1, par2, z, par3, par4, par5, par6, 0.00390625F, 0.00390625F);
}
public static void drawTexturedModalRect(int par1, int par2, float z, int par3, int par4, int par5, int par6, float f, float f1) {
Tessellator tessellator = Tessellator.instance;
tessellator.startDrawingQuads();
tessellator.addVertexWithUV(par1 + 0, par2 + par6, z, (par3 + 0) * f, (par4 + par6) * f1);
tessellator.addVertexWithUV(par1 + par5, par2 + par6, z, (par3 + par5) * f, (par4 + par6) * f1);
tessellator.addVertexWithUV(par1 + par5, par2 + 0, z, (par3 + par5) * f, (par4 + 0) * f1);
tessellator.addVertexWithUV(par1 + 0, par2 + 0, z, (par3 + 0) * f, (par4 + 0) * f1);
tessellator.draw();
}
public static void renderStar(int color, float xScale, float yScale, float zScale, long seed) {
Tessellator tessellator = Tessellator.instance;
int ticks = ClientTickHandler.ticksInGame % 200;
if (ticks >= 100)
ticks = 200 - ticks - 1;
float f1 = ticks / 200F;
float f2 = 0F;
if (f1 > 0.7F)
f2 = (f1 - 0.7F) / 0.2F;
Random random = new Random(seed);
GL11.glPushMatrix();
GL11.glDisable(GL11.GL_TEXTURE_2D);
GL11.glShadeModel(GL11.GL_SMOOTH);
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(770, 1);
GL11.glDisable(GL11.GL_ALPHA_TEST);
GL11.glEnable(GL11.GL_CULL_FACE);
GL11.glDepthMask(false);
GL11.glTranslatef(0F, -1F, -2F);
GL11.glScalef(xScale, yScale, zScale);
for (int i = 0; i < (f1 + f1 * f1) / 2F * 90F + 30F; i++) {
GL11.glRotatef(random.nextFloat() * 360F, 1F, 0F, 0F);
GL11.glRotatef(random.nextFloat() * 360F, 0F, 1F, 0F);
GL11.glRotatef(random.nextFloat() * 360F, 0F, 0F, 1F);
GL11.glRotatef(random.nextFloat() * 360F, 1F, 0F, 0F);
GL11.glRotatef(random.nextFloat() * 360F, 0F, 1F, 0F);
GL11.glRotatef(random.nextFloat() * 360F + f1 * 90F, 0F, 0F, 1F);
tessellator.startDrawing(GL11.GL_TRIANGLE_FAN);
float f3 = random.nextFloat() * 20F + 5F + f2 * 10F;
float f4 = random.nextFloat() * 2F + 1F + f2 * 2F;
tessellator.setColorRGBA_I(color, (int) (255F * (1F - f2)));
tessellator.addVertex(0, 0, 0);
tessellator.setColorRGBA_F(0F, 0F, 0F, 0);
tessellator.addVertex(-0.866D * f4, f3, -0.5F * f4);
tessellator.addVertex(0.866D * f4, f3, -0.5F * f4);
tessellator.addVertex(0, f3, 1F * f4);
tessellator.addVertex(-0.866D * f4, f3, -0.5F * f4);
tessellator.draw();
}
GL11.glDepthMask(true);
GL11.glDisable(GL11.GL_CULL_FACE);
GL11.glDisable(GL11.GL_BLEND);
GL11.glShadeModel(GL11.GL_FLAT);
GL11.glColor4f(1F, 1F, 1F, 1F);
GL11.glEnable(GL11.GL_TEXTURE_2D);
GL11.glEnable(GL11.GL_ALPHA_TEST);
GL11.glPopMatrix();
}
public static String getKeyDisplayString(String keyName) {
String key = null;
KeyBinding[] keys = Minecraft.getMinecraft().gameSettings.keyBindings;
for(KeyBinding otherKey : keys)
if(otherKey.getKeyDescription().equals(keyName)) {
key = Keyboard.getKeyName(otherKey.getKeyCode());
break;
}
return key;
}
}
@@ -0,0 +1,193 @@
/**
* This class was created by <Vazkii>. 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 a
* Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License
* (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB)
*
* File Created @ [Apr 9, 2014, 11:20:26 PM (GMT)]
*/
package vazkii.botania.client.core.helper;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import net.minecraft.client.renderer.OpenGlHelper;
import org.apache.logging.log4j.Level;
import org.lwjgl.opengl.ARBFragmentShader;
import org.lwjgl.opengl.ARBShaderObjects;
import org.lwjgl.opengl.ARBVertexShader;
import org.lwjgl.opengl.GL11;
import vazkii.botania.api.internal.ShaderCallback;
import vazkii.botania.client.core.handler.ClientTickHandler;
import vazkii.botania.client.lib.LibResources;
import vazkii.botania.common.core.handler.ConfigHandler;
import cpw.mods.fml.common.FMLLog;
public final class ShaderHelper {
private static final int VERT = ARBVertexShader.GL_VERTEX_SHADER_ARB;
private static final int FRAG = ARBFragmentShader.GL_FRAGMENT_SHADER_ARB;
public static int pylonGlow = 0;
public static int enchanterRune = 0;
public static int manaPool = 0;
public static int doppleganger = 0;
public static int halo = 0;
public static int dopplegangerBar = 0;
public static void initShaders() {
if(!useShaders())
return;
pylonGlow = createProgram(null, LibResources.SHADER_PYLON_GLOW_FRAG);
enchanterRune = createProgram(null, LibResources.SHADER_ENCHANTER_RUNE_FRAG);
manaPool = createProgram(null, LibResources.SHADER_MANA_POOL_FRAG);
doppleganger = createProgram(LibResources.SHADER_DOPLLEGANGER_VERT, LibResources.SHADER_DOPLLEGANGER_FRAG);
halo = createProgram(null, LibResources.SHADER_HALO_FRAG);
dopplegangerBar = createProgram(null, LibResources.SHADER_DOPLLEGANGER_BAR_FRAG);
}
public static void useShader(int shader, ShaderCallback callback) {
if(!useShaders())
return;
ARBShaderObjects.glUseProgramObjectARB(shader);
if(shader != 0) {
int time = ARBShaderObjects.glGetUniformLocationARB(shader, "time");
ARBShaderObjects.glUniform1iARB(time, ClientTickHandler.ticksInGame);
if(callback != null)
callback.call(shader);
}
}
public static void useShader(int shader) {
useShader(shader, null);
}
public static void releaseShader() {
useShader(0);
}
public static boolean useShaders() {
return ConfigHandler.useShaders && OpenGlHelper.shadersSupported;
}
// Most of the code taken from the LWJGL wiki
// http://lwjgl.org/wiki/index.php?title=GLSL_Shaders_with_LWJGL
private static int createProgram(String vert, String frag) {
int vertId = 0, fragId = 0, program = 0;
if(vert != null)
vertId = createShader(vert, VERT);
if(frag != null)
fragId = createShader(frag, FRAG);
program = ARBShaderObjects.glCreateProgramObjectARB();
if(program == 0)
return 0;
if(vert != null)
ARBShaderObjects.glAttachObjectARB(program, vertId);
if(frag != null)
ARBShaderObjects.glAttachObjectARB(program, fragId);
ARBShaderObjects.glLinkProgramARB(program);
if(ARBShaderObjects.glGetObjectParameteriARB(program, ARBShaderObjects.GL_OBJECT_LINK_STATUS_ARB) == GL11.GL_FALSE) {
FMLLog.log(Level.ERROR, getLogInfo(program));
return 0;
}
ARBShaderObjects.glValidateProgramARB(program);
if (ARBShaderObjects.glGetObjectParameteriARB(program, ARBShaderObjects.GL_OBJECT_VALIDATE_STATUS_ARB) == GL11.GL_FALSE) {
FMLLog.log(Level.ERROR, getLogInfo(program));
return 0;
}
return program;
}
private static int createShader(String filename, int shaderType){
int shader = 0;
try {
shader = ARBShaderObjects.glCreateShaderObjectARB(shaderType);
if(shader == 0)
return 0;
ARBShaderObjects.glShaderSourceARB(shader, readFileAsString(filename));
ARBShaderObjects.glCompileShaderARB(shader);
if (ARBShaderObjects.glGetObjectParameteriARB(shader, ARBShaderObjects.GL_OBJECT_COMPILE_STATUS_ARB) == GL11.GL_FALSE)
throw new RuntimeException("Error creating shader: " + getLogInfo(shader));
return shader;
}
catch(Exception e) {
ARBShaderObjects.glDeleteObjectARB(shader);
e.printStackTrace();
return -1;
}
}
private static String getLogInfo(int obj) {
return ARBShaderObjects.glGetInfoLogARB(obj, ARBShaderObjects.glGetObjectParameteriARB(obj, ARBShaderObjects.GL_OBJECT_INFO_LOG_LENGTH_ARB));
}
private static String readFileAsString(String filename) throws Exception {
StringBuilder source = new StringBuilder();
InputStream in = ShaderHelper.class.getResourceAsStream(filename);
Exception exception = null;
BufferedReader reader;
if(in == null)
return "";
try {
reader = new BufferedReader(new InputStreamReader(in, "UTF-8"));
Exception innerExc= null;
try {
String line;
while((line = reader.readLine()) != null)
source.append(line).append('\n');
} catch(Exception exc) {
exception = exc;
} finally {
try {
reader.close();
} catch(Exception exc) {
if(innerExc == null)
innerExc = exc;
else exc.printStackTrace();
}
}
if(innerExc != null)
throw innerExc;
} catch(Exception exc) {
exception = exc;
} finally {
try {
in.close();
} catch(Exception exc) {
if(exception == null)
exception = exc;
else exc.printStackTrace();
}
if(exception != null)
throw exception;
}
return source.toString();
}
}
@@ -0,0 +1,295 @@
/**
* This class was created by <Vazkii>. 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 a
* Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License
* (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB)
*
* File Created @ [Jan 13, 2014, 7:46:05 PM (GMT)]
*/
package vazkii.botania.client.core.proxy;
import java.awt.Desktop;
import java.net.URI;
import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.PlayerControllerMP;
import net.minecraft.client.network.NetHandlerPlayClient;
import net.minecraft.client.renderer.entity.RenderSnowball;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntitySkull;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.util.StatCollector;
import net.minecraft.util.StringTranslate;
import net.minecraft.world.World;
import net.minecraft.world.WorldSettings.GameType;
import net.minecraftforge.client.MinecraftForgeClient;
import net.minecraftforge.common.MinecraftForge;
import vazkii.botania.api.item.IExtendedPlayerController;
import vazkii.botania.api.lexicon.LexiconEntry;
import vazkii.botania.api.wiki.IWikiProvider;
import vazkii.botania.api.wiki.WikiHooks;
import vazkii.botania.client.core.handler.BotaniaPlayerController;
import vazkii.botania.client.core.handler.BoundTileRenderer;
import vazkii.botania.client.core.handler.ClientTickHandler;
import vazkii.botania.client.core.handler.DebugHandler;
import vazkii.botania.client.core.handler.HUDHandler;
import vazkii.botania.client.core.handler.LightningHandler;
import vazkii.botania.client.core.handler.TiaraWingRenderHandler;
import vazkii.botania.client.core.handler.TooltipHandler;
import vazkii.botania.client.core.helper.ShaderHelper;
import vazkii.botania.client.fx.FXSparkle;
import vazkii.botania.client.fx.FXWisp;
import vazkii.botania.client.gui.lexicon.GuiLexicon;
import vazkii.botania.client.gui.lexicon.GuiLexiconEntry;
import vazkii.botania.client.gui.lexicon.GuiLexiconIndex;
import vazkii.botania.client.lib.LibRenderIDs;
import vazkii.botania.client.render.block.RenderAltar;
import vazkii.botania.client.render.block.RenderBrewery;
import vazkii.botania.client.render.block.RenderMiniIsland;
import vazkii.botania.client.render.block.RenderPool;
import vazkii.botania.client.render.block.RenderPylon;
import vazkii.botania.client.render.block.RenderSpawnerClaw;
import vazkii.botania.client.render.block.RenderSpecialFlower;
import vazkii.botania.client.render.block.RenderSpreader;
import vazkii.botania.client.render.block.RenderTinyPotato;
import vazkii.botania.client.render.entity.RenderDoppleganger;
import vazkii.botania.client.render.entity.RenderPixie;
import vazkii.botania.client.render.entity.RenderSpark;
import vazkii.botania.client.render.item.RenderLens;
import vazkii.botania.client.render.item.RenderLexicon;
import vazkii.botania.client.render.item.RenderTransparentItem;
import vazkii.botania.client.render.tile.RenderTileAlfPortal;
import vazkii.botania.client.render.tile.RenderTileAltar;
import vazkii.botania.client.render.tile.RenderTileBrewery;
import vazkii.botania.client.render.tile.RenderTileEnchanter;
import vazkii.botania.client.render.tile.RenderTileMiniIsland;
import vazkii.botania.client.render.tile.RenderTilePool;
import vazkii.botania.client.render.tile.RenderTilePylon;
import vazkii.botania.client.render.tile.RenderTileRuneAltar;
import vazkii.botania.client.render.tile.RenderTileSkullOverride;
import vazkii.botania.client.render.tile.RenderTileSpawnerClaw;
import vazkii.botania.client.render.tile.RenderTileSpreader;
import vazkii.botania.client.render.tile.RenderTileStarfield;
import vazkii.botania.client.render.tile.RenderTileTinyPotato;
import vazkii.botania.common.block.tile.TileAlfPortal;
import vazkii.botania.common.block.tile.TileAltar;
import vazkii.botania.common.block.tile.TileBrewery;
import vazkii.botania.common.block.tile.TileEnchanter;
import vazkii.botania.common.block.tile.TileMiniIsland;
import vazkii.botania.common.block.tile.TilePylon;
import vazkii.botania.common.block.tile.TileRuneAltar;
import vazkii.botania.common.block.tile.TileSpawnerClaw;
import vazkii.botania.common.block.tile.TileStarfield;
import vazkii.botania.common.block.tile.TileTinyPotato;
import vazkii.botania.common.block.tile.mana.TilePool;
import vazkii.botania.common.block.tile.mana.TileSpreader;
import vazkii.botania.common.core.handler.ConfigHandler;
import vazkii.botania.common.core.helper.Vector3;
import vazkii.botania.common.core.proxy.CommonProxy;
import vazkii.botania.common.core.version.VersionChecker;
import vazkii.botania.common.entity.EntityDoppleganger;
import vazkii.botania.common.entity.EntityPixie;
import vazkii.botania.common.entity.EntitySpark;
import vazkii.botania.common.entity.EntityVineBall;
import vazkii.botania.common.item.ModItems;
import vazkii.botania.common.lib.LibObfuscation;
import cpw.mods.fml.client.registry.ClientRegistry;
import cpw.mods.fml.client.registry.RenderingRegistry;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.Loader;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.common.registry.LanguageRegistry;
import cpw.mods.fml.relauncher.ReflectionHelper;
public class ClientProxy extends CommonProxy {
@Override
public void init(FMLInitializationEvent event) {
super.init(event);
FMLCommonHandler.instance().bus().register(new ClientTickHandler());
MinecraftForge.EVENT_BUS.register(new HUDHandler());
MinecraftForge.EVENT_BUS.register(new LightningHandler());
if(ConfigHandler.boundBlockWireframe)
MinecraftForge.EVENT_BUS.register(new BoundTileRenderer());
MinecraftForge.EVENT_BUS.register(new TooltipHandler());
MinecraftForge.EVENT_BUS.register(new TiaraWingRenderHandler());
MinecraftForge.EVENT_BUS.register(new DebugHandler());
if(ConfigHandler.versionCheckEnabled)
new VersionChecker().init();
initRenderers();
}
private void initRenderers() {
LibRenderIDs.idAltar = RenderingRegistry.getNextAvailableRenderId();
LibRenderIDs.idSpecialFlower = RenderingRegistry.getNextAvailableRenderId();
LibRenderIDs.idSpreader = RenderingRegistry.getNextAvailableRenderId();
LibRenderIDs.idPool = RenderingRegistry.getNextAvailableRenderId();
LibRenderIDs.idPylon = RenderingRegistry.getNextAvailableRenderId();
LibRenderIDs.idMiniIsland = RenderingRegistry.getNextAvailableRenderId();
LibRenderIDs.idTinyPotato = RenderingRegistry.getNextAvailableRenderId();
LibRenderIDs.idSpawnerClaw = RenderingRegistry.getNextAvailableRenderId();
LibRenderIDs.idBrewery = RenderingRegistry.getNextAvailableRenderId();
RenderingRegistry.registerBlockHandler(new RenderAltar());
RenderingRegistry.registerBlockHandler(new RenderSpecialFlower(LibRenderIDs.idSpecialFlower));
RenderingRegistry.registerBlockHandler(new RenderSpreader());
RenderingRegistry.registerBlockHandler(new RenderPool());
RenderingRegistry.registerBlockHandler(new RenderPylon());
RenderingRegistry.registerBlockHandler(new RenderMiniIsland());
RenderingRegistry.registerBlockHandler(new RenderTinyPotato());
RenderingRegistry.registerBlockHandler(new RenderSpawnerClaw());
RenderingRegistry.registerBlockHandler(new RenderBrewery());
MinecraftForgeClient.registerItemRenderer(ModItems.lens, new RenderLens());
if(ConfigHandler.lexicon3dModel)
MinecraftForgeClient.registerItemRenderer(ModItems.lexicon, new RenderLexicon());
MinecraftForgeClient.registerItemRenderer(ModItems.glassPick, new RenderTransparentItem());
MinecraftForgeClient.registerItemRenderer(ModItems.spark, new RenderTransparentItem());
ClientRegistry.bindTileEntitySpecialRenderer(TileAltar.class, new RenderTileAltar());
ClientRegistry.bindTileEntitySpecialRenderer(TileSpreader.class, new RenderTileSpreader());
ClientRegistry.bindTileEntitySpecialRenderer(TilePool.class, new RenderTilePool());
ClientRegistry.bindTileEntitySpecialRenderer(TileRuneAltar.class, new RenderTileRuneAltar());
ClientRegistry.bindTileEntitySpecialRenderer(TilePylon.class, new RenderTilePylon());
ClientRegistry.bindTileEntitySpecialRenderer(TileEnchanter.class, new RenderTileEnchanter());
ClientRegistry.bindTileEntitySpecialRenderer(TileAlfPortal.class, new RenderTileAlfPortal());
ClientRegistry.bindTileEntitySpecialRenderer(TileMiniIsland.class, new RenderTileMiniIsland());
ClientRegistry.bindTileEntitySpecialRenderer(TileTinyPotato.class, new RenderTileTinyPotato());
ClientRegistry.bindTileEntitySpecialRenderer(TileSpawnerClaw.class, new RenderTileSpawnerClaw());
ClientRegistry.bindTileEntitySpecialRenderer(TileStarfield.class, new RenderTileStarfield());
ClientRegistry.bindTileEntitySpecialRenderer(TileBrewery.class, new RenderTileBrewery());
if(Loader.instance().getMCVersionString().equals("Minecraft 1.7.10"))
ClientRegistry.bindTileEntitySpecialRenderer(TileEntitySkull.class, new RenderTileSkullOverride());
RenderingRegistry.registerEntityRenderingHandler(EntityPixie.class, new RenderPixie());
RenderingRegistry.registerEntityRenderingHandler(EntityVineBall.class, new RenderSnowball(ModItems.vineBall));
RenderingRegistry.registerEntityRenderingHandler(EntityDoppleganger.class, new RenderDoppleganger());
RenderingRegistry.registerEntityRenderingHandler(EntitySpark.class, new RenderSpark());
ShaderHelper.initShaders();
}
@Override
public void setEntryToOpen(LexiconEntry entry) {
GuiLexicon.currentOpenLexicon = new GuiLexiconEntry(entry, new GuiLexiconIndex(entry.category));
}
@Override
public boolean isTheClientPlayer(EntityLivingBase entity) {
return entity == Minecraft.getMinecraft().thePlayer;
}
@Override
public void setExtraReach(EntityLivingBase entity, float reach) {
super.setExtraReach(entity, reach);
Minecraft mc = Minecraft.getMinecraft();
EntityPlayer player = mc.thePlayer;
if(entity == player) {
if(!(mc.playerController instanceof IExtendedPlayerController)) {
GameType type = ReflectionHelper.getPrivateValue(PlayerControllerMP.class, mc.playerController, LibObfuscation.CURRENT_GAME_TYPE);
NetHandlerPlayClient net = ReflectionHelper.getPrivateValue(PlayerControllerMP.class, mc.playerController, LibObfuscation.NET_CLIENT_HANDLER);
BotaniaPlayerController controller = new BotaniaPlayerController(mc, net);
controller.setGameType(type);
mc.playerController = controller;
}
((IExtendedPlayerController) mc.playerController).setReachDistanceExtension(Math.max(0, ((IExtendedPlayerController) mc.playerController).getReachDistanceExtension() + reach));
}
}
@Override
public boolean openWikiPage(World world, Block block, MovingObjectPosition pos) {
IWikiProvider wiki = WikiHooks.getWikiFor(block);
String url = wiki.getWikiURL(world, pos);
if(url != null && !url.isEmpty()) {
try {
Desktop.getDesktop().browse(new URI(url));
} catch(Exception e) {
e.printStackTrace();
return false;
}
return true;
}
return false;
}
@Override
public long getWorldElapsedTicks() {
return Minecraft.getMinecraft().theWorld == null ? 0 : Minecraft.getMinecraft().theWorld.getTotalWorldTime();
}
private static boolean noclipEnabled = false;
@Override
public void setSparkleFXNoClip(boolean noclip) {
noclipEnabled = noclip;
}
@Override
public void sparkleFX(World world, double x, double y, double z, float r, float g, float b, float size, int m, boolean fake) {
if(!doParticle() && !fake)
return;
FXSparkle sparkle = new FXSparkle(world, x, y, z, size, r, g, b, m);
sparkle.fake = sparkle.noClip = fake;
if(noclipEnabled)
sparkle.noClip = true;
Minecraft.getMinecraft().effectRenderer.addEffect(sparkle);
}
private static boolean distanceLimit = true;
private static boolean depthTest = true;
@Override
public void setWispFXDistanceLimit(boolean limit) {
distanceLimit = limit;
}
@Override
public void setWispFXDepthTest(boolean test) {
depthTest = test;
}
@Override
public void wispFX(World world, double x, double y, double z, float r, float g, float b, float size, float motionx, float motiony, float motionz, float maxAgeMul) {
if(!doParticle())
return;
FXWisp wisp = new FXWisp(world, x, y, z, size, r, g, b, distanceLimit, depthTest, maxAgeMul);
wisp.motionX = motionx;
wisp.motionY = motiony;
wisp.motionZ = motionz;
Minecraft.getMinecraft().effectRenderer.addEffect(wisp);
}
private boolean doParticle() {
if(!ConfigHandler.useVanillaParticleLimiter)
return true;
float chance = 1F;
if(Minecraft.getMinecraft().gameSettings.particleSetting == 1)
chance = 0.6F;
else if(Minecraft.getMinecraft().gameSettings.particleSetting == 2)
chance = 0.2F;
return Math.random() < chance;
}
@Override
public void lightningFX(World world, Vector3 vectorStart, Vector3 vectorEnd, float ticksPerMeter, long seed, int colorOuter, int colorInner) {
LightningHandler.spawnLightningBolt(world, vectorStart, vectorEnd, ticksPerMeter, seed, colorOuter, colorInner);
}
}
@@ -0,0 +1,43 @@
/**
* This class was created by <Vazkii>. 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 a
* Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License
* (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB)
*
* File Created @ [Jun 27, 2014, 1:50:49 AM (GMT)]
*/
package vazkii.botania.client.core.proxy;
import java.util.Set;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiScreen;
import vazkii.botania.client.gui.GuiBotaniaConfig;
import cpw.mods.fml.client.IModGuiFactory;
public class GuiFactory implements IModGuiFactory {
@Override
public void initialize(Minecraft minecraftInstance) {
// NO-OP
}
@Override
public Class<? extends GuiScreen> mainConfigGuiClass() {
return GuiBotaniaConfig.class;
}
@Override
public Set<RuntimeOptionCategoryElement> runtimeGuiCategories() {
return null;
}
@Override
public RuntimeOptionGuiHandler getHandlerFor(RuntimeOptionCategoryElement element) {
return null;
}
}
@@ -0,0 +1,246 @@
/**
* This class was created by <Azanor>. 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 a
* Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License
* (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB)
*
* File Created @ [? (GMT)]
*/
package vazkii.botania.client.fx;
import java.util.ArrayDeque;
import java.util.Queue;
import net.minecraft.client.Minecraft;
import net.minecraft.client.particle.EntityFX;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.util.MathHelper;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;
import org.lwjgl.opengl.GL11;
import vazkii.botania.client.lib.LibResources;
import vazkii.botania.common.core.handler.ConfigHandler;
import vazkii.botania.common.core.helper.ObfuscationHelper;
public class FXSparkle extends EntityFX {
public static final ResourceLocation particles = new ResourceLocation(LibResources.MISC_PARTICLES);
public static Queue<FXSparkle> queuedRenders = new ArrayDeque();
// Queue values
float f;
float f1;
float f2;
float f3;
float f4;
float f5;
public FXSparkle(World world, double x, double y, double z, float size, float red, float green, float blue, int m) {
super(world, x, y, z, 0.0D, 0.0D, 0.0D);
particleRed = red;
particleGreen = green;
particleBlue = blue;
particleGravity = 0;
motionX = motionY = motionZ = 0;
particleScale *= size;
particleMaxAge = 3 * m;
multiplier = m;
noClip = false;
setSize(0.01F, 0.01F);
prevPosX = posX;
prevPosY = posY;
prevPosZ = posZ;
}
public static void dispatchQueuedRenders(Tessellator tessellator) {
ParticleRenderDispatcher.sparkleFxCount = 0;
ParticleRenderDispatcher.fakeSparkleFxCount = 0;
GL11.glColor4f(1.0F, 1.0F, 1.0F, 0.75F);
Minecraft.getMinecraft().renderEngine.bindTexture(ConfigHandler.matrixMode ? ObfuscationHelper.getParticleTexture() : particles);
tessellator.startDrawingQuads();
for(FXSparkle sparkle : queuedRenders)
sparkle.renderQueued(tessellator);
tessellator.draw();
queuedRenders.clear();
}
private void renderQueued(Tessellator tessellator) {
if(fake)
ParticleRenderDispatcher.fakeSparkleFxCount++;
else ParticleRenderDispatcher.sparkleFxCount++;
int part = particle + particleAge/multiplier;
float var8 = part % 8 / 8.0F;
float var9 = var8 + 0.0624375F*2;
float var10 = part / 8 / 8.0F;
float var11 = var10 + 0.0624375F*2;
float var12 = 0.1F * particleScale;
if (shrink) var12 *= (particleMaxAge-particleAge+1)/(float)particleMaxAge;
float var13 = (float)(prevPosX + (posX - prevPosX) * f - interpPosX);
float var14 = (float)(prevPosY + (posY - prevPosY) * f - interpPosY);
float var15 = (float)(prevPosZ + (posZ - prevPosZ) * f - interpPosZ);
float var16 = 1.0F;
tessellator.setBrightness(0x0000f0);
tessellator.setColorRGBA_F(particleRed * var16, particleGreen * var16, particleBlue * var16, 1);
tessellator.addVertexWithUV(var13 - f1 * var12 - f4 * var12, var14 - f2 * var12, var15 - f3 * var12 - f5 * var12, var9, var11);
tessellator.addVertexWithUV(var13 - f1 * var12 + f4 * var12, var14 + f2 * var12, var15 - f3 * var12 + f5 * var12, var9, var10);
tessellator.addVertexWithUV(var13 + f1 * var12 + f4 * var12, var14 + f2 * var12, var15 + f3 * var12 + f5 * var12, var8, var10);
tessellator.addVertexWithUV(var13 + f1 * var12 - f4 * var12, var14 - f2 * var12, var15 + f3 * var12 - f5 * var12, var8, var11);
}
@Override
public void renderParticle(Tessellator tessellator, float f, float f1, float f2, float f3, float f4, float f5) {
this.f = f;
this.f1 = f1;
this.f2 = f2;
this.f3 = f3;
this.f4 = f4;
this.f5 = f5;
queuedRenders.add(this);
}
@Override
public void onUpdate() {
prevPosX = posX;
prevPosY = posY;
prevPosZ = posZ;
if (particleAge++ >= particleMaxAge)
setDead();
motionY -= 0.04D * particleGravity;
if (!noClip && !fake)
pushOutOfBlocks(posX, (boundingBox.minY + boundingBox.maxY) / 2.0D, posZ);
posX += motionX;
posY += motionY;
posZ += motionZ;
if (slowdown) {
motionX *= 0.908000001907348633D;
motionY *= 0.908000001907348633D;
motionZ *= 0.908000001907348633D;
if (onGround) {
motionX *= 0.69999998807907104D;
motionZ *= 0.69999998807907104D;
}
}
if(fake && particleAge > 1)
setDead();
}
public void setGravity(float value) {
particleGravity = value;
}
protected boolean pushOutOfBlocks(double par1, double par3, double par5) {
int var7 = MathHelper.floor_double(par1);
int var8 = MathHelper.floor_double(par3);
int var9 = MathHelper.floor_double(par5);
double var10 = par1 - var7;
double var12 = par3 - var8;
double var14 = par5 - var9;
if (!worldObj.isAirBlock(var7, var8, var9)) {
boolean var16 = !worldObj.isBlockNormalCubeDefault(var7 - 1, var8, var9, false);
boolean var17 = !worldObj.isBlockNormalCubeDefault(var7 + 1, var8, var9, false);
boolean var18 = !worldObj.isBlockNormalCubeDefault(var7, var8 - 1, var9, false);
boolean var19 = !worldObj.isBlockNormalCubeDefault(var7, var8 + 1, var9, false);
boolean var20 = !worldObj.isBlockNormalCubeDefault(var7, var8, var9 - 1, false);
boolean var21 = !worldObj.isBlockNormalCubeDefault(var7, var8, var9 + 1, false);
byte var22 = -1;
double var23 = 9999.0D;
if (var16 && var10 < var23) {
var23 = var10;
var22 = 0;
}
if (var17 && 1.0D - var10 < var23) {
var23 = 1.0D - var10;
var22 = 1;
}
if (var18 && var12 < var23) {
var23 = var12;
var22 = 2;
}
if (var19 && 1.0D - var12 < var23) {
var23 = 1.0D - var12;
var22 = 3;
}
if (var20 && var14 < var23) {
var23 = var14;
var22 = 4;
}
if (var21 && 1.0D - var14 < var23) {
var23 = 1.0D - var14;
var22 = 5;
}
float var25 = rand.nextFloat() * 0.05F + 0.025F;
float var26 = (rand.nextFloat() - rand.nextFloat()) * 0.1F;
if (var22 == 0) {
motionX = -var25;
motionY=motionZ=var26;
}
if (var22 == 1) {
motionX = var25;
motionY=motionZ=var26;
}
if (var22 == 2) {
motionY = -var25;
motionX=motionZ=var26;
}
if (var22 == 3) {
motionY = var25;
motionX=motionZ=var26;
}
if (var22 == 4) {
motionZ = -var25;
motionY=motionX=var26;
}
if (var22 == 5) {
motionZ = var25;
motionY=motionX=var26;
}
return true;
} else return false;
}
public boolean fake = false;
public int multiplier = 2;
public boolean shrink = true;
public int particle = 16;
public boolean tinkle = false;
public boolean slowdown = true;
public int currentColor = 0;
}
@@ -0,0 +1,171 @@
/**
* This class was created by <Azanor>. 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 a
* Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License
* (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB)
*
* File Created @ [? (GMT)]
*/
package vazkii.botania.client.fx;
import java.util.ArrayDeque;
import java.util.Queue;
import net.minecraft.client.Minecraft;
import net.minecraft.client.particle.EntityFX;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;
import org.lwjgl.opengl.GL11;
import vazkii.botania.client.lib.LibResources;
import vazkii.botania.common.core.handler.ConfigHandler;
import vazkii.botania.common.core.helper.ObfuscationHelper;
import cpw.mods.fml.client.FMLClientHandler;
public class FXWisp extends EntityFX {
public static final ResourceLocation particles = new ResourceLocation(LibResources.MISC_WISP_LARGE);
public static Queue<FXWisp> queuedRenders = new ArrayDeque();
public static Queue<FXWisp> queuedDepthIgnoringRenders = new ArrayDeque();
// Queue values
float f;
float f1;
float f2;
float f3;
float f4;
float f5;
public FXWisp(World world, double d, double d1, double d2, float size, float red, float green, float blue, boolean distanceLimit, boolean depthTest, float maxAgeMul) {
super(world, d, d1, d2, 0.0D, 0.0D, 0.0D);
particleRed = red;
particleGreen = green;
particleBlue = blue;
particleGravity = 0;
motionX = motionY = motionZ = 0;
particleScale *= size;
moteParticleScale = particleScale;
particleMaxAge = (int)(28D / (Math.random() * 0.3D + 0.7D) * maxAgeMul);
this.depthTest = depthTest;
moteHalfLife = particleMaxAge / 2;
noClip = true;
setSize(0.01F, 0.01F);
EntityLivingBase renderentity = FMLClientHandler.instance().getClient().renderViewEntity;
if(distanceLimit) {
int visibleDistance = 50;
if (!FMLClientHandler.instance().getClient().gameSettings.fancyGraphics)
visibleDistance = 25;
if (renderentity == null || renderentity.getDistance(posX, posY, posZ) > visibleDistance)
particleMaxAge = 0;
}
prevPosX = posX;
prevPosY = posY;
prevPosZ = posZ;
}
public static void dispatchQueuedRenders(Tessellator tessellator) {
ParticleRenderDispatcher.wispFxCount = 0;
ParticleRenderDispatcher.depthIgnoringWispFxCount = 0;
GL11.glColor4f(1.0F, 1.0F, 1.0F, 0.75F);
Minecraft.getMinecraft().renderEngine.bindTexture(ConfigHandler.matrixMode ? ObfuscationHelper.getParticleTexture() : particles);
if(!queuedRenders.isEmpty()) {
tessellator.startDrawingQuads();
for(FXWisp wisp : queuedRenders)
wisp.renderQueued(tessellator, true);
tessellator.draw();
}
if(!queuedDepthIgnoringRenders.isEmpty()) {
GL11.glDisable(GL11.GL_DEPTH_TEST);
tessellator.startDrawingQuads();
for(FXWisp wisp : queuedDepthIgnoringRenders)
wisp.renderQueued(tessellator, false);
tessellator.draw();
GL11.glEnable(GL11.GL_DEPTH_TEST);
}
queuedRenders.clear();
queuedDepthIgnoringRenders.clear();
}
private void renderQueued(Tessellator tessellator, boolean depthEnabled) {
if(depthEnabled)
ParticleRenderDispatcher.wispFxCount++;
else ParticleRenderDispatcher.depthIgnoringWispFxCount++;
float agescale = 0;
agescale = (float)particleAge / (float) moteHalfLife;
if (agescale > 1F)
agescale = 2 - agescale;
particleScale = moteParticleScale * agescale;
float f10 = 0.5F * particleScale;
float f11 = (float)(prevPosX + (posX - prevPosX) * f - interpPosX);
float f12 = (float)(prevPosY + (posY - prevPosY) * f - interpPosY);
float f13 = (float)(prevPosZ + (posZ - prevPosZ) * f - interpPosZ);
tessellator.setBrightness(240);
tessellator.setColorRGBA_F(particleRed, particleGreen, particleBlue, 0.5F);
tessellator.addVertexWithUV(f11 - f1 * f10 - f4 * f10, f12 - f2 * f10, f13 - f3 * f10 - f5 * f10, 0, 1);
tessellator.addVertexWithUV(f11 - f1 * f10 + f4 * f10, f12 + f2 * f10, f13 - f3 * f10 + f5 * f10, 1, 1);
tessellator.addVertexWithUV(f11 + f1 * f10 + f4 * f10, f12 + f2 * f10, f13 + f3 * f10 + f5 * f10, 1, 0);
tessellator.addVertexWithUV(f11 + f1 * f10 - f4 * f10, f12 - f2 * f10, f13 + f3 * f10 - f5 * f10, 0, 0);
}
@Override
public void renderParticle(Tessellator tessellator, float f, float f1, float f2, float f3, float f4, float f5) {
this.f = f;
this.f1 = f1;
this.f2 = f2;
this.f3 = f3;
this.f4 = f4;
this.f5 = f5;
if(depthTest)
queuedRenders.add(this);
else queuedDepthIgnoringRenders.add(this);
}
@Override
public void onUpdate() {
prevPosX = posX;
prevPosY = posY;
prevPosZ = posZ;
if (particleAge++ >= particleMaxAge)
setDead();
motionY -= 0.04D * particleGravity;
posX += motionX;
posY += motionY;
posZ += motionZ;
motionX *= 0.98000001907348633D;
motionY *= 0.98000001907348633D;
motionZ *= 0.98000001907348633D;
}
public void setGravity(float value) {
particleGravity = value;
}
boolean depthTest = true;
public boolean distanceLimit = true;
float moteParticleScale;
int moteHalfLife;
public boolean tinkle = false;
public int blendmode = 1;
}
@@ -0,0 +1,56 @@
/**
* This class was created by <Vazkii>. 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 a
* Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License
* (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB)
*
* File Created @ [Jul 2, 2014, 12:12:45 AM (GMT)]
*/
package vazkii.botania.client.fx;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.profiler.Profiler;
import org.lwjgl.opengl.GL11;
public final class ParticleRenderDispatcher {
public static int wispFxCount = 0;
public static int depthIgnoringWispFxCount = 0;
public static int sparkleFxCount = 0;
public static int fakeSparkleFxCount = 0;
public static int lightningCount = 0;
// Called from LightningHandler.onRenderWorldLast since that was
// already registered. /shrug
public static void dispatch() {
Tessellator tessellator = Tessellator.instance;
boolean isLightingEnabled = GL11.glGetBoolean(GL11.GL_LIGHTING);
Profiler profiler = Minecraft.getMinecraft().mcProfiler;
GL11.glDepthMask(false);
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE);
GL11.glAlphaFunc(GL11.GL_GREATER, 0.003921569F);
if(isLightingEnabled)
GL11.glDisable(GL11.GL_LIGHTING);
profiler.startSection("sparkle");
FXSparkle.dispatchQueuedRenders(tessellator);
profiler.endStartSection("wisp");
FXWisp.dispatchQueuedRenders(tessellator);
profiler.endSection();
if(isLightingEnabled)
GL11.glEnable(GL11.GL_LIGHTING);
GL11.glAlphaFunc(GL11.GL_GREATER, 0.1F);
GL11.glDisable(GL11.GL_BLEND);
GL11.glDepthMask(true);
}
}
@@ -0,0 +1,27 @@
/**
* This class was created by <Vazkii>. 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 a
* Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License
* (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB)
*
* File Created @ [Jun 27, 2014, 1:52:33 AM (GMT)]
*/
package vazkii.botania.client.gui;
import net.minecraft.client.gui.GuiScreen;
import net.minecraftforge.common.config.ConfigElement;
import net.minecraftforge.common.config.Configuration;
import vazkii.botania.common.core.handler.ConfigHandler;
import vazkii.botania.common.lib.LibMisc;
import cpw.mods.fml.client.config.GuiConfig;
public class GuiBotaniaConfig extends GuiConfig {
public GuiBotaniaConfig(GuiScreen parentScreen) {
super(parentScreen, new ConfigElement(ConfigHandler.config.getCategory(Configuration.CATEGORY_GENERAL)).getChildElements(), LibMisc.MOD_ID, false, false, GuiConfig.getAbridgedConfigPath(ConfigHandler.config.toString()));
}
}
@@ -0,0 +1,289 @@
/**
* This class was created by <Vazkii>. 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 a
* Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License
* (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB)
*
* File Created @ [Jan 14, 2014, 6:48:05 PM (GMT)]
*/
package vazkii.botania.client.gui.lexicon;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.StatCollector;
import org.lwjgl.opengl.GL11;
import vazkii.botania.api.BotaniaAPI;
import vazkii.botania.api.lexicon.LexiconCategory;
import vazkii.botania.client.core.handler.ClientTickHandler;
import vazkii.botania.client.core.helper.RenderHelper;
import vazkii.botania.client.gui.lexicon.button.GuiButtonBookmark;
import vazkii.botania.client.gui.lexicon.button.GuiButtonCategory;
import vazkii.botania.client.gui.lexicon.button.GuiButtonInvisible;
import vazkii.botania.client.lib.LibResources;
import vazkii.botania.common.item.ItemLexicon;
public class GuiLexicon extends GuiScreen {
public static GuiLexicon currentOpenLexicon = new GuiLexicon();
public static ItemStack stackUsed;
public static final int BOOKMARK_START = 1337;
public static List<GuiLexicon> bookmarks = new ArrayList();
boolean bookmarksNeedPopulation = false;
public static final ResourceLocation texture = new ResourceLocation(LibResources.GUI_LEXICON);
public static final ResourceLocation textureToff = new ResourceLocation(LibResources.GUI_TOFF);
public float lastTime = 0F;
public float partialTicks = 0F;
public float timeDelta = 0F;
String title;
int guiWidth = 146;
int guiHeight = 180;
int left, top;
@Override
public void initGui() {
super.initGui();
lastTime = ClientTickHandler.ticksInGame;
title = Minecraft.getMinecraft().thePlayer.getCurrentEquippedItem().getDisplayName();
currentOpenLexicon = this;
left = width / 2 - guiWidth / 2;
top = height / 2 - guiHeight / 2;
buttonList.clear();
if(isIndex()) {
int x = 18;
for(int i = 0; i < 12; i++) {
int y = 16 + i * 12;
buttonList.add(new GuiButtonInvisible(i, left + x, top + y, 110, 10, ""));
}
populateIndex();
} else if(isCategoryIndex()) {
int categories = BotaniaAPI.getAllCategories().size();
for(int i = 0; i < categories + 1; i++) {
LexiconCategory category = null;
category = i >= categories ? null : BotaniaAPI.getAllCategories().get(i);
int x = i % 4;
int y = i / 4;
int size = 27;
GuiButtonCategory button = new GuiButtonCategory(i, left + 18 + x * size, top + 35 + y * size, this, category);
buttonList.add(button);
}
}
populateBookmarks();
}
@Override
public void drawScreen(int par1, int par2, float par3) {
float time = ClientTickHandler.ticksInGame + par3;
timeDelta = time - lastTime;
lastTime = time;
partialTicks = par3;
GL11.glColor4f(1F, 1F, 1F, 1F);
mc.renderEngine.bindTexture(texture);
drawTexturedModalRect(left, top, 0, 0, guiWidth, guiHeight);
drawBookmark(left + guiWidth / 2, top - getTitleHeight(), getTitle(), true);
String subtitle = getSubtitle();
if(subtitle != null) {
GL11.glScalef(0.5F, 0.5F, 1F);
drawCenteredString(fontRendererObj, subtitle, left * 2 + guiWidth, (top - getTitleHeight() + 11) * 2, 0x00FF00);
GL11.glScalef(2F, 2F, 1F);
}
drawHeader();
if(bookmarksNeedPopulation) {
populateBookmarks();
bookmarksNeedPopulation = false;
}
if(mc.thePlayer.getCommandSenderName().equals("haighyorkie")) {
GL11.glColor4f(1F, 1F, 1F, 1F);
mc.renderEngine.bindTexture(texture);
drawTexturedModalRect(left - 19, top + 12, 67, 180, 19, 26);
if(par1 >= left - 19 && par1 < left && par2 >= top + 12 && par2 < top + 38) {
mc.renderEngine.bindTexture(textureToff);
GL11.glScalef(0.5F, 0.5F, 0.5F);
drawTexturedModalRect((left - 92) * 2, (top + 40) * 2, 0, 0, 184, 248);
GL11.glScalef(2F, 2F, 2F);
RenderHelper.renderTooltip(par1, par2, Arrays.asList(EnumChatFormatting.GOLD + "#goldfishchris", EnumChatFormatting.AQUA + "CONGRATS ON YOUR NEW COMPUTER!!", "vazkii.us/goldfish"));
}
}
super.drawScreen(par1, par2, par3);
}
public void drawBookmark(int x, int y, String s, boolean drawLeft) {
// This function is called from the buttons so I can't use fontRendererObj
FontRenderer font = Minecraft.getMinecraft().fontRenderer;
boolean unicode = font.getUnicodeFlag();
font.setUnicodeFlag(true);
int l = font.getStringWidth(s);
int fontOff = 0;
if(!drawLeft) {
x += l / 2;
fontOff = 2;
}
Minecraft.getMinecraft().renderEngine.bindTexture(texture);
GL11.glColor4f(1F, 1F, 1F, 1F);
drawTexturedModalRect(x + l / 2 + 3, y - 1, 54, 180, 6, 11);
if(drawLeft)
drawTexturedModalRect(x - l / 2 - 9, y - 1, 61, 180, 6, 11);
for(int i = 0; i < l + 6; i++)
drawTexturedModalRect(x - l / 2 - 3 + i, y - 1, 60, 180, 1, 11);
font.drawString(s, x - l / 2 + fontOff, y, 0x111111, false);
font.setUnicodeFlag(unicode);
}
void drawHeader() {
boolean unicode = fontRendererObj.getUnicodeFlag();
fontRendererObj.setUnicodeFlag(true);
fontRendererObj.drawSplitString(String.format(StatCollector.translateToLocal("botania.gui.lexicon.header"), ItemLexicon.getEdition()), left + 18, top + 12, 110, 0);
fontRendererObj.setUnicodeFlag(unicode);
}
@Override
protected void actionPerformed(GuiButton par1GuiButton) {
if(par1GuiButton.id >= BOOKMARK_START)
handleBookmark(par1GuiButton);
else if(par1GuiButton instanceof GuiButtonCategory) {
LexiconCategory category = ((GuiButtonCategory) par1GuiButton).getCategory();
mc.displayGuiScreen(new GuiLexiconIndex(category));
ClientTickHandler.notifyPageChange();
}
}
public void handleBookmark(GuiButton par1GuiButton) {
int i = par1GuiButton.id - BOOKMARK_START;
if(i == bookmarks.size()) {
if(!bookmarks.contains(this))
bookmarks.add(this);
} else {
if(isShiftKeyDown())
bookmarks.remove(i);
else {
GuiLexicon bookmark = bookmarks.get(i);
Minecraft.getMinecraft().displayGuiScreen(bookmark);
if(!bookmark.getTitle().equals(getTitle())) {
if(bookmark instanceof IParented)
((IParented) bookmark).setParent(this);
ClientTickHandler.notifyPageChange();
}
}
}
bookmarksNeedPopulation = true;
}
@Override
public boolean doesGuiPauseGame() {
return false;
}
public int bookmarkWidth(String b) {
boolean unicode = fontRendererObj.getUnicodeFlag();
fontRendererObj.setUnicodeFlag(true);
int width = fontRendererObj.getStringWidth(b) + 15;
fontRendererObj.setUnicodeFlag(unicode);
return width;
}
String getTitle() {
return title;
}
String getSubtitle() {
return null;
}
int getTitleHeight() {
return getSubtitle() == null ? 12 : 16;
}
boolean isIndex() {
return false;
}
boolean isCategoryIndex() {
return true;
}
void populateIndex() {
List<LexiconCategory> categoryList = BotaniaAPI.getAllCategories();
int shift = 2;
for(int i = shift; i < 12; i++) {
int i_ = i - shift;
GuiButtonInvisible button = (GuiButtonInvisible) buttonList.get(i);
LexiconCategory category = i_ >= categoryList.size() ? null : categoryList.get(i_);
if(category != null)
button.displayString = StatCollector.translateToLocal(category.getUnlocalizedName());
else {
button.displayString = StatCollector.translateToLocal("botaniamisc.lexiconIndex");
break;
}
}
}
void populateBookmarks() {
List remove = new ArrayList();
List<GuiButton> buttons = buttonList;
for(GuiButton button : buttons)
if(button.id >= BOOKMARK_START)
remove.add(button);
buttonList.removeAll(remove);
int len = bookmarks.size();
boolean thisExists = false;
for(GuiLexicon lex : bookmarks)
if(lex.getTitle().equals(getTitle()))
thisExists = true;
boolean addEnabled = len < 8 && this instanceof IParented && !thisExists;
for(int i = 0; i < len + (addEnabled ? 1 : 0); i++) {
boolean isAdd = i == bookmarks.size();
GuiLexicon gui = isAdd ? null : bookmarks.get(i);
buttonList.add(new GuiButtonBookmark(BOOKMARK_START + i, left + 138, top + 18 + 14 * i, gui == null ? this : gui, gui == null ? "+" : gui.getTitle()));
}
}
boolean closeScreenOnInvKey() {
return true;
}
@Override
protected void keyTyped(char par1, int par2) {
if(closeScreenOnInvKey() && mc.gameSettings.keyBindInventory.getKeyCode() == par2) {
mc.displayGuiScreen(null);
mc.setIngameFocus();
}
super.keyTyped(par1, par2);
}
}
@@ -0,0 +1,288 @@
/**
* This class was created by <Vazkii>. 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 a
* Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License
* (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB)
*
* File Created @ [Jan 14, 2014, 6:47:06 PM (GMT)]
*/
package vazkii.botania.client.gui.lexicon;
import java.util.List;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.StatCollector;
import org.lwjgl.input.Mouse;
import vazkii.botania.api.internal.IGuiLexiconEntry;
import vazkii.botania.api.lexicon.IAddonEntry;
import vazkii.botania.api.lexicon.LexiconEntry;
import vazkii.botania.api.lexicon.LexiconPage;
import vazkii.botania.client.core.handler.ClientTickHandler;
import vazkii.botania.client.gui.lexicon.button.GuiButtonBackWithShift;
import vazkii.botania.client.gui.lexicon.button.GuiButtonPage;
import vazkii.botania.client.gui.lexicon.button.GuiButtonShare;
public class GuiLexiconEntry extends GuiLexicon implements IGuiLexiconEntry, IParented {
public int page = 0;
LexiconEntry entry;
GuiScreen parent;
String title;
String subtitle;
GuiButton leftButton, rightButton, backButton, shareButton;
public GuiLexiconEntry(LexiconEntry entry, GuiScreen parent) {
this.entry = entry;
this.parent = parent;
title = StatCollector.translateToLocal(entry.getUnlocalizedName());
if(entry instanceof IAddonEntry)
subtitle = StatCollector.translateToLocal(((IAddonEntry) entry).getSubtitle());
else subtitle = null;
}
@Override
public void initGui() {
super.initGui();
buttonList.add(backButton = new GuiButtonBackWithShift(0, left + guiWidth / 2 - 8, top + guiHeight + 2));
buttonList.add(leftButton = new GuiButtonPage(1, left, top + guiHeight - 10, false));
buttonList.add(rightButton = new GuiButtonPage(2, left + guiWidth - 18, top + guiHeight - 10, true));
buttonList.add(shareButton = new GuiButtonShare(3, left + guiWidth - 6, top - 2));
LexiconPage page = entry.pages.get(this.page);
page.onOpened(this);
updatePageButtons();
}
@Override
public LexiconEntry getEntry() {
return entry;
}
@Override
public int getPageOn() {
return page;
}
@Override
void drawHeader() {
// NO-OP
}
@Override
String getTitle() {
return String.format("%s " + EnumChatFormatting.ITALIC + "(%s/%s)", title, page + 1, entry.pages.size());
}
@Override
String getSubtitle() {
return subtitle;
}
@Override
boolean isCategoryIndex() {
return false;
}
@Override
protected void actionPerformed(GuiButton par1GuiButton) {
LexiconPage currentPage = entry.pages.get(page);
LexiconPage newPage;
if(par1GuiButton.id >= BOOKMARK_START)
handleBookmark(par1GuiButton);
else
switch(par1GuiButton.id) {
case 0 :
currentPage.onClosed(this);
mc.displayGuiScreen(GuiScreen.isShiftKeyDown() ? new GuiLexicon() : parent);
ClientTickHandler.notifyPageChange();
break;
case 1 :
currentPage.onClosed(this);
page--;
newPage = entry.pages.get(page);
newPage.onOpened(this);
ClientTickHandler.notifyPageChange();
break;
case 2 :
currentPage.onClosed(this);
page++;
newPage = entry.pages.get(page);
newPage.onOpened(this);
ClientTickHandler.notifyPageChange();
break;
case 3 :
Minecraft mc = Minecraft.getMinecraft();
String cmd = "/botania-share " + entry.unlocalizedName;
mc.ingameGUI.getChatGUI().addToSentMessages(cmd);
mc.thePlayer.sendChatMessage(cmd);
break;
}
updatePageButtons();
currentPage.onActionPerformed(this, par1GuiButton);
}
public void updatePageButtons() {
leftButton.enabled = page != 0;
rightButton.enabled = page + 1 < entry.pages.size();
}
@Override
public void drawScreen(int par1, int par2, float par3) {
super.drawScreen(par1, par2, par3);
LexiconPage page = entry.pages.get(this.page);
page.renderScreen(this, par1, par2);
}
@Override
public void updateScreen() {
LexiconPage page = entry.pages.get(this.page);
page.updateScreen(this);
}
@Override
public int getLeft() {
return left;
}
@Override
public int getTop() {
return top;
}
@Override
public int getWidth() {
return guiWidth;
}
@Override
public int getHeight() {
return guiHeight;
}
@Override
public float getZLevel() {
return zLevel;
}
@Override
public void setParent(GuiLexicon gui) {
parent = gui;
}
int fx = 0;
boolean swiped = false;
@Override
protected void mouseClickMove(int x, int y, int button, long time) {
if(button == 0 && Math.abs(x - fx) > 100 && mc.gameSettings.touchscreen && !swiped) {
double swipe = (x - fx) / Math.max(1, (double) time);
if(swipe < 0.5) {
nextPage();
swiped = true;
} else if(swipe > 0.5) {
prevPage();
swiped = true;
}
}
}
@Override
protected void mouseClicked(int par1, int par2, int par3) {
super.mouseClicked(par1, par2, par3);
fx = par1;
if(par3 == 1)
back();
}
@Override
public void handleMouseInput() {
super.handleMouseInput();
if(Mouse.getEventButton() == 0)
swiped = false;
int w = Mouse.getEventDWheel();
if(w < 0)
nextPage();
else if(w > 0)
prevPage();
}
@Override
protected void keyTyped(char par1, int par2) {
LexiconPage page = entry.pages.get(this.page);
page.onKeyPressed(par1, par2);
if(par2 == 203 || par2 == 200 || par2 == 201) // Left, Up, Page Up
prevPage();
else if(par2 == 205 || par2 == 208 || par2 == 209) // Right, Down Page Down
nextPage();
else if(par2 == 14) // Backspace
back();
else if(par2 == 199) { // Home
mc.displayGuiScreen(new GuiLexicon());
ClientTickHandler.notifyPageChange();
}
super.keyTyped(par1, par2);
}
void back() {
if(backButton.enabled) {
actionPerformed(backButton);
backButton.func_146113_a(mc.getSoundHandler());
}
}
void nextPage() {
if(rightButton.enabled) {
actionPerformed(rightButton);
rightButton.func_146113_a(mc.getSoundHandler());
}
}
void prevPage() {
if(leftButton.enabled) {
actionPerformed(leftButton);
leftButton.func_146113_a(mc.getSoundHandler());
}
}
@Override
public List<GuiButton> getButtonList() {
return buttonList;
}
@Override
public float getElapsedTicks() {
return lastTime;
}
@Override
public float getPartialTicks() {
return partialTicks;
}
@Override
public float getTickDelta() {
return timeDelta;
}
}
@@ -0,0 +1,262 @@
/**
* This class was created by <Vazkii>. 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 a
* Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License
* (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB)
*
* File Created @ [Jan 14, 2014, 6:46:59 PM (GMT)]
*/
package vazkii.botania.client.gui.lexicon;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiTextField;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.StatCollector;
import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.GL11;
import vazkii.botania.api.BotaniaAPI;
import vazkii.botania.api.lexicon.ILexicon;
import vazkii.botania.api.lexicon.LexiconCategory;
import vazkii.botania.api.lexicon.LexiconEntry;
import vazkii.botania.client.core.handler.ClientTickHandler;
import vazkii.botania.client.gui.lexicon.button.GuiButtonBack;
import vazkii.botania.client.gui.lexicon.button.GuiButtonInvisible;
import vazkii.botania.client.gui.lexicon.button.GuiButtonPage;
public class GuiLexiconIndex extends GuiLexicon implements IParented {
LexiconCategory category;
String title;
int page = 0;
GuiButton leftButton, rightButton, backButton;
GuiLexicon parent;
GuiTextField searchField;
List<LexiconEntry> entriesToDisplay = new ArrayList();
public GuiLexiconIndex(LexiconCategory category) {
this.category = category;
title = StatCollector.translateToLocal(category == null ? "botaniamisc.lexiconIndex" : category.getUnlocalizedName());
parent = new GuiLexicon();
}
@Override
void drawHeader() {
// NO-OP
}
@Override
String getTitle() {
return title;
}
@Override
boolean isIndex() {
return true;
}
@Override
boolean isCategoryIndex() {
return false;
}
@Override
public void initGui() {
super.initGui();
buttonList.add(backButton = new GuiButtonBack(12, left + guiWidth / 2 - 8, top + guiHeight + 2));
buttonList.add(leftButton = new GuiButtonPage(13, left, top + guiHeight - 10, false));
buttonList.add(rightButton = new GuiButtonPage(14, left + guiWidth - 18, top + guiHeight - 10, true));
searchField = new GuiTextField(fontRendererObj, left + guiWidth / 2 + 28, top + guiHeight + 6, 200, 10);
searchField.setCanLoseFocus(false);
searchField.setFocused(true);
searchField.setEnableBackgroundDrawing(false);
updateAll();
}
void updateAll() {
buildEntries();
updatePageButtons();
populateIndex();
}
void buildEntries() {
entriesToDisplay.clear();
ILexicon lex = (ILexicon) stackUsed.getItem();
for(LexiconEntry entry : category == null ? BotaniaAPI.getAllEntries() : category.entries) {
if(lex.isKnowledgeUnlocked(stackUsed, entry.getKnowledgeType()) && StatCollector.translateToLocal(entry.getUnlocalizedName()).toLowerCase().contains(searchField.getText().toLowerCase().trim()))
entriesToDisplay.add(entry);
}
Collections.sort(entriesToDisplay);
}
@Override
void populateIndex() {
for(int i = page * 12; i < (page + 1) * 12; i++) {
GuiButtonInvisible button = (GuiButtonInvisible) buttonList.get(i - page * 12);
LexiconEntry entry = i >= entriesToDisplay.size() ? null : entriesToDisplay.get(i);
if(entry != null)
button.displayString = entry.getKnowledgeType().color + "" + (entry.isPriority() ? EnumChatFormatting.ITALIC : "") + StatCollector.translateToLocal(entry.getUnlocalizedName());
else button.displayString = "";
}
}
@Override
public void drawScreen(int par1, int par2, float par3) {
super.drawScreen(par1, par2, par3);
if(!searchField.getText().isEmpty()) {
drawBookmark(left + 138, top + guiHeight - 24, " " + searchField.getText(), false);
mc.renderEngine.bindTexture(texture);
GL11.glColor4f(1F, 1F, 1F, 1F);
drawTexturedModalRect(left + 134, top + guiHeight - 26, 86, 180, 12, 12);
}
}
@Override
protected void actionPerformed(GuiButton par1GuiButton) {
if(par1GuiButton.id >= BOOKMARK_START)
handleBookmark(par1GuiButton);
else
switch(par1GuiButton.id) {
case 12 :
mc.displayGuiScreen(parent);
ClientTickHandler.notifyPageChange();
break;
case 13 :
page--;
updatePageButtons();
populateIndex();
ClientTickHandler.notifyPageChange();
break;
case 14 :
page++;
updatePageButtons();
populateIndex();
ClientTickHandler.notifyPageChange();
break;
default :
int index = par1GuiButton.id + page * 12;
openEntry(index);
}
}
void openEntry(int index) {
if(index >= entriesToDisplay.size())
return;
LexiconEntry entry = entriesToDisplay.get(index);
mc.displayGuiScreen(new GuiLexiconEntry(entry, this));
ClientTickHandler.notifyPageChange();
}
public void updatePageButtons() {
leftButton.enabled = page != 0;
rightButton.enabled = page < (entriesToDisplay.size() - 1) / 12;
}
@Override
public void setParent(GuiLexicon gui) {
parent = gui;
}
int fx = 0;
boolean swiped = false;
@Override
protected void mouseClickMove(int x, int y, int button, long time) {
if(button == 0 && Math.abs(x - fx) > 100 && mc.gameSettings.touchscreen && !swiped) {
double swipe = (x - fx) / Math.max(1, (double) time);
if(swipe < 0.5) {
nextPage();
swiped = true;
} else if(swipe > 0.5) {
prevPage();
swiped = true;
}
}
}
@Override
protected void mouseClicked(int par1, int par2, int par3) {
super.mouseClicked(par1, par2, par3);
searchField.mouseClicked(par1, par2, par3);
fx = par1;
if(par3 == 1)
back();
}
@Override
public void handleMouseInput() {
super.handleMouseInput();
if(Mouse.getEventButton() == 0)
swiped = false;
int w = Mouse.getEventDWheel();
if(w < 0)
nextPage();
else if(w > 0)
prevPage();
}
@Override
boolean closeScreenOnInvKey() {
return false;
}
@Override
protected void keyTyped(char par1, int par2) {
if(par2 == 203 || par2 == 200 || par2 == 201) // Left, Up, Page Up
prevPage();
else if(par2 == 205 || par2 == 208 || par2 == 209) // Right, Down Page Down
nextPage();
else if(par2 == 14 && searchField.getText().isEmpty()) // Backspace
back();
else if(par2 == 199) { // Home
mc.displayGuiScreen(new GuiLexicon());
ClientTickHandler.notifyPageChange();
} else if(par2 == 28 && entriesToDisplay.size() == 1) // Enter
openEntry(0);
String search = searchField.getText();
searchField.textboxKeyTyped(par1, par2);
if(!searchField.getText().equalsIgnoreCase(search))
updateAll();
super.keyTyped(par1, par2);
}
void back() {
if(backButton.enabled) {
actionPerformed(backButton);
backButton.func_146113_a(mc.getSoundHandler());
}
}
void nextPage() {
if(rightButton.enabled) {
actionPerformed(rightButton);
rightButton.func_146113_a(mc.getSoundHandler());
}
}
void prevPage() {
if(leftButton.enabled) {
actionPerformed(leftButton);
leftButton.func_146113_a(mc.getSoundHandler());
}
}
}
Loaded 100 of 1177 files, more files were not shown because too many files have changed in this diff. Show more