From eacc54128293951eb9a14d9b42c23199e4999b42 Mon Sep 17 00:00:00 2001 From: 17146 <1714673995@qq.com> Date: Tue, 13 Aug 2024 17:26:47 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=9D=E8=AF=95=E8=B0=83=E6=95=B4=E5=BC=80?= =?UTF-8?q?=E7=81=AB=E4=BD=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../superbwarfare/block/JumpPadBlock.java | 7 ++-- .../superbwarfare/client/ClickHandler.java | 1 - .../superbwarfare/entity/Mk42Entity.java | 6 ++-- .../superbwarfare/entity/Mle1934Entity.java | 35 ++++++++++--------- 4 files changed, 24 insertions(+), 25 deletions(-) diff --git a/src/main/java/net/mcreator/superbwarfare/block/JumpPadBlock.java b/src/main/java/net/mcreator/superbwarfare/block/JumpPadBlock.java index f307e72b3..95944025e 100644 --- a/src/main/java/net/mcreator/superbwarfare/block/JumpPadBlock.java +++ b/src/main/java/net/mcreator/superbwarfare/block/JumpPadBlock.java @@ -1,7 +1,6 @@ package net.mcreator.superbwarfare.block; -import net.mcreator.superbwarfare.entity.Mk42Entity; -import net.mcreator.superbwarfare.entity.Mle1934Entity; +import net.mcreator.superbwarfare.entity.ICannonEntity; import net.mcreator.superbwarfare.entity.TargetEntity; import net.mcreator.superbwarfare.init.ModSounds; import net.mcreator.superbwarfare.network.ModVariables; @@ -23,6 +22,7 @@ import net.minecraft.world.phys.shapes.CollisionContext; import net.minecraft.world.phys.shapes.Shapes; import net.minecraft.world.phys.shapes.VoxelShape; +@SuppressWarnings("deprecation") public class JumpPadBlock extends Block { public static final DirectionProperty FACING = HorizontalDirectionalBlock.FACING; @@ -31,7 +31,6 @@ public class JumpPadBlock extends Block { this.registerDefaultState(this.stateDefinition.any().setValue(FACING, Direction.NORTH)); } - @Override public boolean propagatesSkylightDown(BlockState state, BlockGetter reader, BlockPos pos) { return true; @@ -79,7 +78,7 @@ public class JumpPadBlock extends Block { super.entityInside(blockstate, level, pos, entity); // 禁止套娃 - if (entity instanceof TargetEntity || entity instanceof Mk42Entity || entity instanceof Mle1934Entity) return; + if (entity instanceof TargetEntity || entity instanceof ICannonEntity) return; boolean zooming = entity.getCapability(ModVariables.PLAYER_VARIABLES_CAPABILITY, null).map(c -> c.zooming).orElse(false); diff --git a/src/main/java/net/mcreator/superbwarfare/client/ClickHandler.java b/src/main/java/net/mcreator/superbwarfare/client/ClickHandler.java index 105737de8..17d53bbab 100644 --- a/src/main/java/net/mcreator/superbwarfare/client/ClickHandler.java +++ b/src/main/java/net/mcreator/superbwarfare/client/ClickHandler.java @@ -43,7 +43,6 @@ public class ClickHandler { int button = event.getButton(); if (button == GLFW.GLFW_MOUSE_BUTTON_LEFT) { ModUtils.PACKET_HANDLER.sendToServer(new FireMessage(1)); - ModUtils.PACKET_HANDLER.sendToServer(new VehicleFireMessage(0)); } if (button == GLFW.GLFW_MOUSE_BUTTON_RIGHT) { if (Minecraft.getInstance().player.hasEffect(ModMobEffects.SHOCK.get())) { diff --git a/src/main/java/net/mcreator/superbwarfare/entity/Mk42Entity.java b/src/main/java/net/mcreator/superbwarfare/entity/Mk42Entity.java index 99e0a167c..3d9a54a9a 100644 --- a/src/main/java/net/mcreator/superbwarfare/entity/Mk42Entity.java +++ b/src/main/java/net/mcreator/superbwarfare/entity/Mk42Entity.java @@ -16,7 +16,6 @@ import net.minecraft.network.protocol.game.ClientGamePacketListener; import net.minecraft.network.syncher.EntityDataAccessor; import net.minecraft.network.syncher.EntityDataSerializers; import net.minecraft.network.syncher.SynchedEntityData; -import net.minecraft.resources.ResourceLocation; import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerPlayer; import net.minecraft.sounds.SoundEvent; @@ -37,7 +36,6 @@ import net.minecraftforge.event.entity.living.LivingHurtEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.network.NetworkHooks; import net.minecraftforge.network.PlayMessages; -import net.minecraftforge.registries.ForgeRegistries; import software.bernie.geckolib.animatable.GeoEntity; import software.bernie.geckolib.core.animatable.instance.AnimatableInstanceCache; import software.bernie.geckolib.core.animation.AnimatableManager; @@ -119,12 +117,12 @@ public class Mk42Entity extends PathfinderMob implements GeoEntity, ICannonEntit @Override public SoundEvent getHurtSound(DamageSource ds) { - return ForgeRegistries.SOUND_EVENTS.getValue(new ResourceLocation("superbwarfare:hit")); + return ModSounds.HIT.get(); } @Override public SoundEvent getDeathSound() { - return ForgeRegistries.SOUND_EVENTS.getValue(new ResourceLocation("superbwarfare:hit")); + return ModSounds.HIT.get(); } @Override diff --git a/src/main/java/net/mcreator/superbwarfare/entity/Mle1934Entity.java b/src/main/java/net/mcreator/superbwarfare/entity/Mle1934Entity.java index 5e677a353..007c752be 100644 --- a/src/main/java/net/mcreator/superbwarfare/entity/Mle1934Entity.java +++ b/src/main/java/net/mcreator/superbwarfare/entity/Mle1934Entity.java @@ -17,7 +17,6 @@ import net.minecraft.network.protocol.game.ClientGamePacketListener; import net.minecraft.network.syncher.EntityDataAccessor; import net.minecraft.network.syncher.EntityDataSerializers; import net.minecraft.network.syncher.SynchedEntityData; -import net.minecraft.resources.ResourceLocation; import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerPlayer; import net.minecraft.sounds.SoundEvent; @@ -38,7 +37,6 @@ import net.minecraftforge.event.entity.living.LivingHurtEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.network.NetworkHooks; import net.minecraftforge.network.PlayMessages; -import net.minecraftforge.registries.ForgeRegistries; import software.bernie.geckolib.animatable.GeoEntity; import software.bernie.geckolib.core.animatable.instance.AnimatableInstanceCache; import software.bernie.geckolib.core.animation.AnimatableManager; @@ -108,12 +106,12 @@ public class Mle1934Entity extends PathfinderMob implements GeoEntity, ICannonEn @Override public SoundEvent getHurtSound(DamageSource ds) { - return ForgeRegistries.SOUND_EVENTS.getValue(new ResourceLocation("superbwarfare:hit")); + return ModSounds.HIT.get(); } @Override public SoundEvent getDeathSound() { - return ForgeRegistries.SOUND_EVENTS.getValue(new ResourceLocation("superbwarfare:hit")); + return ModSounds.HIT.get(); } @Override @@ -232,13 +230,22 @@ public class Mle1934Entity extends PathfinderMob implements GeoEntity, ICannonEn stack.shrink(salvoShoot ? 2 : 1); } - // TODO 将炮弹生成在正确的位置(现在均在中心) + // TODO 将炮弹生成在正确的位置(现在偏差值很大) + // 中心点距离发射位置(炮口)的距离 + final float radius = 1.5f; + // 两个炮管之间的距离 + final float length = 0.15f; + // 可能用的偏差值 + final float offset = 0.0f; + float yRot = this.getYRot(); //左炮管 CannonShellEntity entityToSpawnLeft = new CannonShellEntity(ModEntities.CANNON_SHELL.get(), player, level, hitDamage, explosionRadius, explosionDamage, fireProbability, fireTime).durability(durability); - entityToSpawnLeft.setPos(this.getX(), this.getEyeY(), this.getZ()); + entityToSpawnLeft.setPos(this.getX() + this.getBbWidth() / 2 + (radius - length) * Mth.cos(yRot) - offset, + this.getEyeY(), + this.getZ() + this.getBbWidth() / 2 + (radius + length) * Mth.sin(yRot)); entityToSpawnLeft.shoot(this.getLookAngle().x, this.getLookAngle().y, this.getLookAngle().z, 18, 0.1f); level.addFreshEntity(entityToSpawnLeft); @@ -247,24 +254,20 @@ public class Mle1934Entity extends PathfinderMob implements GeoEntity, ICannonEn CannonShellEntity entityToSpawnRight = new CannonShellEntity(ModEntities.CANNON_SHELL.get(), player, level, hitDamage, explosionRadius, explosionDamage, fireProbability, fireTime).durability(durability); - entityToSpawnRight.setPos(this.getX(), this.getEyeY(), this.getZ()); + entityToSpawnRight.setPos(this.getX() + this.getBbWidth() / 2 + (radius + length) * Mth.cos(yRot) + offset, + this.getEyeY(), + this.getZ() + this.getBbWidth() / 2 + (radius - length) * Mth.sin(yRot)); entityToSpawnRight.shoot(this.getLookAngle().x, this.getLookAngle().y, this.getLookAngle().z, 18, 0.1f); level.addFreshEntity(entityToSpawnRight); - player.getCapability(ModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> { - capability.recoilHorizon = 1; - }); + player.getCapability(ModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> capability.recoilHorizon = 1); } else { - player.getCapability(ModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> { - capability.recoilHorizon = -1; - }); + player.getCapability(ModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> capability.recoilHorizon = -1); } if (player instanceof ServerPlayer serverPlayer) { SoundTool.playLocalSound(serverPlayer, ModSounds.MK_42_FIRE_1P.get(), 2, 1); - ModUtils.queueServerWork(44, () -> { - SoundTool.playLocalSound(serverPlayer, ModSounds.MK_42_RELOAD.get(), 2, 1); - }); + ModUtils.queueServerWork(44, () -> SoundTool.playLocalSound(serverPlayer, ModSounds.MK_42_RELOAD.get(), 2, 1)); serverPlayer.level().playSound(null, serverPlayer.getOnPos(), ModSounds.MK_42_FIRE_3P.get(), SoundSource.PLAYERS, 6, 1); serverPlayer.level().playSound(null, serverPlayer.getOnPos(), ModSounds.MK_42_FAR.get(), SoundSource.PLAYERS, 16, 1); serverPlayer.level().playSound(null, serverPlayer.getOnPos(), ModSounds.MK_42_VERYFAR.get(), SoundSource.PLAYERS, 32, 1);