Skip to content

Commit

Permalink
Add missing stack size check to jug items (fixes #313). Added more va…
Browse files Browse the repository at this point in the history
…nilla foods to the capability whitelist (golden apples and golden carrots). (Fixes #356.) Fixed dye recipes. Removed heat cap from item heat - TFC still will internally restrict heat from device fuel heat, but the actual capability is unlimited. (inadvertently fixes #387).
  • Loading branch information
alcatrazEscapee committed Oct 9, 2019
1 parent ad8fb93 commit 9dd4861
Show file tree
Hide file tree
Showing 18 changed files with 70 additions and 52 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Expand Up @@ -50,7 +50,7 @@ file "build.properties" withReader {
* The version number is a sacred tool that a computer must understand and be able to compare to see what's what.
* `-SNAPSHOT` or `.rc0v14s4dffds2` communicates nothing useful.
*/
version = "0.24.6" // To be clear, you can edit this if you are submitting a patch PR, or if you are merging a feature into master.
version = "0.24.7" // To be clear, you can edit this if you are submitting a patch PR, or if you are merging a feature into master.
if (System.getenv().BUILD_NUMBER != null) version += "." + System.getenv().BUILD_NUMBER

group = "net.dries007.tfc" // According to java standards, as I have control over this domain. If you fork this and release your own version, change this.
Expand Down
Expand Up @@ -50,7 +50,6 @@ public class CapabilityFood
public static final IFoodTrait.Impl PRESERVED = new IFoodTrait.Impl("preserved", 0.5f);

private static final Map<String, IFoodTrait> TRAITS = new HashMap<>();
private static boolean markNonDecayingStacks = true;

public static void preInit()
{
Expand All @@ -67,6 +66,8 @@ public static void init()
{
// Add custom vanilla food instances
CUSTOM_FOODS.put(IIngredient.of(Items.ROTTEN_FLESH), () -> new FoodHandler(null, new float[] {0, 0, 0, 0, 0}, 0, 0, Float.POSITIVE_INFINITY));
CUSTOM_FOODS.put(IIngredient.of(Items.GOLDEN_APPLE), () -> new FoodHandler(null, new float[] {0, 0, 2, 2, 0}, 3, 12, 0));
CUSTOM_FOODS.put(IIngredient.of(Items.GOLDEN_CARROT), () -> new FoodHandler(null, new float[] {0.5f, 0, 1.2f, 1.2f, 0}, 2, 5, 0));
}

public static Map<String, IFoodTrait> getTraits()
Expand Down
Expand Up @@ -33,13 +33,6 @@ public final class CapabilityItemHeat

public static final Map<IIngredient<ItemStack>, Supplier<ICapabilityProvider>> CUSTOM_ITEMS = new HashMap<>(); //Used inside CT, set custom IItemHeat for items outside TFC

public static final float MIN_TEMPERATURE = 0f;
/**
* For most practical purposes this is the max temperature than an item should reach.
* i.e. all metals should melt either before this, or never.
*/
public static final float MAX_TEMPERATURE = 1601f;

public static void preInit()
{
CapabilityManager.INSTANCE.register(IItemHeat.class, new DumbStorage<>(), ItemHeatHandler::new);
Expand All @@ -52,7 +45,7 @@ public static float adjustTemp(float temp, float heatCapacity, long ticksSinceUp
{
if (ticksSinceUpdate <= 0) return temp;
final float newTemp = temp - heatCapacity * (float) ticksSinceUpdate * (float) ConfigTFC.GENERAL.temperatureModifierGlobal;
return newTemp < MIN_TEMPERATURE ? MIN_TEMPERATURE : newTemp;
return newTemp < 0 ? 0 : newTemp;
}

public static void addTemp(IItemHeat instance)
Expand All @@ -69,7 +62,7 @@ public static void addTemp(IItemHeat instance)
public static void addTemp(IItemHeat instance, float modifier)
{
final float temp = instance.getTemperature() + modifier * instance.getHeatCapacity() * (float) ConfigTFC.GENERAL.temperatureModifierGlobal;
instance.setTemperature(temp > MAX_TEMPERATURE ? MAX_TEMPERATURE : temp);
instance.setTemperature(temp);
}

@Nullable
Expand Down
14 changes: 11 additions & 3 deletions src/main/java/net/dries007/tfc/api/capability/heat/Heat.java
Expand Up @@ -12,8 +12,6 @@

import net.dries007.tfc.util.Helpers;

import static net.dries007.tfc.api.capability.heat.CapabilityItemHeat.MAX_TEMPERATURE;

public enum Heat
{
WARMING(1f, 80f, TextFormatting.GRAY),
Expand All @@ -26,7 +24,12 @@ public enum Heat
YELLOW(1100f, 1300f, TextFormatting.YELLOW),
YELLOW_WHITE(1300f, 1400f, TextFormatting.YELLOW),
WHITE(1400f, 1500f, TextFormatting.WHITE),
BRILLIANT_WHITE(1500f, MAX_TEMPERATURE, TextFormatting.WHITE);
BRILLIANT_WHITE(1500f, 1601f, TextFormatting.WHITE);

public static float maxVisibleTemperature()
{
return BRILLIANT_WHITE.max;
}

private static final Heat[] VALUES = values();

Expand All @@ -40,6 +43,11 @@ public static Heat getHeat(float temperature)
return heat;
}
}
if (temperature > BRILLIANT_WHITE.max)
{
// Default to "hotter than brilliant white" for max
return BRILLIANT_WHITE;
}
return null;
}

Expand Down
Expand Up @@ -13,20 +13,20 @@

import net.dries007.tfc.api.capability.food.CapabilityFood;
import net.dries007.tfc.api.capability.heat.CapabilityItemHeat;
import net.dries007.tfc.api.capability.heat.Heat;
import net.dries007.tfc.api.capability.heat.IItemHeat;
import net.dries007.tfc.api.types.Metal;
import net.dries007.tfc.objects.inventory.ingredient.IIngredient;

@ParametersAreNonnullByDefault
public class HeatRecipeSimple extends HeatRecipe
{

private final ItemStack output;
private final float maxTemp;

public HeatRecipeSimple(IIngredient<ItemStack> ingredient, ItemStack output, float transformTemp)
{
this(ingredient, output, transformTemp, CapabilityItemHeat.MAX_TEMPERATURE, Metal.Tier.TIER_0);
this(ingredient, output, transformTemp, Heat.maxVisibleTemperature(), Metal.Tier.TIER_0);
}

public HeatRecipeSimple(IIngredient<ItemStack> ingredient, ItemStack output, float transformTemp, float maxTemp)
Expand All @@ -36,7 +36,7 @@ public HeatRecipeSimple(IIngredient<ItemStack> ingredient, ItemStack output, flo

public HeatRecipeSimple(IIngredient<ItemStack> ingredient, ItemStack output, float transformTemp, Metal.Tier minTier)
{
this(ingredient, output, transformTemp, CapabilityItemHeat.MAX_TEMPERATURE, minTier);
this(ingredient, output, transformTemp, Heat.maxVisibleTemperature(), minTier);
}

public HeatRecipeSimple(IIngredient<ItemStack> ingredient, ItemStack output, float transformTemp, float maxTemp, Metal.Tier minTier)
Expand Down
Expand Up @@ -19,7 +19,7 @@ public interface IHeatConsumerBlock
*
* @param world The world
* @param pos The position of the {@code IHeatConsumerBlock}
* @param temperature a temperature in the range [0, {@link net.dries007.tfc.api.capability.heat.CapabilityItemHeat#MAX_TEMPERATURE}]
* @param temperature a temperature. Will be in [0, max temp in config]
*/
void acceptHeat(World world, BlockPos pos, float temperature);
}
19 changes: 3 additions & 16 deletions src/main/java/net/dries007/tfc/client/ClientRegisterEvents.java
Expand Up @@ -159,22 +159,9 @@ public ModelResourceLocation getModelLocation(@Nonnull ItemStack stack)

for (ItemBlock item : BlocksTFC.getAllBarrelItemBlocks())
{
ModelLoader.setCustomMeshDefinition(item, new ItemMeshDefinition()
{
private final ModelResourceLocation sealed = new ModelResourceLocation(item.getRegistryName(), "sealed=true");
private final ModelResourceLocation unsealed = new ModelResourceLocation(item.getRegistryName(), "sealed=false");

@Override
@Nonnull
public ModelResourceLocation getModelLocation(@Nonnull ItemStack stack)
{
if (stack.getTagCompound() != null)
{
return sealed;
}
return unsealed;
}
});
final ModelResourceLocation sealed = new ModelResourceLocation(item.getRegistryName(), "sealed=true");
final ModelResourceLocation unsealed = new ModelResourceLocation(item.getRegistryName(), "sealed=false");
ModelLoader.setCustomMeshDefinition(item, stack -> stack.getTagCompound() != null ? sealed : unsealed);
}

// BLOCKS - STATE MAPPERS //
Expand Down
Expand Up @@ -12,9 +12,9 @@
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

import net.dries007.tfc.api.capability.heat.Heat;
import net.dries007.tfc.objects.te.TEBlastFurnace;

import static net.dries007.tfc.api.capability.heat.CapabilityItemHeat.MAX_TEMPERATURE;
import static net.dries007.tfc.api.util.TFCConstants.MOD_ID;

@SideOnly(Side.CLIENT)
Expand All @@ -32,9 +32,13 @@ protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, i
{
super.drawGuiContainerBackgroundLayer(partialTicks, mouseX, mouseY);

int temperature = (int) (51 * tile.getField(TEBlastFurnace.FIELD_TEMPERATURE) / MAX_TEMPERATURE);
int temperature = (int) (51 * tile.getField(TEBlastFurnace.FIELD_TEMPERATURE) / Heat.maxVisibleTemperature());
if (temperature > 0)
{
if (temperature > 51)
{
temperature = 51;
}
drawTexturedModalRect(guiLeft + 8, guiTop + 66 - temperature, 185, 32, 15, 5);
}

Expand Down
Expand Up @@ -11,9 +11,9 @@
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

import net.dries007.tfc.api.capability.heat.Heat;
import net.dries007.tfc.objects.te.TECharcoalForge;

import static net.dries007.tfc.api.capability.heat.CapabilityItemHeat.MAX_TEMPERATURE;
import static net.dries007.tfc.api.util.TFCConstants.MOD_ID;

@SideOnly(Side.CLIENT)
Expand All @@ -32,9 +32,13 @@ protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, i
super.drawGuiContainerBackgroundLayer(partialTicks, mouseX, mouseY);

// Draw the temperature indicator
int temperature = (int) (51 * tile.getField(TECharcoalForge.FIELD_TEMPERATURE) / MAX_TEMPERATURE);
int temperature = (int) (51 * tile.getField(TECharcoalForge.FIELD_TEMPERATURE) / Heat.maxVisibleTemperature());
if (temperature > 0)
{
if (temperature > 51)
{
temperature = 51;
}
drawTexturedModalRect(guiLeft + 8, guiTop + 66 - temperature, 176, 0, 15, 5);
}
}
Expand Down
8 changes: 6 additions & 2 deletions src/main/java/net/dries007/tfc/client/gui/GuiCrucible.java
Expand Up @@ -13,11 +13,11 @@
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.text.TextFormatting;

import net.dries007.tfc.api.capability.heat.Heat;
import net.dries007.tfc.api.types.Metal;
import net.dries007.tfc.objects.te.TECrucible;
import net.dries007.tfc.util.Alloy;

import static net.dries007.tfc.api.capability.heat.CapabilityItemHeat.MAX_TEMPERATURE;
import static net.dries007.tfc.api.util.TFCConstants.MOD_ID;

public class GuiCrucible extends GuiContainerTE<TECrucible>
Expand Down Expand Up @@ -48,9 +48,13 @@ protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, i
super.drawGuiContainerBackgroundLayer(partialTicks, mouseX, mouseY);

// Draw the temperature indicator
int temperature = (int) (51 * tile.getField(TECrucible.FIELD_TEMPERATURE) / MAX_TEMPERATURE);
int temperature = (int) (51 * tile.getField(TECrucible.FIELD_TEMPERATURE) / Heat.maxVisibleTemperature());
if (temperature > 0)
{
if (temperature > 51)
{
temperature = 51;
}
drawTexturedModalRect(guiLeft + 153, guiTop + 80 - temperature, 176, 0, 15, 5);
}

Expand Down
8 changes: 6 additions & 2 deletions src/main/java/net/dries007/tfc/client/gui/GuiFirePit.java
Expand Up @@ -9,9 +9,9 @@
import net.minecraft.inventory.Container;
import net.minecraft.util.ResourceLocation;

import net.dries007.tfc.api.capability.heat.Heat;
import net.dries007.tfc.objects.te.TEFirePit;

import static net.dries007.tfc.api.capability.heat.CapabilityItemHeat.MAX_TEMPERATURE;
import static net.dries007.tfc.api.util.TFCConstants.MOD_ID;

public class GuiFirePit extends GuiContainerTE<TEFirePit>
Expand All @@ -29,9 +29,13 @@ protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, i
super.drawGuiContainerBackgroundLayer(partialTicks, mouseX, mouseY);

// Draw the fire / burn time indicator
int temperature = (int) (51 * tile.getField(TEFirePit.FIELD_TEMPERATURE) / MAX_TEMPERATURE);
int temperature = (int) (51 * tile.getField(TEFirePit.FIELD_TEMPERATURE) / Heat.maxVisibleTemperature());
if (temperature > 0)
{
if (temperature > 51)
{
temperature = 51;
}
drawTexturedModalRect(guiLeft + 30, guiTop + 66 - temperature, 176, 0, 15, 5);
}
}
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/net/dries007/tfc/objects/items/ceramics/ItemJug.java
Expand Up @@ -140,6 +140,17 @@ public int getMaxItemUseDuration(ItemStack stack)
return 32;
}

@Override
public int getItemStackLimit(ItemStack stack)
{
IFluidHandler jugCap = stack.getCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, null);
if (jugCap != null && jugCap.drain(CAPACITY, false) != null)
{
return getStackSize(stack);
}
return 1;
}

@Override
@Nonnull
public String getItemStackDisplayName(@Nonnull ItemStack stack)
Expand Down
Expand Up @@ -35,6 +35,7 @@

import net.dries007.tfc.api.capability.IMoldHandler;
import net.dries007.tfc.api.capability.heat.CapabilityItemHeat;
import net.dries007.tfc.api.capability.heat.Heat;
import net.dries007.tfc.api.capability.heat.IItemHeat;
import net.dries007.tfc.api.capability.heat.ItemHeatHandler;
import net.dries007.tfc.api.types.Metal;
Expand All @@ -59,7 +60,10 @@ public static ItemMold get(Metal.ItemType category)
public ItemMold(Metal.ItemType type)
{
this.type = type;
if (MAP.put(type, this) != null) throw new IllegalStateException("There can only be one.");
if (MAP.put(type, this) != null)
{
throw new IllegalStateException("There can only be one.");
}
}

@Override
Expand Down Expand Up @@ -306,7 +310,7 @@ private void updateFluidData()

private void updateFluidData(FluidStack fluid)
{
meltTemp = CapabilityItemHeat.MAX_TEMPERATURE;
meltTemp = Heat.maxVisibleTemperature();
heatCapacity = 1;
if (fluid != null)
{
Expand Down
Expand Up @@ -39,7 +39,6 @@
import net.dries007.tfc.util.fuel.Fuel;
import net.dries007.tfc.util.fuel.FuelManager;

import static net.dries007.tfc.api.capability.heat.CapabilityItemHeat.MAX_TEMPERATURE;
import static net.dries007.tfc.objects.blocks.property.ILightableBlock.LIT;

@ParametersAreNonnullByDefault
Expand Down Expand Up @@ -287,7 +286,7 @@ public void update()

if (temperature > 0 || burnTemperature > 0)
{
float targetTemperature = Math.min(MAX_TEMPERATURE, burnTemperature + airTicks);
float targetTemperature = burnTemperature + airTicks;
if (temperature < targetTemperature)
{
// Modifier for heating = 2x for bellows
Expand Down
Expand Up @@ -26,7 +26,6 @@
import net.dries007.tfc.util.fuel.Fuel;
import net.dries007.tfc.util.fuel.FuelManager;

import static net.dries007.tfc.api.capability.heat.CapabilityItemHeat.MAX_TEMPERATURE;
import static net.dries007.tfc.objects.blocks.property.ILightableBlock.LIT;

@ParametersAreNonnullByDefault
Expand Down Expand Up @@ -129,7 +128,7 @@ else if (burnTemperature > 0)
if (temperature > 0 || burnTemperature > 0)
{
// Update temperature
float targetTemperature = Math.min(MAX_TEMPERATURE, burnTemperature + airTicks);
float targetTemperature = burnTemperature + airTicks;
if (temperature < targetTemperature)
{
// Modifier for heating = 2x for bellows
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/net/dries007/tfc/objects/te/TEFirePit.java
Expand Up @@ -29,7 +29,6 @@
import net.dries007.tfc.util.fuel.Fuel;
import net.dries007.tfc.util.fuel.FuelManager;

import static net.dries007.tfc.api.capability.heat.CapabilityItemHeat.MAX_TEMPERATURE;
import static net.dries007.tfc.objects.blocks.devices.BlockFirePit.LIT;

@ParametersAreNonnullByDefault
Expand Down Expand Up @@ -109,7 +108,7 @@ public void update()
if (temperature > 0 || burnTemperature > 0)
{
// Update temperature
float targetTemp = Math.min(MAX_TEMPERATURE, burnTemperature + airTicks);
float targetTemp = burnTemperature + airTicks;
if (temperature < targetTemp)
{
temperature += (airTicks > 0 ? 2 : 1) * ConfigTFC.GENERAL.temperatureModifierHeating;
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/net/dries007/tfc/objects/te/TEPitKiln.java
Expand Up @@ -32,6 +32,7 @@

import net.dries007.tfc.ConfigTFC;
import net.dries007.tfc.api.capability.heat.CapabilityItemHeat;
import net.dries007.tfc.api.capability.heat.Heat;
import net.dries007.tfc.api.capability.heat.IItemHeat;
import net.dries007.tfc.api.recipes.heat.HeatRecipe;
import net.dries007.tfc.api.types.Metal;
Expand Down Expand Up @@ -136,7 +137,7 @@ public void update()
IItemHeat heat = stack.getCapability(CapabilityItemHeat.ITEM_HEAT_CAPABILITY, null);
if (heat != null)
{
heat.setTemperature(CapabilityItemHeat.MAX_TEMPERATURE);
heat.setTemperature(Heat.maxVisibleTemperature());

// Only Tier I and below can be melted in a pit kiln
HeatRecipe recipe = HeatRecipe.get(stack, Metal.Tier.TIER_I);
Expand Down

0 comments on commit 9dd4861

Please sign in to comment.