-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add config options for melter/heater fuels temperature #32
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,8 @@ public class Config { | |
|
||
public static float oreToIngotRatio = 1.0f; | ||
public static boolean blacklistMelterStone = true; | ||
|
||
public static String[] heaterFuels; | ||
public static int defaultHeaterFuelTemperature; | ||
|
||
static Configuration configFile; | ||
|
||
|
@@ -30,6 +31,8 @@ public static void load(FMLPreInitializationEvent event) { | |
"Disallows creating seared stone in the melter using cobblestone or tool parts"); | ||
oreToIngotRatio = configFile.getFloat("oreToIngotRatio", "melter", 1.0f, 0f, 16.0f, | ||
"Ratio of ore to material produced in the melter."); | ||
heaterFuels = configFile.getStringList("heaterFuels", "melter", new String[]{}, "List of fuels that can be used in the heater and their respective temp (in Celcius).items mod:xxx[:data_value]=temp\nFuels in this list require to be valid minecraft furnace fuels."); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Comment should be more clear that the format is a format. |
||
defaultHeaterFuelTemperature = configFile.getInt("defaultHeaterFuelTemperature", "melter", 200,0, Integer.MAX_VALUE, "Default temperature (in Celcius) for any valid fuel that is not registred in heaterFuels.\nIf set to 0, disable all heater fuels but the ones in heaterFuels.\n200 is meant to be just about enough to melt clay or most metals, but not iron"); | ||
|
||
if(configFile.hasChanged()) { | ||
configFile.save(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,18 @@ | ||
package knightminer.tcomplement.feature.inventory; | ||
|
||
import knightminer.tcomplement.feature.tileentity.TileMelter; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.tileentity.TileEntityFurnace; | ||
import net.minecraftforge.items.IItemHandler; | ||
import net.minecraftforge.items.SlotItemHandler; | ||
|
||
public class SlotHeaterFuel extends SlotItemHandler { | ||
|
||
public SlotHeaterFuel(IItemHandler itemHandler, int index, int xPosition, int yPosition) { | ||
super(itemHandler, index, xPosition, yPosition); | ||
} | ||
|
||
@Override | ||
public boolean isItemValid(ItemStack stack) { | ||
return TileEntityFurnace.isItemFuel(stack); | ||
return TileMelter.isFuelValid(stack); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should use TCompRegistry |
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,13 @@ | ||
package knightminer.tcomplement.feature.tileentity; | ||
|
||
import java.util.Map; | ||
import java.util.HashMap; | ||
|
||
import javax.annotation.Nonnull; | ||
import javax.annotation.Nullable; | ||
|
||
import knightminer.tcomplement.TinkersComplement; | ||
import knightminer.tcomplement.common.Config; | ||
import knightminer.tcomplement.common.TCompNetwork; | ||
import knightminer.tcomplement.feature.client.GuiMelter; | ||
import knightminer.tcomplement.feature.inventory.ContainerMelter; | ||
|
@@ -14,6 +19,7 @@ | |
import net.minecraft.client.gui.inventory.GuiContainer; | ||
import net.minecraft.entity.player.InventoryPlayer; | ||
import net.minecraft.inventory.Container; | ||
import net.minecraft.item.Item; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.nbt.NBTTagCompound; | ||
import net.minecraft.tileentity.TileEntity; | ||
|
@@ -43,6 +49,8 @@ | |
|
||
public class TileMelter extends TileHeatingStructureFuelTank<MultiblockMelter> implements ITickable, IInventoryGui { | ||
|
||
private static Map<String, Integer> fuelsMap = new HashMap<>(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be in TCompRegistry. Also, I really do not like using strings here, that is so inefficient. Try something like Inspirations ItemMetaKey. |
||
|
||
private int tick; | ||
|
||
// liquid stored inside | ||
|
@@ -75,6 +83,38 @@ public TileHeater getSolidHeater() { | |
return null; | ||
} | ||
|
||
public static void init() { | ||
for(String item : Config.heaterFuels) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be in Config. Add an init method there and have it feed into TCompRegistry |
||
boolean valid = false; | ||
|
||
if(item.contains("=")) { | ||
String[] parts = item.split("="); | ||
|
||
if(parts.length == 2) { | ||
if(parts[0].contains(":")) { | ||
String[] name = parts[0].split(":"); | ||
Item fuel = Item.getByNameOrId(name[0] + ":" + name[1]); | ||
if(fuel == null) { | ||
TinkersComplement.log.error("heatersFuels item '" + parts[0] + "' not found"); | ||
continue; | ||
} else { | ||
try { | ||
fuelsMap.put(parts[0], Integer.parseInt(parts[1])); | ||
valid = true; | ||
} catch (NumberFormatException e) { | ||
// Won't be valid | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
if(!valid) { | ||
TinkersComplement.log.error("heatersFuels item '" + item + "' has an incorrect format"); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public void update() { | ||
if(isClientWorld()) { | ||
|
@@ -148,12 +188,12 @@ protected void consumeFuel() { | |
if(!stack.isEmpty()) { | ||
ItemStack fuel = stack.copy(); | ||
int time = TileEntityFurnace.getItemBurnTime(fuel) / 2; | ||
if(time > 0) { | ||
int temperature = getTemperature(fuel); | ||
if(time > 0 && temperature > 0) { | ||
currentFuel = null; | ||
fuelQuality = time; | ||
// just about enough to melt clay or most metals, but not iron | ||
// also, about the temperature of a conventional oven I guess | ||
addFuel(time, 200); | ||
|
||
addFuel(time, temperature); | ||
|
||
fuel.shrink(1); | ||
// if the stack is now empty, return the container | ||
|
@@ -177,6 +217,29 @@ protected void consumeFuel() { | |
} | ||
} | ||
|
||
public static boolean isFuelValid(ItemStack stack) { | ||
return (TileEntityFurnace.isItemFuel(stack) && getTemperature(stack) > 0); | ||
} | ||
|
||
protected static int getTemperature(ItemStack stack) { | ||
// 1. with metadata | ||
String itemName = stack.getItem().getRegistryName().toString(); | ||
|
||
Integer temp = fuelsMap.get(itemName + ":" + String.valueOf(stack.getMetadata())); | ||
|
||
if(temp != null) { | ||
return temp; | ||
} | ||
// 2. Generic item (without metadata) | ||
temp = fuelsMap.get(itemName); | ||
if(temp != null) { | ||
return temp; | ||
} | ||
|
||
// 3. Default temp | ||
return Config.defaultHeaterFuelTemperature; | ||
} | ||
|
||
@Override | ||
protected void updateStructureInfo(MultiblockDetection.MultiblockStructure structure) { | ||
if(structure.blocks.size() < 2) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Formatting