2025-03-11 00:23:54 +01:00
package game.potion ;
import java.util.Map ;
import java.util.Map.Entry ;
2025-03-16 17:40:47 +01:00
import com.google.common.collect.Maps ;
2025-03-11 00:23:54 +01:00
import java.util.Set ;
import game.entity.DamageSource ;
import game.entity.attributes.Attribute ;
import game.entity.attributes.AttributeInstance ;
import game.entity.attributes.AttributeMap ;
import game.entity.attributes.AttributeModifier ;
import game.entity.attributes.Attributes ;
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 < String , Potion > POTION_MAP = Maps . < String , Potion > 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 final int id ;
private final Map < Attribute , AttributeModifier > modifiers = Maps . < Attribute , AttributeModifier > 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 ;
protected Potion ( int potionID , String location , boolean badEffect , int potionColor )
{
this . id = potionID ;
POTION_TYPES [ potionID ] = this ;
POTION_MAP . put ( location , this ) ;
this . bad = badEffect ;
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 < String > 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 ;
}
/ * *
* 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 ;
}
public String getDisplay ( )
{
return this . display ;
}
public String getPotionDisplay ( )
{
return this . potionDisplay ;
}
/ * *
* Returns true if the potion has a associated status icon to display in then inventory when active .
* /
// public boolean hasStatusIcon()
// {
// return this.icon >= 0;
// }
// /**
// * Returns the index for the icon to display when the potion is active.
// */
// public int getStatusIconIndex()
// {
// return this.icon;
// }
/ * *
* This method returns true if the potion effect is bad - negative - for the entity .
* /
public boolean isBadEffect ( )
{
return this . bad ;
}
public static String getDurationString ( PotionEffect effect )
{
if ( effect . getIsPotionDurationMax ( ) )
{
return " **:** " ;
}
else
{
int i = effect . getDuration ( ) ;
return ticksToElapsedTime ( i ) ;
}
}
protected Potion setEffectiveness ( double effectivenessIn )
{
this . effectiveness = effectivenessIn ;
return this ;
}
public double getEffectiveness ( )
{
return this . effectiveness ;
}
public boolean isUsable ( )
{
return this . usable ;
}
/ * *
* Returns the color of the potion liquid .
* /
public int getLiquidColor ( )
{
return this . color ;
}
/ * *
* 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 Map < Attribute , AttributeModifier > getAttributeModifierMap ( )
{
return this . modifiers ;
}
public void removeAttributesModifiersFromEntity ( EntityLiving entityLivingBaseIn , AttributeMap p_111187_2_ , int amplifier )
{
for ( Entry < Attribute , AttributeModifier > entry : this . modifiers . entrySet ( ) )
{
AttributeInstance iattributeinstance = p_111187_2_ . getAttributeInstance ( ( Attribute ) entry . getKey ( ) ) ;
if ( iattributeinstance ! = null )
{
iattributeinstance . removeModifier ( ( AttributeModifier ) entry . getValue ( ) ) ;
}
}
}
public void applyAttributesModifiersToEntity ( EntityLiving entityLivingBaseIn , AttributeMap p_111185_2_ , int amplifier )
{
for ( Entry < Attribute , AttributeModifier > entry : this . modifiers . entrySet ( ) )
{
AttributeInstance iattributeinstance = p_111185_2_ . getAttributeInstance ( ( Attribute ) entry . getKey ( ) ) ;
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 getAttributeModifierAmount ( int p_111183_1_ , AttributeModifier modifier )
{
return modifier . getAmount ( ) * ( double ) ( p_111183_1_ + 1 ) ;
}
}