Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Item Heat is working (?)
  • Loading branch information
alcatrazEscapee committed Aug 24, 2018
1 parent 3cc7fea commit 7538925
Show file tree
Hide file tree
Showing 25 changed files with 308 additions and 223 deletions.
4 changes: 2 additions & 2 deletions src/main/java/net/dries007/tfc/CommonEventHandler.java
Expand Up @@ -44,7 +44,7 @@ public class CommonEventHandler
* Make leaves drop sticks
*/
@SubscribeEvent
public static void onBlockHarvestDrops(BlockEvent.HarvestDropsEvent event)
public void onBlockHarvestDrops(BlockEvent.HarvestDropsEvent event)
{
final EntityPlayer harvester = event.getHarvester();
final ItemStack heldItem = harvester == null ? ItemStack.EMPTY : harvester.getHeldItemMainhand();
Expand All @@ -68,7 +68,7 @@ public static void onBlockHarvestDrops(BlockEvent.HarvestDropsEvent event)
* We have this event already, might as well use it.
*/
@SubscribeEvent
public static void onRightClickBlock(PlayerInteractEvent.RightClickBlock event)
public void onRightClickBlock(PlayerInteractEvent.RightClickBlock event)
{
World world = event.getWorld();
BlockPos pos = event.getPos();
Expand Down
14 changes: 11 additions & 3 deletions src/main/java/net/dries007/tfc/ConfigTFC.java
Expand Up @@ -62,14 +62,22 @@ public static class GeneralCFG

@Config.Comment("Normal decay leaf drop chance for sticks")
@Config.RangeDouble(min = 0, max = 1)
public double leafStickDropChance = 0.1; // todo: lang key
@Config.LangKey("config." + MOD_ID + ".general.leafStickDropChance")
public double leafStickDropChance = 0.1;

@Config.Comment("Bonus decay leaf drop chance for sticks")
@Config.RangeDouble(min = 0, max = 1)
public double leafStickDropChanceBonus = 0.25; // todo: lang key
@Config.LangKey("config." + MOD_ID + ".general.leafStickDropChanceBonus")
public double leafStickDropChanceBonus = 0.25;

@Config.Comment("Bonus decay leaf drop chance for sticks tool classes")
public String[] leafStickDropChanceBonusClasses = new String[] {"knife", "scythe"}; // todo: lang key
@Config.LangKey("config." + MOD_ID + ".general.leafStickDropChanceBonusClasses")
public String[] leafStickDropChanceBonusClasses = new String[] {"knife", "scythe"};

@Config.Comment("Modifier for how quickly item's lose heat. Smaller number = slower temperature changes")
@Config.RangeDouble(min = 0, max = 1)
@Config.LangKey("config." + MOD_ID + ".general.temperatureModifier")
public double temperatureModifier = 0.01;
}

public static class ClientCFG
Expand Down
Expand Up @@ -33,4 +33,5 @@ public interface IMoldHandler extends IFluidHandler, INBTSerializable<NBTTagComp
* @return The amount of metal, in mB / units
*/
int getAmount();

}
Expand Up @@ -6,41 +6,36 @@

package net.dries007.tfc.api.capability;

import javax.annotation.Nullable;

import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.common.util.INBTSerializable;
import net.minecraftforge.fluids.capability.IFluidHandler;
import net.minecraftforge.items.IItemHandler;

import net.dries007.tfc.api.capability.heat.IItemHeat;
import net.dries007.tfc.api.types.Metal;

/**
* This is an interface for the capability that is returned by a Small Vessel. You can safely cast it to this.
*/
public interface ISmallVesselHandler extends IItemHandler, IFluidHandler, INBTSerializable<NBTTagCompound>, IItemHeat
public interface ISmallVesselHandler extends IItemHandler, IFluidHandler, INBTSerializable<NBTTagCompound>, IItemHeat, IMoldHandler
{

/**
* This sets the fluid mode. When fluid is empty, it defaults to item mode
*
* @param mode true = fluids, false = items
*/
void setFluidMode(boolean fluidMode);

/**
* Gets the metal currently in the vessel. Null if empty. Used in model loading.
*
* @return The metal
* This gets the fluid mode, including liquid temperature status
* @return INVENTORY = items, LIQUID = fluids molten or solid based on temperature
*/
@Nullable
Metal getMetal();
Mode getFluidMode();

enum Mode
{
INVENTORY,
LIQUID_MOLTEN,
LIQUID_SOLID
}

/**
* Gets the current amount of metal in the mold. Zero if empty.
*
* @return The amount of metal, in mB / units
*/
int getAmount();
}
Expand Up @@ -16,7 +16,9 @@
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.common.capabilities.*;

