Skip to content

Commit

Permalink
kotlinized PotionEffect.java
Browse files Browse the repository at this point in the history
  • Loading branch information
SpoilerRules committed Jan 23, 2024
1 parent 609e689 commit 6f30646
Show file tree
Hide file tree
Showing 4 changed files with 132 additions and 223 deletions.
41 changes: 11 additions & 30 deletions src/main/java/net/minecraft/entity/EntityLivingBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,13 @@
import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
import com.google.common.collect.Maps;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.UUID;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.client.settings.GameSettings;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.ai.attributes.AttributeModifier;
import net.minecraft.entity.ai.attributes.BaseAttributeMap;
import net.minecraft.entity.ai.attributes.IAttribute;
import net.minecraft.entity.ai.attributes.IAttributeInstance;
import net.minecraft.entity.ai.attributes.ServersideAttributeMap;
import net.minecraft.entity.ai.attributes.*;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.item.EntityXPOrb;
import net.minecraft.entity.passive.EntityWolf;
Expand All @@ -30,35 +20,26 @@
import net.minecraft.item.Item;
import net.minecraft.item.ItemArmor;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTBase;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagFloat;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.nbt.NBTTagShort;
import net.minecraft.nbt.*;
import net.minecraft.network.play.server.S04PacketEntityEquipment;
import net.minecraft.network.play.server.S0BPacketAnimation;
import net.minecraft.network.play.server.S0DPacketCollectItem;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import net.minecraft.potion.PotionHelper;
import net.minecraft.scoreboard.Team;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.BlockPos;
import net.minecraft.util.CombatTracker;
import net.minecraft.util.DamageSource;
import net.minecraft.util.EntitySelectors;
import net.minecraft.util.EnumParticleTypes;
import net.minecraft.util.MathHelper;
import net.minecraft.util.Vector3D;
import net.minecraft.util.*;
import net.minecraft.world.World;
import net.minecraft.world.WorldServer;

import java.util.*;

