你使用的系统:<window 64>
你用的JDK是: <1.8>
你使用的IDE:
你使用的IDE版本:<2020 02>
Forge版本: <31.2.0>
Minecraft版本: <1.15.2>
Mapping 文件版本: <20200514-1.15.1>
1.问题
如题
2.相关代码
只在重写的onPlayerStoppedUsing
方法中添加了一句
playerentity.attackEntityFrom(DamageSource.LIGHTNING_BOLT,2.0F);
代码如下:
public class ObsidianBow extends BowItem {
public ObsidianBow() {
super(new Properties().group(ModGroup.itemGroup));
}
@Override
public void onPlayerStoppedUsing(ItemStack stack, World worldIn, LivingEntity entityLiving, int timeLeft) {
if (entityLiving instanceof PlayerEntity) {
PlayerEntity playerentity = (PlayerEntity) entityLiving;
boolean flag = playerentity.abilities.isCreativeMode || EnchantmentHelper.getEnchantmentLevel(Enchantments.INFINITY, stack) > 0;
ItemStack itemstack = playerentity.findAmmo(stack);
int i = this.getUseDuration(stack) - timeLeft;
i = net.minecraftforge.event.ForgeEventFactory.onArrowLoose(stack, worldIn, playerentity, i, !itemstack.isEmpty() || flag);
if (i < 0) {
return;
}
playerentity.attackEntityFrom(DamageSource.LIGHTNING_BOLT,2.0F);//自行添加的语句
if (!itemstack.isEmpty() || flag) {
if (itemstack.isEmpty()) {
itemstack = new ItemStack(Items.ARROW);
}
float f = getArrowVelocity(i);
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);
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));
}
}
}
}
}
3.参考教程如下
参考教程