你使用的系统:window 64
你用的JDK是: 1.8
你使用的IDE:idea
你使用的IDE版本:2020
Forge版本: 31.2.0
Minecraft版本: 1.15.2
Mapping 文件版本: 20200514-1.15.1
为什么我这么写拿弓射人 那个人不会中毒
package com.tutorial.neutrino.instantiation.items;
import com.tutorial.neutrino.groups.ModGroup;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.enchantment.Enchantments;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.projectile.AbstractArrowEntity;
import net.minecraft.item.*;
import net.minecraft.potion.EffectInstance;
import net.minecraft.potion.Effects;
import net.minecraft.stats.Stats;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.SoundEvents;
import net.minecraft.world.World;
public class ObsidianBow extends BowItem {
private static final EffectInstance _effectInstance = new EffectInstance(Effects.POISON, 10 * 20, 1);
public ObsidianBow() {
super(new Properties().group(ModGroup.itemGroup));
}
@Override
public void onPlayerStoppedUsing(ItemStack stack, World worldIn, LivingEntity entityLiving, int timeLeft) {
if (entityLiving instanceof PlayerEntity) {//判断entityLiving是否为PlayerEntity实体 判断entityLiving是否为玩家
PlayerEntity playerentity = (PlayerEntity) entityLiving;//向上转型
//是创造或者游戏难度简单赋值flag为true
boolean flag = playerentity.abilities.isCreativeMode || EnchantmentHelper.getEnchantmentLevel(Enchantments.INFINITY, stack) > 0;
ItemStack itemstack = playerentity.findAmmo(stack);//找到stack的弹药赋值为itemstack
int i = this.getUseDuration(stack) - timeLeft;//获取蓄力了多久赋值i
i = net.minecraftforge.event.ForgeEventFactory.onArrowLoose(stack, worldIn, playerentity, i, !itemstack.isEmpty() || flag);//不知道
//如果没有蓄力则跳出方法
if (i < 0) {
return;
}
//如果有弹药或者在创造模式执行的语句
if (!itemstack.isEmpty() || flag) {
if (itemstack.isEmpty()) {
itemstack = new ItemStack(Items.ARROW);
}
//现在的变量f是箭的伤害
float f = getArrowVelocity(i);
//如果箭伤害大于0.1执行语句
if (!((double) f < 0.1D)) {
boolean flag1 = playerentity.abilities.isCreativeMode || (itemstack.getItem() instanceof ArrowItem && ((ArrowItem) itemstack.getItem()).isInfinite(itemstack, stack, playerentity));
if (!worldIn.isRemote) {
ArrowItem arrowitem = (ArrowItem) (itemstack.getItem() instanceof ArrowItem ? itemstack.getItem() : Items.ARROW);
playerentity.addPotionEffect(_effectInstance);
// entityLiving.addPotionEffect(_effectInstance);
AbstractArrowEntity abstractarrowentity = arrowitem.createArrow(worldIn, itemstack, playerentity);
abstractarrowentity = customeArrow(abstractarrowentity);
abstractarrowentity.shoot(playerentity, playerentity.rotationPitch, playerentity.rotationYaw, 0.0F, f * 3.0F, 1.0F);
if (f == 1.0F) {
abstractarrowentity.setIsCritical(true);
}
int j = EnchantmentHelper.getEnchantmentLevel(Enchantments.POWER, stack);
if (j > 0) {
abstractarrowentity.setDamage(abstractarrowentity.getDamage() + (double) j * 0.5D + 0.5D);
}
int k = EnchantmentHelper.getEnchantmentLevel(Enchantments.PUNCH, stack);
if (k > 0) {
abstractarrowentity.setKnockbackStrength(k);
}
if (EnchantmentHelper.getEnchantmentLevel(Enchantments.FLAME, stack) > 0) {
abstractarrowentity.setFire(100);
}
stack.damageItem(1, playerentity, (p_220009_1_) -> {
p_220009_1_.sendBreakAnimation(playerentity.getActiveHand());
});
if (flag1 || playerentity.abilities.isCreativeMode && (itemstack.getItem() == Items.SPECTRAL_ARROW || itemstack.getItem() == Items.TIPPED_ARROW)) {
abstractarrowentity.pickupStatus = AbstractArrowEntity.PickupStatus.CREATIVE_ONLY;
}
worldIn.addEntity(abstractarrowentity);
}
worldIn.playSound((PlayerEntity) null, playerentity.getPosX(), playerentity.getPosY(), playerentity.getPosZ(), SoundEvents.ENTITY_ARROW_SHOOT, SoundCategory.PLAYERS, 1.0F, 1.0F / (random.nextFloat() * 0.4F + 1.2F) + f * 0.5F);
if (!flag1 && !playerentity.abilities.isCreativeMode) {
itemstack.shrink(1);
if (itemstack.isEmpty()) {
playerentity.inventory.deleteStack(itemstack);
}
}
playerentity.addStat(Stats.ITEM_USED.get(this));
}
}
}
}
}