Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Added welding - recipe infrastructure, mehonix and more. Also did som…
…e refactoring renaming and cleanup by Intellij's magic whispers. Added the hammer on top of the anvil for both stone + metal. Made anvil have full 4x direction rotatability instead of just axis aligned. Pls send cheque via western union for more tfc updates
  • Loading branch information
alcatrazEscapee committed Feb 14, 2019
1 parent e6b3354 commit b9cebba
Show file tree
Hide file tree
Showing 38 changed files with 608 additions and 315 deletions.
6 changes: 4 additions & 2 deletions generateResources.py
Expand Up @@ -503,8 +503,10 @@ def item(filename_parts, *layers, parent='item/generated'):
('all', 'particle'): 'tfc:blocks/metal/%s' % key
}, variants={
'axis': {
'true': {'y': 90},
'false': {}
'north': {},
'east': {'y': 90},
'south': {'y': 180},
'west': {'y': 270}
}
})

Expand Down
18 changes: 14 additions & 4 deletions src/main/java/net/dries007/tfc/ConfigTFC.java
Expand Up @@ -74,14 +74,24 @@ public static class GeneralCFG
@Config.LangKey("config." + MOD_ID + ".general.leafStickDropChanceBonusClasses")
public String[] leafStickDropChanceBonusClasses = new String[] {"knife", "scythe"};

@Config.Comment("Modifier for how quickly items gain and lose heat. Smaller number = slower temperature changes")
@Config.Comment("Modifier for how quickly EVERYTHING gains and loses heat. Smaller number = slower temperature changes")
@Config.RangeDouble(min = 0, max = 10)
@Config.LangKey("config." + MOD_ID + ".general.temperatureModifier")
public double temperatureModifier = 0.5; // todo: items cool too fast at 0.5, needs tweaking
@Config.LangKey("config." + MOD_ID + ".general.temperatureModifierGlobal")
public double temperatureModifierGlobal = 0.5; // todo: items cool too fast at 0.5, needs tweaking

@Config.Comment("Modifier for how quickly devices (i.e. charcoal forge, firepit) gain and lose heat. Smaller number = slower temperature changes")
@Config.RangeDouble(min = 0, max = 10)
@Config.LangKey("config." + MOD_ID + ".general.temperatureModifierHeating")
public double temperatureModifierHeating = 1;

@Config.Comment("Modifier for how quickly devices (i.e. charcoal forge, firepit) transfer heat to items / heat up items. Smaller number = slower temperature change")
@Config.RangeDouble(min = 0, max = 10)
@Config.LangKey("config." + MOD_ID + ".general.temperatureModifierItemHeating")
public double temperatureModifierItemHeating = 3;

@Config.Comment("Number of ticks required for a pit kiln to burn out. (1000 = 1 in game hour), default is 8 hours.")
@Config.RangeInt(min = 20)
@Config.LangKey("config." + MOD_ID + ".general.temperatureModifier")
@Config.LangKey("config." + MOD_ID + ".general.temperatureModifierGlobal")
public int pitKilnTime = 8000;

@Config.Comment("Number of ticks required for a torch to burn out (72000 = 1 in game hour), default is 72 hours. Set to -1 to disable torch burnout.")
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/net/dries007/tfc/TerraFirmaCraft.java
Expand Up @@ -118,10 +118,9 @@ public void preInit(FMLPreInitializationEvent event)
int id = 0;
// Received on server
network.registerMessage(new PacketKnappingUpdate.Handler(), PacketKnappingUpdate.class, ++id, Side.SERVER);
network.registerMessage(new PacketAnvilRecipe.Handler(), PacketAnvilRecipe.class, ++id, Side.SERVER);
network.registerMessage(new PacketGuiButton.Handler(), PacketGuiButton.class, ++id, Side.SERVER);
// Received on client
network.registerMessage(new PacketAnvilRecipe.Handler(), PacketAnvilRecipe.class, ++id, Side.CLIENT);
network.registerMessage(new PacketAnvilUpdate.Handler(), PacketAnvilUpdate.class, ++id, Side.CLIENT);
network.registerMessage(new PacketChunkData.Handler(), PacketChunkData.class, ++id, Side.CLIENT);
network.registerMessage(new PacketCapabilityContainerUpdate.Handler(), PacketCapabilityContainerUpdate.class, ++id, Side.CLIENT);

Expand Down
Expand Up @@ -36,7 +36,7 @@ public ItemStickCapability(@Nullable NBTTagCompound nbt)
public void addHeatInfo(@Nonnull ItemStack stack, @Nonnull List<String> text)
{
float temperature = getTemperature();
if (temperature > getMeltingPoint() * 0.9f)
if (temperature > getMeltTemp() * 0.9f)
text.add(I18n.format("tfc.enum.heat.torch.lit"));
else if (temperature > 1f)
text.add(I18n.format("tfc.enum.heat.torch.catching_fire"));
Expand Down
Expand Up @@ -14,22 +14,19 @@
import net.minecraftforge.common.capabilities.Capability;

import net.dries007.tfc.api.capability.heat.ItemHeatHandler;
import net.dries007.tfc.api.recipes.AnvilRecipe;
import net.dries007.tfc.util.forge.ForgeStep;
import net.dries007.tfc.util.forge.ForgeSteps;

public class ForgeableHandler extends ItemHeatHandler implements IForgeable
{
private final ForgeSteps steps;
private int work;
private ResourceLocation recipeName;
private float workingPoint;
protected final ForgeSteps steps;
protected int work;
protected ResourceLocation recipeName;

public ForgeableHandler(@Nullable NBTTagCompound nbt, float heatCapacity, float workingPoint, float meltingPoint)
public ForgeableHandler(@Nullable NBTTagCompound nbt, float heatCapacity, float meltTemp)
{
this.heatCapacity = heatCapacity;
this.workingPoint = workingPoint;
this.meltingPoint = meltingPoint;
this.meltTemp = meltTemp;

steps = new ForgeSteps();

Expand Down Expand Up @@ -62,9 +59,9 @@ public ResourceLocation getRecipeName()
}

@Override
public void setRecipe(@Nullable AnvilRecipe recipe)
public void setRecipe(@Nullable ResourceLocation recipeName)
{
recipeName = (recipe == null ? null : recipe.getRegistryName());
this.recipeName = recipeName;
}

@Override
Expand All @@ -89,12 +86,6 @@ public void reset()
work = 0;
}

@Override
public float getWorkingPoint()
{
return workingPoint;
}

@Override
@Nonnull
public NBTTagCompound serializeNBT()
Expand Down
Expand Up @@ -42,7 +42,17 @@ public interface IForgeable extends IItemHeat
/**
* Sets the recipe name from an {@link AnvilRecipe}. If null, sets the recipe name to null
*/
void setRecipe(@Nullable AnvilRecipe recipe);
default void setRecipe(@Nullable AnvilRecipe recipe)
{
setRecipe(recipe != null ? recipe.getRegistryName() : null);
}

/**
* Sets the recipe name from an {@link AnvilRecipe}'s registry name.
*
* @param recipeName a registry name of an anvil recipe
*/
void setRecipe(@Nullable ResourceLocation recipeName);

/**
* Gets the last three steps, wrapped in a {@link ForgeSteps} instance.
Expand All @@ -53,29 +63,53 @@ public interface IForgeable extends IItemHeat

/**
* Adds a step to the object, shuffling the last three steps down
* @param step The step to add. In general this should not be null, although it is perfectly valid for it to be
*/
void addStep(ForgeStep step);
void addStep(@Nullable ForgeStep step);

/**
* Resets the object's {@link IForgeable} components. Used if an item falls out of an anvil without getting worked
* Purpose is to preserve stackability on items that haven't been worked yet.
*/
void reset();

/**
* Gets the working temperature of the item
*
* @return a temperature
*/
default float getWorkTemp()
{
return getMeltTemp() * 0.6f;
}

/**
* Checks if the item is hot enough to be worked
*
* @return true if the item is workable
*/
default boolean isWorkable()
{
return getTemperature() > getWorkingPoint();
return getTemperature() > getWorkTemp();
}

/**
* Gets the working temperature of the item
* Gets the welding temperature of the item
*
* @return a temperature
*/
float getWorkingPoint();
default float getWeldTemp()
{
return getMeltTemp() * 0.8f;
}

/**
* Checks if the item is hot enough to be worked
*
* @return true if the item is weldable
*/
default boolean isWeldable()
{
return getTemperature() > getWeldTemp();
}
}
Expand Up @@ -5,7 +5,6 @@

package net.dries007.tfc.api.capability.heat;

import net.minecraft.item.ItemStack;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.capabilities.CapabilityInject;
import net.minecraftforge.common.capabilities.CapabilityManager;
Expand All @@ -22,47 +21,29 @@ public final class CapabilityItemHeat
public static final float MIN_TEMPERATURE = 0f;
public static final float MAX_TEMPERATURE = 1600f;

// todo: make this configurable
// todo: adjust this to change how fast things (Fire Pit / Charcoal Forge) heat up items (item_heating_mod) or how fast it heats up (temperature_modifier)
public static final float TEMPERATURE_MODIFIER = 1f;
public static final float ITEM_HEATING_MODIFIER = 3f;

public static void preInit()
{
CapabilityManager.INSTANCE.register(IItemHeat.class, new DumbStorage<>(), ItemHeatHandler::new);
}

/**
* Call this from within IItemHeat#getTemperature();
* Call this from within {@link IItemHeat#getTemperature()}
*/
public static float adjustTemp(float temp, float heatCapacity, long ticksSinceUpdate)
{
if (ticksSinceUpdate == -1) return 0;
final float newTemp = temp - heatCapacity * (float) ticksSinceUpdate * (float) ConfigTFC.GENERAL.temperatureModifier;
if (ticksSinceUpdate == -1) return MIN_TEMPERATURE;
final float newTemp = temp - heatCapacity * (float) ticksSinceUpdate * (float) ConfigTFC.GENERAL.temperatureModifierGlobal;
return newTemp < MIN_TEMPERATURE ? MIN_TEMPERATURE : newTemp;
}

/**
* Use this to increase the heat on an item stack
*/
public static void addTemp(ItemStack stack, float modifier)
{
final IItemHeat cap = stack.getCapability(ITEM_HEAT_CAPABILITY, null);
if (cap != null)
{
addTemp(cap, modifier);
}
}

/**
* Use this to increase the heat on an IItemHeat instance.
* Note: to save the change you will need to still call stack.setTagCompound(cap.serializeNBT());
*
* @param modifier the modifier for how much this will heat up: 0 - 1 slows down cooling, 1 = no heating or cooling, > 1 heats, 2 heats at the same rate it cools
* @param modifier the modifier for how much this will heat up: 0 - 1 slows down cooling, 1 = no heating or cooling, > 1 heats, 2 heats at the same rate of normal cooling, 2+ heats faster
*/
public static void addTemp(IItemHeat instance, float modifier)
{
final float temp = instance.getTemperature() + modifier * instance.getHeatCapacity() * (float) ConfigTFC.GENERAL.temperatureModifier;
final float temp = instance.getTemperature() + modifier * instance.getHeatCapacity() * (float) ConfigTFC.GENERAL.temperatureModifierGlobal;
instance.setTemperature(temp > MAX_TEMPERATURE ? MAX_TEMPERATURE : temp);
}
}
Expand Up @@ -41,7 +41,7 @@ public interface IItemHeat extends INBTSerializable<NBTTagCompound>
*
* @return a temperature between 0 - 1600 that is the melting point
*/
float getMeltingPoint();
float getMeltTemp();

/**
* Sets the temperature. Used for anything that modifies the temperature.
Expand All @@ -58,7 +58,7 @@ public interface IItemHeat extends INBTSerializable<NBTTagCompound>
*/
default boolean isMolten()
{
return getTemperature() > getMeltingPoint();
return getTemperature() > getMeltTemp();
}

/**
Expand Down
Expand Up @@ -24,7 +24,7 @@ public class ItemHeatHandler implements ICapabilitySerializable<NBTTagCompound>,
{
// These are "constants". Some implementations will want to change these based on other factors. (See ItemMold)
protected float heatCapacity;
protected float meltingPoint;
protected float meltTemp;

// These are the values from last point of update. They are updated when read from NBT, or when the temperature is set manually.
// Note that if temperature is == 0, lastUpdateTick should set itself to -1 to keep their capabilities compatible - i.e. stackable
Expand All @@ -36,17 +36,17 @@ public class ItemHeatHandler implements ICapabilitySerializable<NBTTagCompound>,
*
* @param nbt The NBT of the itemstack. (Provided in Item#initCapabilities())
* @param heatCapacity The heat capacity
* @param meltingPoint The melting point
* @param meltTemp The melting point
*/
public ItemHeatHandler(@Nullable NBTTagCompound nbt, float heatCapacity, float meltingPoint)
public ItemHeatHandler(@Nullable NBTTagCompound nbt, float heatCapacity, float meltTemp)
{
this.heatCapacity = heatCapacity;
this.meltingPoint = meltingPoint;
this.meltTemp = meltTemp;

deserializeNBT(nbt);
}

public ItemHeatHandler() { } // This is here so you can do a custom implementation
public ItemHeatHandler() {} // This is here so you can do a custom implementation

/**
* This gets the outwards facing temperature. It will differ from the internal temperature value or the value saved to NBT
Expand Down Expand Up @@ -78,15 +78,15 @@ public float getHeatCapacity()
}

@Override
public float getMeltingPoint()
public float getMeltTemp()
{
return meltingPoint;
return meltTemp;
}

@Override
public boolean isMolten()
{
return getTemperature() >= meltingPoint;
return getTemperature() >= meltTemp;
}

@Override
Expand Down
18 changes: 5 additions & 13 deletions src/main/java/net/dries007/tfc/api/recipes/AnvilRecipe.java
Expand Up @@ -9,7 +9,6 @@
import java.util.Random;
import java.util.stream.Collectors;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;

import net.minecraft.item.ItemStack;
Expand All @@ -22,19 +21,18 @@
import net.dries007.tfc.util.forge.ForgeRule;
import net.dries007.tfc.util.forge.ForgeSteps;

/**
* Anvil Recipe
*
* They all take a single item input and will produce a single item output
*/
@ParametersAreNonnullByDefault
public class AnvilRecipe extends IForgeRegistryEntry.Impl<AnvilRecipe>
{
private static long SEED = 0;

private static final Random RNG = new Random();

@Nullable
public static AnvilRecipe getFirstFor(ItemStack stack)
{
return TFCRegistries.ANVIL.getValuesCollection().stream().filter(x -> x.matches(stack)).findFirst().orElse(null);
}

@Nonnull
public static List<AnvilRecipe> getAllFor(ItemStack stack)
{
Expand Down Expand Up @@ -85,12 +83,6 @@ public ItemStack getOutput()
return output.copy();
}

@Nonnull
public ItemStack getInput()
{
return input.copy();
}

@Nonnull
public ForgeRule[] getRules()
{
Expand Down

0 comments on commit b9cebba

Please sign in to comment.