mirror of
https://github.com/GTNewHorizons/Botania.git
synced 2026-11-27 15:33:08 +00:00
Fixed SoundLogic's mess.
This commit is contained in:
1 parent
5dedff6a85
commit
ce5148f5a4
7 files changed
+162
-147
No files matched your search
@@ -16,7 +16,6 @@ import java.io.File;
|
||||
import net.minecraftforge.common.config.Configuration;
|
||||
import net.minecraftforge.common.config.Property;
|
||||
import vazkii.botania.common.lib.LibMisc;
|
||||
import vazkii.botania.common.shedding.SheddingTracker;
|
||||
import cpw.mods.fml.client.event.ConfigChangedEvent;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
@@ -151,7 +150,7 @@ public final class ConfigHandler {
|
||||
}
|
||||
|
||||
public static void loadPostInit() {
|
||||
SheddingTracker.loadFromConfig(config);
|
||||
SheddingHandler.loadFromConfig(config);
|
||||
|
||||
if(config.hasChanged())
|
||||
config.save();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* This class was created by <Vazkii>. It's distributed as
|
||||
* This class was created by <SoundLogic>. It's distributed as
|
||||
* part of the Botania Mod. Get the Source Code in github:
|
||||
* https://github.com/Vazkii/Botania
|
||||
*
|
||||
@@ -11,22 +11,147 @@
|
||||
*/
|
||||
package vazkii.botania.common.core.handler;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import vazkii.botania.common.lexicon.LexiconData;
|
||||
import vazkii.botania.common.lexicon.page.PageShedding;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityList;
|
||||
import net.minecraft.entity.EntityLiving;
|
||||
import net.minecraft.entity.monster.EntityBlaze;
|
||||
import net.minecraft.entity.monster.EntityGhast;
|
||||
import net.minecraft.entity.monster.EntitySkeleton;
|
||||
import net.minecraft.entity.monster.EntitySlime;
|
||||
import net.minecraft.entity.monster.EntitySpider;
|
||||
import net.minecraft.entity.passive.EntityChicken;
|
||||
import net.minecraft.entity.passive.EntitySquid;
|
||||
import net.minecraft.entity.passive.EntityVillager;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.common.config.Configuration;
|
||||
import net.minecraftforge.common.config.Property;
|
||||
import net.minecraftforge.event.entity.living.LivingEvent.LivingUpdateEvent;
|
||||
import vazkii.botania.common.shedding.SheddingTracker;
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
|
||||
public final class SheddingHandler {
|
||||
|
||||
public static ArrayList<ShedPattern> patterns = new ArrayList<ShedPattern>();
|
||||
public static ArrayList<ShedPattern> defaultPatterns = new ArrayList<ShedPattern>();
|
||||
|
||||
@SubscribeEvent
|
||||
public void onLivingUpdate(LivingUpdateEvent event) {
|
||||
if(event.entity.worldObj.isRemote)
|
||||
return;
|
||||
|
||||
SheddingTracker.ShedPattern pattern = SheddingTracker.getShedPattern(event.entity);
|
||||
ShedPattern pattern = getShedPattern(event.entity);
|
||||
|
||||
if(pattern != null) {
|
||||
if(event.entity.worldObj.rand.nextInt(pattern.getRate()) == 0)
|
||||
event.entity.entityDropItem(pattern.getItemStack(), 0.0F);
|
||||
}
|
||||
}
|
||||
|
||||
public static ShedPattern getShedPattern(Entity entity) {
|
||||
for(ShedPattern pattern : patterns)
|
||||
if(pattern.EntityClass.isInstance(entity))
|
||||
return pattern;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static boolean hasShedding() {
|
||||
return patterns.size() > 0;
|
||||
}
|
||||
|
||||
public static void addToLexicon() {
|
||||
if(!hasShedding())
|
||||
return;
|
||||
|
||||
int i = 1;
|
||||
for(ShedPattern pattern : patterns) {
|
||||
PageShedding page = new PageShedding(String.valueOf(i), (String)EntityList.classToStringMapping.get(pattern.EntityClass), pattern.lexiconSize, pattern.getItemStack());
|
||||
LexiconData.shedding.addPage(page);
|
||||
}
|
||||
}
|
||||
|
||||
public static void loadFromConfig(Configuration config) {
|
||||
defaultPatterns.add(new ShedPattern(EntityChicken.class, new ItemStack(Items.feather), 26000, 20));
|
||||
defaultPatterns.add(new ShedPattern(EntitySquid.class, new ItemStack(Items.dye), 18000, 20));
|
||||
defaultPatterns.add(new ShedPattern(EntityVillager.class, new ItemStack(Items.emerald), 226000, 40));
|
||||
defaultPatterns.add(new ShedPattern(EntitySpider.class, new ItemStack(Items.string), 12000, 40));
|
||||
defaultPatterns.add(new ShedPattern(EntityBlaze.class, new ItemStack(Items.blaze_powder), 8000, 40));
|
||||
defaultPatterns.add(new ShedPattern(EntityGhast.class, new ItemStack(Items.ghast_tear), 9001, 30));
|
||||
defaultPatterns.add(new ShedPattern(EntitySkeleton.class, new ItemStack(Items.bone), 36000, 40));
|
||||
defaultPatterns.add(new ShedPattern(EntitySlime.class, new ItemStack(Items.slime_ball), 21000, 40));
|
||||
|
||||
ArrayList<String> defaultNames = new ArrayList<String>();
|
||||
|
||||
for(ShedPattern pattern : defaultPatterns) {
|
||||
loadFromConfig(config, pattern.getEntityString(), pattern);
|
||||
defaultNames.add(pattern.getEntityString());
|
||||
}
|
||||
|
||||
for(Object o : EntityList.stringToClassMapping.entrySet()) {
|
||||
Entry<String, Class> entry = (Entry<String, Class>) o;
|
||||
|
||||
if(EntityLiving.class.isAssignableFrom(entry.getValue())) {
|
||||
String name = entry.getKey();
|
||||
if(!defaultNames.contains(name))
|
||||
loadFromConfig(config, name, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void loadFromConfig(Configuration config, String key, ShedPattern defaultPattern) {
|
||||
String itemName = "";
|
||||
int metadata = 0;
|
||||
int rate = -1;
|
||||
int lexiconSize = 40;
|
||||
|
||||
if(defaultPattern != null) {
|
||||
itemName = Item.itemRegistry.getNameForObject(defaultPattern.getItemStack().getItem());
|
||||
metadata = defaultPattern.getItemStack().getItemDamage();
|
||||
rate = defaultPattern.rate;
|
||||
lexiconSize = defaultPattern.lexiconSize;
|
||||
}
|
||||
|
||||
Property prop=config.get("Shedding", key + ".item", itemName);
|
||||
prop.comment = "Configuration of Shedding for "+key;
|
||||
itemName = prop.getString();
|
||||
rate = config.get("Shedding", key + ".rate", rate).getInt();
|
||||
metadata = config.get("Shedding", key + ".metadata", metadata).getInt();
|
||||
lexiconSize = config.get("Shedding", key + ".lexiconDisplaySize", lexiconSize).getInt();
|
||||
|
||||
if(itemName != "" && rate != -1)
|
||||
patterns.add(new ShedPattern((Class)EntityList.stringToClassMapping.get(key), new ItemStack((Item) Item.itemRegistry.getObject(itemName), 1, metadata), rate, lexiconSize));
|
||||
}
|
||||
|
||||
public static class ShedPattern {
|
||||
|
||||
Class EntityClass;
|
||||
ItemStack itemStack;
|
||||
int rate;
|
||||
int lexiconSize;
|
||||
|
||||
public ShedPattern(Class EntityClass, ItemStack itemStack, int rate, int lexiconSize) {
|
||||
this.EntityClass = EntityClass;
|
||||
this.itemStack = itemStack;
|
||||
this.rate = rate;
|
||||
this.lexiconSize = lexiconSize;
|
||||
}
|
||||
public ItemStack getItemStack() {
|
||||
return itemStack.copy();
|
||||
}
|
||||
|
||||
public int getRate() {
|
||||
return rate;
|
||||
}
|
||||
|
||||
public String getEntityString() {
|
||||
return (String) EntityList.classToStringMapping.get(EntityClass);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -11,7 +11,6 @@
|
||||
*/
|
||||
package vazkii.botania.common.lexicon;
|
||||
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import vazkii.botania.api.BotaniaAPI;
|
||||
import vazkii.botania.api.lexicon.LexiconCategory;
|
||||
@@ -20,6 +19,7 @@ import vazkii.botania.api.lexicon.LexiconRecipeMappings;
|
||||
import vazkii.botania.client.lib.LibResources;
|
||||
import vazkii.botania.common.block.ModBlocks;
|
||||
import vazkii.botania.common.core.handler.ConfigHandler;
|
||||
import vazkii.botania.common.core.handler.SheddingHandler;
|
||||
import vazkii.botania.common.crafting.ModCrafingRecipes;
|
||||
import vazkii.botania.common.crafting.ModElvenTradeRecipes;
|
||||
import vazkii.botania.common.crafting.ModManaAlchemyRecipes;
|
||||
@@ -30,16 +30,13 @@ import vazkii.botania.common.crafting.ModRuneRecipes;
|
||||
import vazkii.botania.common.item.ModItems;
|
||||
import vazkii.botania.common.lexicon.page.PageCraftingRecipe;
|
||||
import vazkii.botania.common.lexicon.page.PageElvenRecipe;
|
||||
import vazkii.botania.common.lexicon.page.PageEntity;
|
||||
import vazkii.botania.common.lexicon.page.PageImage;
|
||||
import vazkii.botania.common.lexicon.page.PageManaInfusionRecipe;
|
||||
import vazkii.botania.common.lexicon.page.PagePetalRecipe;
|
||||
import vazkii.botania.common.lexicon.page.PageRuneRecipe;
|
||||
import vazkii.botania.common.lexicon.page.PageShedding;
|
||||
import vazkii.botania.common.lexicon.page.PageTerrasteel;
|
||||
import vazkii.botania.common.lexicon.page.PageText;
|
||||
import vazkii.botania.common.lib.LibLexicon;
|
||||
import vazkii.botania.common.shedding.SheddingTracker;
|
||||
|
||||
public final class LexiconData {
|
||||
|
||||
@@ -621,10 +618,10 @@ public final class LexiconData {
|
||||
}
|
||||
|
||||
public static void postInit() {
|
||||
if(SheddingTracker.hasShedding()) {
|
||||
if(SheddingHandler.hasShedding()) {
|
||||
shedding = new BLexiconEntry(LibLexicon.MISC_SHEDDING, categoryMisc);
|
||||
shedding.setLexiconPages(new PageText("0"));
|
||||
SheddingTracker.addToLexicon();
|
||||
SheddingHandler.addToLexicon();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,14 @@
|
||||
/**
|
||||
* This class was created by <SoundLogic>. 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 4, 2014, 10:38:50 PM (GMT)]
|
||||
*/
|
||||
package vazkii.botania.common.lexicon.page;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
@@ -26,8 +37,8 @@ public class PageEntity extends LexiconPage{
|
||||
|
||||
public PageEntity(String unlocalizedName, String entity, int size) {
|
||||
super(unlocalizedName);
|
||||
Class EntityClass=(Class) EntityList.stringToClassMapping.get(entity);
|
||||
this.size=size;
|
||||
Class EntityClass = (Class) EntityList.stringToClassMapping.get(entity);
|
||||
this.size = size;
|
||||
try {
|
||||
dummyEntity = (Entity)EntityClass.getConstructor(new Class[] {World.class}).newInstance(new Object[] {null});
|
||||
} catch (Exception e) {
|
||||
@@ -44,12 +55,9 @@ public class PageEntity extends LexiconPage{
|
||||
int entity_x = gui.getLeft() + gui.getWidth() / 2;
|
||||
int entity_y = gui.getTop() + gui.getHeight() / 2 + MathHelper.floor_float(dummyEntity.height * entity_scale / 2);
|
||||
|
||||
tickEntity(dummyEntity);
|
||||
|
||||
renderEntity(gui, dummyEntity, entity_x, entity_y, entity_scale, dummyEntity.ticksExisted * 2);
|
||||
|
||||
PageText.renderText(text_x, text_y, gui.getWidth() - 30, gui.getHeight(), getUnlocalizedName());
|
||||
|
||||
}
|
||||
|
||||
public int getEntityScale(int targetSize) {
|
||||
@@ -61,8 +69,9 @@ public class PageEntity extends LexiconPage{
|
||||
return MathHelper.floor_float(size / entity_size);
|
||||
|
||||
}
|
||||
|
||||
public void tickEntity(Entity entity) {
|
||||
|
||||
@Override
|
||||
public void updateScreen() {
|
||||
dummyEntity.ticksExisted++;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,14 @@
|
||||
/**
|
||||
* This class was created by <SoundLogic>. 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 4, 2014, 10:38:50 PM (GMT)]
|
||||
*/
|
||||
package vazkii.botania.common.lexicon.page;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -28,7 +39,7 @@ import net.minecraft.util.MathHelper;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.StatCollector;
|
||||
|
||||
public class PageShedding extends PageEntity{
|
||||
public class PageShedding extends PageEntity {
|
||||
|
||||
private static final ResourceLocation sheddingOverlay = new ResourceLocation(LibResources.GUI_SHEDDING_OVERLAY);
|
||||
|
||||
@@ -46,16 +57,13 @@ public class PageShedding extends PageEntity{
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void renderScreen(IGuiLexiconEntry gui, int mx, int my) {
|
||||
|
||||
relativeMouseX = mx;
|
||||
relativeMouseY = my;
|
||||
int stack_x = gui.getLeft() + gui.getWidth() / 2 - 8;
|
||||
int stack_y = gui.getTop() + gui.getHeight() - 40 - 24 - 5;
|
||||
int stack_y = gui.getTop() + gui.getHeight() - 40 - 18 - 5;
|
||||
int entity_scale = getEntityScale(size);
|
||||
int entity_x = gui.getLeft() + gui.getWidth() / 2;
|
||||
int entity_y = gui.getTop() + gui.getHeight() / 2 + MathHelper.floor_float(dummyEntity.height * entity_scale / 2) - 35;
|
||||
|
||||
tickEntity(dummyEntity);
|
||||
int entity_y = gui.getTop() + gui.getHeight() / 2 + MathHelper.floor_float(dummyEntity.height * entity_scale / 2) - 29;
|
||||
|
||||
renderEntity(gui, dummyEntity, entity_x, entity_y, entity_scale, dummyEntity.ticksExisted * 2);
|
||||
|
||||
|
||||
@@ -1,123 +0,0 @@
|
||||
package vazkii.botania.common.shedding;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityList;
|
||||
import net.minecraft.entity.EntityLiving;
|
||||
import net.minecraft.entity.monster.EntityBlaze;
|
||||
import net.minecraft.entity.monster.EntityGhast;
|
||||
import net.minecraft.entity.monster.EntitySkeleton;
|
||||
import net.minecraft.entity.monster.EntitySlime;
|
||||
import net.minecraft.entity.monster.EntitySpider;
|
||||
import net.minecraft.entity.passive.EntityChicken;
|
||||
import net.minecraft.entity.passive.EntitySquid;
|
||||
import net.minecraft.entity.passive.EntityVillager;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.common.config.Configuration;
|
||||
import net.minecraftforge.common.config.Property;
|
||||
import vazkii.botania.common.lexicon.LexiconData;
|
||||
import vazkii.botania.common.lexicon.page.PageShedding;
|
||||
|
||||
public class SheddingTracker {
|
||||
|
||||
public static ArrayList<ShedPattern> patterns = new ArrayList<ShedPattern>();
|
||||
public static ArrayList<ShedPattern> defaultPatterns = new ArrayList<ShedPattern>();
|
||||
|
||||
public static class ShedPattern {
|
||||
Class EntityClass;
|
||||
ItemStack itemStack;
|
||||
int rate;
|
||||
int lexiconSize;
|
||||
public ShedPattern(Class EntityClass, ItemStack itemStack, int rate, int lexiconSize) {
|
||||
this.EntityClass = EntityClass;
|
||||
this.itemStack = itemStack;
|
||||
this.rate = rate;
|
||||
this.lexiconSize=lexiconSize;
|
||||
}
|
||||
public ItemStack getItemStack() {
|
||||
return itemStack.copy();
|
||||
}
|
||||
public int getRate() {
|
||||
return rate;
|
||||
}
|
||||
public String getEntityString() {
|
||||
return (String)EntityList.classToStringMapping.get(EntityClass);
|
||||
}
|
||||
}
|
||||
|
||||
public static ShedPattern getShedPattern(Entity entity) {
|
||||
for(ShedPattern pattern : patterns)
|
||||
{
|
||||
if(pattern.EntityClass.isInstance(entity))
|
||||
return pattern;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static boolean hasShedding() {
|
||||
return patterns.size() > 0;
|
||||
}
|
||||
|
||||
public static void addToLexicon() {
|
||||
if(!hasShedding())
|
||||
return;
|
||||
int i = 1;
|
||||
for(ShedPattern pattern : patterns) {
|
||||
PageShedding page = new PageShedding(String.valueOf(i), (String)EntityList.classToStringMapping.get(pattern.EntityClass), pattern.lexiconSize, pattern.getItemStack());
|
||||
LexiconData.shedding.addPage(page);
|
||||
}
|
||||
}
|
||||
|
||||
public static void loadFromConfig(Configuration config) {
|
||||
|
||||
defaultPatterns.add(new ShedPattern(EntityChicken.class, new ItemStack(Items.feather), 26000, 20));
|
||||
defaultPatterns.add(new ShedPattern(EntitySquid.class, new ItemStack(Items.dye), 18000, 20));
|
||||
defaultPatterns.add(new ShedPattern(EntityVillager.class, new ItemStack(Items.emerald), 226000, 40));
|
||||
defaultPatterns.add(new ShedPattern(EntitySpider.class, new ItemStack(Items.string), 12000, 40));
|
||||
defaultPatterns.add(new ShedPattern(EntityBlaze.class, new ItemStack(Items.blaze_powder), 8000, 40));
|
||||
defaultPatterns.add(new ShedPattern(EntityGhast.class, new ItemStack(Items.ghast_tear), 9001, 30));
|
||||
defaultPatterns.add(new ShedPattern(EntitySkeleton.class, new ItemStack(Items.bone), 36000, 40));
|
||||
defaultPatterns.add(new ShedPattern(EntitySlime.class, new ItemStack(Items.slime_ball), 21000, 40));
|
||||
|
||||
ArrayList<String> defaultNames = new ArrayList<String>();
|
||||
|
||||
for(ShedPattern pattern : defaultPatterns) {
|
||||
loadFromConfig(config, pattern.getEntityString(), pattern);
|
||||
defaultNames.add(pattern.getEntityString());
|
||||
}
|
||||
for(Object o : EntityList.stringToClassMapping.entrySet()) {
|
||||
Entry<String, Class> entry = (Entry<String, Class>)o;
|
||||
if(EntityLiving.class.isAssignableFrom(entry.getValue())) {
|
||||
String name = entry.getKey();
|
||||
if(!defaultNames.contains(name))
|
||||
loadFromConfig(config, name, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void loadFromConfig(Configuration config, String key, ShedPattern defaultPattern) {
|
||||
String itemName = "";
|
||||
int metadata = 0;
|
||||
int rate = -1;
|
||||
int lexiconSize = 40;
|
||||
if(defaultPattern != null) {
|
||||
itemName = Item.itemRegistry.getNameForObject(defaultPattern.getItemStack().getItem());
|
||||
metadata = defaultPattern.getItemStack().getItemDamage();
|
||||
rate = defaultPattern.rate;
|
||||
lexiconSize = defaultPattern.lexiconSize;
|
||||
}
|
||||
Property prop=config.get("Shedding", key+".item", itemName);
|
||||
prop.comment = "Configuration of Shedding for "+key;
|
||||
itemName = prop.getString();
|
||||
rate = config.get("Shedding", key+".rate", rate).getInt();
|
||||
metadata = config.get("Shedding", key+".metadata", metadata).getInt();
|
||||
lexiconSize = config.get("Shedding", key+".size", lexiconSize).getInt();
|
||||
|
||||
if(itemName != "" && rate != -1)
|
||||
patterns.add(new ShedPattern((Class)EntityList.stringToClassMapping.get(key), new ItemStack((Item)Item.itemRegistry.getObject(itemName),1 ,metadata), rate, lexiconSize));
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 4.3 KiB After Width: | Height: | Size: 4.5 KiB |
Reference in new issue
Block a user