Skip to content

Commit

Permalink
Added new food
Browse files Browse the repository at this point in the history
  • Loading branch information
Garkatron committed Jan 11, 2025
1 parent 788c2cc commit c664f62
Show file tree
Hide file tree
Showing 12 changed files with 201 additions and 88 deletions.
13 changes: 13 additions & 0 deletions src/main/java/deus/stanleytemperature/StanleyRecipeRegistries.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package deus.stanleytemperature;

import net.minecraft.core.data.registry.recipe.RecipeNamespace;
import net.minecraft.core.data.registry.recipe.RecipeRegistry;

public class StanleyRecipeRegistries extends RecipeRegistry {
public static final RecipeNamespace STANLEY = new RecipeNamespace();

public StanleyRecipeRegistries() {

}

}
16 changes: 16 additions & 0 deletions src/main/java/deus/stanleytemperature/StanleyRecipes.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,20 @@
package deus.stanleytemperature;

import deus.stanleytemperature.items.StanleyItems;
import net.minecraft.core.block.Blocks;
import net.minecraft.core.item.Item;
import turniplabs.halplibe.helper.RecipeBuilder;

public class StanleyRecipes {
public static void initialize() {

RecipeBuilder.Shaped(StanleyTemperature.MOD_ID)
.setShape(
" ",
"ppp",
" ")
.addInput('p', Blocks.PERMAFROST.asItem())
.create("StanleyRecipeIceCubes", StanleyItems.iceCubes.getDefaultStack());

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import deus.stanleytemperature.items.StanleyItems;
import deus.stanleytemperature.overlay.HudManager;
import net.fabricmc.api.ModInitializer;
import net.minecraft.core.data.registry.Registries;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import turniplabs.halplibe.util.ClientStartEntrypoint;
Expand Down Expand Up @@ -55,11 +56,13 @@ public void afterClientStart() {

@Override
public void onRecipesReady() {
StanleyRecipes.initialize();

}

@Override
public void initNamespaces() {

new StanleyRecipeRegistries();
Registries.RECIPES.register("stanley", StanleyRecipeRegistries.STANLEY);
}
}
27 changes: 16 additions & 11 deletions src/main/java/deus/stanleytemperature/config/ConfigHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ public class ConfigHandler {
;

toml.addCategory("weatherEffects")
.addEntry("weatherAffectsTemperature", true)
.addEntry("enabled", true)
.addEntry("overworldRain", -0.5)
.addEntry("overworldSnow", -1.0)
.addEntry("overworldStorm", -0.1)
.addEntry("overworldClear", 0.0);

toml.addCategory("itemEffects")
.addEntry("itemAffectsTemperature", true)
.addEntry("enabled", true)
.addEntry("torch", 0.5)
.addEntry("redstoneTorch", 0.05)
.addEntry("lavaBucket", 2.0)
Expand All @@ -49,29 +49,34 @@ public class ConfigHandler {
.addEntry("bucketIcecream", -2.0)
.addEntry("iceBlock", -2.0);

toml.addCategory("foodEffects")
.addEntry("foodAffectsTemperature", true)
toml.addCategory("vanillaFoodEffects")
.addEntry("enabled", true)
.addEntry("bucketIcecream", -10.0);

toml.addCategory("foodEffects")
.addEntry("enabled", true)
.addEntry("iceCubes", -5.0)
.addEntry("netherrackMeatBalls", 5.0);

toml.addCategory("lifeEffects")
.addEntry("lifeAffectsTemperature", true)
.addEntry("enabled", true)
.addEntry("applyEffectEveryXHearts", 2)
.addEntry("temperatureResistancePenalizationPerHeart", -1.0);

toml.addCategory("blockEffects")
.addEntry("playerOverBlockAffectsTemperature", true)
.addEntry("enabled", true)
.addEntry("snowBlock", -0.05)
.addEntry("waterBlock", -0.05)
.addEntry("fire", -2.00)
.addEntry("lava", -2.00)
.addEntry("iceBlock", -0.03);

toml.addCategory("snowballEffects")
.addEntry("snowballAffectsTemperature", true)
.addEntry("enabled", true)
.addEntry("snowballEffect", 0.01);

toml.addCategory("biomeEffects")
.addEntry("biomeAffectsTemperature", true)
.addEntry("enabled", true)
.addEntry("plains", 0.0)
.addEntry("taiga", -0.1)
.addEntry("nether", 3.0)
Expand All @@ -83,11 +88,11 @@ public class ConfigHandler {
.addEntry("forest", -0.015);

toml.addCategory("leatherProtection")
.addEntry("leatherProtectionPercentage", 0.01)
.addEntry("leatherProtectsTemperature", true);
.addEntry("enabled", true)
.addEntry("leatherProtectionPercentage", 0.01);

toml.addCategory("seasonEffects")
.addEntry("seasonAffectsTemperature", true)
.addEntry("enabled", true)
.addEntry("summerTemperature", 0.04)
.addEntry("fallTemperature", 0.0)
.addEntry("winterTemperature", -0.05)
Expand Down
115 changes: 64 additions & 51 deletions src/main/java/deus/stanleytemperature/config/TemperatureConfig.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
package deus.stanleytemperature.config;

import net.minecraft.client.Minecraft;
import net.minecraft.core.block.material.Material;
import net.minecraft.core.item.Item;
import net.minecraft.core.item.ItemBucketIceCream;
import net.minecraft.core.item.ItemFood;
import net.minecraft.core.item.ItemSoup;
import net.minecraft.core.world.biome.*;
import net.minecraft.core.world.season.*;
import net.minecraft.core.world.weather.*;
Expand All @@ -16,82 +13,98 @@

public class TemperatureConfig {

private final Map<Class<? extends Weather>, Double> weatherTemperatureAdjustments;
private final Map<Material, Double> blockTemperatureAdjustments;
private final Map<Class<? extends Season>, Double> seasonAdjustments;
private final Map<Class<? extends Biome>, Double> biomeAdjustments;
private final Map<Class<? extends ItemFood>, Double> foodAdjustments;
private final Map<Class<? extends Weather>, Double> weatherValues;
private final Map<Material, Double> blockValues;
private final Map<Class<? extends Season>, Double> seasonValues;
private final Map<Class<? extends Biome>, Double> biomeValues;
private final Map<Class<? extends ItemFood>, Double> vanillaFoodValues;
private final Map<String, Double> foodValues;

public TemperatureConfig(TomlConfigHandler configHandler) {
weatherTemperatureAdjustments = new HashMap<>();
blockTemperatureAdjustments = new HashMap<>();
seasonAdjustments = new HashMap<>();
biomeAdjustments = new HashMap<>();
foodAdjustments = new HashMap<>();
weatherValues = new HashMap<>();
blockValues = new HashMap<>();
seasonValues = new HashMap<>();
biomeValues = new HashMap<>();
vanillaFoodValues = new HashMap<>();
foodValues = new HashMap<>();

// Weather adjustments
if (configHandler.getBoolean("weatherEffects.weatherAffectsTemperature")) {
weatherTemperatureAdjustments.put(WeatherRain.class, configHandler.getDouble("weatherEffects.overworldRain"));
weatherTemperatureAdjustments.put(WeatherSnow.class, configHandler.getDouble("weatherEffects.overworldSnow"));
weatherTemperatureAdjustments.put(WeatherStorm.class, configHandler.getDouble("weatherEffects.overworldStorm"));
weatherTemperatureAdjustments.put(WeatherClear.class, configHandler.getDouble("weatherEffects.overworldClear"));
if (configHandler.getBoolean("weatherEffects.enabled")) {
weatherValues.put(WeatherRain.class, configHandler.getDouble("weatherEffects.overworldRain"));
weatherValues.put(WeatherSnow.class, configHandler.getDouble("weatherEffects.overworldSnow"));
weatherValues.put(WeatherStorm.class, configHandler.getDouble("weatherEffects.overworldStorm"));
weatherValues.put(WeatherClear.class, configHandler.getDouble("weatherEffects.overworldClear"));
// Add more weather types if needed
}

if (configHandler.getBoolean("foodEffects.foodAffectsTemperature")) {
foodAdjustments.put(ItemBucketIceCream.class, configHandler.getDouble("foodEffects.bucketIcecream"));
if (configHandler.getBoolean("vanillaFoodEffects.enabled")) {
vanillaFoodValues.put(ItemBucketIceCream.class, configHandler.getDouble("vanillaFoodEffects.bucketIcecream"));
// Add more weather types if needed
}


if (configHandler.getBoolean("foodEffects.enabled")) {
foodValues.put("netherrackMeatBalls", configHandler.getDouble("foodEffects.netherrackMeatBalls"));
foodValues.put("iceCubes", configHandler.getDouble("foodEffects.iceCubes"));
// Add more weather types if needed
}


// Block adjustments
if (configHandler.getBoolean("blockEffects.playerOverBlockAffectsTemperature")) {
blockTemperatureAdjustments.put(Material.snow, configHandler.getDouble("blockEffects.snowBlock"));
blockTemperatureAdjustments.put(Material.water, configHandler.getDouble("blockEffects.waterBlock"));
blockTemperatureAdjustments.put(Material.ice, configHandler.getDouble("blockEffects.iceBlock"));
blockTemperatureAdjustments.put(Material.lava, configHandler.getDouble("blockEffects.lava"));
blockTemperatureAdjustments.put(Material.fire, configHandler.getDouble("blockEffects.fire"));
if (configHandler.getBoolean("blockEffects.enabled")) {
blockValues.put(Material.snow, configHandler.getDouble("blockEffects.snowBlock"));
blockValues.put(Material.water, configHandler.getDouble("blockEffects.waterBlock"));
blockValues.put(Material.ice, configHandler.getDouble("blockEffects.iceBlock"));
blockValues.put(Material.lava, configHandler.getDouble("blockEffects.lava"));
blockValues.put(Material.fire, configHandler.getDouble("blockEffects.fire"));
// Add more block materials if needed
}

// Season adjustments
if (configHandler.getBoolean("seasonEffects.seasonAffectsTemperature")) {
seasonAdjustments.put(SeasonSummer.class, configHandler.getDouble("seasonEffects.summerTemperature"));
seasonAdjustments.put(SeasonFall.class, configHandler.getDouble("seasonEffects.fallTemperature"));
seasonAdjustments.put(SeasonSpring.class, configHandler.getDouble("seasonEffects.springTemperature"));
seasonAdjustments.put(SeasonWinter.class, configHandler.getDouble("seasonEffects.winterTemperature"));
if (configHandler.getBoolean("seasonEffects.enabled")) {
seasonValues.put(SeasonSummer.class, configHandler.getDouble("seasonEffects.summerTemperature"));
seasonValues.put(SeasonFall.class, configHandler.getDouble("seasonEffects.fallTemperature"));
seasonValues.put(SeasonSpring.class, configHandler.getDouble("seasonEffects.springTemperature"));
seasonValues.put(SeasonWinter.class, configHandler.getDouble("seasonEffects.winterTemperature"));
}

// Biome adjustments
if (configHandler.getBoolean("biomeEffects.biomeAffectsTemperature")) {
biomeAdjustments.put(BiomeDesert.class, configHandler.getDouble("biomeEffects.desert"));
biomeAdjustments.put(BiomeBorealForest.class, configHandler.getDouble("biomeEffects.borealForest"));
biomeAdjustments.put(BiomeBirchForest.class, configHandler.getDouble("biomeEffects.birchForest"));
biomeAdjustments.put(BiomeCaatinga.class, configHandler.getDouble("biomeEffects.caatinga"));
biomeAdjustments.put(BiomePlains.class, configHandler.getDouble("biomeEffects.plains"));
biomeAdjustments.put(BiomeSwamp.class, configHandler.getDouble("biomeEffects.swampLand"));
biomeAdjustments.put(BiomeTaiga.class, configHandler.getDouble("biomeEffects.taiga"));
biomeAdjustments.put(BiomeForest.class, configHandler.getDouble("biomeEffects.forest"));
biomeAdjustments.put(BiomeNether.class, configHandler.getDouble("biomeEffects.nether"));
if (configHandler.getBoolean("biomeEffects.enabled")) {
biomeValues.put(BiomeDesert.class, configHandler.getDouble("biomeEffects.desert"));
biomeValues.put(BiomeBorealForest.class, configHandler.getDouble("biomeEffects.borealForest"));
biomeValues.put(BiomeBirchForest.class, configHandler.getDouble("biomeEffects.birchForest"));
biomeValues.put(BiomeCaatinga.class, configHandler.getDouble("biomeEffects.caatinga"));
biomeValues.put(BiomePlains.class, configHandler.getDouble("biomeEffects.plains"));
biomeValues.put(BiomeSwamp.class, configHandler.getDouble("biomeEffects.swampLand"));
biomeValues.put(BiomeTaiga.class, configHandler.getDouble("biomeEffects.taiga"));
biomeValues.put(BiomeForest.class, configHandler.getDouble("biomeEffects.forest"));
biomeValues.put(BiomeNether.class, configHandler.getDouble("biomeEffects.nether"));
}
}

public Double getWeatherTemperatureAdjustment(Class<? extends Weather> weather) {
return weatherTemperatureAdjustments.getOrDefault(weather, 0.0);
public Double getFoodValues(String item) {
return foodValues.getOrDefault(item, 0.0);
}

public Double getBlockTemperatureAdjustment(Material material) {
return blockTemperatureAdjustments.getOrDefault(material, 0.0);
public Double getWeatherValues(Class<? extends Weather> weather) {
return weatherValues.getOrDefault(weather, 0.0);
}

public Double getFoodAdjustment(Class<? extends ItemFood> item) {
return foodAdjustments.getOrDefault(item, 0.0);
public Double getBlockValues(Material material) {
return blockValues.getOrDefault(material, 0.0);
}



public Double getVanillaFoodValues(Class<? extends ItemFood> item) {
return vanillaFoodValues.getOrDefault(item, 0.0);
}

public Double getSeasonAdjustment(Season season) {
return seasonAdjustments.getOrDefault(season.getClass(), 0.0);
public Double getSeasonValues(Season season) {
return seasonValues.getOrDefault(season.getClass(), 0.0);
}

public Double getBiomeAdjustment(Biome biome) {
return biomeAdjustments.getOrDefault(biome.getClass(), 0.0);
public Double getBiomeValues(Biome biome) {
return biomeValues.getOrDefault(biome.getClass(), 0.0);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package deus.stanleytemperature.items;

public enum StanleyFoodType {
HOT,
COLD
}
55 changes: 55 additions & 0 deletions src/main/java/deus/stanleytemperature/items/StanleyItemFood.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package deus.stanleytemperature.items;

import deus.stanleytemperature.StanleyTemperature;
import deus.stanleytemperature.enums.PlayerTemperatureState;
import deus.stanleytemperature.interfaces.IStanleyPlayerEntity;
import net.minecraft.core.entity.player.Player;
import net.minecraft.core.item.*;
import net.minecraft.core.world.World;

public class StanleyItemFood extends ItemFood {

protected double sAmount;
protected StanleyFoodType type;

public StanleyItemFood(String name, String namespaceId, int id, int healAmount, int ticksPerHeal, boolean favouriteWolfMeat, int maxStackSize, double sAmount, StanleyFoodType type) {
super(name, namespaceId, id, healAmount, ticksPerHeal, favouriteWolfMeat, maxStackSize);
this.sAmount = sAmount;
}

@Override
public ItemStack onUseItem(ItemStack itemstack, World world, Player entityplayer) {

PlayerTemperatureState state = ((IStanleyPlayerEntity) entityplayer).stanley$getState();
String soundEffect = this.getTicksPerHeal() >= 10 ? "random.bite_extended" : "random.bite";

boolean canConsumeIceCream = entityplayer.getHealth() < entityplayer.getMaxHealth()
&& entityplayer.getHealth() + entityplayer.getTotalHealingRemaining() < entityplayer.getMaxHealth()
&& itemstack.consumeItem(entityplayer);


if (canConsumeIceCream) {
entityplayer.eatFood(this);
}


if (StanleyFoodType.COLD.equals(type)) {
((IStanleyPlayerEntity)entityplayer).stanley$decreasePlayerTemperature(sAmount);

} else {
((IStanleyPlayerEntity)entityplayer).stanley$increasePlayerTemperature(sAmount);

}

playSound(world, entityplayer, soundEffect);

return new ItemStack(this, itemstack.stackSize-1);
}

// Helper method to play sound at the entity
private void playSound(World world, Player entityplayer, String soundEffect) {
world.playSoundAtEntity(entityplayer, entityplayer, soundEffect,
0.5F + (itemRand.nextFloat() - itemRand.nextFloat()) * 0.1F,
1.1F + (itemRand.nextFloat() - itemRand.nextFloat()) * 0.1F);
}
}
14 changes: 9 additions & 5 deletions src/main/java/deus/stanleytemperature/items/StanleyItems.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

public class StanleyItems {

public static ItemFood iceCubes;
public static StanleyItemFood iceCubes;
public static ItemFood netherrackMeatBalls;

private static int currentBlockId = StanleyTemperature.MOD_CONFIG.getConfig().getInt("StartingIDs.blocks");
Expand All @@ -27,26 +27,30 @@ public static void initialize() {

iceCubes = genericItemBuilder
.setIcon(StanleyTemperature.MOD_ID + ":item/iceCubes")
.build(new ItemFood(
.build(new StanleyItemFood(
"iceCubes",
StanleyTemperature.MOD_ID + ":item/ice_cubes",
newItemId(),
1,
1,
false,
DEFAULT_STACK_SIZE
DEFAULT_STACK_SIZE,
StanleyTemperature.MOD_CONFIG.getTemperatureConfig().getFoodValues("iceCubes"),
StanleyFoodType.COLD
));

netherrackMeatBalls = genericItemBuilder
.setIcon(StanleyTemperature.MOD_ID + ":item/netherrackMeatBalls")
.build(new ItemFood(
.build(new StanleyItemFood(
"netherrackMeatBalls",
StanleyTemperature.MOD_ID + ":item/netherrack_meat_balls",
newItemId(),
1,
1,
false,
DEFAULT_STACK_SIZE
DEFAULT_STACK_SIZE,
StanleyTemperature.MOD_CONFIG.getTemperatureConfig().getFoodValues("netherrackMeatBalls"),
StanleyFoodType.HOT
));
}
}
Loading

0 comments on commit c664f62

Please sign in to comment.