Advertisement
Guest User

0001-added list of accepted fuels to coalgenerator.patch

a guest
Feb 23rd, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.05 KB | None | 0 0
  1. From 8577051b59654cca74e802c09794735e3e7bf462 Mon Sep 17 00:00:00 2001
  2. From: a <a>
  3. Date: Fri, 23 Feb 2018 13:44:30 +0200
  4. Subject: added list of accepted fuels to coalgenerator
  5.  
  6.  
  7. diff --git a/src/main/java/mcjty/rftools/blocks/generator/CoalGeneratorConfiguration.java b/src/main/java/mcjty/rftools/blocks/generator/CoalGeneratorConfiguration.java
  8. index ce902f2..c526928 100644
  9. --- a/src/main/java/mcjty/rftools/blocks/generator/CoalGeneratorConfiguration.java
  10. +++ b/src/main/java/mcjty/rftools/blocks/generator/CoalGeneratorConfiguration.java
  11. @@ -1,16 +1,30 @@
  12. package mcjty.rftools.blocks.generator;
  13.  
  14. +import mcjty.lib.varia.Logging;
  15. import net.minecraftforge.common.config.Configuration;
  16. +import net.minecraftforge.common.config.ConfigCategory;
  17. +import net.minecraft.tileentity.TileEntityFurnace;
  18. +import net.minecraft.item.Item;
  19. +import net.minecraft.item.ItemStack;
  20. +import net.minecraft.block.Block;
  21. +import net.minecraft.util.ResourceLocation;
  22. +import net.minecraftforge.common.config.Property;
  23. +import java.util.ArrayList;
  24. +import java.util.HashMap;
  25. +import java.util.List;
  26. +import java.util.Map;
  27.  
  28. public class CoalGeneratorConfiguration {
  29. -
  30. public static final String CATEGORY_COALGEN = "coalgen";
  31. + public static final String CATEGORY_COALGENFUEL = "coalgenfuel";
  32. public static boolean enabled = true;
  33. public static int MAXENERGY = 500000;
  34. public static int SENDPERTICK = 2000;
  35. public static int CHARGEITEMPERTICK = 1000;
  36. public static int rfPerTick = 60;
  37. public static int ticksPerCoal = 600;
  38. + public static final Map<String,UsableFuel> FUELLIST = new HashMap<>();
  39. + public static ItemStack[] fuelList;
  40.  
  41. public static void init(Configuration cfg) {
  42. enabled = cfg.get(CATEGORY_COALGEN, "enabled", enabled, "Whether the coal generator should exist").getBoolean();
  43. @@ -23,4 +37,124 @@ public class CoalGeneratorConfiguration {
  44. CHARGEITEMPERTICK = cfg.get(CATEGORY_COALGEN, "generatorChargePerTick", CHARGEITEMPERTICK,
  45. "RF per tick that the generator can charge items with").getInt();
  46. }
  47. +
  48. + public static void postInit(Configuration cfg) {
  49. + readFuelList(cfg);
  50. + }
  51. +
  52. + private static void readFuelList(Configuration cfg) {
  53. + ConfigCategory category = cfg.getCategory(CATEGORY_COALGENFUEL);
  54. + if (category.isEmpty()) {
  55. + setupInitialFuelList(cfg);
  56. + } else {
  57. + for (Map.Entry<String, Property> entry : category.entrySet()) {
  58. + String[] value = entry.getValue().getStringList();
  59. + try {
  60. + String type = value[0];
  61. + String name = value[1];
  62. + Integer meta = Integer.parseInt(value[2]);
  63. + Integer burntime = Integer.parseInt(value[3]);
  64. + //Logging.log("LOADING FUEL ... 0:"+value[0]+" 1:"+value[1]+" 2:"+value[2]+" 3:"+value[3]);
  65. + UsableFuel fuel=null;
  66. + if (type.equals("I"))
  67. + fuel=new UsableFuel(new ItemStack(Item.REGISTRY.getObject(new ResourceLocation(name)),1,meta),burntime);
  68. + else if (type.equals("B"))
  69. + fuel=new UsableFuel(new ItemStack(Block.REGISTRY.getObject(new ResourceLocation(name)),1,meta),burntime);
  70. + else
  71. + continue;
  72. + FUELLIST.put(name + "@" + meta.toString(), fuel);
  73. + } catch (Exception e) {
  74. + Logging.logError("Badly formatted 'coalgenfuel' configuration option!");
  75. + return;
  76. + }
  77. + }
  78. + }
  79. + int arraysize=FUELLIST.size();
  80. + fuelList=new ItemStack[arraysize];
  81. + for (Map.Entry<String, UsableFuel> entry : FUELLIST.entrySet()) {
  82. + fuelList[--arraysize]=entry.getValue().getObject();
  83. + }
  84. + }
  85. +
  86. + private static void setupInitialFuelList(Configuration cfg) {
  87. + int counter = 0;
  88. + counter = addFuel(cfg,"minecraft:coal",0,counter);
  89. + counter = addFuel(cfg,"minecraft:coal",1,counter);
  90. + counter = addFuel(cfg,"minecraft:coal_block",0,counter);
  91. + counter = addFuel(cfg,"immersiveengineering:stone_decoration",3,counter);
  92. + counter = addFuel(cfg,"immersiveengineering:material",6,counter);
  93. + }
  94. +
  95. + private static int addFuel(Configuration cfg,String item,int meta,int counter)
  96. + {
  97. + Item obitem = Item.REGISTRY.getObject(new ResourceLocation(item));
  98. + Block obblock = Block.REGISTRY.getObject(new ResourceLocation(item));
  99. + ItemStack myitem = new ItemStack(obitem);
  100. + ItemStack myblock = new ItemStack(obblock);
  101. + if (myblock.isEmpty())
  102. + {
  103. + if ( !myitem.isEmpty())
  104. + return addFuel(cfg,obitem,meta,counter);
  105. + else return counter;
  106. + }else
  107. + {
  108. + return addFuel(cfg,obblock,meta,counter);
  109. + }
  110. + }
  111. +
  112. + private static int addFuel(Configuration cfg,Item item,int meta,int counter)
  113. + {
  114. + ItemStack stack=null;
  115. + int burntime=TileEntityFurnace.getItemBurnTime(stack=new ItemStack(item,1,meta)) * ticksPerCoal / 1600;
  116. + if (burntime >= 0)
  117. + {
  118. + cfg.get(CATEGORY_COALGENFUEL, "coalgenfuel." + counter, new String[] { "I", item.getRegistryName().toString(), Integer.toString(meta), Integer.toString(burntime)});
  119. + UsableFuel fuel=new UsableFuel(stack,burntime);
  120. + FUELLIST.put(item.getRegistryName().toString() + "@" + Integer.toString(meta),fuel);
  121. + return counter + 1;
  122. + }
  123. + return counter;
  124. + }
  125. +
  126. + private static int addFuel(Configuration cfg,Block item,int meta,int counter)
  127. + {
  128. + ItemStack stack=null;
  129. + int burntime=TileEntityFurnace.getItemBurnTime(stack=new ItemStack(item,1,meta)) * ticksPerCoal / 1600;
  130. + if (burntime >= 0)
  131. + {
  132. + cfg.get(CATEGORY_COALGENFUEL, "coalgenfuel." + counter, new String[] { "B", item.getRegistryName().toString(), Integer.toString(meta), Integer.toString(burntime)});
  133. + UsableFuel fuel=new UsableFuel(stack,burntime);
  134. + FUELLIST.put(item.getRegistryName().toString() + "@" + Integer.toString(meta),fuel);
  135. + return counter + 1;
  136. + }
  137. + return counter;
  138. + }
  139. +
  140. + public static class UsableFuel {
  141. + private final ItemStack object;
  142. + private final int burntime;
  143. +
  144. + public UsableFuel(ItemStack object, int burntime) {
  145. + this.object = object;
  146. + this.burntime = burntime;
  147. + }
  148. +
  149. + public ItemStack getObject() {
  150. + return object;
  151. + }
  152. +
  153. + public int getBurntime() {
  154. + return burntime;
  155. + }
  156. +
  157. + public boolean match(ItemStack stack) {
  158. + if (object.isEmpty()) {
  159. + return false;
  160. + }
  161. + if (stack.isItemEqual(object)) {
  162. + return true;
  163. + }
  164. + return false;
  165. + }
  166. + }
  167. }
  168. diff --git a/src/main/java/mcjty/rftools/blocks/generator/CoalGeneratorContainer.java b/src/main/java/mcjty/rftools/blocks/generator/CoalGeneratorContainer.java
  169. index 508f7e1..655ac1a 100644
  170. --- a/src/main/java/mcjty/rftools/blocks/generator/CoalGeneratorContainer.java
  171. +++ b/src/main/java/mcjty/rftools/blocks/generator/CoalGeneratorContainer.java
  172. @@ -20,8 +20,7 @@ public class CoalGeneratorContainer extends GenericContainer {
  173. @Override
  174. protected void setup() {
  175. addSlotBox(new SlotDefinition(SlotType.SLOT_SPECIFICITEM,
  176. - new ItemStack(Items.COAL),
  177. - new ItemStack(Blocks.COAL_BLOCK)),
  178. + CoalGeneratorConfiguration.fuelList),
  179. CONTAINER_INVENTORY, SLOT_COALINPUT, 82, 24, 1, 18, 1, 18);
  180. addSlotBox(new SlotDefinition(SlotType.SLOT_CONTAINER), CONTAINER_INVENTORY, SLOT_CHARGEITEM, 118, 24, 1, 18, 1, 18);
  181. layoutPlayerInventorySlots(10, 70);
  182. diff --git a/src/main/java/mcjty/rftools/blocks/generator/CoalGeneratorTileEntity.java b/src/main/java/mcjty/rftools/blocks/generator/CoalGeneratorTileEntity.java
  183. index 9aa928a..0494fe0 100644
  184. --- a/src/main/java/mcjty/rftools/blocks/generator/CoalGeneratorTileEntity.java
  185. +++ b/src/main/java/mcjty/rftools/blocks/generator/CoalGeneratorTileEntity.java
  186. @@ -113,12 +113,18 @@ public class CoalGeneratorTileEntity extends GenericEnergyProviderTileEntity imp
  187. }
  188.  
  189. if (inventoryHelper.containsItem(CoalGeneratorContainer.SLOT_COALINPUT)) {
  190. - ItemStack extracted = inventoryHelper.decrStackSize(CoalGeneratorContainer.SLOT_COALINPUT, 1);
  191. - burning = CoalGeneratorConfiguration.ticksPerCoal;
  192. - if (extracted.getItem() == Item.getItemFromBlock(Blocks.COAL_BLOCK)) {
  193. - burning *= 9;
  194. - }
  195. + ItemStack theitem = inventoryHelper.getStackInSlot(CoalGeneratorContainer.SLOT_COALINPUT);
  196. + if (theitem.isEmpty())
  197. + return;
  198. + String thekey = theitem.getItem().getRegistryName().toString()+"@"+theitem.getMetadata();
  199. + if (!CoalGeneratorConfiguration.FUELLIST.containsKey(thekey))
  200. + return;
  201. + burning = CoalGeneratorConfiguration.FUELLIST.get(thekey).getBurntime();
  202. burning += (int) (burning * getInfusedFactor() / 2.0f);
  203. + if (burning >= 0)
  204. + inventoryHelper.decrStackSize(CoalGeneratorContainer.SLOT_COALINPUT, 1);
  205. + else
  206. + return;
  207. if (working) {
  208. markDirty();
  209. } else {
  210. diff --git a/src/main/java/mcjty/rftools/proxy/CommonProxy.java b/src/main/java/mcjty/rftools/proxy/CommonProxy.java
  211. index ca4f643..abbe897 100644
  212. --- a/src/main/java/mcjty/rftools/proxy/CommonProxy.java
  213. +++ b/src/main/java/mcjty/rftools/proxy/CommonProxy.java
  214. @@ -194,7 +194,7 @@ public abstract class CommonProxy {
  215. TeleportConfiguration.init(cfg);
  216.  
  217. } catch (Exception e1) {
  218. - Logging.getLogger().log(Level.ERROR, "Problem loading config file!", e1);
  219. + Logging.getLogger().log(Level.ERROR, "Problem loading config file! (preInit)", e1);
  220. } finally {
  221. if (mainConfig.hasChanged()) {
  222. mainConfig.save();
  223. @@ -209,6 +209,16 @@ public abstract class CommonProxy {
  224. }
  225.  
  226. public void postInit(FMLPostInitializationEvent e) {
  227. + Configuration cfg = mainConfig;
  228. + try{
  229. + CoalGeneratorConfiguration.postInit(cfg);
  230. + } catch (Exception e1) {
  231. + Logging.getLogger().log(Level.ERROR, "Problem loading config file! (postInit)", e1);
  232. + } finally {
  233. + if (mainConfig.hasChanged()) {
  234. + mainConfig.save();
  235. + }
  236. + }
  237. // MobConfiguration.readModdedMobConfig(mainConfig);
  238. // if (mainConfig.hasChanged()) {
  239. // mainConfig.save();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement