From b0ecb69ced07ec00a402267a65d51a8d6a5cf442 Mon Sep 17 00:00:00 2001 From: Colin McDonald Date: Sat, 4 Jul 2015 00:56:36 -0400 Subject: [PATCH] Add configurable potion effects diff --git a/src/main/java/net/minecraft/server/MobEffectAttackDamage.java b/src/main/java/net/minecraft/server/MobEffectAttackDamage.java index c44878931..8503c2c78 100644 --- a/src/main/java/net/minecraft/server/MobEffectAttackDamage.java +++ b/src/main/java/net/minecraft/server/MobEffectAttackDamage.java @@ -1,7 +1,5 @@ package net.minecraft.server; -import org.github.paperspigot.PaperSpigotConfig; - public class MobEffectAttackDamage extends MobEffectList { protected MobEffectAttackDamage(int i, boolean flag, int j) { @@ -9,7 +7,6 @@ public class MobEffectAttackDamage extends MobEffectList { } public double a(int i, AttributeModifier attributemodifier) { - // PaperSpigot - Configurable modifiers for strength and weakness effects - return this.id == MobEffectList.WEAKNESS.id ? (double) (PaperSpigotConfig.weaknessEffectModifier * (float) (i + 1)) : PaperSpigotConfig.strengthEffectModifier * (double) (i + 1); + return amount * (double) (i + 1); } } diff --git a/src/main/java/net/minecraft/server/MobEffectList.java b/src/main/java/net/minecraft/server/MobEffectList.java index 6ec03bbe2..1aa6c4a0e 100644 --- a/src/main/java/net/minecraft/server/MobEffectList.java +++ b/src/main/java/net/minecraft/server/MobEffectList.java @@ -9,23 +9,32 @@ import net.minecraft.util.com.google.common.collect.Maps; // CraftBukkit start import org.bukkit.craftbukkit.event.CraftEventFactory; +import org.bukkit.craftbukkit.potion.CraftPotionEffectType; import org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason; // CraftBukkit end +// Kohi start +import java.io.File; +import org.bukkit.configuration.file.YamlConfiguration; +// Kohi end + public class MobEffectList { + private static final File CONFIG_FILE = new File("effects.yml"); + protected static YamlConfiguration config = YamlConfiguration.loadConfiguration(CONFIG_FILE); + public static final MobEffectList[] byId = new MobEffectList[32]; public static final MobEffectList b = null; public static final MobEffectList FASTER_MOVEMENT = (new MobEffectList(1, false, 8171462)).b("potion.moveSpeed").b(0, 0).a(GenericAttributes.d, "91AEAA56-376B-4498-935B-2F7F68070635", 0.20000000298023224D, 2); public static final MobEffectList SLOWER_MOVEMENT = (new MobEffectList(2, true, 5926017)).b("potion.moveSlowdown").b(1, 0).a(GenericAttributes.d, "7107DE5E-7CE8-4030-940E-514C1F160890", -0.15000000596046448D, 2); public static final MobEffectList FASTER_DIG = (new MobEffectList(3, false, 14270531)).b("potion.digSpeed").b(2, 0).a(1.5D); public static final MobEffectList SLOWER_DIG = (new MobEffectList(4, true, 4866583)).b("potion.digSlowDown").b(3, 0); - public static final MobEffectList INCREASE_DAMAGE = (new MobEffectAttackDamage(5, false, 9643043)).b("potion.damageBoost").b(4, 0).a(GenericAttributes.e, "648D7064-6A60-4F59-8ABE-C2C23A6DD7A9", 3.0D, 2); - public static final MobEffectList HEAL = (new InstantMobEffect(6, false, 16262179)).b("potion.heal"); - public static final MobEffectList HARM = (new InstantMobEffect(7, true, 4393481)).b("potion.harm"); + public static final MobEffectList INCREASE_DAMAGE = (new MobEffectAttackDamage(5, false, 9643043)).b("potion.damageBoost").b(4, 0).a(GenericAttributes.e, "648D7064-6A60-4F59-8ABE-C2C23A6DD7A9", 3.0D, 2).setAmount(1.3F); + public static final MobEffectList HEAL = (new InstantMobEffect(6, false, 16262179)).b("potion.heal").setAmount(4); + public static final MobEffectList HARM = (new InstantMobEffect(7, true, 4393481)).b("potion.harm").setAmount(6); public static final MobEffectList JUMP = (new MobEffectList(8, false, 7889559)).b("potion.jump").b(2, 1); public static final MobEffectList CONFUSION = (new MobEffectList(9, true, 5578058)).b("potion.confusion").b(3, 1).a(0.25D); - public static final MobEffectList REGENERATION = (new MobEffectList(10, false, 13458603)).b("potion.regeneration").b(7, 0).a(0.25D); + public static final MobEffectList REGENERATION = (new MobEffectList(10, false, 13458603)).b("potion.regeneration").b(7, 0).a(0.25D).setTickRate(50); public static final MobEffectList RESISTANCE = (new MobEffectList(11, false, 10044730)).b("potion.resistance").b(6, 1); public static final MobEffectList FIRE_RESISTANCE = (new MobEffectList(12, false, 14981690)).b("potion.fireResistance").b(7, 1); public static final MobEffectList WATER_BREATHING = (new MobEffectList(13, false, 3035801)).b("potion.waterBreathing").b(0, 2); @@ -33,9 +42,9 @@ public class MobEffectList { public static final MobEffectList BLINDNESS = (new MobEffectList(15, true, 2039587)).b("potion.blindness").b(5, 1).a(0.25D); public static final MobEffectList NIGHT_VISION = (new MobEffectList(16, false, 2039713)).b("potion.nightVision").b(4, 1); public static final MobEffectList HUNGER = (new MobEffectList(17, true, 5797459)).b("potion.hunger").b(1, 1); - public static final MobEffectList WEAKNESS = (new MobEffectAttackDamage(18, true, 4738376)).b("potion.weakness").b(5, 0).a(GenericAttributes.e, "22653B89-116E-49DC-9B6B-9971489B5BE5", 2.0D, 0); - public static final MobEffectList POISON = (new MobEffectList(19, true, 5149489)).b("potion.poison").b(6, 0).a(0.25D); - public static final MobEffectList WITHER = (new MobEffectList(20, true, 3484199)).b("potion.wither").b(1, 2).a(0.25D); + public static final MobEffectList WEAKNESS = (new MobEffectAttackDamage(18, true, 4738376)).b("potion.weakness").b(5, 0).a(GenericAttributes.e, "22653B89-116E-49DC-9B6B-9971489B5BE5", 2.0D, 0).setAmount(-0.5F); + public static final MobEffectList POISON = (new MobEffectList(19, true, 5149489)).b("potion.poison").b(6, 0).a(0.25D).setTickRate(25); + public static final MobEffectList WITHER = (new MobEffectList(20, true, 3484199)).b("potion.wither").b(1, 2).a(0.25D).setTickRate(40); public static final MobEffectList HEALTH_BOOST = (new MobEffectHealthBoost(21, false, 16284963)).b("potion.healthBoost").b(2, 2).a(GenericAttributes.maxHealth, "5D6F0BA2-1186-46AC-B896-C61C5CEE99CC", 4.0D, 0); public static final MobEffectList ABSORPTION = (new MobEffectAbsorption(22, false, 2445989)).b("potion.absorption").b(2, 2); public static final MobEffectList SATURATION = (new InstantMobEffect(23, false, 16262179)).b("potion.saturation"); @@ -55,6 +64,10 @@ public class MobEffectList { private int M = -1; private double N; private boolean O; + private String configName; // Kohi + protected Float amount; // Kohi: amount this potion does, example: HP healed + private Integer operation; // Kohi: attribute modifier operation + private Integer tickRate; // Kohi: how often the potion does its tick protected MobEffectList(int i, boolean flag, int j) { this.id = i; @@ -68,7 +81,41 @@ public class MobEffectList { this.K = j; - org.bukkit.potion.PotionEffectType.registerPotionEffectType(new org.bukkit.craftbukkit.potion.CraftPotionEffectType(this)); // CraftBukkit + // CraftBukkit start + CraftPotionEffectType craftEffect = new CraftPotionEffectType(this); + org.bukkit.potion.PotionEffectType.registerPotionEffectType(craftEffect); + // CraftBukkit end + + configName = craftEffect.getName().toLowerCase().replace('_', '-'); + + if (config.isDouble(configName + ".amount") || config.isInt(configName + ".amount")) { + amount = (float) config.getDouble(configName + ".amount"); + System.out.println(configName + ".amount = " + amount); + } + + if (config.isInt(configName + ".operation")) { + operation = config.getInt(configName + ".operation"); + System.out.println(configName + ".operation = " + operation); + } + + if (config.isInt(configName + ".tick-rate")) { + tickRate = config.getInt(configName + ".tick-rate"); + System.out.println(configName + ".tick-rate = " + tickRate); + } + } + + private MobEffectList setAmount(float amount) { + if (this.amount == null) { + this.amount = amount; + } + return this; + } + + private MobEffectList setTickRate(int tickRate) { + if (this.tickRate == null) { + this.tickRate = tickRate; + } + return this; } protected MobEffectList b(int i, int j) { @@ -110,10 +157,10 @@ public class MobEffectList { } } else if ((this.id != HEAL.id || entityliving.aR()) && (this.id != HARM.id || !entityliving.aR())) { if (this.id == HARM.id && !entityliving.aR() || this.id == HEAL.id && entityliving.aR()) { - entityliving.damageEntity(DamageSource.MAGIC, (float) (6 << i)); + entityliving.damageEntity(DamageSource.MAGIC, (float) (amount.intValue() << i)); } } else { - entityliving.heal((float) Math.max(4 << i, 0), RegainReason.MAGIC); // CraftBukkit + entityliving.heal((float) Math.max(amount.intValue() << i, 0), RegainReason.MAGIC); // CraftBukkit } } @@ -128,7 +175,7 @@ public class MobEffectList { if ((this.id != HEAL.id || entityliving1.aR()) && (this.id != HARM.id || !entityliving1.aR())) { if (this.id == HARM.id && !entityliving1.aR() || this.id == HEAL.id && entityliving1.aR()) { - j = (int) (d0 * (double) (6 << i) + 0.5D); + j = (int) (d0 * (double) (amount.intValue() << i) + 0.5D); if (entityliving == null) { entityliving1.damageEntity(DamageSource.MAGIC, (float) j); } else { @@ -137,7 +184,7 @@ public class MobEffectList { } } } else { - j = (int) (d0 * (double) (4 << i) + 0.5D); + j = (int) (d0 * (double) (amount.intValue() << i) + 0.5D); entityliving1.heal((float) j, RegainReason.MAGIC); // CraftBukkit } } @@ -149,14 +196,8 @@ public class MobEffectList { public boolean a(int i, int j) { int k; - if (this.id == REGENERATION.id) { - k = 50 >> j; - return k > 0 ? i % k == 0 : true; - } else if (this.id == POISON.id) { - k = 25 >> j; - return k > 0 ? i % k == 0 : true; - } else if (this.id == WITHER.id) { - k = 40 >> j; + if (this.id == REGENERATION.id || this.id == POISON.id || this.id == WITHER.id) { + k = tickRate >> j; return k > 0 ? i % k == 0 : true; } else { return this.id == HUNGER.id; @@ -220,7 +261,7 @@ public class MobEffectList { AttributeModifier attributemodifier = (AttributeModifier) entry.getValue(); attributeinstance.b(attributemodifier); - attributeinstance.a(new AttributeModifier(attributemodifier.a(), this.a() + " " + i, this.a(i, attributemodifier), attributemodifier.c())); + attributeinstance.a(new AttributeModifier(attributemodifier.a(), this.a() + " " + i, this.a(i, attributemodifier), operation == null ? attributemodifier.c() : operation)); } } } -- 2.13.3