Added Configuration GUI

This commit is contained in:
Ellpeck 2015-07-17 11:17:55 +02:00
parent 1387114a8c
commit 8636a92df0
12 changed files with 102 additions and 103 deletions

View file

@ -33,7 +33,7 @@ import ellpeck.actuallyadditions.tile.TileEntityBase;
import ellpeck.actuallyadditions.util.ModUtil; import ellpeck.actuallyadditions.util.ModUtil;
import ellpeck.actuallyadditions.util.Util; import ellpeck.actuallyadditions.util.Util;
@Mod(modid = ModUtil.MOD_ID, name = ModUtil.NAME, version = ModUtil.VERSION, canBeDeactivated = false) @Mod(modid = ModUtil.MOD_ID, name = ModUtil.NAME, version = ModUtil.VERSION, canBeDeactivated = false, guiFactory = "ellpeck.actuallyadditions.config.GuiFactory")
public class ActuallyAdditions{ public class ActuallyAdditions{
@Instance(ModUtil.MOD_ID) @Instance(ModUtil.MOD_ID)
@ -46,7 +46,7 @@ public class ActuallyAdditions{
public void preInit(FMLPreInitializationEvent event){ public void preInit(FMLPreInitializationEvent event){
ModUtil.LOGGER.info("Starting PreInitialization Phase..."); ModUtil.LOGGER.info("Starting PreInitialization Phase...");
ConfigurationHandler.init(event.getSuggestedConfigurationFile()); new ConfigurationHandler(event.getSuggestedConfigurationFile());
PacketHandler.init(); PacketHandler.init();
InitToolMaterials.init(); InitToolMaterials.init();
InitArmorMaterials.init(); InitArmorMaterials.init();

View file

@ -1,6 +1,9 @@
package ellpeck.actuallyadditions.config; package ellpeck.actuallyadditions.config;
import cpw.mods.fml.client.event.ConfigChangedEvent;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import ellpeck.actuallyadditions.util.ModUtil; import ellpeck.actuallyadditions.util.ModUtil;
import ellpeck.actuallyadditions.util.Util;
import net.minecraftforge.common.config.Configuration; import net.minecraftforge.common.config.Configuration;
import java.io.File; import java.io.File;
@ -9,22 +12,31 @@ public class ConfigurationHandler{
public static final String ISSUES_WARNING = " [THIS COULD CAUSE ISSUES, CHANGE AT YOUR OWN RISK!]"; public static final String ISSUES_WARNING = " [THIS COULD CAUSE ISSUES, CHANGE AT YOUR OWN RISK!]";
public static void init(File configFile){ public static Configuration config;
public ConfigurationHandler(File configFile){
ModUtil.LOGGER.info("Grabbing Configurations..."); ModUtil.LOGGER.info("Grabbing Configurations...");
Configuration config = new Configuration(configFile);
try{ Util.registerEvent(this);
config.load();
ConfigValues.defineConfigValues(config);
}
catch(Exception e){
ModUtil.LOGGER.error("Loading the Config File failed!", e);
}
finally{
if(config.hasChanged()){
config.save();
}
}
if(config == null){
config = new Configuration(configFile);
loadConfig();
}
}
private static void loadConfig(){
ConfigValues.defineConfigValues(config);
if(config.hasChanged()){
config.save();
}
}
@SubscribeEvent
public void onConfigurationChangedEvent(ConfigChangedEvent.OnConfigChangedEvent event){
if (event.modID.equalsIgnoreCase(ModUtil.MOD_ID)){
loadConfig();
}
} }
} }

View file

@ -0,0 +1,26 @@
package ellpeck.actuallyadditions.config;
import cpw.mods.fml.client.config.GuiConfig;
import cpw.mods.fml.client.config.IConfigElement;
import ellpeck.actuallyadditions.util.ModUtil;
import net.minecraft.client.gui.GuiScreen;
import net.minecraftforge.common.config.ConfigCategory;
import net.minecraftforge.common.config.ConfigElement;
import java.util.ArrayList;
import java.util.List;
public class GuiConfiguration extends GuiConfig{
public GuiConfiguration(GuiScreen parentScreen){
super(parentScreen, getConfigElements(), ModUtil.MOD_ID, true, true, ModUtil.NAME);
}
private static List<IConfigElement> getConfigElements(){
List<IConfigElement> list = new ArrayList<>();
for(int i = 0; i < ConfigCategories.values().length; i++){
list.add(new ConfigElement<ConfigCategory>(ConfigurationHandler.config.getCategory(ConfigCategories.values()[i].name.toLowerCase())));
}
return list;
}
}

View file

@ -0,0 +1,31 @@
package ellpeck.actuallyadditions.config;
import cpw.mods.fml.client.IModGuiFactory;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiScreen;
import java.util.Set;
@SuppressWarnings("unused")
public class GuiFactory implements IModGuiFactory{
@Override
public void initialize(Minecraft minecraftInstance){
}
@Override
public Class<? extends GuiScreen> mainConfigGuiClass(){
return GuiConfiguration.class;
}
@Override
public Set<RuntimeOptionCategoryElement> runtimeGuiCategories(){
return null;
}
@Override
public RuntimeOptionGuiHandler getHandlerFor(RuntimeOptionCategoryElement element){
return null;
}
}

View file

@ -38,6 +38,7 @@ public enum ConfigBoolValues{
DO_TREASURE_CHEST_GEN("Treasure Chest Gen", ConfigCategories.WORLD_GEN, true, "If Treasure Chests should generate in the World"), DO_TREASURE_CHEST_GEN("Treasure Chest Gen", ConfigCategories.WORLD_GEN, true, "If Treasure Chests should generate in the World"),
DO_SPIDER_DROPS("Spider Cobweb Drop", ConfigCategories.MOB_DROPS, true, "If Cobwebs should sometimes drop from Spiders"), DO_SPIDER_DROPS("Spider Cobweb Drop", ConfigCategories.MOB_DROPS, true, "If Cobwebs should sometimes drop from Spiders"),
DO_BAT_DROPS("Bat Wing Drop", ConfigCategories.MOB_DROPS, true, "If Wings should sometimes drop from Bats"),
PREVENT_OIL_OVERRIDE("Oil Fluid Override", ConfigCategories.FLUIDS, false, "If not registering Oil Fluids from Actually Additions if other Oil is already registered should be prevented"+ConfigurationHandler.ISSUES_WARNING), PREVENT_OIL_OVERRIDE("Oil Fluid Override", ConfigCategories.FLUIDS, false, "If not registering Oil Fluids from Actually Additions if other Oil is already registered should be prevented"+ConfigurationHandler.ISSUES_WARNING),
PREVENT_CANOLA_OVERRIDE("Canola Oil Fluid Override", ConfigCategories.FLUIDS, false, "If not registering Canola Oil Fluids from Actually Additions if other Canola Oil is already registered should be prevented"+ConfigurationHandler.ISSUES_WARNING), PREVENT_CANOLA_OVERRIDE("Canola Oil Fluid Override", ConfigCategories.FLUIDS, false, "If not registering Canola Oil Fluids from Actually Additions if other Canola Oil is already registered should be prevented"+ConfigurationHandler.ISSUES_WARNING),

View file

@ -107,7 +107,7 @@ public enum ConfigCrafting{
ENERGIZER("Energizer", ConfigCategories.BLOCKS_CRAFTING), ENERGIZER("Energizer", ConfigCategories.BLOCKS_CRAFTING),
ENERVATOR("Enervator", ConfigCategories.BLOCKS_CRAFTING), ENERVATOR("Enervator", ConfigCategories.BLOCKS_CRAFTING),
QUARTZ("Black Quartz in a Crafting Table (as a Backup if there's no Ores to be found anywhere)", ConfigCategories.ITEMS_CRAFTING), QUARTZ("Black Quartz in a Crafting Table", ConfigCategories.ITEMS_CRAFTING),
LAMPS("Lamps", ConfigCategories.BLOCKS_CRAFTING), LAMPS("Lamps", ConfigCategories.BLOCKS_CRAFTING),
REDSTONE("Redstone Ore -> Redstone", ConfigCategories.CRUSHER_RECIPES, "Crusher"), REDSTONE("Redstone Ore -> Redstone", ConfigCategories.CRUSHER_RECIPES, "Crusher"),
@ -143,7 +143,7 @@ public enum ConfigCrafting{
this.name = name; this.name = name;
this.category = category.name; this.category = category.name;
this.defaultValue = defaultValue; this.defaultValue = defaultValue;
this.extraText = extraText + " "; this.extraText = extraText.length() > 0 ? extraText + " " : "";
} }
ConfigCrafting(String name, ConfigCategories category, boolean defaultValue){ ConfigCrafting(String name, ConfigCategories category, boolean defaultValue){

View file

@ -70,7 +70,8 @@ public enum ConfigIntValues{
DROPPER_TIME_NEEDED("Dropper: Time Needed", ConfigCategories.MACHINE_VALUES, 10, 1, 10000, "The Time Needed for the Dropper to drop an Item"), DROPPER_TIME_NEEDED("Dropper: Time Needed", ConfigCategories.MACHINE_VALUES, 10, 1, 10000, "The Time Needed for the Dropper to drop an Item"),
CAT_DROP_CHANCE("Cat Drops: Chance", ConfigCategories.OTHER, 5000, 5, 10000000, "The 1 in X chance for a Hairy Ball to Drop from a Cat with X being this value"), CAT_DROP_CHANCE("Cat Drops: Chance", ConfigCategories.OTHER, 5000, 5, 10000000, "The 1 in X chance for a Hairy Ball to Drop from a Cat with X being this value"),
SPIDER_DROP_CHANCE("Cobweb Drop from Spider: Chance", ConfigCategories.MOB_DROPS, 300, 1, 1000000000, "The 1 in X chance for a Cobweb to drop from a Spider"), SPIDER_DROP_CHANCE("Cobweb Drop from Spider: Chance", ConfigCategories.MOB_DROPS, 500, 1, 1000000000, "The 1 in X chance for a Cobweb to drop from a Spider"),
BAT_DROP_CHANCE("Wings from Bats: Chance", ConfigCategories.MOB_DROPS, 250, 1, 1000000000, "The 1 in X chance for a Wing to drop from a Bat"),
RICE_AMOUNT("Rice Amount", ConfigCategories.WORLD_GEN, 15, 1, 100, "The Chance of Rice generating"), RICE_AMOUNT("Rice Amount", ConfigCategories.WORLD_GEN, 15, 1, 100, "The Chance of Rice generating"),
CANOLA_AMOUNT("Canola Amount", ConfigCategories.WORLD_GEN, 10, 1, 50, "The Chance of Canola generating"), CANOLA_AMOUNT("Canola Amount", ConfigCategories.WORLD_GEN, 10, 1, 50, "The Chance of Canola generating"),

View file

@ -48,6 +48,7 @@ public class EntityLivingEvent{
//Allow the Player to fly when he has Wings equipped every tick //Allow the Player to fly when he has Wings equipped every tick
//It appears to be reset somewhere if you don't update it every tick //It appears to be reset somewhere if you don't update it every tick
//but I haven't found the place where it gets reset which is slightly odd //but I haven't found the place where it gets reset which is slightly odd
//Maybe I just haven't searched enough or I am really stupid :D
player.capabilities.allowFlying = true; player.capabilities.allowFlying = true;
} }
else{ else{

View file

@ -4,8 +4,10 @@ import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import ellpeck.actuallyadditions.config.values.ConfigBoolValues; import ellpeck.actuallyadditions.config.values.ConfigBoolValues;
import ellpeck.actuallyadditions.config.values.ConfigIntValues; import ellpeck.actuallyadditions.config.values.ConfigIntValues;
import ellpeck.actuallyadditions.items.InitItems; import ellpeck.actuallyadditions.items.InitItems;
import ellpeck.actuallyadditions.items.metalists.TheMiscItems;
import ellpeck.actuallyadditions.items.metalists.TheSpecialDrops; import ellpeck.actuallyadditions.items.metalists.TheSpecialDrops;
import net.minecraft.entity.monster.EntitySpider; import net.minecraft.entity.monster.EntitySpider;
import net.minecraft.entity.passive.EntityBat;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks; import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
@ -34,6 +36,13 @@ public class LivingDropEvent{
event.entityLiving.entityDropItem(new ItemStack(Blocks.web, new Random().nextInt(2)+1), 0); event.entityLiving.entityDropItem(new ItemStack(Blocks.web, new Random().nextInt(2)+1), 0);
} }
} }
//Drop Wings from Bats
if(ConfigBoolValues.DO_BAT_DROPS.isEnabled() && event.entityLiving instanceof EntityBat){
if(new Random().nextInt(ConfigIntValues.BAT_DROP_CHANCE.getValue()) <= 0){
event.entityLiving.entityDropItem(new ItemStack(InitItems.itemMisc, new Random().nextInt(2)+1, TheMiscItems.BAT_WING.ordinal()), 0);
}
}
} }
} }
} }