import net.dries007.tfc.ConfigTFC;
import net.dries007.tfc.Constants;
import net.dries007.tfc.world.classic.CalenderTFC;

public class CapabilityItemHeat
{
Expand All @@ -39,6 +41,27 @@ public static IItemHeat getIItemHeat(@Nonnull ItemStack stack)
return stack.getCapability(ITEM_HEAT_CAPABILITY, null);
}

public static float getTempChange(float temp, float environmentTemp, long ticksSinceUpdate)
{
return getTempChange(temp, 1, environmentTemp, ticksSinceUpdate);
}

public static float getTempChange(float temp, float specificHeat, float enviromentTemp, long ticksSinceUpdate)
{
float tempMod = specificHeat * ticksSinceUpdate * (float) ConfigTFC.GENERAL.temperatureModifier;
if (tempMod > Math.abs(enviromentTemp - temp))
{
return enviromentTemp < 0 ? 0 : enviromentTemp;
}
else
{
if (enviromentTemp > temp)
return temp + tempMod;
else
return temp -= tempMod;
}
}

public ICapabilityProvider getCapability(ItemStack stack, NBTTagCompound nbt, float heatCapacity, float meltingPoint)
{
return new ItemHeat(heatCapacity, meltingPoint);
Expand Down Expand Up @@ -76,19 +99,9 @@ public float getTemperature()
}

@Override
public void updateTemperature(float enviromentTemperature, float weight)
public void updateTemperature(float enviromentTemperature, long ticks)
{
if (heatCapacity * weight > Math.abs(enviromentTemperature - temperature))
{
this.temperature = enviromentTemperature;
}
else
{
if (enviromentTemperature > temperature)
temperature += weight * heatCapacity;
else
temperature -= weight * heatCapacity;
}
CapabilityItemHeat.getTempChange(temperature, heatCapacity, enviromentTemperature, ticks);
}

@Override
Expand All @@ -107,9 +120,7 @@ public boolean hasCapability(@Nonnull Capability<?> capability, @Nullable EnumFa
@Override
public <T> T getCapability(@Nonnull Capability<T> capability, @Nullable EnumFacing facing)
{
if (capability != ITEM_HEAT_CAPABILITY)
return null;
return CapabilityItemHeat.ITEM_HEAT_CAPABILITY.cast(this);
return hasCapability(capability, facing) ? (T) this : null;
}

@Override
Expand All @@ -133,6 +144,7 @@ public NBTBase writeNBT(Capability<IItemHeat> capability, IItemHeat instance, En
{
NBTTagCompound nbt = new NBTTagCompound();
nbt.setFloat("heat", instance.getTemperature());
nbt.setLong("ticks", CalenderTFC.getTotalTime());
return nbt;
}

Expand All @@ -145,7 +157,9 @@ public void readNBT(Capability<IItemHeat> capability, IItemHeat instance, EnumFa
return;
}
NBTTagCompound nbt = (NBTTagCompound) base;
instance.setTemperature(nbt.getFloat("heat"));
final float oldTemp = nbt.getFloat("heat");
final long ticks = CalenderTFC.getTotalTime() - nbt.getLong("ticks");
instance.setTemperature(CapabilityItemHeat.getTempChange(oldTemp, 0, (int) ticks));
}
}

Expand Down
Expand Up @@ -12,20 +12,23 @@
import net.minecraft.client.resources.I18n;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.common.capabilities.ICapabilitySerializable;
import net.minecraftforge.common.util.INBTSerializable;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

import net.dries007.tfc.util.Helpers;

public interface IItemHeat extends ICapabilitySerializable<NBTTagCompound>
public interface IItemHeat extends INBTSerializable<NBTTagCompound>
{

float getTemperature();

void setTemperature(float temperature);

void updateTemperature(float enviromentTemperature, float weight);
default void updateTemperature(float enviromentTemperature, long ticksSinceLastUpdate)
{
setTemperature(CapabilityItemHeat.getTempChange(getTemperature(), enviromentTemperature, ticksSinceLastUpdate));
}

@SideOnly(Side.CLIENT)
default void addHeatInfo(ItemStack stack, List<String> text)
Expand Down
38 changes: 19 additions & 19 deletions src/main/java/net/dries007/tfc/api/types/Metal.java
Expand Up @@ -33,38 +33,38 @@ public static Metal get(String name)
}

public final Tier tier;
public final double specificHeat;
public final float specificHeat;
public final int meltTemp;
public final Item.ToolMaterial toolMetal;
public final boolean usable;
public final int color;

