mirror of
https://github.com/GTNewHorizons/TinkersConstruct.git
synced 2026-10-26 14:33:50 +00:00
Effects system for concentrated essence berries (#194)
Co-authored-by: GamingB3ast <dennis.ortin@gmail.com> Co-authored-by: Martin Robertz <dream-master@gmx.net> Co-authored-by: boubou19 <miisterunknown@gmail.com> Co-authored-by: UltraProdigy <187078471+UltraProdigy@users.noreply.github.com>
This commit is contained in:
2 files changed
+93
-1
No files matched your search
@@ -234,6 +234,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",
|
||||
@@ -443,6 +455,8 @@ public class PHConstruct {
|
||||
public static boolean tconComesFirst;
|
||||
|
||||
public static boolean consumeXPBerryStacks;
|
||||
public static boolean disgustingXPBerries;
|
||||
public static String[] disgustingXPBerryEffects;
|
||||
|
||||
public static boolean disableAllRecipes;
|
||||
public static double HarvestToolAOERelativeStrength;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -53,7 +55,7 @@ public class OreBerries extends CraftingItem {
|
||||
@Override
|
||||
public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player) {
|
||||
if (stack.getItemDamage() == 5) {
|
||||
if (!PHConstruct.consumeXPBerryStacks || !player.isSneaking()) {
|
||||
if (!PHConstruct.consumeXPBerryStacks || !player.isSneaking() || stack.stackSize == 1) {
|
||||
EntityXPOrb entity = new EntityXPOrb(
|
||||
world,
|
||||
player.posX,
|
||||
@@ -62,11 +64,28 @@ public class OreBerries extends CraftingItem {
|
||||
itemRand.nextInt(14) + 6);
|
||||
spawnEntity(player.posX, player.posY + 1, player.posZ, entity, world, player);
|
||||
if (!player.capabilities.isCreativeMode) stack.stackSize--;
|
||||
if (PHConstruct.disgustingXPBerries) {
|
||||
if (applyBerryEffects(player, false) && !world.isRemote) 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 && !world.isRemote)
|
||||
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 +98,63 @@ public class OreBerries extends CraftingItem {
|
||||
world.spawnEntityInWorld(entity);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* parameters ID | DURATION | initialAmplifier | maxDuration | maxAmplifier | stackExclusive
|
||||
*
|
||||
* @param player the player that's eating the 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;
|
||||
if (player.capabilities.isCreativeMode || player.worldObj.isRemote) return 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);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user