public abstract class EntityLivingBase extends Entity {
private static final UUID sprintingSpeedBoostModifierUUID = UUID.fromString("662A6B8D-DA3E-4C1C-8813-96EA6097278D");
private static final AttributeModifier sprintingSpeedBoostModifier = (new AttributeModifier(sprintingSpeedBoostModifierUUID, "Sprinting speed boost", 0.30000001192092896D, 2)).setSaved(false);
private BaseAttributeMap attributeMap;
private final CombatTracker _combatTracker = new CombatTracker(this);
private final Map<Integer, PotionEffect> activePotionsMap = Maps.<Integer, PotionEffect>newHashMap();
private final Map<Integer, PotionEffect> activePotionsMap = Maps.newHashMap();
private final ItemStack[] previousEquipment = new ItemStack[5];
public boolean isSwingInProgress;
public int swingProgressInt;
Expand Down Expand Up @@ -397,10 +378,10 @@ public void readEntityFromNBT(NBTTagCompound tagCompund) {

for (int i = 0; i < nbttaglist.tagCount(); ++i) {
NBTTagCompound nbttagcompound = nbttaglist.getCompoundTagAt(i);
PotionEffect potioneffect = PotionEffect.readCustomPotionEffectFromNBT(nbttagcompound);
PotionEffect potioneffect = PotionEffect.Companion.readCustomPotionEffectFromNBT(nbttagcompound);

if (potioneffect != null) {
this.activePotionsMap.put(Integer.valueOf(potioneffect.getPotionID()), potioneffect);
this.activePotionsMap.put(potioneffect.getPotionID(), potioneffect);
}
}
}
Expand Down Expand Up @@ -431,7 +412,7 @@ protected void updatePotionEffects() {
Integer integer = (Integer) iterator.next();
PotionEffect potioneffect = (PotionEffect) this.activePotionsMap.get(integer);

if (!potioneffect.onUpdate(this)) {
if (!potioneffect.updatePotionDuration(this)) {
if (!this.worldObj.isRemote) {
iterator.remove();
this.onFinishedPotionEffect(potioneffect);
Expand Down Expand Up @@ -926,7 +907,7 @@ public final void setArrowCountInEntity(int count) {
}

private int getArmSwingAnimationEnd() {
return this.isPotionActive(Potion.digSpeed) ? 6 - (1 + this.getActivePotionEffect(Potion.digSpeed).getAmplifier()) * 1 : (this.isPotionActive(Potion.digSlowdown) ? 6 + (1 + this.getActivePotionEffect(Potion.digSlowdown).getAmplifier()) * 2 : 6);
return this.isPotionActive(Potion.digSpeed) ? 6 - (1 + this.getActivePotionEffect(Potion.digSpeed).getAmplifier()) : (this.isPotionActive(Potion.digSlowdown) ? 6 + (1 + this.getActivePotionEffect(Potion.digSlowdown).getAmplifier()) * 2 : 6);
}

public void swingItem() {
Expand Down Expand Up @@ -1083,7 +1064,7 @@ protected void jump() {
this.motionY = (double) this.getJumpUpwardsMotion();

if (this.isPotionActive(Potion.jump)) {
this.motionY += (double) ((float) (this.getActivePotionEffect(Potion.jump).getAmplifier() + 1) * 0.1F);
this.motionY += (float) (this.getActivePotionEffect(Potion.jump).getAmplifier() + 1) * 0.1F;
}

if (this.isSprinting()) {
Expand Down
37 changes: 19 additions & 18 deletions src/main/java/net/minecraft/item/ItemPotion.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Multimap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.ai.attributes.AttributeModifier;
import net.minecraft.entity.ai.attributes.IAttribute;
Expand All @@ -24,10 +20,15 @@
import net.minecraft.util.StatCollector;
import net.minecraft.world.World;

import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

public class ItemPotion extends Item
{
private Map<Integer, List<PotionEffect>> effectCache = Maps.<Integer, List<PotionEffect>>newHashMap();
private static final Map<List<PotionEffect>, Integer> SUB_ITEMS_CACHE = Maps.<List<PotionEffect>, Integer>newLinkedHashMap();
private final Map<Integer, List<PotionEffect>> effectCache = Maps.newHashMap();
private static final Map<List<PotionEffect>, Integer> SUB_ITEMS_CACHE = Maps.newLinkedHashMap();

public ItemPotion()
{
Expand All @@ -41,13 +42,13 @@ public List<PotionEffect> getEffects(ItemStack stack)
{
if (stack.hasTagCompound() && stack.getTagCompound().hasKey("CustomPotionEffects", 9))
{
List<PotionEffect> list1 = Lists.<PotionEffect>newArrayList();
List<PotionEffect> list1 = Lists.newArrayList();
NBTTagList nbttaglist = stack.getTagCompound().getTagList("CustomPotionEffects", 10);

for (int i = 0; i < nbttaglist.tagCount(); ++i)
{
NBTTagCompound nbttagcompound = nbttaglist.getCompoundTagAt(i);
PotionEffect potioneffect = PotionEffect.readCustomPotionEffectFromNBT(nbttagcompound);
PotionEffect potioneffect = PotionEffect.Companion.readCustomPotionEffectFromNBT(nbttagcompound);

if (potioneffect != null)
{
Expand All @@ -59,12 +60,12 @@ public List<PotionEffect> getEffects(ItemStack stack)
}
else
{
List<PotionEffect> list = (List)this.effectCache.get(Integer.valueOf(stack.getMetadata()));
List<PotionEffect> list = this.effectCache.get(stack.getMetadata());

if (list == null)
{
list = PotionHelper.getPotionEffects(stack.getMetadata(), false);
this.effectCache.put(Integer.valueOf(stack.getMetadata()), list);
this.effectCache.put(stack.getMetadata(), list);
}

return list;
Expand All @@ -73,7 +74,7 @@ public List<PotionEffect> getEffects(ItemStack stack)

public List<PotionEffect> getEffects(int meta)
{
List<PotionEffect> list = (List)this.effectCache.get(Integer.valueOf(meta));
List<PotionEffect> list = this.effectCache.get(Integer.valueOf(meta));

if (list == null)
{
Expand Down Expand Up @@ -211,7 +212,7 @@ public String getItemStackDisplayName(ItemStack stack)

if (list != null && !list.isEmpty())
{
String s2 = ((PotionEffect)list.get(0)).getEffectName();
String s2 = list.get(0).getEffectName();
s2 = s2 + ".postfix";
return s + StatCollector.translateToLocal(s2).trim();
}
Expand All @@ -228,7 +229,7 @@ public void addInformation(ItemStack stack, EntityPlayer playerIn, List<String>
if (stack.getMetadata() != 0)
{
List<PotionEffect> list = Items.potionitem.getEffects(stack);
Multimap<String, AttributeModifier> multimap = HashMultimap.<String, AttributeModifier>create();
Multimap<String, AttributeModifier> multimap = HashMultimap.create();

if (list != null && !list.isEmpty())
{
Expand All @@ -242,9 +243,9 @@ public void addInformation(ItemStack stack, EntityPlayer playerIn, List<String>
{
for (Entry<IAttribute, AttributeModifier> entry : map.entrySet())
{
AttributeModifier attributemodifier = (AttributeModifier)entry.getValue();
AttributeModifier attributemodifier = entry.getValue();
AttributeModifier attributemodifier1 = new AttributeModifier(attributemodifier.getName(), potion.getAttributeModifierAmount(potioneffect.getAmplifier(), attributemodifier), attributemodifier.getOperation());
multimap.put(((IAttribute)entry.getKey()).getAttributeUnlocalizedName(), attributemodifier1);
multimap.put(entry.getKey().getAttributeUnlocalizedName(), attributemodifier1);
}
}

Expand Down Expand Up @@ -281,7 +282,7 @@ public void addInformation(ItemStack stack, EntityPlayer playerIn, List<String>

for (Entry<String, AttributeModifier> entry1 : multimap.entries())
{
AttributeModifier attributemodifier2 = (AttributeModifier)entry1.getValue();
AttributeModifier attributemodifier2 = entry1.getValue();
double d0 = attributemodifier2.getAmount();
double d1;

Expand All @@ -296,12 +297,12 @@ public void addInformation(ItemStack stack, EntityPlayer playerIn, List<String>

if (d0 > 0.0D)
{
tooltip.add(EnumChatFormatting.BLUE + StatCollector.translateToLocalFormatted("attribute.modifier.plus." + attributemodifier2.getOperation(), new Object[] {ItemStack.DECIMALFORMAT.format(d1), StatCollector.translateToLocal("attribute.name." + (String)entry1.getKey())}));
tooltip.add(EnumChatFormatting.BLUE + StatCollector.translateToLocalFormatted("attribute.modifier.plus." + attributemodifier2.getOperation(), new Object[] {ItemStack.DECIMALFORMAT.format(d1), StatCollector.translateToLocal("attribute.name." + entry1.getKey())}));
}
else if (d0 < 0.0D)
{
d1 = d1 * -1.0D;
tooltip.add(EnumChatFormatting.RED + StatCollector.translateToLocalFormatted("attribute.modifier.take." + attributemodifier2.getOperation(), new Object[] {ItemStack.DECIMALFORMAT.format(d1), StatCollector.translateToLocal("attribute.name." + (String)entry1.getKey())}));
tooltip.add(EnumChatFormatting.RED + StatCollector.translateToLocalFormatted("attribute.modifier.take." + attributemodifier2.getOperation(), new Object[] {ItemStack.DECIMALFORMAT.format(d1), StatCollector.translateToLocal("attribute.name." + entry1.getKey())}));
}
}
}
Expand Down
Loading

0 comments on commit 6f30646

Please sign in to comment.