private final Item.ToolMaterial toolMetal;
private final ResourceLocation name;

public Metal(ResourceLocation name, Tier tier, double sh, int melt, int color)
{
this(name, tier, true, sh, melt, color, null);
}

public Metal(ResourceLocation name, Tier tier, double sh, int melt, int color, Item.ToolMaterial toolMetal)
{
this(name, tier, true, sh, melt, color, toolMetal);
}

public Metal(ResourceLocation name, Tier tier, boolean usable, double sh, int melt, int color)
{
this(name, tier, usable, sh, melt, color, null);
}

public Metal(ResourceLocation name, Tier tier, boolean usable, double sh, int melt, int color, Item.ToolMaterial toolMetal)
/**
* This is a registry object that will create a number of things.
*
* Use the provided Builder to create your own metals
*
* @param name the registry name of the object. The path must also be unique
* @param tier the tier of the metal
* @param usable is the metal usable to create basic metal items? (not tools)
* @param sh specific heat capacity. Higher = harder to heat up / cool down. Most IRL metals are between 0.3 - 0.7
* @param melt melting point. See @link Heat for temperature scale. Similar to IRL melting point in celcius.
* @param color color of the metal when in fluid form. Used to autogenerate a fluid texture
* @param toolMetal The tool material. Null if metal is not able to create tools
* @param alloyRecipe The alloy recipe. Null if the metal is not an alloy
*/
public Metal(@Nonnull ResourceLocation name, Tier tier, boolean usable, float sh, int melt, int color, @Nullable Item.ToolMaterial toolMetal)
{
this.usable = usable;
this.tier = tier;
this.specificHeat = sh;
this.meltTemp = melt;
this.toolMetal = toolMetal;
this.color = color;

this.toolMetal = toolMetal;

this.name = name;
setRegistryName(name);
}
Expand Down
8 changes: 7 additions & 1 deletion src/main/java/net/dries007/tfc/api/types/TFCRegistries.java
Expand Up @@ -27,13 +27,14 @@
@Mod.EventBusSubscriber(modid = MOD_ID)
public class TFCRegistries
{
static final String MOD_ID = "tfc"; // This is here to avoid a import statement.
public static final String MOD_ID = "tfc"; // This is here to avoid a import statement.

private static final ResourceLocation ROCK_TYPE = new ResourceLocation(MOD_ID, "rock_type");
private static final ResourceLocation METAL = new ResourceLocation(MOD_ID, "metal");
private static final ResourceLocation ROCK = new ResourceLocation(MOD_ID, "rock");
private static final ResourceLocation ORE = new ResourceLocation(MOD_ID, "ore");
private static final ResourceLocation TREE = new ResourceLocation(MOD_ID, "tree");
private static final ResourceLocation ALLOY = new ResourceLocation(MOD_ID, "alloy");

private static final Map<ResourceLocation, IForgeRegistry<?>> preBlockRegistries = new LinkedHashMap<>();

Expand All @@ -42,6 +43,7 @@ public class TFCRegistries
private static IForgeRegistry<Ore> oreRegistry;
private static IForgeRegistry<Tree> treeRegistry;
private static IForgeRegistry<Metal> metalRegistry;
private static IForgeRegistry<AlloyRecipe> alloyRegistry;

@SubscribeEvent
public static void onNewRegistryEvent(RegistryEvent.NewRegistry event)
Expand All @@ -51,6 +53,8 @@ public static void onNewRegistryEvent(RegistryEvent.NewRegistry event)
rockRegistry = newRegistry(ROCK, Rock.class, true);
oreRegistry = newRegistry(ORE, Ore.class, true);
treeRegistry = newRegistry(TREE, Tree.class, true);

alloyRegistry = newRegistry(ALLOY, AlloyRecipe.class, false);
}

