From e02410ee842973357123fbdf6ac15aba1b1df0c4 Mon Sep 17 00:00:00 2001 From: 17146 <1714673995@qq.com> Date: Tue, 30 Jul 2024 02:55:14 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=89=8B=E9=9B=B7=E7=9A=84?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../entity/HandGrenadeEntity.java | 21 +++++++------------ .../superbwarfare/item/HandGrenade.java | 21 +++++++++++++++++-- 2 files changed, 26 insertions(+), 16 deletions(-) diff --git a/src/main/java/net/mcreator/superbwarfare/entity/HandGrenadeEntity.java b/src/main/java/net/mcreator/superbwarfare/entity/HandGrenadeEntity.java index 8d7aa53f0..de411120f 100644 --- a/src/main/java/net/mcreator/superbwarfare/entity/HandGrenadeEntity.java +++ b/src/main/java/net/mcreator/superbwarfare/entity/HandGrenadeEntity.java @@ -59,18 +59,15 @@ public class HandGrenadeEntity extends ThrowableItemProjectile { @Override - protected void onHit(HitResult result) - { - switch(result.getType()) - { + protected void onHit(HitResult result) { + switch (result.getType()) { case BLOCK: BlockHitResult blockResult = (BlockHitResult) result; BlockPos resultPos = blockResult.getBlockPos(); BlockState state = this.level().getBlockState(resultPos); SoundEvent event = state.getBlock().getSoundType(state, this.level(), resultPos, this).getStepSound(); double speed = this.getDeltaMovement().length(); - if(speed > 0.1) - { + if (speed > 0.1) { this.level().playSound(null, result.getLocation().x, result.getLocation().y, result.getLocation().z, event, SoundSource.AMBIENT, 1.0F, 1.0F); } this.bounce(blockResult.getDirection()); @@ -81,8 +78,7 @@ public class HandGrenadeEntity extends ThrowableItemProjectile { Entity entity = entityResult.getEntity(); double speed_e = this.getDeltaMovement().length(); - if(speed_e > 0.1) - { + if (speed_e > 0.1) { entity.hurt(entity.damageSources().thrown(this, this.getOwner()), 1.0F); } this.bounce(Direction.getNearest(this.getDeltaMovement().x(), this.getDeltaMovement().y(), this.getDeltaMovement().z()).getOpposite()); @@ -93,17 +89,14 @@ public class HandGrenadeEntity extends ThrowableItemProjectile { } } - private void bounce(Direction direction) - { - switch(direction.getAxis()) - { + private void bounce(Direction direction) { + switch (direction.getAxis()) { case X: this.setDeltaMovement(this.getDeltaMovement().multiply(-0.5, 0.75, 0.75)); break; case Y: this.setDeltaMovement(this.getDeltaMovement().multiply(0.75, -0.25, 0.75)); - if(this.getDeltaMovement().y() < this.getGravity()) - { + if (this.getDeltaMovement().y() < this.getGravity()) { this.setDeltaMovement(this.getDeltaMovement().multiply(1, 0, 1)); } break; diff --git a/src/main/java/net/mcreator/superbwarfare/item/HandGrenade.java b/src/main/java/net/mcreator/superbwarfare/item/HandGrenade.java index bd902d8b1..34e1059df 100644 --- a/src/main/java/net/mcreator/superbwarfare/item/HandGrenade.java +++ b/src/main/java/net/mcreator/superbwarfare/item/HandGrenade.java @@ -1,6 +1,9 @@ package net.mcreator.superbwarfare.item; import net.mcreator.superbwarfare.entity.HandGrenadeEntity; +import net.mcreator.superbwarfare.init.ModDamageTypes; +import net.mcreator.superbwarfare.tools.CustomExplosion; +import net.mcreator.superbwarfare.tools.ParticleTool; import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResultHolder; import net.minecraft.world.entity.LivingEntity; @@ -9,6 +12,7 @@ import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Rarity; import net.minecraft.world.item.UseAnim; +import net.minecraft.world.level.Explosion; import net.minecraft.world.level.Level; import org.jetbrains.annotations.NotNull; @@ -33,8 +37,6 @@ public class HandGrenade extends Item { public void releaseUsing(ItemStack stack, Level worldIn, LivingEntity entityLiving, int timeLeft) { if (!worldIn.isClientSide) { if (entityLiving instanceof Player player) { - - int usingTime = this.getUseDuration(stack) - timeLeft; float power = Math.min(usingTime / 10.0f, 1.5f); @@ -52,6 +54,21 @@ public class HandGrenade extends Item { } } + @Override + public ItemStack finishUsingItem(ItemStack pStack, Level pLevel, LivingEntity pLivingEntity) { + if (!pLevel.isClientSide) { + CustomExplosion explosion = new CustomExplosion(pLevel, null, + ModDamageTypes.causeProjectileBoomDamage(pLevel.registryAccess(), pLivingEntity, pLivingEntity), 90, + pLivingEntity.getX(), pLivingEntity.getY(), pLivingEntity.getZ(), 10f, Explosion.BlockInteraction.KEEP).setDamageMultiplier(2); + explosion.explode(); + net.minecraftforge.event.ForgeEventFactory.onExplosionStart(pLevel, explosion); + explosion.finalizeExplosion(false); + ParticleTool.spawnMediumExplosionParticles(pLevel, pLivingEntity.position()); + } + + return super.finishUsingItem(pStack, pLevel, pLivingEntity); + } + @Override public int getUseDuration(ItemStack stack) { return 100;