View file

@ -98,8 +98,6 @@ public class InitItems{
public static Item itemTeleStaff; public static Item itemTeleStaff;
public static Item itemWingsOfTheBats; public static Item itemWingsOfTheBats;
public static Item itemPicturePlacer;
public static void init(){ public static void init(){
ModUtil.LOGGER.info("Initializing Items..."); ModUtil.LOGGER.info("Initializing Items...");
@ -118,9 +116,6 @@ public class InitItems{
itemTeleStaff = new ItemTeleStaff(); itemTeleStaff = new ItemTeleStaff();
ItemUtil.register(itemTeleStaff); ItemUtil.register(itemTeleStaff);
itemPicturePlacer = new ItemPicturePlacer();
ItemUtil.register(itemPicturePlacer);
itemWingsOfTheBats = new ItemWingsOfTheBats(); itemWingsOfTheBats = new ItemWingsOfTheBats();
ItemUtil.register(itemWingsOfTheBats); ItemUtil.register(itemWingsOfTheBats);

View file

@ -1,78 +0,0 @@
package ellpeck.actuallyadditions.items;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import ellpeck.actuallyadditions.ActuallyAdditions;
import ellpeck.actuallyadditions.inventory.GuiHandler;
import ellpeck.actuallyadditions.util.INameableItem;
import ellpeck.actuallyadditions.util.ItemUtil;
import ellpeck.actuallyadditions.util.ModUtil;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.EntityHanging;
import net.minecraft.entity.item.EntityPainting;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.EnumRarity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Direction;
import net.minecraft.util.IIcon;
import net.minecraft.world.World;
import java.util.List;
public class ItemPicturePlacer extends Item implements INameableItem{
@Override
@SuppressWarnings("unchecked")
@SideOnly(Side.CLIENT)
public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean isHeld){
ItemUtil.addInformation(this, list, 1, "");
}
@Override
public IIcon getIcon(ItemStack stack, int pass){
return this.itemIcon;
}
@Override
@SideOnly(Side.CLIENT)
public void registerIcons(IIconRegister iconReg){
this.itemIcon = iconReg.registerIcon(ModUtil.MOD_ID_LOWER+":"+this.getName());
}
@Override
public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player){
if(!world.isRemote)
player.openGui(ActuallyAdditions.instance, GuiHandler.GuiTypes.CRAFTER.ordinal(), world, (int)player.posX, (int)player.posY, (int)player.posZ);
return stack;
}
@Override
public EnumRarity getRarity(ItemStack stack){
return EnumRarity.epic;
}
@Override
public String getName(){
return "itemPicturePlacer";
}
@Override
public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int hitSide, float hitX, float hitY, float hitZ){
if(hitSide == 0 || hitSide == 1) return false;
else{
EntityHanging hanging = new EntityPainting(world, x, y, z, Direction.facingToDirection[hitSide]);
if(!player.canPlayerEdit(x, y, z, hitSide, stack)) return false;
else{
if(hanging.onValidSurface()){
if(!world.isRemote){
world.spawnEntityInWorld(hanging);
}
stack.stackSize--;
}
return true;
}
}
}
}

View file

@ -19,7 +19,8 @@ public enum TheMiscItems implements INameableItem{
TINY_CHAR("TinyCharcoal", EnumRarity.common), TINY_CHAR("TinyCharcoal", EnumRarity.common),
RICE_SLIME("RiceSlime", EnumRarity.uncommon), RICE_SLIME("RiceSlime", EnumRarity.uncommon),
CANOLA("Canola", EnumRarity.uncommon), CANOLA("Canola", EnumRarity.uncommon),
CUP("Cup", EnumRarity.uncommon); CUP("Cup", EnumRarity.uncommon),
BAT_WING("BatWing", EnumRarity.rare);
public final String name; public final String name;
public final EnumRarity rarity; public final EnumRarity rarity;