Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- From 8577051b59654cca74e802c09794735e3e7bf462 Mon Sep 17 00:00:00 2001
- From: a <a>
- Date: Fri, 23 Feb 2018 13:44:30 +0200
- Subject: added list of accepted fuels to coalgenerator
- diff --git a/src/main/java/mcjty/rftools/blocks/generator/CoalGeneratorConfiguration.java b/src/main/java/mcjty/rftools/blocks/generator/CoalGeneratorConfiguration.java
- index ce902f2..c526928 100644
- --- a/src/main/java/mcjty/rftools/blocks/generator/CoalGeneratorConfiguration.java
- +++ b/src/main/java/mcjty/rftools/blocks/generator/CoalGeneratorConfiguration.java
- @@ -1,16 +1,30 @@
- package mcjty.rftools.blocks.generator;
- +import mcjty.lib.varia.Logging;
- import net.minecraftforge.common.config.Configuration;
- +import net.minecraftforge.common.config.ConfigCategory;
- +import net.minecraft.tileentity.TileEntityFurnace;
- +import net.minecraft.item.Item;
- +import net.minecraft.item.ItemStack;
- +import net.minecraft.block.Block;
- +import net.minecraft.util.ResourceLocation;
- +import net.minecraftforge.common.config.Property;
- +import java.util.ArrayList;
- +import java.util.HashMap;
- +import java.util.List;
- +import java.util.Map;
- public class CoalGeneratorConfiguration {
- -
- public static final String CATEGORY_COALGEN = "coalgen";
- + public static final String CATEGORY_COALGENFUEL = "coalgenfuel";
- public static boolean enabled = true;
- public static int MAXENERGY = 500000;
- public static int SENDPERTICK = 2000;
- public static int CHARGEITEMPERTICK = 1000;
- public static int rfPerTick = 60;
- public static int ticksPerCoal = 600;
- + public static final Map<String,UsableFuel> FUELLIST = new HashMap<>();
- + public static ItemStack[] fuelList;
- public static void init(Configuration cfg) {
- enabled = cfg.get(CATEGORY_COALGEN, "enabled", enabled, "Whether the coal generator should exist").getBoolean();
- @@ -23,4 +37,124 @@ public class CoalGeneratorConfiguration {
- CHARGEITEMPERTICK = cfg.get(CATEGORY_COALGEN, "generatorChargePerTick", CHARGEITEMPERTICK,
- "RF per tick that the generator can charge items with").getInt();
- }
- +
- + public static void postInit(Configuration cfg) {
- + readFuelList(cfg);
- + }
- +
- + private static void readFuelList(Configuration cfg) {
- + ConfigCategory category = cfg.getCategory(CATEGORY_COALGENFUEL);
- + if (category.isEmpty()) {
- + setupInitialFuelList(cfg);
- + } else {
- + for (Map.Entry<String, Property> entry : category.entrySet()) {
- + String[] value = entry.getValue().getStringList();
- + try {
- + String type = value[0];
- + String name = value[1];
- + Integer meta = Integer.parseInt(value[2]);
- + Integer burntime = Integer.parseInt(value[3]);
- + //Logging.log("LOADING FUEL ... 0:"+value[0]+" 1:"+value[1]+" 2:"+value[2]+" 3:"+value[3]);
- + UsableFuel fuel=null;
- + if (type.equals("I"))
- + fuel=new UsableFuel(new ItemStack(Item.REGISTRY.getObject(new ResourceLocation(name)),1,meta),burntime);
- + else if (type.equals("B"))
- + fuel=new UsableFuel(new ItemStack(Block.REGISTRY.getObject(new ResourceLocation(name)),1,meta),burntime);
- + else
- + continue;
- + FUELLIST.put(name + "@" + meta.toString(), fuel);
- + } catch (Exception e) {
- + Logging.logError("Badly formatted 'coalgenfuel' configuration option!");
- + return;
- + }
- + }
- + }
- + int arraysize=FUELLIST.size();
- + fuelList=new ItemStack[arraysize];
- + for (Map.Entry<String, UsableFuel> entry : FUELLIST.entrySet()) {
- + fuelList[--arraysize]=entry.getValue().getObject();
- + }
- + }
- +
- + private static void setupInitialFuelList(Configuration cfg) {
- + int counter = 0;
- + counter = addFuel(cfg,"minecraft:coal",0,counter);
- + counter = addFuel(cfg,"minecraft:coal",1,counter);
- + counter = addFuel(cfg,"minecraft:coal_block",0,counter);
- + counter = addFuel(cfg,"immersiveengineering:stone_decoration",3,counter);
- + counter = addFuel(cfg,"immersiveengineering:material",6,counter);
- + }
- +
- + private static int addFuel(Configuration cfg,String item,int meta,int counter)
- + {
- + Item obitem = Item.REGISTRY.getObject(new ResourceLocation(item));
- + Block obblock = Block.REGISTRY.getObject(new ResourceLocation(item));
- + ItemStack myitem = new ItemStack(obitem);
- + ItemStack myblock = new ItemStack(obblock);
- + if (myblock.isEmpty())
- + {
- + if ( !myitem.isEmpty())
- + return addFuel(cfg,obitem,meta,counter);
- + else return counter;
- + }else
- + {
- + return addFuel(cfg,obblock,meta,counter);
- + }
- + }
- +
- + private static int addFuel(Configuration cfg,Item item,int meta,int counter)
- + {
- + ItemStack stack=null;
- + int burntime=TileEntityFurnace.getItemBurnTime(stack=new ItemStack(item,1,meta)) * ticksPerCoal / 1600;
- + if (burntime >= 0)
- + {
- + cfg.get(CATEGORY_COALGENFUEL, "coalgenfuel." + counter, new String[] { "I", item.getRegistryName().toString(), Integer.toString(meta), Integer.toString(burntime)});
- + UsableFuel fuel=new UsableFuel(stack,burntime);
- + FUELLIST.put(item.getRegistryName().toString() + "@" + Integer.toString(meta),fuel);
- + return counter + 1;
- + }
- + return counter;
- + }
- +
- + private static int addFuel(Configuration cfg,Block item,int meta,int counter)
- + {
- + ItemStack stack=null;
- + int burntime=TileEntityFurnace.getItemBurnTime(stack=new ItemStack(item,1,meta)) * ticksPerCoal / 1600;
- + if (burntime >= 0)
- + {
- + cfg.get(CATEGORY_COALGENFUEL, "coalgenfuel." + counter, new String[] { "B", item.getRegistryName().toString(), Integer.toString(meta), Integer.toString(burntime)});
- + UsableFuel fuel=new UsableFuel(stack,burntime);
- + FUELLIST.put(item.getRegistryName().toString() + "@" + Integer.toString(meta),fuel);
- + return counter + 1;
- + }
- + return counter;
- + }
- +
- + public static class UsableFuel {
- + private final ItemStack object;
- + private final int burntime;
- +
- + public UsableFuel(ItemStack object, int burntime) {
- + this.object = object;
- + this.burntime = burntime;
- + }
- +
- + public ItemStack getObject() {
- + return object;
- + }
- +
- + public int getBurntime() {
- + return burntime;
- + }
- +
- + public boolean match(ItemStack stack) {
- + if (object.isEmpty()) {
- + return false;
- + }
- + if (stack.isItemEqual(object)) {
- + return true;
- + }
- + return false;
- + }
- + }
- }
- diff --git a/src/main/java/mcjty/rftools/blocks/generator/CoalGeneratorContainer.java b/src/main/java/mcjty/rftools/blocks/generator/CoalGeneratorContainer.java
- index 508f7e1..655ac1a 100644
- --- a/src/main/java/mcjty/rftools/blocks/generator/CoalGeneratorContainer.java
- +++ b/src/main/java/mcjty/rftools/blocks/generator/CoalGeneratorContainer.java
- @@ -20,8 +20,7 @@ public class CoalGeneratorContainer extends GenericContainer {
- @Override
- protected void setup() {
- addSlotBox(new SlotDefinition(SlotType.SLOT_SPECIFICITEM,
- - new ItemStack(Items.COAL),
- - new ItemStack(Blocks.COAL_BLOCK)),
- + CoalGeneratorConfiguration.fuelList),
- CONTAINER_INVENTORY, SLOT_COALINPUT, 82, 24, 1, 18, 1, 18);
- addSlotBox(new SlotDefinition(SlotType.SLOT_CONTAINER), CONTAINER_INVENTORY, SLOT_CHARGEITEM, 118, 24, 1, 18, 1, 18);
- layoutPlayerInventorySlots(10, 70);
- diff --git a/src/main/java/mcjty/rftools/blocks/generator/CoalGeneratorTileEntity.java b/src/main/java/mcjty/rftools/blocks/generator/CoalGeneratorTileEntity.java
- index 9aa928a..0494fe0 100644
- --- a/src/main/java/mcjty/rftools/blocks/generator/CoalGeneratorTileEntity.java
- +++ b/src/main/java/mcjty/rftools/blocks/generator/CoalGeneratorTileEntity.java
- @@ -113,12 +113,18 @@ public class CoalGeneratorTileEntity extends GenericEnergyProviderTileEntity imp
- }
- if (inventoryHelper.containsItem(CoalGeneratorContainer.SLOT_COALINPUT)) {
- - ItemStack extracted = inventoryHelper.decrStackSize(CoalGeneratorContainer.SLOT_COALINPUT, 1);
- - burning = CoalGeneratorConfiguration.ticksPerCoal;
- - if (extracted.getItem() == Item.getItemFromBlock(Blocks.COAL_BLOCK)) {
- - burning *= 9;
- - }
- + ItemStack theitem = inventoryHelper.getStackInSlot(CoalGeneratorContainer.SLOT_COALINPUT);
- + if (theitem.isEmpty())
- + return;
- + String thekey = theitem.getItem().getRegistryName().toString()+"@"+theitem.getMetadata();
- + if (!CoalGeneratorConfiguration.FUELLIST.containsKey(thekey))
- + return;
- + burning = CoalGeneratorConfiguration.FUELLIST.get(thekey).getBurntime();
- burning += (int) (burning * getInfusedFactor() / 2.0f);
- + if (burning >= 0)
- + inventoryHelper.decrStackSize(CoalGeneratorContainer.SLOT_COALINPUT, 1);
- + else
- + return;
- if (working) {
- markDirty();
- } else {
- diff --git a/src/main/java/mcjty/rftools/proxy/CommonProxy.java b/src/main/java/mcjty/rftools/proxy/CommonProxy.java
- index ca4f643..abbe897 100644
- --- a/src/main/java/mcjty/rftools/proxy/CommonProxy.java
- +++ b/src/main/java/mcjty/rftools/proxy/CommonProxy.java
- @@ -194,7 +194,7 @@ public abstract class CommonProxy {
- TeleportConfiguration.init(cfg);
- } catch (Exception e1) {
- - Logging.getLogger().log(Level.ERROR, "Problem loading config file!", e1);
- + Logging.getLogger().log(Level.ERROR, "Problem loading config file! (preInit)", e1);
- } finally {
- if (mainConfig.hasChanged()) {
- mainConfig.save();
- @@ -209,6 +209,16 @@ public abstract class CommonProxy {
- }
- public void postInit(FMLPostInitializationEvent e) {
- + Configuration cfg = mainConfig;
- + try{
- + CoalGeneratorConfiguration.postInit(cfg);
- + } catch (Exception e1) {
- + Logging.getLogger().log(Level.ERROR, "Problem loading config file! (postInit)", e1);
- + } finally {
- + if (mainConfig.hasChanged()) {
- + mainConfig.save();
- + }
- + }
- // MobConfiguration.readModdedMobConfig(mainConfig);
- // if (mainConfig.hasChanged()) {
- // mainConfig.save();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement