Skip to content

Commit

Permalink
Fire pit works (just) Lots of tweaks and fixes here and there: biome …
Browse files Browse the repository at this point in the history
…registry no longer gives type warnings; opening a gui now should make use of an enum; trees now have heat + burn time values. Added stick heat capability for stick -> torch recipe. Also added Firepit recipe manager (for future recipe madness)

Signed-off-by: alcatrazEscapee <alex@molleroneill.com>
  • Loading branch information
alcatrazEscapee committed Sep 22, 2018
1 parent aa960bd commit 162b02d
Show file tree
Hide file tree
Showing 28 changed files with 630 additions and 92 deletions.
6 changes: 4 additions & 2 deletions src/main/java/net/dries007/tfc/CommonEventHandler.java
@@ -1,6 +1,7 @@
/*
* Work under Copyright. Licensed under the EUPL.
* See the project README.md and LICENSE.txt for more information.
*
*/

package net.dries007.tfc;
Expand All @@ -24,6 +25,7 @@
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;

import net.dries007.tfc.api.capability.ItemStickCapability;
import net.dries007.tfc.api.capability.size.CapabilityItemSize;
import net.dries007.tfc.api.capability.size.Size;
import net.dries007.tfc.api.capability.size.Weight;
Expand Down Expand Up @@ -57,7 +59,7 @@ public void onBlockHarvestDrops(BlockEvent.HarvestDropsEvent event)
double chance = ConfigTFC.GENERAL.leafStickDropChance;
if (!heldItem.isEmpty() && Helpers.containsAnyOfCaseInsensitive(heldItem.getItem().getToolClasses(heldItem), ConfigTFC.GENERAL.leafStickDropChanceBonusClasses))
chance = ConfigTFC.GENERAL.leafStickDropChanceBonus;
if (event.getWorld().rand.nextFloat() < chance)
if (Constants.RNG.nextFloat() < chance)
event.getDrops().add(new ItemStack(Items.STICK));
}
}
Expand Down Expand Up @@ -234,7 +236,7 @@ public void attachItemCapabilities(AttachCapabilitiesEvent<ItemStack> e)
if (item == Items.COAL)
CapabilityItemSize.add(e, Items.COAL, Size.SMALL, Weight.MEDIUM, canStack);
else if (item == Items.STICK)
CapabilityItemSize.add(e, Items.STICK, Size.SMALL, Weight.LIGHT, canStack);
e.addCapability(ItemStickCapability.KEY, new ItemStickCapability(e.getObject().getTagCompound()));

// Final checks for general item types
else if (item instanceof ItemTool)
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/net/dries007/tfc/TerraFirmaCraft.java
@@ -1,6 +1,7 @@
/*
* Work under Copyright. Licensed under the EUPL.
* See the project README.md and LICENSE.txt for more information.
*
*/

package net.dries007.tfc;
Expand All @@ -26,6 +27,7 @@
import net.dries007.tfc.cmd.TreeGenCommand;
import net.dries007.tfc.objects.entity.EntitiesTFC;
import net.dries007.tfc.objects.items.ItemsTFC;
import net.dries007.tfc.objects.recipes.firepit.FirePitRecipeManager;
import net.dries007.tfc.util.OreDictionaryHelper;
import net.dries007.tfc.util.OreSpawnData;
import net.dries007.tfc.world.classic.CalenderTFC;
Expand Down Expand Up @@ -155,6 +157,8 @@ public void postInit(FMLPostInitializationEvent event)
if (!isSignedBuild)
log.warn("You are not running an official build. Please do not use this and then report bugs or issues.");

FirePitRecipeManager.postInit();

OreSpawnData.reloadOreGen();
}

Expand Down
@@ -0,0 +1,96 @@
/*
* Work under Copyright. Licensed under the EUPL.
* See the project README.md and LICENSE.txt for more information.
*
*/

package net.dries007.tfc.api.capability;

import java.util.List;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;

import net.minecraft.client.resources.I18n;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

import net.dries007.tfc.api.capability.heat.CapabilityItemHeat;
import net.dries007.tfc.api.capability.heat.ItemHeatHandler;
import net.dries007.tfc.api.capability.size.CapabilityItemSize;
import net.dries007.tfc.api.capability.size.IItemSize;
import net.dries007.tfc.api.capability.size.Size;
import net.dries007.tfc.api.capability.size.Weight;

import static net.dries007.tfc.api.util.TFCConstants.MOD_ID;

public class ItemStickCapability extends ItemHeatHandler implements IItemSize
{
public static final ResourceLocation KEY = new ResourceLocation(MOD_ID, "stick");
private static final float MELTING_POINT = 80f;
private static final float HEAT_CAPACITY = 1f;

public ItemStickCapability(@Nullable NBTTagCompound nbt)
{
//todo: check values
super(nbt, HEAT_CAPACITY, MELTING_POINT);
if (nbt != null)
deserializeNBT(nbt);
}

@Override
public Size getSize(@Nonnull ItemStack stack)
{
return Size.SMALL;
}

@Override
public Weight getWeight(@Nonnull ItemStack stack)
{
return Weight.LIGHT;
}

@Override
public float getHeatCapacity()
{
return HEAT_CAPACITY;
}

@Override
public float getMeltingPoint()
{
return MELTING_POINT;
}

@Override
public boolean hasCapability(@Nonnull Capability<?> capability, @Nullable EnumFacing facing)
{
return capability == CapabilityItemHeat.ITEM_HEAT_CAPABILITY || capability == CapabilityItemSize.ITEM_SIZE_CAPABILITY;
}

@Nullable
@Override
@SuppressWarnings("unchecked")
public <T> T getCapability(@Nonnull Capability<T> capability, @Nullable EnumFacing facing)
{
return hasCapability(capability, facing) ? (T) this : null;
}

@SideOnly(Side.CLIENT)
@Override
public void addHeatInfo(ItemStack stack, List<String> text, boolean clearStackNBT)
{
float temperature = getTemperature();
if (temperature > MELTING_POINT * 0.9f)
text.add(I18n.format("tfc.enum.heat.torch.lit"));
else if (temperature > 1f)
text.add(I18n.format("tfc.enum.heat.torch.catchingFire"));

if (clearStackNBT && temperature <= 0 && stack.hasTagCompound())
stack.setTagCompound(null);
}
}
@@ -1,12 +1,14 @@
/*
* Work under Copyright. Licensed under the EUPL.
* See the project README.md and LICENSE.txt for more information.
*
*/

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

import javax.annotation.Nonnull;

import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTBase;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumFacing;
Expand All @@ -26,12 +28,40 @@ public static void preInit()
CapabilityManager.INSTANCE.register(IItemHeat.class, new ItemHeatStorage(), ItemHeatHandler::new);
}

/**
* Call this from within IItemHeat#getTemperature();
*/
public static float adjustTemp(float temp, float heatCapacity, long ticksSinceUpdate)
{
float newTemp = temp - heatCapacity * (float) ticksSinceUpdate * (float) ConfigTFC.GENERAL.temperatureModifier;
final float newTemp = temp - heatCapacity * (float) ticksSinceUpdate * (float) ConfigTFC.GENERAL.temperatureModifier;
return newTemp < 0 ? 0 : 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);
stack.setTagCompound(cap.serializeNBT());
}
}

/**
* 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
*/
public static void addTemp(IItemHeat instance, float modifier)
{
final float temp = instance.getTemperature() + modifier * instance.getHeatCapacity() * (float) ConfigTFC.GENERAL.temperatureModifier;
instance.setTemperature(temp > 1600f ? 1600f : temp);
}

public static class ItemHeatStorage implements Capability.IStorage<IItemHeat>
{
@Nonnull
Expand Down
21 changes: 18 additions & 3 deletions src/main/java/net/dries007/tfc/api/capability/heat/IItemHeat.java
@@ -1,6 +1,7 @@
/*
* Work under Copyright. Licensed under the EUPL.
* See the project README.md and LICENSE.txt for more information.
*
*/

package net.dries007.tfc.api.capability.heat;
Expand All @@ -25,11 +26,26 @@ public interface IItemHeat extends INBTSerializable<NBTTagCompound>
{
/**
* Gets the current temperature. Should call CapabilityItemHeat.adjustTemp() internally
*
* @return the temperature. Between 0 - 1600
*/
float getTemperature();

/**
* Gets the Heat capacity. (A measure of how fast this items heats up or cools down)
* Implementation is left up to the heating object. (See TEFirePit for example)
*
* @return a value between 0 and 1
*/
float getHeatCapacity();

/**
* Gets the melting point of the item.
* Depending on the item, this may not mean anything.
*
* @return a temperature between 0 - 1600 that is the melting point
*/
float getMeltingPoint();

/**
* Sets the temperature. Used for anything that modifies the temperature.
* @param temperature the temperature to set. Between 0 - 1600
Expand All @@ -39,12 +55,11 @@ public interface IItemHeat extends INBTSerializable<NBTTagCompound>
/**
* If the object can melt / transform, return if it is transformed
* This can mean many different things depending on the object
*
* @return is the object transformed.
*/
default boolean isMolten()
{
return false;
return getTemperature() > getMeltingPoint();
}

/**
Expand Down
@@ -1,6 +1,7 @@
/*
* Work under Copyright. Licensed under the EUPL.
* See the project README.md and LICENSE.txt for more information.
*
*/

package net.dries007.tfc.api.capability.heat;
Expand All @@ -19,8 +20,6 @@
* This is an implementation of ItemHeat that automatically cools down over time
* Prefer extending or using this than implementing IItemHeat directly
* Exceptions if you want to extend another capability object (see SmallVessel) but you should still implement this functionality somewhere
*
* todo: make this into an interface with defaults?
*/
public class ItemHeatHandler implements ICapabilitySerializable<NBTTagCompound>, IItemHeat
{
Expand Down Expand Up @@ -66,6 +65,19 @@ public void setTemperature(float temperature)
this.lastUpdateTick = CalenderTFC.getTotalTime();
}

@Override
public float getHeatCapacity()
{
return heatCapacity;
}

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

// Override for that 0.00001% efficiency
@Override
public boolean isMolten()
{
Expand Down

0 comments on commit 162b02d

Please sign in to comment.