Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/main/java/knightminer/tcomplement/TinkersComplement.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import knightminer.tcomplement.common.Config;
import knightminer.tcomplement.common.TCompNetwork;
import knightminer.tcomplement.feature.ModuleFeature;
import knightminer.tcomplement.feature.tileentity.TileMelter;
import knightminer.tcomplement.plugin.ceramics.CeramicsPlugin;
import knightminer.tcomplement.plugin.chisel.ChiselPlugin;
import knightminer.tcomplement.plugin.exnihilo.ExNihiloPlugin;
Expand All @@ -15,6 +16,7 @@
import net.minecraftforge.common.util.ModFixs;
import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.network.NetworkRegistry;
import slimeknights.mantle.common.GuiHandler;
Expand Down Expand Up @@ -61,4 +63,9 @@ public void preInit(FMLPreInitializationEvent event) {
ModFixs fixer = FMLCommonHandler.instance().getDataFixer().init(modID, 1);
fixer.registerFix(FixTypes.BLOCK_ENTITY, new TileEntityRenamer());
}

@Mod.EventHandler
public void init(FMLInitializationEvent event) {
TileMelter.init();
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Formatting

}
5 changes: 4 additions & 1 deletion src/main/java/knightminer/tcomplement/common/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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.");
Copy link
Owner

Choose a reason for hiding this comment

The 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();
Expand Down
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);
Copy link
Owner

Choose a reason for hiding this comment

The 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;
Expand All @@ -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;
Expand Down Expand Up @@ -43,6 +49,8 @@

public class TileMelter extends TileHeatingStructureFuelTank<MultiblockMelter> implements ITickable, IInventoryGui {

private static Map<String, Integer> fuelsMap = new HashMap<>();
Copy link
Owner

Choose a reason for hiding this comment

The 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
Expand Down Expand Up @@ -75,6 +83,38 @@ public TileHeater getSolidHeater() {
return null;
}

public static void init() {
for(String item : Config.heaterFuels) {
Copy link
Owner

Choose a reason for hiding this comment

The 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()) {
Expand Down Expand Up @@ -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
Expand All @@ -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) {
Expand Down