/**
Expand Down Expand Up @@ -90,6 +94,8 @@ static IForgeRegistry<RockCategory> getRockCategories()

static IForgeRegistry<Metal> getMetals() { return metalRegistry; }

static IForgeRegistry<AlloyRecipe> getAlloys() { return alloyRegistry; }

private static <T extends IForgeRegistryEntry<T>> IForgeRegistry<T> newRegistry(ResourceLocation name, Class<T> tClass, boolean isPreBlockRegistry)
{
IForgeRegistry<T> reg = new RegistryBuilder<T>().setName(name).setType(tClass).create();
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/net/dries007/tfc/api/types/Tree.java
Expand Up @@ -52,6 +52,7 @@ public static Tree get(String name)
private final ResourceLocation name;
// Used when growing a tree
private final ITreeGenerator gen;

/**
* This is a registry object that will create a number of things:
* 1. Wood logs, planks, and leaf blocks, and all the respective variants
Expand Down Expand Up @@ -79,9 +80,9 @@ public static Tree get(String name)
* @param hasBushes will the tree generate small bushes
* @param minGrowthTime the amount of time (in in-game days) that this tree requires to grow
*/
private Tree(@Nonnull ResourceLocation name, @Nonnull ITreeGenerator gen,
float minTemp, float maxTemp, float minRain, float maxRain, float minDensity, float maxDensity, float dominance,
int maxGrowthRadius, int maxHeight, int maxDecayDistance, boolean isConifer, boolean hasBushes, float minGrowthTime)
public Tree(@Nonnull ResourceLocation name, @Nonnull ITreeGenerator gen,
float minTemp, float maxTemp, float minRain, float maxRain, float minDensity, float maxDensity, float dominance,
int maxGrowthRadius, int maxHeight, int maxDecayDistance, boolean isConifer, boolean hasBushes, float minGrowthTime)
{
this.minTemp = minTemp;
this.maxTemp = maxTemp;
Expand Down
16 changes: 6 additions & 10 deletions src/main/java/net/dries007/tfc/client/TFCGuiHandler.java
Expand Up @@ -17,12 +17,11 @@

import net.dries007.tfc.Constants;
import net.dries007.tfc.client.gui.GuiContainerTFC;
import net.dries007.tfc.client.gui.GuiSmallVesselLiquid;
import net.dries007.tfc.client.gui.GuiLiquidTransfer;
import net.dries007.tfc.objects.blocks.BlocksTFC;
import net.dries007.tfc.objects.container.ContainerLiquidTransfer;
import net.dries007.tfc.objects.container.ContainerLogPile;
import net.dries007.tfc.objects.container.ContainerMold;
import net.dries007.tfc.objects.container.ContainerSmallVessel;
import net.dries007.tfc.objects.container.ContainerSmallVesselLiquid;
import net.dries007.tfc.objects.items.ItemsTFC;
import net.dries007.tfc.objects.items.ceramics.ItemMold;
import net.dries007.tfc.objects.items.ceramics.ItemSmallVessel;
Expand All @@ -37,7 +36,6 @@ public class TFCGuiHandler implements IGuiHandler
public static final int MOLD = 3;

private static final ResourceLocation SMALL_INVENTORY_BACKGROUND = new ResourceLocation(Constants.MOD_ID, "textures/gui/small_inventory.png");
private static final ResourceLocation MOLD_BACKGROUND = new ResourceLocation(Constants.MOD_ID, "textures/gui/mold.png");

@Override
@Nullable
Expand All @@ -56,11 +54,11 @@ public Container getServerGuiElement(int ID, EntityPlayer player, World world, i
stack : player.getHeldItemOffhand());
case SMALL_VESSEL_LIQUID:
stack = player.getHeldItemMainhand();
return new ContainerSmallVesselLiquid(player.inventory, stack.getItem() instanceof ItemSmallVessel ?
return new ContainerLiquidTransfer(player.inventory, stack.getItem() instanceof ItemSmallVessel ?
stack : player.getHeldItemOffhand());
case MOLD:
stack = player.getHeldItemMainhand();
return new ContainerMold(player.inventory, stack.getItem() instanceof ItemMold ?
return new ContainerLiquidTransfer(player.inventory, stack.getItem() instanceof ItemMold ?
stack : player.getHeldItemOffhand());
default:
return null;
Expand All @@ -80,11 +78,9 @@ public Object getClientGuiElement(int ID, EntityPlayer player, World world, int
case SMALL_VESSEL:
return new GuiContainerTFC(container, player.inventory, SMALL_INVENTORY_BACKGROUND, ItemsTFC.CERAMICS_FIRED_VESSEL.getTranslationKey());
case SMALL_VESSEL_LIQUID:
return new GuiSmallVesselLiquid(container, player.inventory);
return new GuiLiquidTransfer(container, player, "", player.getHeldItemMainhand().getItem() instanceof ItemSmallVessel);
case MOLD:
stack = player.getHeldItemMainhand();
return new GuiContainerTFC(container, player.inventory, MOLD_BACKGROUND, stack.getItem() instanceof ItemMold ?
stack.getTranslationKey() : player.getHeldItemOffhand().getTranslationKey());
return new GuiLiquidTransfer(container, player, "", player.getHeldItemMainhand().getItem() instanceof ItemMold);
default:
return null;
}
Expand Down

0 comments on commit 7538925

Please sign in to comment.