Skip to content

Commit

Permalink
Use the EnchantmentHelper instead of iteration
Browse files Browse the repository at this point in the history
  • Loading branch information
Ethryan committed Aug 8, 2024
1 parent 474e9e1 commit fa41dc7
Showing 1 changed file with 2 additions and 21 deletions.
23 changes: 2 additions & 21 deletions src/main/java/tb/common/block/BlockTBPlant.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import net.minecraft.block.IGrowable;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
Expand Down Expand Up @@ -150,27 +151,7 @@ public boolean onBlockActivated(World aWorld, int aX, int aY, int aZ, EntityPlay
// check for Growth Stage
if (aMeta >= growthStages - 1) {
// eval fortune on rightclick
int fortune = 0;
ItemStack heldItem = aPlayer.getHeldItem();
if (heldItem != null) {
if (heldItem.getEnchantmentTagList() != null) {
for (int i = 0; i < heldItem.getEnchantmentTagList()
.tagCount(); ++i) {
if (heldItem.getEnchantmentTagList()
.getCompoundTagAt(i)
.getInteger("id") == Enchantment.fortune.effectId) {
fortune = heldItem.getEnchantmentTagList()
.getCompoundTagAt(i)
.getInteger("lvl");

// Damage fortune item on crop break?
// heldItem.setItemDamage(heldItem.getItemDamage() + 1);
break;
}
}
}
}

int fortune = EnchantmentHelper.getFortuneModifier(aPlayer);
this.pRightClick = true;
this.dropBlockAsItem(aWorld, aX, aY, aZ, aMeta, fortune);
this.pRightClick = false;
Expand Down

0 comments on commit fa41dc7

Please sign in to comment.