From 5bbac5e8fb41f9fb8c63ea0236a3c90fa15837c9 Mon Sep 17 00:00:00 2001 From: GamingB3ast Date: Wed, 23 Jul 2025 14:46:58 -0500 Subject: [PATCH] Created an effects system for eating concentrated essence berries - Configurable - OFF BY DEFAULT - Can apply individual effects based off whether the player ate an individual berry or a stack (held shift (NOT stackSize dependent)) - Added because it feels like berries should be kinda disgusting and hard to eat, maybe even prickly. --- .../tconstruct/util/config/PHConstruct.java | 14 ++++ .../tconstruct/world/items/OreBerries.java | 82 ++++++++++++++++++- 2 files changed, 95 insertions(+), 1 deletion(-) diff --git a/src/main/java/tconstruct/util/config/PHConstruct.java b/src/main/java/tconstruct/util/config/PHConstruct.java index fcb1a698..2d1dab89 100644 --- a/src/main/java/tconstruct/util/config/PHConstruct.java +++ b/src/main/java/tconstruct/util/config/PHConstruct.java @@ -226,6 +226,18 @@ public class PHConstruct { true, "Allow stacks of essence berries to be consumed at once when shifting (this does not spawn XP orbs in world).") .getBoolean(); + disgustingXPBerries = config.get( + "general", + "Allow effects for consumption", + false, + "Grants effects to players when consuming XP berries").getBoolean(); + disgustingXPBerryEffects = config.get( + "general", + "Applied effects", + new String[] { "9, 200, 1, 1200, 2, false", "17, 160, 1, 1000, 3, false", "DAMAGE, 0.5, false ", + "9, 400, 2, 1200, 2, true", "17, 320, 1, 1000, 3, true", "DAMAGE, 0.3, true" }, + " If an effect fails to apply, check the console for information \n FORMAT: \n potionID (Can also put \"DAMAGE\" to hurt the player instead, \n effectDuration (in ticks) (or DAMAGE effect strength) , \n initialAmplifier (Exclude if the first parameter is DAMAGE), \n maxDuration (this is the maximum duration the potions can stack in ticks (Exclude if the first parameter is DAMAGE)), \n maxAmplifier (the maximum allowed potionAmplifier with multiple effects uses (Exclude if the first parameter is DAMAGE)), \n stackExclusiveEffect (a true or false value which allows the effect to be only applied when the essence berries are eaten while shift is held (Only works if Allow stackwise consumption = true)") + .getStringList(); disableAllRecipes = config.get( "general", "Disable All Recipes", @@ -435,6 +447,8 @@ public class PHConstruct { public static boolean tconComesFirst; public static boolean consumeXPBerryStacks; + public static boolean disgustingXPBerries; + public static String[] disgustingXPBerryEffects; public static boolean disableAllRecipes; diff --git a/src/main/java/tconstruct/world/items/OreBerries.java b/src/main/java/tconstruct/world/items/OreBerries.java index d3bf582f..a0dfc35a 100644 --- a/src/main/java/tconstruct/world/items/OreBerries.java +++ b/src/main/java/tconstruct/world/items/OreBerries.java @@ -6,12 +6,14 @@ import net.minecraft.entity.Entity; import net.minecraft.entity.item.EntityXPOrb; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; +import net.minecraft.potion.PotionEffect; import net.minecraft.util.StatCollector; import net.minecraft.world.World; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import mantle.items.abstracts.CraftingItem; +import tconstruct.TConstruct; import tconstruct.library.TConstructRegistry; import tconstruct.util.config.PHConstruct; @@ -61,12 +63,30 @@ public class OreBerries extends CraftingItem { player.posZ, itemRand.nextInt(14) + 6); spawnEntity(player.posX, player.posY + 1, player.posZ, entity, world, player); - if (!player.capabilities.isCreativeMode) stack.stackSize--; + if (!player.capabilities.isCreativeMode) { + stack.stackSize--; + if (PHConstruct.disgustingXPBerries) { + if (applyBerryEffects(player, false)) player.worldObj.playSoundAtEntity( + player, + "game.player.hurt", + 0.5F, + player.worldObj.rand.nextFloat() * 0.1F + 0.9F); + } + } } else if (PHConstruct.consumeXPBerryStacks) { int xpToAdd = 0; + boolean wasPlayerDamaged = false; for (int i = stack.stackSize; i > 0; i--) { xpToAdd += itemRand.nextInt(14) + 6; + if (PHConstruct.disgustingXPBerries) { + wasPlayerDamaged = applyBerryEffects(player, true); + } } + if (PHConstruct.disgustingXPBerries && wasPlayerDamaged) player.worldObj.playSoundAtEntity( + player, + "game.player.hurt", + 0.5F, + player.worldObj.rand.nextFloat() * 0.1F + 0.9F); player.addExperience(xpToAdd); if (!player.capabilities.isCreativeMode) stack.stackSize = 0; } @@ -79,4 +99,64 @@ public class OreBerries extends CraftingItem { world.spawnEntityInWorld(entity); } } + + boolean soundPlayedFlag = false; + + /** + * parameters ID | DURATION | initialAmplifier | maxDuration | maxAmplifier | stackExclusive + * + * @param player the player that's eatingthe berries + * @param isShifting is the player shifting? + * @return Was one of the effects DAMAGE (used properly play the damage sound in account to the player shifting) + */ + private static boolean applyBerryEffects(EntityPlayer player, boolean isShifting) { + boolean output = false; + for (String effect : PHConstruct.disgustingXPBerryEffects) { + try { + String[] parameters = effect.replaceAll(" ", "").split(","); + boolean isDamageEffect = parameters[0].equals("DAMAGE"); + if (!(isDamageEffect && parameters.length == 3) && parameters.length != 6) { + throw new RuntimeException("Too many or few parameters"); + } else { + if (isShifting == Boolean.parseBoolean(parameters[isDamageEffect ? 2 : 5])) { + if (isDamageEffect) { + player.setHealth(player.getHealth() - Float.parseFloat(parameters[1])); + output = true; + } else { + player.addPotionEffect(getBerryEffect(player, parameters)); + } + } + } + } catch (Exception e) { + TConstruct.logger.error( + "ERROR APPLYING ESSENCE BERRY EFFECT: {} ERROR: {} STACKTRACE: {}", + effect, + e.getMessage(), + e.getStackTrace()); + } + } + return output; + } + + /** + * Don't ask how the amplifier increase system works, I'm not fully sure myself @GamingB3ast + * + * @param player + * @param parameters ID | DURATION | initialAmplifier | maxDuration | maxAmplifier | stackExclusive + * @return The potion effect which is applied onto the player + */ + private static PotionEffect getBerryEffect(EntityPlayer player, String[] parameters) { + int duration = Integer.parseInt(parameters[1]); + int amplifier = Integer.parseInt(parameters[2]); + for (PotionEffect currentEffect : player.getActivePotionEffects()) { + if (currentEffect.getPotionID() == Integer.parseInt(parameters[0])) { + duration = Math.min(Integer.parseInt(parameters[3]), currentEffect.getDuration() + 40); + amplifier = currentEffect.getAmplifier() + 1; + int step = Integer.parseInt(parameters[3]) / (Integer.parseInt(parameters[4]) + 1 - amplifier) - 80; + amplifier += Math.min(Integer.parseInt(parameters[3]) - 1, (duration >= step * amplifier ? 1 : 0)); + break; + } + } + return new PotionEffect(Integer.parseInt(parameters[0]), duration, amplifier - 1); + } }