From e108650cd49bf14a1d67ed6669e5b8f6e4b93acf Mon Sep 17 00:00:00 2001 From: Sen Date: Wed, 26 Mar 2025 21:07:23 +0100 Subject: [PATCH] potion cleanup --- java/src/game/Game.java | 9 +- .../game/command/commands/CommandMilk.java | 6 +- .../game/command/commands/CommandPotion.java | 27 +- java/src/game/entity/animal/EntityHorse.java | 4 +- java/src/game/entity/animal/EntityRabbit.java | 2 +- java/src/game/entity/npc/EntityArachnoid.java | 12 +- java/src/game/entity/npc/EntityFlyingNPC.java | 6 + java/src/game/entity/npc/EntityMage.java | 6 +- java/src/game/entity/npc/EntityNPC.java | 28 +- .../src/game/entity/projectile/EntityBox.java | 2 +- .../game/entity/projectile/EntityPotion.java | 8 +- java/src/game/entity/types/EntityLiving.java | 80 +-- java/src/game/init/ItemRegistry.java | 6 +- java/src/game/item/ItemAppleGold.java | 8 +- java/src/game/item/ItemFishFood.java | 4 +- java/src/game/item/ItemFood.java | 7 +- java/src/game/item/ItemPotion.java | 16 +- java/src/game/network/ClientPlayer.java | 4 +- java/src/game/network/Player.java | 34 +- .../game/packet/S1DPacketEntityEffect.java | 55 +- .../packet/S1EPacketRemoveEntityEffect.java | 11 +- java/src/game/potion/Potion.java | 591 +++++++----------- java/src/game/potion/PotionAbsorption.java | 25 - java/src/game/potion/PotionAttackDamage.java | 17 - java/src/game/potion/PotionEffect.java | 350 ++++------- java/src/game/potion/PotionHealth.java | 27 - java/src/game/potion/PotionHealthBoost.java | 23 - java/src/game/potion/PotionHelper.java | 188 +++--- java/src/game/renderer/EntityRenderer.java | 16 +- .../src/game/tileentity/TileEntityBeacon.java | 40 +- 30 files changed, 644 insertions(+), 968 deletions(-) delete mode 100755 java/src/game/potion/PotionAbsorption.java delete mode 100755 java/src/game/potion/PotionAttackDamage.java delete mode 100755 java/src/game/potion/PotionHealth.java delete mode 100755 java/src/game/potion/PotionHealthBoost.java diff --git a/java/src/game/Game.java b/java/src/game/Game.java index 2e49535..7168e7c 100755 --- a/java/src/game/Game.java +++ b/java/src/game/Game.java @@ -851,12 +851,13 @@ public class Game implements IThreadListener { x = 40; y = 40; for(PotionEffect effect : this.thePlayer.getEffects()) { - Potion potion = Potion.POTION_TYPES[effect.getPotionID()]; - int color = potion.getLiquidColor(); + Potion potion = effect.getPotion(); + int color = potion.getColor(); String name = (potion.isBadEffect() ? TextColor.ORANGE : TextColor.ACID) + potion.getDisplay() + PotionHelper.getPotionPotency(effect.getAmplifier()); - String desc = TextColor.NEON + Potion.getDurationString(effect); + String desc = TextColor.NEON + effect.getDurationString(); // Drawing.drawRectColor(x, y, 250, Font.DEFAULT.yglyph + 2, color | 0xff000000); - Drawing.drawGradientBorder(x, y, 250, Font.YGLYPH + 4, color | 0xff000000, Util.mixColor(color | 0xff000000, 0xff000000), 0xff202020, 0xffcfcfcf, 0xff6f6f6f); + Drawing.drawRectBorder(x, y, 250, Font.YGLYPH + 4, 0xff000000, 0xff202020, 0xffcfcfcf, 0xff6f6f6f); + Drawing.drawGradient(x + 2, y + 2, effect.isInfinite() ? 246 : ((int)(246.0f * ((float)effect.getRemaining() / (float)effect.getDuration()))), Font.YGLYPH, color | 0xff000000, Util.mixColor(color | 0xff000000, 0xff000000)); Drawing.drawText(name, x + 4, y + 2, 0xffffffff); Drawing.drawTextRight(desc, x + 250 - 4, y + 2, 0xffffffff); y += 24; diff --git a/java/src/game/command/commands/CommandMilk.java b/java/src/game/command/commands/CommandMilk.java index 8419b7d..66c6769 100644 --- a/java/src/game/command/commands/CommandMilk.java +++ b/java/src/game/command/commands/CommandMilk.java @@ -15,8 +15,8 @@ public class CommandMilk extends Command { this.addLivingEntityList("entities", true); this.setParamsOptional(); List potions = Lists.newArrayList(); - for(Potion potion : Potion.POTION_TYPES) { - if(potion != null) + for(Potion potion : Potion.values()) { + if(!potion.isInstant()) potions.add(potion); } this.addEnum("type", Potion.class, potions); @@ -28,7 +28,7 @@ public class CommandMilk extends Command { int done = 0; for(EntityLiving entity : entities) { if(type != null && entity.hasEffect(type)) { - entity.removeEffect(type.id); + entity.removeEffect(type); exec.logConsole("%s von %s entfernt", type.getDisplay(), entity.getCommandName()); done++; } diff --git a/java/src/game/command/commands/CommandPotion.java b/java/src/game/command/commands/CommandPotion.java index 1f2196c..1268d5f 100644 --- a/java/src/game/command/commands/CommandPotion.java +++ b/java/src/game/command/commands/CommandPotion.java @@ -14,14 +14,13 @@ public class CommandPotion extends Command { super("potion"); List potions = Lists.newArrayList(); - for(Potion potion : Potion.POTION_TYPES) { - if(potion != null) - potions.add(potion); + for(Potion potion : Potion.values()) { + potions.add(potion); } this.addLivingEntityList("entities", true); this.addEnum("type", Potion.class, potions); this.setParamsOptional(); - this.addInt("duration", 1, 1000000, 1000000); + this.addInt("duration", 0, 1000000, 1000000); this.addInt("strength", 1, 256, 1); this.addFlag("particles", 'p'); @@ -32,12 +31,20 @@ public class CommandPotion extends Command { public Object exec(CommandEnvironment env, Executor exec, List entities, Potion type, int duration, int strength, boolean particles, boolean ambient, boolean keep) { int done = 0; for(EntityLiving entity : entities) { - PotionEffect effect = new PotionEffect(type.id, duration * 20, strength - 1, ambient, particles); - if(entity.isPotionApplicable(effect)) { - if(!keep && entity.hasEffect(type)) - entity.removeEffect(type.id); - entity.addEffect(effect); - exec.logConsole("%d * %s für %d Sekunden an %s gegeben", strength, type.getDisplay(), duration, entity.getCommandName()); + if(entity.isPotionApplicable(type)) { + if(type.isInstant()) { + type.onImpact(null, null, entity, strength - 1, 1.0); + } + else { + PotionEffect effect = new PotionEffect(type, duration == 0 ? Integer.MAX_VALUE : (duration * 20), strength - 1, ambient, particles); + if(!keep && entity.hasEffect(type)) + entity.removeEffect(type); + entity.addEffect(effect); + } + if(type.isInstant() || duration == 0) + exec.logConsole("%d * %s an %s gegeben", strength, type.getDisplay(), entity.getCommandName()); + else + exec.logConsole("%d * %s für %d Sekunden an %s gegeben", strength, type.getDisplay(), duration, entity.getCommandName()); done++; } } diff --git a/java/src/game/entity/animal/EntityHorse.java b/java/src/game/entity/animal/EntityHorse.java index 2ee9bed..b9ed9b2 100755 --- a/java/src/game/entity/animal/EntityHorse.java +++ b/java/src/game/entity/animal/EntityHorse.java @@ -1329,9 +1329,9 @@ public class EntityHorse extends EntityAnimal implements IInvBasic { this.motionY = this.getHorseJumpStrength() * (double)this.jumpPower; - if (this.hasEffect(Potion.jump)) + if (this.hasEffect(Potion.JUMP)) { - this.motionY += (double)((float)(this.getEffect(Potion.jump).getAmplifier() + 1) * 0.1F); + this.motionY += (double)((float)(this.getEffect(Potion.JUMP).getAmplifier() + 1) * 0.1F); } this.setHorseJumping(true); diff --git a/java/src/game/entity/animal/EntityRabbit.java b/java/src/game/entity/animal/EntityRabbit.java index ae781ff..9c4da72 100755 --- a/java/src/game/entity/animal/EntityRabbit.java +++ b/java/src/game/entity/animal/EntityRabbit.java @@ -342,7 +342,7 @@ public class EntityRabbit extends EntityAnimal { }).isEmpty()) this.setInLove(null); if(state.getBlock() == Blocks.blue_mushroom) - this.addEffect(new PotionEffect(Potion.moveSpeed.id, this.rand.range(400, 2600), this.rand.chance(0, 1, 5))); + this.addEffect(new PotionEffect(Potion.SPEED, this.rand.range(400, 2600), this.rand.chance(0, 1, 5))); this.worldObj.destroyBlock(pos, false); this.worldObj.setState(pos, Blocks.air.getState(), 2); } diff --git a/java/src/game/entity/npc/EntityArachnoid.java b/java/src/game/entity/npc/EntityArachnoid.java index 091ad35..99f0eca 100755 --- a/java/src/game/entity/npc/EntityArachnoid.java +++ b/java/src/game/entity/npc/EntityArachnoid.java @@ -111,11 +111,11 @@ public class EntityArachnoid extends EntityNPC if (livingdata instanceof EntityArachnoid.GroupData) { - int i = ((EntityArachnoid.GroupData)livingdata).potionEffectId; + Potion i = ((EntityArachnoid.GroupData)livingdata).potionEffectId; - if (i > 0 && Potion.POTION_TYPES[i] != null) + if (i != null) { - this.addEffect(new PotionEffect(i, Integer.MAX_VALUE)); + this.addEffect(new PotionEffect(i, Integer.MAX_VALUE, 0)); } if(((EntityArachnoid.GroupData)livingdata).isChild) @@ -228,7 +228,7 @@ public class EntityArachnoid extends EntityNPC { if(super.attackEntityAsMob(entityIn)) { if(entityIn instanceof EntityLiving && this.rand.chance(50)) - ((EntityLiving)entityIn).addEffect(new PotionEffect(Potion.poison.id, this.rand.range(14, 35) * 20, 0)); + ((EntityLiving)entityIn).addEffect(new PotionEffect(Potion.POISON, this.rand.range(14, 35) * 20, 0)); return true; } return false; @@ -248,7 +248,7 @@ public class EntityArachnoid extends EntityNPC public static class GroupData { - public int potionEffectId; + public Potion potionEffectId; public boolean isChild; public GroupData(boolean isChild) { @@ -257,7 +257,7 @@ public class EntityArachnoid extends EntityNPC public void pickEffect(Random rand) { - this.potionEffectId = rand.pick(Potion.moveSpeed.id, Potion.moveSpeed.id, Potion.damageBoost.id, Potion.regeneration.id); + this.potionEffectId = rand.pick(Potion.SPEED, Potion.SPEED, Potion.STRENGTH, Potion.REGENERATION); } } } diff --git a/java/src/game/entity/npc/EntityFlyingNPC.java b/java/src/game/entity/npc/EntityFlyingNPC.java index cf017cf..ed58eff 100755 --- a/java/src/game/entity/npc/EntityFlyingNPC.java +++ b/java/src/game/entity/npc/EntityFlyingNPC.java @@ -5,6 +5,7 @@ import game.ai.EntityMoveHelper; import game.block.Block; import game.entity.attributes.Attributes; import game.entity.types.EntityLiving; +import game.potion.Potion; import game.rng.Random; import game.util.ExtMath; import game.world.BlockPos; @@ -112,6 +113,11 @@ public abstract class EntityFlyingNPC extends EntityNPC return false; } + public boolean isPotionApplicable(Potion potion) + { + return potion != Potion.FLYING && super.isPotionApplicable(potion); + } + static class AILookAround extends EntityAIBase { private EntityFlyingNPC parentEntity; diff --git a/java/src/game/entity/npc/EntityMage.java b/java/src/game/entity/npc/EntityMage.java index 9e890ac..c44130c 100755 --- a/java/src/game/entity/npc/EntityMage.java +++ b/java/src/game/entity/npc/EntityMage.java @@ -64,7 +64,7 @@ public class EntityMage extends EntityNPC // i = 8237; // } // else - if (this.rand.floatv() < 0.15F && this.isBurning() && !this.hasEffect(Potion.fireResistance)) + if (this.rand.floatv() < 0.15F && this.isBurning() && !this.hasEffect(Potion.FIRE_RESISTANCE)) { i = 16307; } @@ -72,11 +72,11 @@ public class EntityMage extends EntityNPC { i = 16341; } - else if (this.rand.floatv() < 0.25F && this.getAttackTarget() != null && !this.hasEffect(Potion.moveSpeed) && this.getAttackTarget().getDistanceSqToEntity(this) > 121.0D) + else if (this.rand.floatv() < 0.25F && this.getAttackTarget() != null && !this.hasEffect(Potion.SPEED) && this.getAttackTarget().getDistanceSqToEntity(this) > 121.0D) { i = 16274; } - else if (this.rand.floatv() < 0.25F && this.getAttackTarget() != null && !this.hasEffect(Potion.moveSpeed) && this.getAttackTarget().getDistanceSqToEntity(this) > 121.0D) + else if (this.rand.floatv() < 0.25F && this.getAttackTarget() != null && !this.hasEffect(Potion.SPEED) && this.getAttackTarget().getDistanceSqToEntity(this) > 121.0D) { i = 16274; } diff --git a/java/src/game/entity/npc/EntityNPC.java b/java/src/game/entity/npc/EntityNPC.java index 5a9f91a..623132e 100755 --- a/java/src/game/entity/npc/EntityNPC.java +++ b/java/src/game/entity/npc/EntityNPC.java @@ -798,15 +798,15 @@ public abstract class EntityNPC extends EntityLiving double d3 = target.posZ + target.motionZ - this.posZ; float f = ExtMath.sqrtd(d1 * d1 + d3 * d3); - if (f >= 8.0F && !target.hasEffect(Potion.moveSlowdown)) + if (f >= 8.0F && !target.hasEffect(Potion.SLOWNESS)) { entitypotion.setPotionDamage(32698); } - else if (target.getHealth() >= 8 && !target.hasEffect(Potion.poison)) + else if (target.getHealth() >= 8 && !target.hasEffect(Potion.POISON)) { entitypotion.setPotionDamage(32660); } - else if (f <= 3.0F && !target.hasEffect(Potion.weakness) && this.rand.floatv() < 0.25F) + else if (f <= 3.0F && !target.hasEffect(Potion.WEAKNESS) && this.rand.floatv() < 0.25F) { entitypotion.setPotionDamage(32696); } @@ -2404,7 +2404,7 @@ public abstract class EntityNPC extends EntityLiving this.pushOutOfBlocks(this.posX + (double)this.width * 0.35D, this.getEntityBoundingBox().minY + 0.5D, this.posZ + (double)this.width * 0.35D); boolean canSprint = true; // (float)this.getFoodStats().getFoodLevel() > 6.0F || this.allowFlying; - if (this.onGround && !flag1 && !flag2 && this.gm.moveForward >= f && !this.isSprinting() && canSprint && !this.isUsingItem() && !this.hasEffect(Potion.blindness)) + if (this.onGround && !flag1 && !flag2 && this.gm.moveForward >= f && !this.isSprinting() && canSprint && !this.isUsingItem() && !this.hasEffect(Potion.BLINDNESS)) { if (this.sprintToggleTimer <= 0 && !this.gm.sprint) { @@ -2416,7 +2416,7 @@ public abstract class EntityNPC extends EntityLiving } } - if (!this.isSprinting() && this.gm.moveForward >= f && canSprint && !this.isUsingItem() && !this.hasEffect(Potion.blindness) && this.gm.sprint) + if (!this.isSprinting() && this.gm.moveForward >= f && canSprint && !this.isUsingItem() && !this.hasEffect(Potion.BLINDNESS) && this.gm.sprint) { this.setSprinting(true); } @@ -2426,7 +2426,7 @@ public abstract class EntityNPC extends EntityLiving this.setSprinting(false); } - if (this.hasEffect(Potion.flying) || this.noclip) + if (this.hasEffect(Potion.FLYING) || this.noclip) { if (this.noclip) { @@ -3037,7 +3037,7 @@ public abstract class EntityNPC extends EntityLiving protected void onFinishedEffect(PotionEffect effect) { super.onFinishedEffect(effect); - if(this.isPlayer() && effect.getPotionID() == Potion.flying.id) + if(this.isPlayer() && effect.getPotion() == Potion.FLYING) this.flying = false; // super.onFinishedEffect(effect); if(this.connection != null) @@ -3380,19 +3380,19 @@ public abstract class EntityNPC extends EntityLiving } } - if (this.hasEffect(Potion.digSpeed)) + if (this.hasEffect(Potion.HASTE)) { - int speed = this.getEffect(Potion.digSpeed).getAmplifier(); + int speed = this.getEffect(Potion.HASTE).getAmplifier(); if(speed >= 255) return 1000000.0f; f *= 1.0F + (float)(speed + 1) * 0.2F; } - if (this.hasEffect(Potion.digSlowdown)) + if (this.hasEffect(Potion.FATIGUE)) { float f1 = 1.0F; - switch (this.getEffect(Potion.digSlowdown).getAmplifier()) + switch (this.getEffect(Potion.FATIGUE).getAmplifier()) { case 0: f1 = 0.3F; @@ -3527,7 +3527,7 @@ public abstract class EntityNPC extends EntityLiving // this.foodStats.readNBT(tagCompund); // this.readCapabilitiesFromNBT(tagCompund); - this.flying = tagCompund.getBoolean("flying") && this.hasEffect(Potion.flying); + this.flying = tagCompund.getBoolean("flying") && this.hasEffect(Potion.FLYING); // if(tagCompund.hasKey("speed", 99)) // this.speed = tagCompund.getFloat("speed"); // this.disableDamagePersist = tagCompund.getBoolean("alwaysInvulnerable"); @@ -3803,7 +3803,7 @@ public abstract class EntityNPC extends EntityLiving if (f > 0 || f1 > 0) { - boolean flag = this.fallDistance > 0.0F && !this.onGround && !this.isOnLadder() && !this.isInLiquid() && !this.hasEffect(Potion.blindness) && this.vehicle == null && targetEntity instanceof EntityLiving; + boolean flag = this.fallDistance > 0.0F && !this.onGround && !this.isOnLadder() && !this.isInLiquid() && !this.hasEffect(Potion.BLINDNESS) && this.vehicle == null && targetEntity instanceof EntityLiving; if (flag && f > 0) { @@ -4118,7 +4118,7 @@ public abstract class EntityNPC extends EntityLiving this.addStat((int)Math.round((double)distance * 100.0D)); } - if(!this.hasEffect(Potion.flying)) + if(!this.hasEffect(Potion.FLYING)) super.fall(distance, damageMultiplier); } } diff --git a/java/src/game/entity/projectile/EntityBox.java b/java/src/game/entity/projectile/EntityBox.java index 475126b..ccb85f1 100755 --- a/java/src/game/entity/projectile/EntityBox.java +++ b/java/src/game/entity/projectile/EntityBox.java @@ -108,7 +108,7 @@ public class EntityBox extends EntityProjectile // // if (i > 0) // { - ((EntityLiving)movingObject.entity).addEffect(new PotionEffect(Potion.moveSlowdown.id, 20 * this.rand.range(35, 55), this.rand.chance(1, 2, 5))); + ((EntityLiving)movingObject.entity).addEffect(new PotionEffect(Potion.SLOWNESS, 20 * this.rand.range(35, 55), this.rand.chance(1, 2, 5))); // } } } diff --git a/java/src/game/entity/projectile/EntityPotion.java b/java/src/game/entity/projectile/EntityPotion.java index 7efa411..21f86b5 100755 --- a/java/src/game/entity/projectile/EntityPotion.java +++ b/java/src/game/entity/projectile/EntityPotion.java @@ -124,11 +124,13 @@ public class EntityPotion extends EntityThrowable implements IObjectData for (PotionEffect potioneffect : list) { - int i = potioneffect.getPotionID(); + Potion i = potioneffect.getPotion(); + if(!entitylivingbase.isPotionApplicable(i)) + continue; - if (Potion.POTION_TYPES[i].isInstant()) + if (i.isInstant()) { - Potion.POTION_TYPES[i].affectEntity(this, this.getThrower(), entitylivingbase, potioneffect.getAmplifier(), d1); + i.onImpact(this, this.getThrower(), entitylivingbase, potioneffect.getAmplifier(), d1); } else { diff --git a/java/src/game/entity/types/EntityLiving.java b/java/src/game/entity/types/EntityLiving.java index d48ee48..4ba56ac 100755 --- a/java/src/game/entity/types/EntityLiving.java +++ b/java/src/game/entity/types/EntityLiving.java @@ -75,7 +75,7 @@ public abstract class EntityLiving extends Entity private AttributeMap attributes; private final List combat = Lists.newArrayList(); - private final Map effects = Maps.newHashMap(); + private final Map effects = Maps.newEnumMap(Potion.class); public int soundTimer; protected int xpValue; private EntityLookHelper lookHelper; @@ -373,7 +373,7 @@ public abstract class EntityLiving extends Entity // if(this.isPlayer()) // Log.SERVER.info("rad:" + radiation); if(radiation >= 0.0f) { - this.addEffect(new PotionEffect(Potion.radiation.id, ExtMath.clampi((int)(radiation * 5.0f), 10, 32766), + this.addEffect(new PotionEffect(Potion.RADIATION, ExtMath.clampi((int)(radiation * 5.0f), 10, 32766), ExtMath.clampi((int)(radiation / 20.0f), 0, 255))); } } @@ -565,7 +565,7 @@ public abstract class EntityLiving extends Entity for (PotionEffect potioneffect : this.effects.values()) { - nbttaglist.appendTag(potioneffect.writeCustomPotionEffectToNBT(new NBTTagCompound())); + nbttaglist.appendTag(potioneffect.toNbt()); } tagCompound.setTag("ActiveEffects", nbttaglist); @@ -615,11 +615,11 @@ public abstract class EntityLiving extends Entity for (int i = 0; i < nbttaglist.tagCount(); ++i) { NBTTagCompound nbttagcompound = nbttaglist.getCompoundTagAt(i); - PotionEffect potioneffect = PotionEffect.readCustomPotionEffectFromNBT(nbttagcompound); + PotionEffect potioneffect = PotionEffect.fromNbt(nbttagcompound); - if (potioneffect != null) + if (potioneffect != null && !potioneffect.getPotion().isInstant()) { - this.effects.put(Integer.valueOf(potioneffect.getPotionID()), potioneffect); + this.effects.put(potioneffect.getPotion(), potioneffect); } } } @@ -665,12 +665,12 @@ public abstract class EntityLiving extends Entity protected void updateEffects() { - Iterator iterator = this.effects.keySet().iterator(); + Iterator iterator = this.effects.keySet().iterator(); while (iterator.hasNext()) { - Integer integer = (Integer)iterator.next(); - PotionEffect potioneffect = (PotionEffect)this.effects.get(integer); + Potion potion = iterator.next(); + PotionEffect potioneffect = this.effects.get(potion); if (!potioneffect.onUpdate(this)) { @@ -680,7 +680,7 @@ public abstract class EntityLiving extends Entity this.onFinishedEffect(potioneffect); } } - else if (potioneffect.getDuration() % 600 == 0) + else if (potioneffect.getRemaining() % 600 == 0) { this.onChangedEffect(potioneffect, false); } @@ -758,14 +758,14 @@ public abstract class EntityLiving extends Entity public void clearEffects(boolean negative) { - Iterator iterator = this.effects.keySet().iterator(); + Iterator iterator = this.effects.keySet().iterator(); while (iterator.hasNext()) { - Integer integer = (Integer)iterator.next(); - PotionEffect potioneffect = (PotionEffect)this.effects.get(integer); + Potion potion = iterator.next(); + PotionEffect potioneffect = this.effects.get(potion); - if (!this.worldObj.client && (!negative || Potion.POTION_TYPES[potioneffect.getPotionID()].isBadEffect())) + if (!this.worldObj.client && (!negative || potioneffect.getPotion().isBadEffect())) { iterator.remove(); this.onFinishedEffect(potioneffect); @@ -778,14 +778,14 @@ public abstract class EntityLiving extends Entity return this.effects.values(); } - public boolean hasEffect(int potionId) - { - return this.effects.containsKey(Integer.valueOf(potionId)); - } +// public boolean hasEffect(int potionId) +// { +// return this.effects.containsKey(Integer.valueOf(potionId)); +// } public boolean hasEffect(Potion potionIn) { - return this.effects.containsKey(Integer.valueOf(potionIn.id)); + return this.effects.containsKey(potionIn); } /** @@ -793,7 +793,7 @@ public abstract class EntityLiving extends Entity */ public PotionEffect getEffect(Potion potionIn) { - return (PotionEffect)this.effects.get(Integer.valueOf(potionIn.id)); + return this.effects.get(potionIn); } /** @@ -801,22 +801,22 @@ public abstract class EntityLiving extends Entity */ public void addEffect(PotionEffect potioneffectIn) { - if (this.isPotionApplicable(potioneffectIn)) + if (!potioneffectIn.getPotion().isInstant() && this.isPotionApplicable(potioneffectIn.getPotion())) { - if (this.effects.containsKey(Integer.valueOf(potioneffectIn.getPotionID()))) + if (this.effects.containsKey(potioneffectIn.getPotion())) { - ((PotionEffect)this.effects.get(Integer.valueOf(potioneffectIn.getPotionID()))).combine(potioneffectIn); - this.onChangedEffect((PotionEffect)this.effects.get(Integer.valueOf(potioneffectIn.getPotionID())), true); + this.effects.put(potioneffectIn.getPotion(), this.effects.get(potioneffectIn.getPotion()).combine(potioneffectIn)); + this.onChangedEffect(this.effects.get(potioneffectIn.getPotion()), true); } else { - this.effects.put(Integer.valueOf(potioneffectIn.getPotionID()), potioneffectIn); + this.effects.put(potioneffectIn.getPotion(), potioneffectIn); this.onNewEffect(potioneffectIn); } } } - public boolean isPotionApplicable(PotionEffect potioneffectIn) + public boolean isPotionApplicable(Potion potion) { // if (this.getCreatureType() == CreatureType.UNDEAD) // { @@ -839,17 +839,17 @@ public abstract class EntityLiving extends Entity /** * Remove the speified potion effect from this entity. */ - public void removeEffectClient(int potionId) + public void removeEffectClient(Potion potionId) { - this.effects.remove(Integer.valueOf(potionId)); + this.effects.remove(potionId); } /** * Remove the specified potion effect from this entity. */ - public void removeEffect(int potionId) + public void removeEffect(Potion potion) { - PotionEffect potioneffect = (PotionEffect)this.effects.remove(Integer.valueOf(potionId)); + PotionEffect potioneffect = this.effects.remove(potion); if (potioneffect != null) { @@ -863,7 +863,7 @@ public abstract class EntityLiving extends Entity if (!this.worldObj.client) { - Potion.POTION_TYPES[id.getPotionID()].applyAttributesModifiersToEntity(this, this.getAttributeMap(), id.getAmplifier()); + id.getPotion().addModifiers(this, this.getAttributeMap(), id.getAmplifier()); } } @@ -873,8 +873,8 @@ public abstract class EntityLiving extends Entity if (added && !this.worldObj.client) { - Potion.POTION_TYPES[id.getPotionID()].removeAttributesModifiersFromEntity(this, this.getAttributeMap(), id.getAmplifier()); - Potion.POTION_TYPES[id.getPotionID()].applyAttributesModifiersToEntity(this, this.getAttributeMap(), id.getAmplifier()); + id.getPotion().removeModifiers(this, this.getAttributeMap(), id.getAmplifier()); + id.getPotion().addModifiers(this, this.getAttributeMap(), id.getAmplifier()); } } @@ -884,7 +884,7 @@ public abstract class EntityLiving extends Entity if (!this.worldObj.client) { - Potion.POTION_TYPES[effect.getPotionID()].removeAttributesModifiersFromEntity(this, this.getAttributeMap(), effect.getAmplifier()); + effect.getPotion().removeModifiers(this, this.getAttributeMap(), effect.getAmplifier()); } } @@ -917,7 +917,7 @@ public abstract class EntityLiving extends Entity } public boolean isImmuneToFire() { - return this.hasEffect(Potion.fireResistance); + return this.hasEffect(Potion.FIRE_RESISTANCE); } /** @@ -1217,7 +1217,7 @@ public abstract class EntityLiving extends Entity { damageMultiplier = Math.max(0.0f, damageMultiplier - (1.65f - (float)this.worldObj.gravity * 1.65f)); super.fall(distance, damageMultiplier); - PotionEffect potioneffect = this.getEffect(Potion.jump); + PotionEffect potioneffect = this.getEffect(Potion.JUMP); float f = potioneffect != null ? (float)(potioneffect.getAmplifier() + 1) : 0.0F; int i = ExtMath.ceilf((distance - 3.0F - f) * damageMultiplier); @@ -1303,9 +1303,9 @@ public abstract class EntityLiving extends Entity */ protected int applyPotionDamageCalculations(DamageSource source, int damage) { - if (this.hasEffect(Potion.resistance) && source != DamageSource.outOfWorld) + if (this.hasEffect(Potion.RESISTANCE) && source != DamageSource.outOfWorld) { - int i = (this.getEffect(Potion.resistance).getAmplifier() + 1) * 5; + int i = (this.getEffect(Potion.RESISTANCE).getAmplifier() + 1) * 5; int j = 25 - i; float f = (float)damage * (float)j; damage = (int)(f / 25.0F); @@ -1638,9 +1638,9 @@ public abstract class EntityLiving extends Entity { this.motionY = (double)this.getJumpUpwardsMotion(); - if (this.hasEffect(Potion.jump)) + if (this.hasEffect(Potion.JUMP)) { - this.motionY += (double)((float)(this.getEffect(Potion.jump).getAmplifier() + 1) * 0.1F); + this.motionY += (double)((float)(this.getEffect(Potion.JUMP).getAmplifier() + 1) * 0.1F); } if (this.isSprinting()) diff --git a/java/src/game/init/ItemRegistry.java b/java/src/game/init/ItemRegistry.java index 1e7ee5d..4ad1d41 100755 --- a/java/src/game/init/ItemRegistry.java +++ b/java/src/game/init/ItemRegistry.java @@ -417,7 +417,7 @@ public abstract class ItemRegistry { registerItem("flint", (new Item()).setDisplay("Feuerstein").setTab(CheatTab.tabMaterials).setMaxStackSize(128)); registerItem("porkchop", (new ItemFood(3, true)).setDisplay("Rohes Schweinefleisch")); registerItem("cooked_porkchop", (new ItemFood(8, true)).setDisplay("Gebratenes Schweinefleisch")); - registerItem("golden_apple", (new ItemAppleGold(4, false)).setPotionEffect(Potion.regeneration.id, 5, 1, 1.0F) + registerItem("golden_apple", (new ItemAppleGold(4, false)).setPotionEffect(Potion.REGENERATION, 5, 1, 1.0F) .setDisplay("Goldener Apfel")); registerItem((new ItemSign()).setDisplay("Schild")); // registerItem("oak_door", (new ItemDoor(Blocks.oak_door)).setUnlocalizedName("doorOak")); @@ -464,7 +464,7 @@ public abstract class ItemRegistry { registerItem((new ItemSeeds(Blocks.soul_wart, Blocks.soul_sand)).setDisplay("Seelenwarze").setPotionEffect("+4").setMaxStackSize(128)); registerItem("potion", (new ItemPotion()).setDisplay("Trank")); registerItem("glass_bottle", (new ItemGlassBottle()).setDisplay("Glasflasche")); - registerItem("spider_eye", (new ItemFood(2, false)).setPotionEffect(Potion.poison.id, 5, 0, 1.0F).setDisplay("Spinnenauge") + registerItem("spider_eye", (new ItemFood(2, false)).setPotionEffect(Potion.POISON, 5, 0, 1.0F).setDisplay("Spinnenauge") .setPotionEffect(PotionHelper.spiderEyeEffect).setMaxStackSize(128)); registerItem("fermented_spider_eye", (new Item()).setDisplay("Fermentiertes Spinnenauge") .setPotionEffect(PotionHelper.fermentedSpiderEyeEffect).setTab(CheatTab.tabMisc).setMaxStackSize(128)); @@ -486,7 +486,7 @@ public abstract class ItemRegistry { registerItem((new ItemSeedFood(3, Blocks.carrot, Blocks.farmland)).setDisplay("Karotte").setMaxStackSize(128)); registerItem((new ItemSeedFood(1, Blocks.potato, Blocks.farmland)).setDisplay("Kartoffel").setMaxStackSize(128)); registerItem("baked_potato", (new ItemFood(5, false)).setDisplay("Ofenkartoffel").setMaxStackSize(128)); - registerItem("poisonous_potato", (new ItemFood(2, false)).setPotionEffect(Potion.poison.id, 5, 0, 0.6F).setDisplay("Giftige Kartoffel").setMaxStackSize(128)); + registerItem("poisonous_potato", (new ItemFood(2, false)).setPotionEffect(Potion.POISON, 5, 0, 0.6F).setDisplay("Giftige Kartoffel").setMaxStackSize(128)); registerItem("golden_carrot", (new ItemFood(6, false)).setDisplay("Goldene Karotte") .setPotionEffect(PotionHelper.goldenCarrotEffect).setTab(CheatTab.tabMisc)); registerItem((new ItemSkull()).setDisplay("Kopf")); diff --git a/java/src/game/item/ItemAppleGold.java b/java/src/game/item/ItemAppleGold.java index c9b0e6a..5528983 100755 --- a/java/src/game/item/ItemAppleGold.java +++ b/java/src/game/item/ItemAppleGold.java @@ -34,16 +34,16 @@ public class ItemAppleGold extends ItemFood { if (!worldIn.client) { - player.addEffect(new PotionEffect(Potion.absorption.id, 2400, 0)); + player.addEffect(new PotionEffect(Potion.ABSORPTION, 2400, 0)); } if (stack.getMetadata() > 0) { if (!worldIn.client) { - player.addEffect(new PotionEffect(Potion.regeneration.id, 600, 4)); - player.addEffect(new PotionEffect(Potion.resistance.id, 6000, 0)); - player.addEffect(new PotionEffect(Potion.fireResistance.id, 6000, 0)); + player.addEffect(new PotionEffect(Potion.REGENERATION, 600, 4)); + player.addEffect(new PotionEffect(Potion.RESISTANCE, 6000, 0)); + player.addEffect(new PotionEffect(Potion.FIRE_RESISTANCE, 6000, 0)); } } else diff --git a/java/src/game/item/ItemFishFood.java b/java/src/game/item/ItemFishFood.java index 6564476..93b554e 100755 --- a/java/src/game/item/ItemFishFood.java +++ b/java/src/game/item/ItemFishFood.java @@ -40,8 +40,8 @@ public class ItemFishFood extends ItemFood if (itemfishfood$fishtype == ItemFishFood.FishType.PUFFERFISH) { - player.addEffect(new PotionEffect(Potion.poison.id, 1200, 3)); - player.addEffect(new PotionEffect(Potion.confusion.id, 300, 1)); + player.addEffect(new PotionEffect(Potion.POISON, 1200, 3)); + player.addEffect(new PotionEffect(Potion.NAUSEA, 300, 1)); } super.onFoodEaten(stack, worldIn, player); diff --git a/java/src/game/item/ItemFood.java b/java/src/game/item/ItemFood.java index 621c5ef..346a215 100755 --- a/java/src/game/item/ItemFood.java +++ b/java/src/game/item/ItemFood.java @@ -2,6 +2,7 @@ package game.item; import game.entity.npc.EntityNPC; import game.init.SoundEvent; +import game.potion.Potion; import game.potion.PotionEffect; import game.world.World; @@ -10,7 +11,7 @@ public class ItemFood extends Item public final int itemUseDuration; private final int healAmount; private final boolean isWolfsFavoriteMeat; - private int potionId; + private Potion potionId; private int potionDuration; private int potionAmplifier; private float potionEffectProbability; @@ -40,7 +41,7 @@ public class ItemFood extends Item protected void onFoodEaten(ItemStack stack, World worldIn, EntityNPC player) { - if (!worldIn.client && this.potionId > 0 && worldIn.rand.floatv() < this.potionEffectProbability) + if (!worldIn.client && this.potionId != null && worldIn.rand.floatv() < this.potionEffectProbability) { player.addEffect(new PotionEffect(this.potionId, this.potionDuration * 20, this.potionAmplifier)); } @@ -88,7 +89,7 @@ public class ItemFood extends Item * sets a potion effect on the item. Args: int potionId, int duration (will be multiplied by 20), int amplifier, * float probability of effect happening */ - public ItemFood setPotionEffect(int id, int duration, int amplifier, float probability) + public ItemFood setPotionEffect(Potion id, int duration, int amplifier, float probability) { this.potionId = id; this.potionDuration = duration; diff --git a/java/src/game/item/ItemPotion.java b/java/src/game/item/ItemPotion.java index 9697b6b..43d5c93 100755 --- a/java/src/game/item/ItemPotion.java +++ b/java/src/game/item/ItemPotion.java @@ -63,7 +63,7 @@ public class ItemPotion extends Item if (list == null) { - list = PotionHelper.getPotionEffects(stack.getMetadata(), false); + list = PotionHelper.getPotionEffects(stack.getMetadata()); this.effectCache.put(Integer.valueOf(stack.getMetadata()), list); } @@ -77,7 +77,7 @@ public class ItemPotion extends Item if (list == null) { - list = PotionHelper.getPotionEffects(meta, false); + list = PotionHelper.getPotionEffects(meta); this.effectCache.put(Integer.valueOf(meta), list); } @@ -194,7 +194,7 @@ public class ItemPotion extends Item { for (PotionEffect potioneffect : list) { - if (Potion.POTION_TYPES[potioneffect.getPotionID()].isInstant()) + if (potioneffect.getPotion().isInstant()) { return true; } @@ -254,15 +254,15 @@ public class ItemPotion extends Item for (PotionEffect potioneffect : list) { String s1 = potioneffect.getEffectName().trim(); - Potion potion = Potion.POTION_TYPES[potioneffect.getPotionID()]; - Map map = potion.getAttributeModifierMap(); + Potion potion = potioneffect.getPotion(); + Map map = potion.getModifiers(); if (map != null && map.size() > 0) { for (Entry entry : map.entrySet()) { AttributeModifier attributemodifier = (AttributeModifier)entry.getValue(); - AttributeModifier attributemodifier1 = new AttributeModifier(attributemodifier.getName(), potion.getAttributeModifierAmount(potioneffect.getAmplifier(), attributemodifier), attributemodifier.isMultiplied()); + AttributeModifier attributemodifier1 = new AttributeModifier(attributemodifier.getName(), potion.getAmount(potioneffect.getAmplifier(), attributemodifier), attributemodifier.isMultiplied()); Set set = multimap.get(entry.getKey()); if(set == null) multimap.put(entry.getKey(), set = Sets.newHashSet()); @@ -283,7 +283,7 @@ public class ItemPotion extends Item if (potioneffect.getDuration() > 20) { - s1 = s1 + " (" + Potion.getDurationString(potioneffect) + ")"; + s1 = s1 + " (" + potioneffect.getDurationString() + ")"; } if (potion.isBadEffect()) @@ -384,7 +384,7 @@ public class ItemPotion extends Item } } - List list = PotionHelper.getPotionEffects(i1, false); + List list = PotionHelper.getPotionEffects(i1); if (list != null && !list.isEmpty()) { diff --git a/java/src/game/network/ClientPlayer.java b/java/src/game/network/ClientPlayer.java index f28fda2..45dc511 100755 --- a/java/src/game/network/ClientPlayer.java +++ b/java/src/game/network/ClientPlayer.java @@ -1404,8 +1404,8 @@ public class ClientPlayer extends NetHandler if (entity instanceof EntityLiving) { - PotionEffect potioneffect = new PotionEffect(packetIn.getEffectId(), packetIn.getDuration(), packetIn.getAmplifier(), false, packetIn.func_179707_f()); - potioneffect.setPotionDurationMax(packetIn.func_149429_c()); + PotionEffect potioneffect = new PotionEffect(packetIn.getEffectId(), packetIn.getDuration(), packetIn.getAmplifier(), false, packetIn.hasParticles()) + .setRemaining(packetIn.getRemaining()); ((EntityLiving)entity).addEffect(potioneffect); } } diff --git a/java/src/game/network/Player.java b/java/src/game/network/Player.java index 62a2b59..c9022eb 100755 --- a/java/src/game/network/Player.java +++ b/java/src/game/network/Player.java @@ -1751,7 +1751,7 @@ public class Player extends NetHandler implements ICrafting, Executor this.admin = admin; if(!this.isAdmin() && this.entity != null && this.entity.noclip) { this.entity.noclip = false; - this.entity.flying &= this.entity.hasEffect(Potion.flying); + this.entity.flying &= this.entity.hasEffect(Potion.FLYING); this.entity.fallDistance = 0.0F; this.sendPlayerAbilities(); this.addFeed(TextColor.RED + "NoClip wurde deaktiviert"); @@ -2520,7 +2520,7 @@ public class Player extends NetHandler implements ICrafting, Executor break; case START_FLYING: - this.entity.flying = this.entity.hasEffect(Potion.flying) || this.entity.noclip; + this.entity.flying = this.entity.hasEffect(Potion.FLYING) || this.entity.noclip; break; case STOP_FLYING: @@ -2640,12 +2640,12 @@ public class Player extends NetHandler implements ICrafting, Executor if(this.isAdmin()) { // this.playerEntity.setCheat(!this.playerEntity.godmode); this.entity.fallDistance = 0.0F; - if(this.entity.hasEffect(Potion.digSpeed) && this.entity.getEffect(Potion.digSpeed).getAmplifier() == 255) { - this.entity.removeEffect(Potion.digSpeed.id); - this.entity.removeEffect(Potion.resistance.id); - this.entity.removeEffect(Potion.fireResistance.id); - this.entity.removeEffect(Potion.flying.id); - this.entity.removeEffect(Potion.manaBoost.id); + if(this.entity.hasEffect(Potion.HASTE) && this.entity.getEffect(Potion.HASTE).getAmplifier() == 255) { + this.entity.removeEffect(Potion.HASTE); + this.entity.removeEffect(Potion.RESISTANCE); + this.entity.removeEffect(Potion.FIRE_RESISTANCE); + this.entity.removeEffect(Potion.FLYING); + this.entity.removeEffect(Potion.MANA); this.addFeed(TextColor.RED + "Statuseffekte wurden entfernt"); } else { @@ -2653,11 +2653,11 @@ public class Player extends NetHandler implements ICrafting, Executor this.entity.setHealth(this.entity.getMaxHealth()); this.entity.setManaPoints(this.entity.getMaxMana()); this.entity.clearEffects(false); - this.entity.addEffect(new PotionEffect(Potion.digSpeed.id, Integer.MAX_VALUE, 255, false, false)); - this.entity.addEffect(new PotionEffect(Potion.resistance.id, Integer.MAX_VALUE, 255, false, false)); - this.entity.addEffect(new PotionEffect(Potion.fireResistance.id, Integer.MAX_VALUE, 0, false, false)); - this.entity.addEffect(new PotionEffect(Potion.flying.id, Integer.MAX_VALUE, 0, false, false)); - this.entity.addEffect(new PotionEffect(Potion.manaBoost.id, Integer.MAX_VALUE, 255, false, false)); + this.entity.addEffect(new PotionEffect(Potion.HASTE, Integer.MAX_VALUE, 255, false, false)); + this.entity.addEffect(new PotionEffect(Potion.RESISTANCE, Integer.MAX_VALUE, 255, false, false)); + this.entity.addEffect(new PotionEffect(Potion.FIRE_RESISTANCE, Integer.MAX_VALUE, 0, false, false)); + this.entity.addEffect(new PotionEffect(Potion.FLYING, Integer.MAX_VALUE, 0, false, false)); + this.entity.addEffect(new PotionEffect(Potion.MANA, Integer.MAX_VALUE, 255, false, false)); this.addFeed(TextColor.GREEN + "Statuseffekte wurden hinzugefügt"); } } @@ -2668,7 +2668,7 @@ public class Player extends NetHandler implements ICrafting, Executor if(!this.entity.noclip) this.entity.mountEntity(null); this.entity.noclip ^= true; - this.entity.flying &= this.entity.hasEffect(Potion.flying) || this.entity.noclip; + this.entity.flying &= this.entity.hasEffect(Potion.FLYING) || this.entity.noclip; this.entity.fallDistance = 0.0F; this.sendPlayerAbilities(); this.addFeed((this.entity.noclip ? TextColor.GREEN : TextColor.RED) + "NoClip ist jetzt " + (this.entity.noclip ? "eingeschaltet" : "ausgeschaltet")); @@ -2677,10 +2677,10 @@ public class Player extends NetHandler implements ICrafting, Executor case SPEED: if(this.isAdmin()) { - if(this.entity.hasEffect(Potion.moveSpeed)) - this.entity.removeEffect(Potion.moveSpeed.id); + if(this.entity.hasEffect(Potion.SPEED)) + this.entity.removeEffect(Potion.SPEED); else - this.entity.addEffect(new PotionEffect(Potion.moveSpeed.id, Integer.MAX_VALUE, 19, false, false)); + this.entity.addEffect(new PotionEffect(Potion.SPEED, Integer.MAX_VALUE, 19, false, false)); this.addFeed(TextColor.GREEN + "Deine Geschwindigkeit wurde auf %dx geändert", (int)(this.entity.getAIMoveSpeed() * 10.0f)); // int speed = this.playerEntity.speed != 1.0f ? 1 : 5; // this.playerEntity.speed = (float)speed; diff --git a/java/src/game/packet/S1DPacketEntityEffect.java b/java/src/game/packet/S1DPacketEntityEffect.java index 285d661..418d84b 100755 --- a/java/src/game/packet/S1DPacketEntityEffect.java +++ b/java/src/game/packet/S1DPacketEntityEffect.java @@ -5,15 +5,17 @@ import java.io.IOException; import game.network.ClientPlayer; import game.network.Packet; import game.network.PacketBuffer; +import game.potion.Potion; import game.potion.PotionEffect; public class S1DPacketEntityEffect implements Packet { private int entityId; - private byte effectId; + private Potion effectId; private int amplifier; private int duration; - private byte hideParticles; + private int remaining; + private boolean particles; public S1DPacketEntityEffect() { @@ -22,19 +24,20 @@ public class S1DPacketEntityEffect implements Packet public S1DPacketEntityEffect(int entityIdIn, PotionEffect effect) { this.entityId = entityIdIn; - this.effectId = (byte)(effect.getPotionID() & 255); + this.effectId = effect.getPotion(); this.amplifier = /* (byte)(*/ effect.getAmplifier(); // & 255); - if (effect.getDuration() > 32767) - { - this.duration = 32767; - } - else - { - this.duration = effect.getDuration(); - } +// if (effect.getDuration() > 32767) +// { +// this.duration = 32767; +// } +// else +// { + this.duration = effect.getDuration(); + this.remaining = effect.getRemaining(); +// } - this.hideParticles = (byte)(effect.getIsShowParticles() ? 1 : 0); + this.particles = effect.getIsShowParticles(); } /** @@ -43,10 +46,11 @@ public class S1DPacketEntityEffect implements Packet public void readPacketData(PacketBuffer buf) throws IOException { this.entityId = buf.readVarIntFromBuffer(); - this.effectId = buf.readByte(); + this.effectId = buf.readEnumValue(Potion.class); this.amplifier = buf.readVarIntFromBuffer(); this.duration = buf.readVarIntFromBuffer(); - this.hideParticles = buf.readByte(); + this.remaining = buf.readVarIntFromBuffer(); + this.particles = buf.readBoolean(); } /** @@ -55,17 +59,13 @@ public class S1DPacketEntityEffect implements Packet public void writePacketData(PacketBuffer buf) throws IOException { buf.writeVarIntToBuffer(this.entityId); - buf.writeByte(this.effectId); + buf.writeEnumValue(this.effectId); buf.writeVarIntToBuffer(this.amplifier); buf.writeVarIntToBuffer(this.duration); - buf.writeByte(this.hideParticles); + buf.writeVarIntToBuffer(this.remaining); + buf.writeBoolean(this.particles); } - - public boolean func_149429_c() - { - return this.duration == 32767; - } - + /** * Passes this Packet on to the NetHandler for processing. */ @@ -79,7 +79,7 @@ public class S1DPacketEntityEffect implements Packet return this.entityId; } - public byte getEffectId() + public Potion getEffectId() { return this.effectId; } @@ -94,8 +94,13 @@ public class S1DPacketEntityEffect implements Packet return this.duration; } - public boolean func_179707_f() + public int getRemaining() { - return this.hideParticles != 0; + return this.remaining; + } + + public boolean hasParticles() + { + return this.particles; } } diff --git a/java/src/game/packet/S1EPacketRemoveEntityEffect.java b/java/src/game/packet/S1EPacketRemoveEntityEffect.java index 09585f5..76af411 100755 --- a/java/src/game/packet/S1EPacketRemoveEntityEffect.java +++ b/java/src/game/packet/S1EPacketRemoveEntityEffect.java @@ -5,12 +5,13 @@ import java.io.IOException; import game.network.ClientPlayer; import game.network.Packet; import game.network.PacketBuffer; +import game.potion.Potion; import game.potion.PotionEffect; public class S1EPacketRemoveEntityEffect implements Packet { private int entityId; - private int effectId; + private Potion effectId; public S1EPacketRemoveEntityEffect() { @@ -19,7 +20,7 @@ public class S1EPacketRemoveEntityEffect implements Packet public S1EPacketRemoveEntityEffect(int entityIdIn, PotionEffect effect) { this.entityId = entityIdIn; - this.effectId = effect.getPotionID(); + this.effectId = effect.getPotion(); } /** @@ -28,7 +29,7 @@ public class S1EPacketRemoveEntityEffect implements Packet public void readPacketData(PacketBuffer buf) throws IOException { this.entityId = buf.readVarIntFromBuffer(); - this.effectId = buf.readUnsignedByte(); + this.effectId = buf.readEnumValue(Potion.class); } /** @@ -37,7 +38,7 @@ public class S1EPacketRemoveEntityEffect implements Packet public void writePacketData(PacketBuffer buf) throws IOException { buf.writeVarIntToBuffer(this.entityId); - buf.writeByte(this.effectId); + buf.writeEnumValue(this.effectId); } /** @@ -53,7 +54,7 @@ public class S1EPacketRemoveEntityEffect implements Packet return this.entityId; } - public int getEffectId() + public Potion getEffectId() { return this.effectId; } diff --git a/java/src/game/potion/Potion.java b/java/src/game/potion/Potion.java index 5e4ce25..f1a413d 100755 --- a/java/src/game/potion/Potion.java +++ b/java/src/game/potion/Potion.java @@ -2,8 +2,6 @@ package game.potion; import java.util.Map; import java.util.Map.Entry; -import java.util.Set; - import game.collect.Maps; import game.entity.DamageSource; @@ -16,398 +14,241 @@ import game.entity.projectile.EntityPotion; import game.entity.types.EntityLiving; import game.init.Config; -public class Potion -{ - public static final Potion[] POTION_TYPES = new Potion[32]; - private static final Map POTION_MAP = Maps.newHashMap(); - -// public static final Potion field_180151_b = null; - - public static final Potion moveSpeed = (new Potion(1, "speed", false, 8171462)) - .setPotionName("potion.moveSpeed", "Schnelligkeit", "Trank der Schnelligkeit").setIconIndex(0, 0).registerPotionAttributeModifier(Attributes.MOVEMENT_SPEED, "PotSpd", 0.20000000298023224D, true); - public static final Potion moveSlowdown = (new Potion(2, "slowness", true, 5926017)) - .setPotionName("potion.moveSlowdown", "Langsamkeit", "Trank der Langsamkeit").setIconIndex(1, 0).registerPotionAttributeModifier(Attributes.MOVEMENT_SPEED, "PotSlow", -0.15000000596046448D, true); - public static final Potion digSpeed = (new Potion(3, "haste", false, 14270531)) - .setPotionName("potion.digSpeed", "Eile", "Trank der Eile").setIconIndex(2, 0).setEffectiveness(1.5D); - public static final Potion digSlowdown = (new Potion(4, "mining_fatigue", true, 4866583)) - .setPotionName("potion.digSlowDown", "Abbaulähmung", "Trank der Trägheit").setIconIndex(3, 0); - public static final Potion damageBoost = (new PotionAttackDamage(5, "strength", false, 9643043)) - .setPotionName("potion.damageBoost", "Stärke", "Trank der Stärke").setIconIndex(4, 0).registerPotionAttributeModifier(Attributes.ATTACK_DAMAGE, "PotDmg", 2.5D, true); - public static final Potion heal = (new PotionHealth(6, "instant_health", false, 16262179)) - .setPotionName("potion.heal", "Direktheilung", "Trank der Heilung"); - public static final Potion harm = (new PotionHealth(7, "instant_damage", true, 4393481)) - .setPotionName("potion.harm", "Direktschaden", "Trank des Schadens"); - public static final Potion jump = (new Potion(8, "jump_boost", false, 2293580)) - .setPotionName("potion.jump", "Sprungkraft", "Trank der Sprungkraft").setIconIndex(2, 1); - public static final Potion confusion = (new Potion(9, "nausea", true, 5578058)) - .setPotionName("potion.confusion", "Übelkeit", "Trank der Übelkeit").setIconIndex(3, 1).setEffectiveness(0.25D); - public static final Potion regeneration = (new Potion(10, "regeneration", false, 13458603)) - .setPotionName("potion.regeneration", "Regeneration", "Trank der Regeneration").setIconIndex(7, 0).setEffectiveness(0.25D); - public static final Potion resistance = (new Potion(11, "resistance", false, 10044730)) - .setPotionName("potion.resistance", "Resistenz", "Trank des Widerstandes").setIconIndex(6, 1); - public static final Potion fireResistance = (new Potion(12, "fire_resistance", false, 14981690)) - .setPotionName("potion.fireResistance", "Feuerschutz", "Trank der Feuerresistenz").setIconIndex(7, 1); - public static final Potion manaBoost = (new Potion(13, "mana_boost", false, 3035801)).setPotionName("potion.manaBoost", "Manaschub", "Trank des Manaschubes").setIconIndex(0, 2); - public static final Potion flying = (new Potion(14, "flying", false, 8356754)) - .setPotionName("potion.flying", "Schweben", "Trank des Schwebens").setIconIndex(0, 1); - public static final Potion blindness = (new Potion(15, "blindness", true, 2039587)) - .setPotionName("potion.blindness", "Blindheit", "Trank der Blindheit").setIconIndex(5, 1).setEffectiveness(0.25D); - public static final Potion nightVision = (new Potion(16, "night_vision", false, 2039713)) - .setPotionName("potion.nightVision", "Nachtsicht", "Trank der Nachtsicht").setIconIndex(4, 1); - public static final Potion stability = (new Potion(17, "stability", false, 5797459)).setPotionName("potion.stability", "Stabilität", "Trank der Standfestigkeit").setIconIndex(1, 1).registerPotionAttributeModifier(Attributes.KNOCKBACK_RESISTANCE, "PotStbl", 1.0D, false); - public static final Potion weakness = (new PotionAttackDamage(18, "weakness", true, 4738376)) - .setPotionName("potion.weakness", "Schwäche", "Trank der Schwäche").setIconIndex(5, 0).registerPotionAttributeModifier(Attributes.ATTACK_DAMAGE, "PotWeak", 2.0D, false); - public static final Potion poison = (new Potion(19, "poison", true, 5149489)) - .setPotionName("potion.poison", "Vergiftung", "Trank der Vergiftung").setIconIndex(6, 0).setEffectiveness(0.25D); -// public static final Potion wither = (new Potion(20, "wither", true, 3484199)).setPotionName("potion.wither").setIconIndex(1, 2).setEffectiveness(0.25D); - public static final Potion healthBoost = (new PotionHealthBoost(21, "health_boost", false, 16284963)) - .setPotionName("potion.healthBoost", "Extraenergie", "Trank der Extraenergie").setIconIndex(2, 2).registerPotionAttributeModifier(Attributes.MAX_HEALTH, "PotHp", 4, false); - public static final Potion absorption = (new PotionAbsorption(22, "absorption", false, 2445989)) - .setPotionName("potion.absorption", "Absorption", "Trank der Absorption").setIconIndex(2, 2); -// public static final Potion saturation = (new PotionHealth(23, "saturation", false, 16262179)).setPotionName("potion.saturation"); - public static final Potion radiation = (new Potion(24, "radiation", true, 0x00ff00)) - .setPotionName("potion.radiation", "Strahlung", "Radioaktiver Trank").setIconIndex(3, 2); - -// public static final Potion field_180153_z = null; -// public static final Potion field_180147_A = null; -// public static final Potion field_180148_B = null; -// public static final Potion field_180149_C = null; -// public static final Potion field_180143_D = null; -// public static final Potion field_180144_E = null; -// public static final Potion field_180145_F = null; -// public static final Potion field_180146_G = null; +public enum Potion { + SPEED("speed", "Schnelligkeit", "Trank der Schnelligkeit", false, 8171462, new PotionModifier(Attributes.MOVEMENT_SPEED, "PotSpd", 0.2, true)), + SLOWNESS("slowness", "Langsamkeit", "Trank der Langsamkeit", true, 5926017, new PotionModifier(Attributes.MOVEMENT_SPEED, "PotSlow", -0.15, true)), + HASTE("haste", "Eile", "Trank der Eile", false, 14270531) { + public double getEffectiveness() { + return 1.5; + } + }, + FATIGUE("mining_fatigue", "Abbaulähmung", "Trank der Trägheit", true, 4866583), + STRENGTH("strength", "Stärke", "Trank der Stärke", false, 9643043, new PotionModifier(Attributes.ATTACK_DAMAGE, "PotDmg", 2.5, true)) { + public double getAmount(int amp, AttributeModifier modifier) { + return 1.3D * (double)(amp + 1); + } + }, + HEAL("instant_health", "Direktheilung", "Trank der Heilung", false, 16262179) { + public boolean isInstant() { + return true; + } + + public void onImpact(EntityPotion potion, EntityLiving thrower, EntityLiving entity, int amp, double effect) { + if(entity.arePotionsInverted()) { + if(Config.damagePotion) { + int dmg = (int)(effect * (double)(6 << amp) + 0.5D); + if(potion == null) + entity.attackEntityFrom(DamageSource.magic, dmg); + else + entity.attackEntityFrom(DamageSource.causeIndirectMagicDamage(potion, thrower), dmg); + } + } + else { + entity.heal(Math.max((int)(effect * (double)(4 << amp) + 0.5D), 0)); + } + } + }, + DAMAGE("instant_damage", "Direktschaden", "Trank des Schadens", true, 4393481) { + public boolean isInstant() { + return true; + } + + public void onImpact(EntityPotion potion, EntityLiving thrower, EntityLiving entity, int amp, double effect) { + if(!entity.arePotionsInverted()) { + if(Config.damagePotion) { + int dmg = (int)(effect * (double)(6 << amp) + 0.5D); + if(potion == null) + entity.attackEntityFrom(DamageSource.magic, dmg); + else + entity.attackEntityFrom(DamageSource.causeIndirectMagicDamage(potion, thrower), dmg); + } + } + else { + entity.heal(Math.max((int)(effect * (double)(4 << amp) + 0.5D), 0)); + } + } + }, + JUMP("jump_boost", "Sprungkraft", "Trank der Sprungkraft", false, 2293580), + NAUSEA("nausea", "Übelkeit", "Trank der Übelkeit", true, 5578058) { + public double getEffectiveness() { + return 0.25; + } + }, + REGENERATION("regeneration", "Regeneration", "Trank der Regeneration", false, 13458603) { + public void onUpdate(EntityLiving entity, int duration, int amp) { + int k = 50 >> amp; + if((k <= 0 || duration % k == 0) && entity.getHealth() < entity.getMaxHealth()) + entity.heal(1); + } - public final int id; - public final String sid; - private final Map modifiers = Maps.newHashMap(); - private final boolean bad; - private final int color; - private String name = ""; - private String display = ""; - private String potionDisplay = ""; -// private int icon = 0; - private double effectiveness; - private boolean usable; + public double getEffectiveness() { + return 0.25; + } + }, + RESISTANCE("resistance", "Resistenz", "Trank des Widerstandes", false, 10044730), + FIRE_RESISTANCE("fire_resistance", "Feuerschutz", "Trank der Feuerresistenz", false, 14981690), + MANA("mana_boost", "Manaschub", "Trank des Manaschubes", false, 3035801) { + public void onUpdate(EntityLiving entity, int duration, int amp) { + int k = 40 >> amp; + if((k <= 0 || duration % k == 0) && entity.getManaPoints() < entity.getMaxMana()) + entity.healMana(1); + } + }, + FLYING("flying", "Schweben", "Trank des Schwebens", false, 8356754), + BLINDNESS("blindness", "Blindheit", "Trank der Blindheit", true, 2039587) { + public double getEffectiveness() { + return 0.25; + } + }, + NIGHT_VISION("night_vision", "Nachtsicht", "Trank der Nachtsicht", false, 2039713), + STABILITY("stability", "Stabilität", "Trank der Standfestigkeit", false, 5797459, new PotionModifier(Attributes.KNOCKBACK_RESISTANCE, "PotStbl", 1.0, false)), + WEAKNESS("weakness", "Schwäche", "Trank der Schwäche", true, 4738376, new PotionModifier(Attributes.ATTACK_DAMAGE, "PotWeak", 2.0, false)) { + public double getAmount(int amp, AttributeModifier modifier) { + return (double)(-0.5F * (float)(amp + 1)); + } + }, + POISON("poison", "Vergiftung", "Trank der Vergiftung", true, 5149489) { + public void onUpdate(EntityLiving entity, int duration, int amp) { + int j = 25 >> amp; + if((j <= 0 || duration % j == 0) && (entity.worldObj.client || Config.damagePoison) && entity.getHealth() > 1) + entity.attackEntityFrom(DamageSource.magic, 1); + } - protected Potion(int potionID, String location, boolean badEffect, int potionColor) - { - this.id = potionID; - this.sid = location; - POTION_TYPES[potionID] = this; - POTION_MAP.put(location, this); - this.bad = badEffect; + public double getEffectiveness() { + return 0.25; + } + }, + HEALTH("health_boost", "Extraenergie", "Trank der Extraenergie", false, 16284963, new PotionModifier(Attributes.MAX_HEALTH, "PotHp", 4.0, false)) { + public void removeModifiers(EntityLiving entity, AttributeMap map, int amp) { + super.removeModifiers(entity, map, amp); + if(entity.getHealth() > entity.getMaxHealth()) + entity.setHealth(entity.getMaxHealth()); + } + }, + ABSORPTION("absorption", "Absorption", "Trank der Absorption", false, 2445989) { + public void removeModifiers(EntityLiving entity, AttributeMap map, int amp) { + entity.setAbsorptionAmount(entity.getAbsorptionAmount() - (4 * (amp + 1))); + super.removeModifiers(entity, map, amp); + } - if (badEffect) - { - this.effectiveness = 0.5D; - } - else - { - this.effectiveness = 1.0D; - } - - this.color = potionColor; - } - - public static Potion getPotionFromResourceLocation(String location) - { - return POTION_MAP.get(location); - } - - public static Set getPotionLocations() - { - return POTION_MAP.keySet(); - } - - private static String ticksToElapsedTime(int ticks) { - int i = ticks / 20; - int j = i / 60; - i = i % 60; - return i < 10 ? j + ":0" + i : j + ":" + i; + public void addModifiers(EntityLiving entity, AttributeMap map, int amp) { + entity.setAbsorptionAmount(entity.getAbsorptionAmount() + (4 * (amp + 1))); + super.addModifiers(entity, map, amp); + } + }, + RADIATION("radiation", "Strahlung", "Radioaktiver Trank", true, 0x00ff00) { + public void onUpdate(EntityLiving entity, int duration, int amp) { + if(entity.ticksExisted % 20 == 0 && (entity.worldObj.client || Config.damageRadiation)) // && entityLivingBaseIn.getHealth() > 1.0F) + entity.attackEntityFrom(DamageSource.radiation, 1 + amp); + } + }; + + private static class PotionModifier { + private final Attribute attribute; + private final String id; + private final double value; + private final boolean multiply; + + public PotionModifier(Attribute attr, String id, double value, boolean multiply) { + this.attribute = attr; + this.id = id; + this.value = value; + this.multiply = multiply; + } } - /** - * Sets the index for the icon displayed in the player's inventory when the status is active. - */ - protected Potion setIconIndex(int color, int p_76399_2_) - { -// this.icon = color; - return this; - } - - /** - * returns the ID of the potion - */ - public int getId() - { - return this.id; - } - - public void performEffect(EntityLiving entityLivingBaseIn, int amp) - { - if (this.id == regeneration.id) - { - if (entityLivingBaseIn.getHealth() < entityLivingBaseIn.getMaxHealth()) - { - entityLivingBaseIn.heal(1); - } - } - else if (this.id == manaBoost.id) - { - if (entityLivingBaseIn.getManaPoints() < entityLivingBaseIn.getMaxMana()) - { - entityLivingBaseIn.healMana(1); - } - } - else if (this.id == poison.id) - { - if ((entityLivingBaseIn.worldObj.client || Config.damagePoison) && entityLivingBaseIn.getHealth() > 1) - { - entityLivingBaseIn.attackEntityFrom(DamageSource.magic, 1); - } - } - else if (this.id == radiation.id) - { - if (entityLivingBaseIn.worldObj.client || Config.damageRadiation) // && entityLivingBaseIn.getHealth() > 1.0F) - { - entityLivingBaseIn.attackEntityFrom(DamageSource.radiation, 1 + amp); - } - } -// else if (this.id == wither.id) -// { -// if(entityLivingBaseIn.worldObj.client || Config.withering) -// entityLivingBaseIn.attackEntityFrom(DamageSource.wither, 1); -// } -// else if (this.id == hunger.id && entityLivingBaseIn.isPlayer()) -// { -// ((EntityNPC)entityLivingBaseIn).addExhaustion(ExhaustionType.POTION, (float)(amp + 1)); -// } -// else if (this.id == saturation.id && entityLivingBaseIn.isPlayer()) -// { -// if (!entityLivingBaseIn.worldObj.client) -// { -// ((EntityNPC)entityLivingBaseIn).getFoodStats().addStats(amp + 1, 1.0F); -// } -// } - else if ((this.id != heal.id || entityLivingBaseIn.arePotionsInverted()) && (this.id != harm.id || !entityLivingBaseIn.arePotionsInverted())) - { - if (this.id == harm.id && !entityLivingBaseIn.arePotionsInverted() || this.id == heal.id && entityLivingBaseIn.arePotionsInverted()) - { - entityLivingBaseIn.attackEntityFrom(DamageSource.magic, 6 << amp); - } - } - else - { - entityLivingBaseIn.heal(Math.max(4 << amp, 0)); - } - } - - public void affectEntity(EntityPotion potion, EntityLiving thrower, EntityLiving entity, int amp, double effect) - { - if ((this.id != heal.id || entity.arePotionsInverted()) && (this.id != harm.id || !entity.arePotionsInverted())) - { - if (Config.damagePotion && (this.id == harm.id && !entity.arePotionsInverted() || this.id == heal.id && entity.arePotionsInverted())) - { - int dmg = (int)(effect * (double)(6 << amp) + 0.5D); - - if (potion == null) - { - entity.attackEntityFrom(DamageSource.magic, dmg); - } - else - { - entity.attackEntityFrom(DamageSource.causeIndirectMagicDamage(potion, thrower), dmg); - } - } - } - else - { - entity.heal(Math.max((int)(effect * (double)(4 << amp) + 0.5D), 0)); - } - } - - /** - * Returns true if the potion has an instant effect instead of a continuous one (eg Harming) - */ - public boolean isInstant() - { - return false; - } - - /** - * checks if Potion effect is ready to be applied this tick. - */ - public boolean isReady(int duration, int amp, int ticks) - { - if (this.id == regeneration.id) - { - int k = 50 >> amp; - return k > 0 ? duration % k == 0 : true; - } - else if (this.id == manaBoost.id) - { - int k = 40 >> amp; - return k > 0 ? duration % k == 0 : true; - } - else if (this.id == poison.id) - { - int j = 25 >> amp; - return j > 0 ? duration % j == 0 : true; - } - else if (this.id == radiation.id) - { - return ticks % 20 == 0; - } -// else if (this.id == wither.id) -// { -// int i = 40 >> amp; -// return i > 0 ? duration % i == 0 : true; -// } - else - { - return false; // this.id == hunger.id; - } - } - - /** - * Set the potion name. - */ - public Potion setPotionName(String name, String display, String potion) - { - this.name = name; - this.display = display; - this.potionDisplay = potion; - return this; - } - - /** - * returns the name of the potion - */ - public String getName() - { - return this.name; - } + private static final Map LOOKUP = Maps.newHashMap(); - public String getDisplay() - { - return this.display; - } - - public String getPotionDisplay() - { - return this.potionDisplay; - } + private final Map modifiers = Maps.newHashMap(); + private final String name; + private final String effectDisplay; + private final String potionDisplay; + private final boolean bad; + private final int color; - /** - * Returns true if the potion has a associated status icon to display in then inventory when active. - */ -// public boolean hasStatusIcon() -// { -// return this.icon >= 0; -// } + static { + for(Potion potion : values()) { + LOOKUP.put(potion.name, potion); + } + } -// /** -// * Returns the index for the icon to display when the potion is active. -// */ -// public int getStatusIconIndex() -// { -// return this.icon; -// } + public static Potion getByName(String name) { + return LOOKUP.get(name); + } - /** - * This method returns true if the potion effect is bad - negative - for the entity. - */ - public boolean isBadEffect() - { - return this.bad; - } + private Potion(String name, String effectDisplay, String potionDisplay, boolean bad, int color, PotionModifier ... modifiers) { + this.name = name; + this.bad = bad; + this.color = color; + this.effectDisplay = effectDisplay; + this.potionDisplay = potionDisplay; + for(PotionModifier modifier : modifiers) { + this.modifiers.put(modifier.attribute, new AttributeModifier(AttributeModifier.getModifierId(modifier.id), "potion." + name, modifier.value, modifier.multiply)); + } + } - public static String getDurationString(PotionEffect effect) - { - if (effect.getIsPotionDurationMax()) - { - return "**:**"; - } - else - { - int i = effect.getDuration(); - return ticksToElapsedTime(i); - } - } + public String getName() { + return this.name; + } - protected Potion setEffectiveness(double effectivenessIn) - { - this.effectiveness = effectivenessIn; - return this; - } + public String toString() { + return this.name; + } - public double getEffectiveness() - { - return this.effectiveness; - } + public String getDisplay() { + return this.effectDisplay; + } - public boolean isUsable() - { - return this.usable; - } + public String getPotionDisplay() { + return this.potionDisplay; + } - /** - * Returns the color of the potion liquid. - */ - public int getLiquidColor() - { - return this.color; - } + public boolean isBadEffect() { + return this.bad; + } - /** - * Used by potions to register the attribute they modify. - */ - public Potion registerPotionAttributeModifier(Attribute attr, String name, double value, boolean multiply) - { - AttributeModifier mod = new AttributeModifier(AttributeModifier.getModifierId(name), this.getName(), value, multiply); - this.modifiers.put(attr, mod); - return this; - } + public int getColor() { + return this.color; + } - public Map getAttributeModifierMap() - { - return this.modifiers; - } + public Map getModifiers() { + return this.modifiers; + } - public void removeAttributesModifiersFromEntity(EntityLiving entityLivingBaseIn, AttributeMap p_111187_2_, int amplifier) - { - for (Entry entry : this.modifiers.entrySet()) - { - AttributeInstance iattributeinstance = p_111187_2_.getAttributeInstance((Attribute)entry.getKey()); + public void onUpdate(EntityLiving entity, int duration, int amp) { + } - if (iattributeinstance != null) - { - iattributeinstance.removeModifier((AttributeModifier)entry.getValue()); - } - } - } + public void onImpact(EntityPotion potion, EntityLiving thrower, EntityLiving entity, int amp, double effect) { + } - public void applyAttributesModifiersToEntity(EntityLiving entityLivingBaseIn, AttributeMap p_111185_2_, int amplifier) - { - for (Entry entry : this.modifiers.entrySet()) - { - AttributeInstance iattributeinstance = p_111185_2_.getAttributeInstance((Attribute)entry.getKey()); + public boolean isInstant() { + return false; + } - if (iattributeinstance != null) - { - AttributeModifier attributemodifier = (AttributeModifier)entry.getValue(); - iattributeinstance.removeModifier(attributemodifier); - iattributeinstance.applyModifier(new AttributeModifier(attributemodifier.getID(), this.getName() + " " + amplifier, this.getAttributeModifierAmount(amplifier, attributemodifier), attributemodifier.isMultiplied())); - } - } - } + public double getAmount(int amp, AttributeModifier modifier) { + return modifier.getAmount() * (double)(amp + 1); + } - public double getAttributeModifierAmount(int p_111183_1_, AttributeModifier modifier) - { - return modifier.getAmount() * (double)(p_111183_1_ + 1); - } - - public String toString() { - return this.sid; - } + public double getEffectiveness() { + return this.bad ? 0.5 : 1.0; + } + + public void removeModifiers(EntityLiving entity, AttributeMap map, int amp) { + for(Entry entry : this.modifiers.entrySet()) { + AttributeInstance attr = map.getAttributeInstance(entry.getKey()); + if(attr != null) + attr.removeModifier(entry.getValue()); + } + } + + public void addModifiers(EntityLiving entity, AttributeMap map, int amp) { + for(Entry entry : this.modifiers.entrySet()) { + AttributeInstance attr = map.getAttributeInstance(entry.getKey()); + if(attr != null) { + AttributeModifier mod = entry.getValue(); + attr.removeModifier(mod); + attr.applyModifier(new AttributeModifier(mod.getID(), "potion." + this.name + " " + amp, this.getAmount(amp, mod), mod.isMultiplied())); + } + } + } } diff --git a/java/src/game/potion/PotionAbsorption.java b/java/src/game/potion/PotionAbsorption.java deleted file mode 100755 index 754d58e..0000000 --- a/java/src/game/potion/PotionAbsorption.java +++ /dev/null @@ -1,25 +0,0 @@ -package game.potion; - -import game.entity.attributes.AttributeMap; -import game.entity.types.EntityLiving; - - -public class PotionAbsorption extends Potion -{ - protected PotionAbsorption(int potionID, String location, boolean badEffect, int potionColor) - { - super(potionID, location, badEffect, potionColor); - } - - public void removeAttributesModifiersFromEntity(EntityLiving entityLivingBaseIn, AttributeMap p_111187_2_, int amplifier) - { - entityLivingBaseIn.setAbsorptionAmount(entityLivingBaseIn.getAbsorptionAmount() - (4 * (amplifier + 1))); - super.removeAttributesModifiersFromEntity(entityLivingBaseIn, p_111187_2_, amplifier); - } - - public void applyAttributesModifiersToEntity(EntityLiving entityLivingBaseIn, AttributeMap p_111185_2_, int amplifier) - { - entityLivingBaseIn.setAbsorptionAmount(entityLivingBaseIn.getAbsorptionAmount() + (4 * (amplifier + 1))); - super.applyAttributesModifiersToEntity(entityLivingBaseIn, p_111185_2_, amplifier); - } -} diff --git a/java/src/game/potion/PotionAttackDamage.java b/java/src/game/potion/PotionAttackDamage.java deleted file mode 100755 index 0e0880c..0000000 --- a/java/src/game/potion/PotionAttackDamage.java +++ /dev/null @@ -1,17 +0,0 @@ -package game.potion; - -import game.entity.attributes.AttributeModifier; - - -public class PotionAttackDamage extends Potion -{ - protected PotionAttackDamage(int potionID, String location, boolean badEffect, int potionColor) - { - super(potionID, location, badEffect, potionColor); - } - - public double getAttributeModifierAmount(int p_111183_1_, AttributeModifier modifier) - { - return this.id == Potion.weakness.id ? (double)(-0.5F * (float)(p_111183_1_ + 1)) : 1.3D * (double)(p_111183_1_ + 1); - } -} diff --git a/java/src/game/potion/PotionEffect.java b/java/src/game/potion/PotionEffect.java index ef1fcbb..fdc7468 100755 --- a/java/src/game/potion/PotionEffect.java +++ b/java/src/game/potion/PotionEffect.java @@ -4,249 +4,151 @@ import game.entity.types.EntityLiving; import game.log.Log; import game.nbt.NBTTagCompound; -public class PotionEffect -{ - /** ID value of the potion this effect matches. */ - private int potionID; +public class PotionEffect { + private final Potion potion; + private final int duration; + private final int amplifier; + private final boolean ambient; + private final boolean particles; - /** The duration of the potion effect */ - private int duration; + private int remaining; + private boolean thrown; + + public PotionEffect(Potion id, int duration, int amplifier) { + this(id, duration, amplifier, false, true); + } - /** The amplifier of the potion effect */ - private int amplifier; + public PotionEffect(Potion id, int duration, int amplifier, boolean ambient, boolean showParticles) { + this.potion = id; + this.duration = this.remaining = duration; + this.amplifier = amplifier; + this.ambient = ambient; + this.particles = showParticles; + } - /** Whether the potion is a splash potion */ - private boolean isSplashPotion; + public PotionEffect(PotionEffect other) { + this.potion = other.potion; + this.duration = this.remaining = other.duration; + this.amplifier = other.amplifier; + this.ambient = other.ambient; + this.particles = other.particles; + } - /** Whether the potion effect came from a beacon */ - private boolean isAmbient; + public PotionEffect combine(PotionEffect other) { + if(this.potion != other.potion) + Log.JNI.warn("PotionEffect.combine(): Diese Methode sollte nur für gleiche Effekte aufgerufen werden!"); + int duration = this.duration; + int amplifier = this.amplifier; + int remaining = this.remaining; + boolean ambient = this.ambient; + if(other.amplifier > this.amplifier) { + amplifier = other.amplifier; + duration = other.duration; + remaining = other.remaining; + } + else if(other.amplifier == this.amplifier && this.remaining < other.remaining) { + duration = other.duration; + remaining = other.remaining; + } + else if(!other.ambient && this.ambient) { + ambient = other.ambient; + } + return new PotionEffect(this.potion, duration, amplifier, ambient, other.particles).setRemaining(remaining); + } - /** True if potion effect duration is at maximum, false otherwise. */ - private boolean isPotionDurationMax; - private boolean showParticles; + public Potion getPotion() { + return this.potion; + } - public PotionEffect(int id, int effectDuration) - { - this(id, effectDuration, 0); - } + public int getDuration() { + return this.duration; + } - public PotionEffect(int id, int effectDuration, int effectAmplifier) - { - this(id, effectDuration, effectAmplifier, false, true); - } + public boolean isInfinite() { + return this.duration == Integer.MAX_VALUE; + } - public PotionEffect(int id, int effectDuration, int effectAmplifier, boolean ambient, boolean showParticles) - { - this.potionID = id; - this.duration = effectDuration; - this.amplifier = effectAmplifier; - this.isAmbient = ambient; - this.showParticles = showParticles; - } + public int getRemaining() { + return this.remaining; + } - public PotionEffect(PotionEffect other) - { - this.potionID = other.potionID; - this.duration = other.duration; - this.amplifier = other.amplifier; - this.isAmbient = other.isAmbient; - this.showParticles = other.showParticles; - } + public int getAmplifier() { + return this.amplifier; + } - /** - * merges the input PotionEffect into this one if this.amplifier <= tomerge.amplifier. The duration in the supplied - * potion effect is assumed to be greater. - */ - public void combine(PotionEffect other) - { - if (this.potionID != other.potionID) - { - Log.JNI.warn("PotionEffect.combine(): Diese Methode sollte nur für gleiche Effekte aufgerufen werden!"); - } + public PotionEffect setThrown(boolean thrown) { + this.thrown = thrown; + return this; + } - if (other.amplifier > this.amplifier) - { - this.amplifier = other.amplifier; - this.duration = other.duration; - } - else if (other.amplifier == this.amplifier && this.duration < other.duration) - { - this.duration = other.duration; - } - else if (!other.isAmbient && this.isAmbient) - { - this.isAmbient = other.isAmbient; - } + public PotionEffect setRemaining(int remaining) { + this.remaining = remaining; + return this; + } - this.showParticles = other.showParticles; - } + public boolean isAmbient() { + return this.ambient; + } - /** - * Retrieve the ID of the potion this effect matches. - */ - public int getPotionID() - { - return this.potionID; - } + public boolean getIsShowParticles() { + return this.particles; + } - public int getDuration() - { - return this.duration; - } + public boolean onUpdate(EntityLiving entityIn) { + if(this.isInfinite() && this.remaining < 20 * 60) + this.remaining = Integer.MAX_VALUE; + if(this.remaining > 0) { + this.potion.onUpdate(entityIn, this.remaining, this.amplifier); + --this.remaining; + } + return this.remaining > 0; + } - public int getAmplifier() - { - return this.amplifier; - } + public String getEffectName() { + return this.potion.getDisplay(); + } - /** - * Set whether this potion is a splash potion. - */ - public void setSplashPotion(boolean splashPotion) - { - this.isSplashPotion = splashPotion; - } + public String getPotionName() { + return this.potion.getPotionDisplay(); + } - /** - * Gets whether this potion effect originated from a beacon - */ - public boolean getIsAmbient() - { - return this.isAmbient; - } + public String getDurationString() { + if(this.isInfinite()) + return "**:**"; + int secs = this.remaining / 20; + int hrs = secs / (60 * 60); + secs = secs % (60 * 60); + int mins = secs / 60; + secs = secs % 60; + return (hrs > 0 ? hrs + ":" + (mins < 10 ? "0" : "") : "") + mins + ":" + (secs < 10 ? "0" : "") + secs; + } - public boolean getIsShowParticles() - { - return this.showParticles; - } + public int hashCode() { + return this.potion.ordinal(); + } - public boolean onUpdate(EntityLiving entityIn) - { - if (this.duration > 0) - { - if (Potion.POTION_TYPES[this.potionID].isReady(this.duration, this.amplifier, entityIn.ticksExisted)) - { - this.performEffect(entityIn); - } + public boolean equals(Object obj) { + if(!(obj instanceof PotionEffect)) + return false; + PotionEffect other = (PotionEffect)obj; + return this.potion == other.potion && this.amplifier == other.amplifier && this.duration == other.duration + && this.thrown == other.thrown && this.remaining == other.remaining && this.ambient == other.ambient; + } - --this.duration; - } + public NBTTagCompound toNbt() { + NBTTagCompound nbt = new NBTTagCompound(); + nbt.setString("Type", this.potion.getName()); + nbt.setByte("Amplifier", (byte)this.amplifier); + nbt.setInteger("Duration", this.duration); + nbt.setInteger("Remaining", this.remaining); + nbt.setBoolean("Ambient", this.ambient); + nbt.setBoolean("Particles", this.particles); + return nbt; + } - return this.duration > 0; - } - - public void performEffect(EntityLiving entityIn) - { - if (this.duration > 0) - { - Potion.POTION_TYPES[this.potionID].performEffect(entityIn, this.amplifier); - } - } - - public String getEffectName() - { - return Potion.POTION_TYPES[this.potionID].getDisplay(); - } - - public String getPotionName() - { - return Potion.POTION_TYPES[this.potionID].getPotionDisplay(); - } - - public int hashCode() - { - return this.potionID; - } - - public String toString() - { - String s = ""; - - if (this.getAmplifier() > 0) - { - s = this.getEffectName() + " x " + (this.getAmplifier() + 1) + ", Duration: " + this.getDuration(); - } - else - { - s = this.getEffectName() + ", Duration: " + this.getDuration(); - } - - if (this.isSplashPotion) - { - s = s + ", Splash: true"; - } - - if (!this.showParticles) - { - s = s + ", Particles: false"; - } - - return Potion.POTION_TYPES[this.potionID].isUsable() ? "(" + s + ")" : s; - } - - public boolean equals(Object p_equals_1_) - { - if (!(p_equals_1_ instanceof PotionEffect)) - { - return false; - } - else - { - PotionEffect potioneffect = (PotionEffect)p_equals_1_; - return this.potionID == potioneffect.potionID && this.amplifier == potioneffect.amplifier && this.duration == potioneffect.duration && this.isSplashPotion == potioneffect.isSplashPotion && this.isAmbient == potioneffect.isAmbient; - } - } - - /** - * Write a custom potion effect to a potion item's NBT data. - */ - public NBTTagCompound writeCustomPotionEffectToNBT(NBTTagCompound nbt) - { - nbt.setByte("Id", (byte)this.getPotionID()); - nbt.setByte("Amplifier", (byte)this.getAmplifier()); - nbt.setInteger("Duration", this.getDuration()); - nbt.setBoolean("Ambient", this.getIsAmbient()); - nbt.setBoolean("ShowParticles", this.getIsShowParticles()); - return nbt; - } - - /** - * Read a custom potion effect from a potion item's NBT data. - */ - public static PotionEffect readCustomPotionEffectFromNBT(NBTTagCompound nbt) - { - int i = nbt.getByte("Id"); - - if (i >= 0 && i < Potion.POTION_TYPES.length && Potion.POTION_TYPES[i] != null) - { - int j = (int)(nbt.getByte("Amplifier") & 255); - int k = nbt.getInteger("Duration"); - boolean flag = nbt.getBoolean("Ambient"); - boolean flag1 = true; - - if (nbt.hasKey("ShowParticles", 1)) - { - flag1 = nbt.getBoolean("ShowParticles"); - } - - return new PotionEffect(i, k, j, flag, flag1); - } - else - { - return null; - } - } - - /** - * Toggle the isPotionDurationMax field. - */ - public void setPotionDurationMax(boolean maxDuration) - { - this.isPotionDurationMax = maxDuration; - } - - public boolean getIsPotionDurationMax() - { - return this.isPotionDurationMax; - } + public static PotionEffect fromNbt(NBTTagCompound nbt) { + Potion potion = Potion.getByName(nbt.getString("Type")); + return potion == null ? null : new PotionEffect(potion, nbt.getInteger("Duration"), (int)(nbt.getByte("Amplifier") & 255), nbt.getBoolean("Ambient"), nbt.getBoolean("Particles")) + .setRemaining(nbt.getInteger("Remaining")); + } } diff --git a/java/src/game/potion/PotionHealth.java b/java/src/game/potion/PotionHealth.java deleted file mode 100755 index 005dadf..0000000 --- a/java/src/game/potion/PotionHealth.java +++ /dev/null @@ -1,27 +0,0 @@ -package game.potion; - - - -public class PotionHealth extends Potion -{ - public PotionHealth(int potionID, String location, boolean badEffect, int potionColor) - { - super(potionID, location, badEffect, potionColor); - } - - /** - * Returns true if the potion has an instant effect instead of a continuous one (eg Harming) - */ - public boolean isInstant() - { - return true; - } - - /** - * checks if Potion effect is ready to be applied this tick. - */ - public boolean isReady(int duration, int amp, int ticks) - { - return duration >= 1; - } -} diff --git a/java/src/game/potion/PotionHealthBoost.java b/java/src/game/potion/PotionHealthBoost.java deleted file mode 100755 index e613736..0000000 --- a/java/src/game/potion/PotionHealthBoost.java +++ /dev/null @@ -1,23 +0,0 @@ -package game.potion; - -import game.entity.attributes.AttributeMap; -import game.entity.types.EntityLiving; - - -public class PotionHealthBoost extends Potion -{ - public PotionHealthBoost(int potionID, String location, boolean badEffect, int potionColor) - { - super(potionID, location, badEffect, potionColor); - } - - public void removeAttributesModifiersFromEntity(EntityLiving entityLivingBaseIn, AttributeMap p_111187_2_, int amplifier) - { - super.removeAttributesModifiersFromEntity(entityLivingBaseIn, p_111187_2_, amplifier); - - if (entityLivingBaseIn.getHealth() > entityLivingBaseIn.getMaxHealth()) - { - entityLivingBaseIn.setHealth(entityLivingBaseIn.getMaxHealth()); - } - } -} diff --git a/java/src/game/potion/PotionHelper.java b/java/src/game/potion/PotionHelper.java index 55014d7..a907121 100755 --- a/java/src/game/potion/PotionHelper.java +++ b/java/src/game/potion/PotionHelper.java @@ -26,8 +26,8 @@ public class PotionHelper public static final String pufferfishEffect = "+0-1+2+3+13&4-4"; // public static final String rabbitFootEffect = "+0+1-2+3&4-4+13"; - private static final Map potionRequirements = Maps.newHashMap(); - private static final Map potionAmplifiers = Maps.newHashMap(); + private static final Map potionRequirements = Maps.newEnumMap(Potion.class); + private static final Map potionAmplifiers = Maps.newEnumMap(Potion.class); private static final Map DATAVALUE_COLORS = Maps.newHashMap(); private static final String[] potionPrefixes = new String[] { @@ -96,7 +96,7 @@ public class PotionHelper { if (potioneffect.getIsShowParticles()) { - int j = Potion.POTION_TYPES[potioneffect.getPotionID()].getLiquidColor(); + int j = potioneffect.getPotion().getColor(); for (int k = 0; k <= potioneffect.getAmplifier(); ++k) { @@ -133,7 +133,7 @@ public class PotionHelper { for (PotionEffect potioneffect : potionEffects) { - if (!potioneffect.getIsAmbient()) + if (!potioneffect.isAmbient()) { return false; } @@ -151,7 +151,7 @@ public class PotionHelper } else { - int i = calcPotionLiquidColor(getPotionEffects(key.intValue(), false)); + int i = calcPotionLiquidColor(getPotionEffects(key.intValue())); DATAVALUE_COLORS.put(key, Integer.valueOf(i)); return i; } @@ -168,32 +168,32 @@ public class PotionHelper return value >= 1 && value <= 9 ? " " + POTENCIES[value - 1] : (value == 0 ? "" : (" " + (value + 1))); } - private static int getPotionEffect(boolean p_77904_0_, boolean p_77904_1_, boolean p_77904_2_, int p_77904_3_, int p_77904_4_, int p_77904_5_, int p_77904_6_) + private static int getPotionEffect(boolean p_77904_0_, boolean p_77904_1_, boolean p_77904_2_, int p_77904_3_, int p_77904_4_, int p_77904_5_, int meta) { int i = 0; if (p_77904_0_) { - i = isFlagUnset(p_77904_6_, p_77904_4_); + i = isFlagUnset(meta, p_77904_4_); } else if (p_77904_3_ != -1) { - if (p_77904_3_ == 0 && countSetFlags(p_77904_6_) == p_77904_4_) + if (p_77904_3_ == 0 && countSetFlags(meta) == p_77904_4_) { i = 1; } - else if (p_77904_3_ == 1 && countSetFlags(p_77904_6_) > p_77904_4_) + else if (p_77904_3_ == 1 && countSetFlags(meta) > p_77904_4_) { i = 1; } - else if (p_77904_3_ == 2 && countSetFlags(p_77904_6_) < p_77904_4_) + else if (p_77904_3_ == 2 && countSetFlags(meta) < p_77904_4_) { i = 1; } } else { - i = isFlagSet(p_77904_6_, p_77904_4_); + i = isFlagSet(meta, p_77904_4_); } if (p_77904_1_) @@ -212,27 +212,27 @@ public class PotionHelper /** * Returns the number of 1 bits in the given integer. */ - private static int countSetFlags(int p_77907_0_) + private static int countSetFlags(int meta) { int i; - for (i = 0; p_77907_0_ > 0; ++i) + for (i = 0; meta > 0; ++i) { - p_77907_0_ &= p_77907_0_ - 1; + meta &= meta - 1; } return i; } - private static int parsePotionEffects(String p_77912_0_, int p_77912_1_, int p_77912_2_, int p_77912_3_) + private static int parsePotionEffects(String data, int start, int end, int meta) { - if (p_77912_1_ < p_77912_0_.length() && p_77912_2_ >= 0 && p_77912_1_ < p_77912_2_) + if (start < data.length() && end >= 0 && start < end) { - int i = p_77912_0_.indexOf(124, p_77912_1_); + int i = data.indexOf(124, start); - if (i >= 0 && i < p_77912_2_) + if (i >= 0 && i < end) { - int l1 = parsePotionEffects(p_77912_0_, p_77912_1_, i - 1, p_77912_3_); + int l1 = parsePotionEffects(data, start, i - 1, meta); if (l1 > 0) { @@ -240,17 +240,17 @@ public class PotionHelper } else { - int j2 = parsePotionEffects(p_77912_0_, i + 1, p_77912_2_, p_77912_3_); + int j2 = parsePotionEffects(data, i + 1, end, meta); return j2 > 0 ? j2 : 0; } } else { - int j = p_77912_0_.indexOf(38, p_77912_1_); + int j = data.indexOf(38, start); - if (j >= 0 && j < p_77912_2_) + if (j >= 0 && j < end) { - int i2 = parsePotionEffects(p_77912_0_, p_77912_1_, j - 1, p_77912_3_); + int i2 = parsePotionEffects(data, start, j - 1, meta); if (i2 <= 0) { @@ -258,7 +258,7 @@ public class PotionHelper } else { - int k2 = parsePotionEffects(p_77912_0_, j + 1, p_77912_2_, p_77912_3_); + int k2 = parsePotionEffects(data, j + 1, end, meta); return k2 <= 0 ? 0 : (i2 > k2 ? i2 : k2); } } @@ -274,9 +274,9 @@ public class PotionHelper int i1 = 0; int j1 = 0; - for (int k1 = p_77912_1_; k1 < p_77912_2_; ++k1) + for (int k1 = start; k1 < end; ++k1) { - char c0 = p_77912_0_.charAt(k1); + char c0 = data.charAt(k1); if (c0 >= 48 && c0 <= 57) { @@ -300,7 +300,7 @@ public class PotionHelper { if (flag2) { - j1 += getPotionEffect(flag3, flag1, flag4, k, l, i1, p_77912_3_); + j1 += getPotionEffect(flag3, flag1, flag4, k, l, i1, meta); flag3 = false; flag4 = false; flag = false; @@ -317,7 +317,7 @@ public class PotionHelper { if (flag2) { - j1 += getPotionEffect(flag3, flag1, flag4, k, l, i1, p_77912_3_); + j1 += getPotionEffect(flag3, flag1, flag4, k, l, i1, meta); flag3 = false; flag4 = false; flag = false; @@ -334,7 +334,7 @@ public class PotionHelper { if (c0 == 43 && flag2) { - j1 += getPotionEffect(flag3, flag1, flag4, k, l, i1, p_77912_3_); + j1 += getPotionEffect(flag3, flag1, flag4, k, l, i1, meta); flag3 = false; flag4 = false; flag = false; @@ -349,7 +349,7 @@ public class PotionHelper { if (flag2) { - j1 += getPotionEffect(flag3, flag1, flag4, k, l, i1, p_77912_3_); + j1 += getPotionEffect(flag3, flag1, flag4, k, l, i1, meta); flag3 = false; flag4 = false; flag = false; @@ -377,7 +377,7 @@ public class PotionHelper if (flag2) { - j1 += getPotionEffect(flag3, flag1, flag4, k, l, i1, p_77912_3_); + j1 += getPotionEffect(flag3, flag1, flag4, k, l, i1, meta); } return j1; @@ -390,67 +390,67 @@ public class PotionHelper } } - public static List getPotionEffects(int meta, boolean all) + public static List getPotionEffects(int meta) { List list = null; - for (Potion potion : Potion.POTION_TYPES) + for (Potion potion : Potion.values()) { - if (potion != null && (!potion.isUsable() || all)) +// if (potion != null) // && (!potion.isUsable() || all)) +// { + String s = potionRequirements.get(potion); + + if (s != null) { - String s = (String)potionRequirements.get(Integer.valueOf(potion.getId())); + int i = parsePotionEffects(s, 0, s.length(), meta); - if (s != null) + if (i > 0) { - int i = parsePotionEffects(s, 0, s.length(), meta); + int j = 0; + String s1 = potionAmplifiers.get(potion); - if (i > 0) + if (s1 != null) { - int j = 0; - String s1 = (String)potionAmplifiers.get(Integer.valueOf(potion.getId())); + j = parsePotionEffects(s1, 0, s1.length(), meta); - if (s1 != null) + if (j < 0) { - j = parsePotionEffects(s1, 0, s1.length(), meta); - - if (j < 0) - { - j = 0; - } + j = 0; } + } - if (potion.isInstant()) - { - i = 1; - } - else - { - i = 1200 * (i * 3 + (i - 1) * 2); - i = i >> j; - i = (int)Math.round((double)i * potion.getEffectiveness()); - - if ((meta & 16384) != 0) - { - i = (int)Math.round((double)i * 0.75D + 0.5D); - } - } - - if (list == null) - { - list = Lists.newArrayList(); - } - - PotionEffect potioneffect = new PotionEffect(potion.getId(), i, j); + if (potion.isInstant()) + { + i = 1; + } + else + { + i = 1200 * (i * 3 + (i - 1) * 2); + i = i >> j; + i = (int)Math.round((double)i * potion.getEffectiveness()); if ((meta & 16384) != 0) { - potioneffect.setSplashPotion(true); + i = (int)Math.round((double)i * 0.75D + 0.5D); } - - list.add(potioneffect); } + + if (list == null) + { + list = Lists.newArrayList(); + } + + PotionEffect potioneffect = new PotionEffect(potion, i, j); + + if ((meta & 16384) != 0) + { + potioneffect.setThrown(true); + } + + list.add(potioneffect); } } +// } } return list; @@ -585,27 +585,27 @@ public class PotionHelper static { - potionRequirements.put(Integer.valueOf(Potion.regeneration.getId()), "0 & !1 & !2 & !3 & 0+6"); - potionRequirements.put(Integer.valueOf(Potion.moveSpeed.getId()), "!0 & 1 & !2 & !3 & 1+6"); - potionRequirements.put(Integer.valueOf(Potion.fireResistance.getId()), "0 & 1 & !2 & !3 & 0+6"); - potionRequirements.put(Integer.valueOf(Potion.heal.getId()), "0 & !1 & 2 & !3"); - potionRequirements.put(Integer.valueOf(Potion.poison.getId()), "!0 & !1 & 2 & !3 & 2+6"); - potionRequirements.put(Integer.valueOf(Potion.weakness.getId()), "!0 & !1 & !2 & 3 & 3+6"); - potionRequirements.put(Integer.valueOf(Potion.harm.getId()), "!0 & !1 & 2 & 3"); - potionRequirements.put(Integer.valueOf(Potion.moveSlowdown.getId()), "!0 & 1 & !2 & 3 & 3+6"); - potionRequirements.put(Integer.valueOf(Potion.damageBoost.getId()), "0 & !1 & !2 & 3 & 3+6"); - potionRequirements.put(Integer.valueOf(Potion.nightVision.getId()), "!0 & 1 & 2 & !3 & 2+6"); - potionRequirements.put(Integer.valueOf(Potion.stability.getId()), "!0 & 1 & 2 & 3 & 2+6"); -// potionRequirements.put(Integer.valueOf(Potion.waterBreathing.getId()), "0 & !1 & 2 & 3 & 2+6"); -// potionRequirements.put(Integer.valueOf(Potion.jump.getId()), "0 & 1 & !2 & 3 & 3+6"); - potionAmplifiers.put(Integer.valueOf(Potion.moveSpeed.getId()), "5"); - potionAmplifiers.put(Integer.valueOf(Potion.digSpeed.getId()), "5"); - potionAmplifiers.put(Integer.valueOf(Potion.damageBoost.getId()), "5"); - potionAmplifiers.put(Integer.valueOf(Potion.regeneration.getId()), "5"); - potionAmplifiers.put(Integer.valueOf(Potion.harm.getId()), "5"); - potionAmplifiers.put(Integer.valueOf(Potion.heal.getId()), "5"); - potionAmplifiers.put(Integer.valueOf(Potion.resistance.getId()), "5"); - potionAmplifiers.put(Integer.valueOf(Potion.poison.getId()), "5"); -// potionAmplifiers.put(Integer.valueOf(Potion.jump.getId()), "5"); + potionRequirements.put(Potion.REGENERATION, "0 & !1 & !2 & !3 & 0+6"); + potionRequirements.put(Potion.SPEED, "!0 & 1 & !2 & !3 & 1+6"); + potionRequirements.put(Potion.FIRE_RESISTANCE, "0 & 1 & !2 & !3 & 0+6"); + potionRequirements.put(Potion.HEAL, "0 & !1 & 2 & !3"); + potionRequirements.put(Potion.POISON, "!0 & !1 & 2 & !3 & 2+6"); + potionRequirements.put(Potion.WEAKNESS, "!0 & !1 & !2 & 3 & 3+6"); + potionRequirements.put(Potion.DAMAGE, "!0 & !1 & 2 & 3"); + potionRequirements.put(Potion.SLOWNESS, "!0 & 1 & !2 & 3 & 3+6"); + potionRequirements.put(Potion.STRENGTH, "0 & !1 & !2 & 3 & 3+6"); + potionRequirements.put(Potion.NIGHT_VISION, "!0 & 1 & 2 & !3 & 2+6"); + potionRequirements.put(Potion.STABILITY, "!0 & 1 & 2 & 3 & 2+6"); +// potionRequirements.put(Potion.waterBreathing, "0 & !1 & 2 & 3 & 2+6"); +// potionRequirements.put(Potion.jump, "0 & 1 & !2 & 3 & 3+6"); + potionAmplifiers.put(Potion.SPEED, "5"); + potionAmplifiers.put(Potion.HASTE, "5"); + potionAmplifiers.put(Potion.STRENGTH, "5"); + potionAmplifiers.put(Potion.REGENERATION, "5"); + potionAmplifiers.put(Potion.DAMAGE, "5"); + potionAmplifiers.put(Potion.HEAL, "5"); + potionAmplifiers.put(Potion.RESISTANCE, "5"); + potionAmplifiers.put(Potion.POISON, "5"); +// potionAmplifiers.put(Potion.jump, "5"); } } diff --git a/java/src/game/renderer/EntityRenderer.java b/java/src/game/renderer/EntityRenderer.java index 1ebb36f..a1c1584 100755 --- a/java/src/game/renderer/EntityRenderer.java +++ b/java/src/game/renderer/EntityRenderer.java @@ -406,7 +406,7 @@ public class EntityRenderer { GL11.glRotatef(40.0F - 8000.0F / (f1 + 200.0F), 0.0F, 0.0F, 1.0F); } - if (f < 0.0F || entitylivingbase.hasEffect(Potion.stability)) + if (f < 0.0F || entitylivingbase.hasEffect(Potion.STABILITY)) { return; } @@ -792,7 +792,7 @@ public class EntityRenderer { // f10 = 0.25F + f7 * 0.75F; // } - if (this.gm.thePlayer.hasEffect(Potion.nightVision)) + if (this.gm.thePlayer.hasEffect(Potion.NIGHT_VISION)) { float vis = this.getNightVisionBrightness(this.gm.thePlayer, partialTicks); float mult = 1.0F / red; @@ -886,7 +886,7 @@ public class EntityRenderer { private float getNightVisionBrightness(EntityLiving entitylivingbaseIn, float partialTicks) { - int i = entitylivingbaseIn.getEffect(Potion.nightVision).getDuration(); + int i = entitylivingbaseIn.getEffect(Potion.NIGHT_VISION).getRemaining(); return i > 200 ? 1.0F : 0.7F + ExtMath.sin(((float)i - partialTicks) * (float)Math.PI * 0.2F) * 0.3F; } @@ -1509,9 +1509,9 @@ public class EntityRenderer { this.fogColorBlue *= mult; double vfog = (entity.lastTickPosY + (entity.posY - entity.lastTickPosY) * (double)partial); // * world.dimension.getVoidFogYFactor(); - if (entity instanceof EntityLiving && ((EntityLiving)entity).hasEffect(Potion.blindness)) + if (entity instanceof EntityLiving && ((EntityLiving)entity).hasEffect(Potion.BLINDNESS)) { - int blind = ((EntityLiving)entity).getEffect(Potion.blindness).getDuration(); + int blind = ((EntityLiving)entity).getEffect(Potion.BLINDNESS).getRemaining(); if (blind < 20) { @@ -1544,7 +1544,7 @@ public class EntityRenderer { // this.fogColorBlue = this.fogColorBlue * (1.0F - shift) + this.fogColorBlue * 0.6F * shift; // } - if (entity instanceof EntityLiving && ((EntityLiving)entity).hasEffect(Potion.nightVision)) + if (entity instanceof EntityLiving && ((EntityLiving)entity).hasEffect(Potion.NIGHT_VISION)) { float vis = this.getNightVisionBrightness((EntityLiving)entity, partial); float mul = 1.0F / this.fogColorRed; @@ -1604,10 +1604,10 @@ public class EntityRenderer { if(distance >= 1.0f) { ; } - else if (entity instanceof EntityLiving && ((EntityLiving)entity).hasEffect(Potion.blindness)) + else if (entity instanceof EntityLiving && ((EntityLiving)entity).hasEffect(Potion.BLINDNESS)) { float far = 5.0F; - int effect = ((EntityLiving)entity).getEffect(Potion.blindness).getDuration(); + int effect = ((EntityLiving)entity).getEffect(Potion.BLINDNESS).getRemaining(); if (effect < 20) { diff --git a/java/src/game/tileentity/TileEntityBeacon.java b/java/src/game/tileentity/TileEntityBeacon.java index 7af15b6..6b57ffa 100755 --- a/java/src/game/tileentity/TileEntityBeacon.java +++ b/java/src/game/tileentity/TileEntityBeacon.java @@ -20,7 +20,7 @@ import game.world.WorldServer; public class TileEntityBeacon extends TileEntity implements ITickable { /** List of effects that Beacon can apply */ - public static final Potion[][] effectsList = new Potion[][] {{Potion.moveSpeed, Potion.digSpeed}, {Potion.resistance, Potion.jump}, {Potion.damageBoost}, {Potion.regeneration}}; + public static final Potion[][] effectsList = new Potion[][] {{Potion.SPEED, Potion.HASTE}, {Potion.RESISTANCE, Potion.JUMP}, {Potion.STRENGTH}, {Potion.REGENERATION}}; // private final List beamSegments = Lists.newArrayList(); // private long lastRenderUpdate; // private float charge; @@ -30,10 +30,10 @@ public class TileEntityBeacon extends TileEntity implements ITickable private int levels = -1; /** Primary potion effect given by this beacon. */ - private int primaryEffect; + private Potion primaryEffect; /** Secondary potion effect given by this beacon. */ - private int secondaryEffect; + private Potion secondaryEffect; /** Item given to this beacon as payment. */ // private ItemStack payment; @@ -65,7 +65,7 @@ public class TileEntityBeacon extends TileEntity implements ITickable private void addEffectsToPlayers() { - if (this.isComplete && this.levels > 0 && this.primaryEffect > 0) + if (this.isComplete && this.levels > 0 && this.primaryEffect != null) { double d0 = (double)(this.levels * 10 + 10); int i = 0; @@ -86,7 +86,7 @@ public class TileEntityBeacon extends TileEntity implements ITickable entityplayer.addEffect(new PotionEffect(this.primaryEffect, 180, i, true, true)); } - if (this.levels >= 4 && this.primaryEffect != this.secondaryEffect && this.secondaryEffect > 0) + if (this.levels >= 4 && this.primaryEffect != this.secondaryEffect && this.secondaryEffect != null) { for (EntityLiving entityplayer1 : list) { @@ -288,24 +288,24 @@ public class TileEntityBeacon extends TileEntity implements ITickable return 65536.0D; } - private int getEffect(int id) + private Potion getEffect(String id) { - if (id >= 0 && id < Potion.POTION_TYPES.length && Potion.POTION_TYPES[id] != null) - { - Potion potion = Potion.POTION_TYPES[id]; - return potion != Potion.moveSpeed && potion != Potion.digSpeed && potion != Potion.resistance && potion != Potion.jump && potion != Potion.damageBoost && potion != Potion.regeneration ? 0 : id; - } - else - { - return 0; - } + Potion potion = Potion.getByName(id); +// if (potion != null) +// { + return potion != Potion.SPEED && potion != Potion.HASTE && potion != Potion.RESISTANCE && potion != Potion.JUMP && potion != Potion.STRENGTH && potion != Potion.REGENERATION ? null : potion; +// } +// else +// { +// return null; +// } } public void readFromNBT(NBTTagCompound compound) { super.readFromNBT(compound); - this.primaryEffect = this.getEffect(compound.getInteger("Primary")); - this.secondaryEffect = this.getEffect(compound.getInteger("Secondary")); + this.primaryEffect = compound.hasKey("Primary", 8) ? this.getEffect(compound.getString("Primary")) : null; + this.secondaryEffect = compound.hasKey("Secondary", 8) ? this.getEffect(compound.getString("Secondary")) : null; this.levels = compound.getInteger("Levels"); // try { this.beamColor = DyeColor.getByName(compound.getString("Color")); @@ -318,8 +318,10 @@ public class TileEntityBeacon extends TileEntity implements ITickable public void writeToNBT(NBTTagCompound compound) { super.writeToNBT(compound); - compound.setInteger("Primary", this.primaryEffect); - compound.setInteger("Secondary", this.secondaryEffect); + if(this.primaryEffect != null) + compound.setString("Primary", this.primaryEffect.getName()); + if(this.secondaryEffect != null) + compound.setString("Secondary", this.secondaryEffect.getName()); compound.setInteger("Levels", this.levels); compound.setString("Color", this.beamColor.getName()); }