diff --git a/src/main/java/net/mcreator/target/command/MediumExpCommand.java b/src/main/java/net/mcreator/target/command/MediumExpCommand.java deleted file mode 100644 index 9b08a687b..000000000 --- a/src/main/java/net/mcreator/target/command/MediumExpCommand.java +++ /dev/null @@ -1,54 +0,0 @@ -package net.mcreator.target.command; - -import net.mcreator.target.init.TargetModSounds; -import net.minecraft.commands.CommandSource; -import net.minecraft.commands.CommandSourceStack; -import net.minecraft.commands.Commands; -import net.minecraft.core.BlockPos; -import net.minecraft.network.chat.Component; -import net.minecraft.server.level.ServerLevel; -import net.minecraft.sounds.SoundSource; -import net.minecraft.world.level.Level; -import net.minecraft.world.phys.Vec2; -import net.minecraft.world.phys.Vec3; -import net.minecraftforge.event.RegisterCommandsEvent; -import net.minecraftforge.eventbus.api.SubscribeEvent; -import net.minecraftforge.fml.common.Mod; - -@Mod.EventBusSubscriber -public class MediumExpCommand { - @SubscribeEvent - public static void registerCommand(RegisterCommandsEvent event) { - event.getDispatcher().register(Commands.literal("target:mediumexp").requires(s -> s.hasPermission(4)) - .executes(arguments -> { - Level world = arguments.getSource().getUnsidedLevel(); - double x = arguments.getSource().getPosition().x(); - double y = arguments.getSource().getPosition().y(); - double z = arguments.getSource().getPosition().z(); - - if (!world.isClientSide()) { - world.playSound(null, BlockPos.containing(x, y + 1, z), TargetModSounds.EXPLOSION.get(), SoundSource.BLOCKS, 8, 1); - world.playSound(null, BlockPos.containing(x, y + 1, z), TargetModSounds.EXPLOSION_FAR.get(), SoundSource.BLOCKS, 16, 1); - world.playSound(null, BlockPos.containing(x, y + 1, z), TargetModSounds.EXPLOSION_VERY_FAR.get(), SoundSource.BLOCKS, 32, 1); - } else { - world.playLocalSound(x, (y + 1), z, TargetModSounds.EXPLOSION.get(), SoundSource.BLOCKS, 24, 1, false); - world.playLocalSound(x, (y + 1), z, TargetModSounds.EXPLOSION_FAR.get(), SoundSource.BLOCKS, 24, 1, false); - world.playLocalSound(x, (y + 1), z, TargetModSounds.EXPLOSION_VERY_FAR.get(), SoundSource.BLOCKS, 64, 1, false); - } - - if (world instanceof ServerLevel server) { -// server.sendParticles(ParticleTypes.CAMPFIRE_COSY_SMOKE, x, y, z, 80, 0.4, 1, 0.4, 0.02); - - server.getServer().getCommands().performPrefixedCommand(new CommandSourceStack(CommandSource.NULL, new Vec3(x, (y + 1), z), Vec2.ZERO, server, 4, "", Component.literal(""), server.getServer(), null).withSuppressedOutput(), - "particle minecraft:campfire_cosy_smoke ~ ~ ~ 0.4 1 0.4 0.02 80 force"); - server.getServer().getCommands().performPrefixedCommand(new CommandSourceStack(CommandSource.NULL, new Vec3(x, (y + 1), z), Vec2.ZERO, server, 4, "", Component.literal(""), server.getServer(), null).withSuppressedOutput(), - "particle minecraft:large_smoke ~ ~1 ~ 0.4 1 0.4 0.02 80 force"); - server.getServer().getCommands().performPrefixedCommand(new CommandSourceStack(CommandSource.NULL, new Vec3(x, (y + 1), z), Vec2.ZERO, server, 4, "", Component.literal(""), server.getServer(), null).withSuppressedOutput(), - "particle minecraft:campfire_cosy_smoke ~ ~ ~ 2 0.001 2 0.01 80 force"); - server.getServer().getCommands().performPrefixedCommand(new CommandSourceStack(CommandSource.NULL, new Vec3(x, (y + 1), z), Vec2.ZERO, server, 4, "", Component.literal(""), server.getServer(), null).withSuppressedOutput(), - "particle target:fire_star ~ ~ ~ 0 0 0 0.2 80 force"); - } - return 0; - })); - } -} diff --git a/src/main/java/net/mcreator/target/entity/GunGrenadeEntity.java b/src/main/java/net/mcreator/target/entity/GunGrenadeEntity.java index 1f76a3d95..f1f049fba 100644 --- a/src/main/java/net/mcreator/target/entity/GunGrenadeEntity.java +++ b/src/main/java/net/mcreator/target/entity/GunGrenadeEntity.java @@ -5,8 +5,8 @@ import net.mcreator.target.headshot.IHeadshotBox; import net.mcreator.target.init.TargetModEntities; import net.mcreator.target.init.TargetModSounds; import net.mcreator.target.network.TargetModVariables; -import net.minecraft.commands.CommandSource; -import net.minecraft.commands.CommandSourceStack; +import net.mcreator.target.tools.ParticleTool; +import net.minecraft.core.particles.ParticleTypes; import net.minecraft.network.protocol.Packet; import net.minecraft.network.protocol.game.ClientGamePacketListener; import net.minecraft.server.level.ServerLevel; @@ -89,9 +89,8 @@ public class GunGrenadeEntity extends AbstractArrow implements ItemSupplier { if (this.level() instanceof ServerLevel level) { level.explode(this, (this.getX()), (this.getY()), (this.getZ()), 5.5f, Level.ExplosionInteraction.NONE); - if (!entity.level().isClientSide() && entity.getServer() != null) { - entity.getServer().getCommands().performPrefixedCommand(new CommandSourceStack(CommandSource.NULL, entity.position(), entity.getRotationVector(), (ServerLevel) entity.level(), 4, - entity.getName().getString(), entity.getDisplayName(), entity.getServer(), entity), "target:mediumexp"); + if (!entity.level().isClientSide()) { + ParticleTool.spawnMediumExplosionParticles(this.level(), this.position()); } this.discard(); } @@ -155,15 +154,13 @@ public class GunGrenadeEntity extends AbstractArrow implements ItemSupplier { this.getPersistentData().putInt("fuse", this.getPersistentData().getInt("fuse") + 1); - // TODO 修改为正确的粒子效果添加 - if (!this.level().isClientSide() && this.getServer() != null) { - this.getServer().getCommands().performPrefixedCommand(new CommandSourceStack(CommandSource.NULL, this.position(), this.getRotationVector(), this.level() instanceof ServerLevel ? (ServerLevel) this.level() : null, 4, - this.getName().getString(), this.getDisplayName(), this.level().getServer(), this), "particle minecraft:campfire_cosy_smoke ~ ~ ~ 0 0 0 0 1 force"); + if (!this.level().isClientSide() && this.level() instanceof ServerLevel serverLevel) { + ParticleTool.sendParticle(serverLevel, ParticleTypes.CAMPFIRE_COSY_SMOKE, this.getX(), this.getY(), this.getZ(), + 1, 0, 0, 0, 0.02, true); } if (this.inGround) { - if (!this.level().isClientSide() && this.getServer() != null) { - this.getServer().getCommands().performPrefixedCommand(new CommandSourceStack(CommandSource.NULL, this.position(), this.getRotationVector(), this.level() instanceof ServerLevel ? (ServerLevel) this.level() : null, 4, - this.getName().getString(), this.getDisplayName(), this.level().getServer(), this), "target:mediumexp"); + if (!this.level().isClientSide()) { + ParticleTool.spawnMediumExplosionParticles(this.level(), this.position()); } this.discard(); } diff --git a/src/main/java/net/mcreator/target/entity/MortarShellEntity.java b/src/main/java/net/mcreator/target/entity/MortarShellEntity.java index ccde6540f..5b50dec6f 100644 --- a/src/main/java/net/mcreator/target/entity/MortarShellEntity.java +++ b/src/main/java/net/mcreator/target/entity/MortarShellEntity.java @@ -1,8 +1,8 @@ package net.mcreator.target.entity; import net.mcreator.target.init.TargetModEntities; -import net.minecraft.commands.CommandSource; -import net.minecraft.commands.CommandSourceStack; +import net.mcreator.target.tools.ParticleTool; +import net.minecraft.core.particles.ParticleTypes; import net.minecraft.network.protocol.Packet; import net.minecraft.network.protocol.game.ClientGamePacketListener; import net.minecraft.server.level.ServerLevel; @@ -71,8 +71,7 @@ public class MortarShellEntity extends AbstractArrow implements ItemSupplier { if (this.level() instanceof ServerLevel level) { level.explode(this, (this.getX()), (this.getY()), (this.getZ()), 10, Level.ExplosionInteraction.NONE); if (!entity.level().isClientSide() && entity.getServer() != null) { - entity.getServer().getCommands().performPrefixedCommand(new CommandSourceStack(CommandSource.NULL, entity.position(), entity.getRotationVector(), (ServerLevel) entity.level(), 4, - entity.getName().getString(), entity.getDisplayName(), entity.getServer(), entity), "target:mediumexp"); + ParticleTool.spawnMediumExplosionParticles(level, entity.position()); } } this.discard(); @@ -81,23 +80,21 @@ public class MortarShellEntity extends AbstractArrow implements ItemSupplier { @Override public void onHitBlock(BlockHitResult blockHitResult) { super.onHitBlock(blockHitResult); - if (this.level() instanceof ServerLevel level) { - level.explode(this, this.getX(), this.getY(), this.getZ(), 10, Level.ExplosionInteraction.NONE); + if (this.level() instanceof ServerLevel level) { + level.explode(this, this.getX(), this.getY(), this.getZ(), 10, Level.ExplosionInteraction.NONE); } } @Override public void tick() { super.tick(); - if (this.getServer() != null) { - // TODO 修改为正确的粒子效果播放方法 - this.getServer().getCommands().performPrefixedCommand(new CommandSourceStack(CommandSource.NULL, this.position(), this.getRotationVector(), this.level() instanceof ServerLevel ? (ServerLevel) this.level() : null, 4, - this.getName().getString(), this.getDisplayName(), this.level().getServer(), this), "particle minecraft:campfire_cosy_smoke ~ ~ ~ 0 0 0 0 2 force"); + if (this.level() instanceof ServerLevel serverLevel) { + ParticleTool.sendParticle(serverLevel, ParticleTypes.CAMPFIRE_COSY_SMOKE, this.getX(), this.getY(), this.getZ(), + 2, 0, 0, 0, 0.02, true); } if (this.inGround) { if (!this.level().isClientSide() && this.getServer() != null) { - this.getServer().getCommands().performPrefixedCommand(new CommandSourceStack(CommandSource.NULL, this.position(), this.getRotationVector(), this.level() instanceof ServerLevel ? (ServerLevel) this.level() : null, 4, - this.getName().getString(), this.getDisplayName(), this.level().getServer(), this), "target:mediumexp"); + ParticleTool.spawnMediumExplosionParticles(this.level(), this.position()); } this.discard(); } diff --git a/src/main/java/net/mcreator/target/tools/ParticleTool.java b/src/main/java/net/mcreator/target/tools/ParticleTool.java index be3fc9a9f..1dbc78c22 100644 --- a/src/main/java/net/mcreator/target/tools/ParticleTool.java +++ b/src/main/java/net/mcreator/target/tools/ParticleTool.java @@ -1,8 +1,15 @@ package net.mcreator.target.tools; +import net.mcreator.target.init.TargetModParticleTypes; +import net.mcreator.target.init.TargetModSounds; +import net.minecraft.core.BlockPos; import net.minecraft.core.particles.ParticleOptions; +import net.minecraft.core.particles.ParticleTypes; import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerPlayer; +import net.minecraft.sounds.SoundSource; +import net.minecraft.world.level.Level; +import net.minecraft.world.phys.Vec3; public class ParticleTool { public static void sendParticle(ServerLevel level, T particle, double x, double y, double z, int count, @@ -11,4 +18,28 @@ public class ParticleTool { level.sendParticles(serverPlayer, particle, force, x, y, z, count, xOffset, yOffset, zOffset, speed); } } + + public static void spawnMediumExplosionParticles(Level level, Vec3 pos) { + double x = pos.x; + double y = pos.y; + double z = pos.z; + + if (!level.isClientSide()) { + level.playSound(null, BlockPos.containing(x, y + 1, z), TargetModSounds.EXPLOSION.get(), SoundSource.BLOCKS, 8, 1); + level.playSound(null, BlockPos.containing(x, y + 1, z), TargetModSounds.EXPLOSION_FAR.get(), SoundSource.BLOCKS, 16, 1); + level.playSound(null, BlockPos.containing(x, y + 1, z), TargetModSounds.EXPLOSION_VERY_FAR.get(), SoundSource.BLOCKS, 32, 1); + } else { + level.playLocalSound(x, (y + 1), z, TargetModSounds.EXPLOSION.get(), SoundSource.BLOCKS, 24, 1, false); + level.playLocalSound(x, (y + 1), z, TargetModSounds.EXPLOSION_FAR.get(), SoundSource.BLOCKS, 24, 1, false); + level.playLocalSound(x, (y + 1), z, TargetModSounds.EXPLOSION_VERY_FAR.get(), SoundSource.BLOCKS, 64, 1, false); + } + + if (level instanceof ServerLevel serverLevel) { + sendParticle(serverLevel, ParticleTypes.CAMPFIRE_COSY_SMOKE, x, y, z, 80, 0.4, 1, 0.4, 0.02, true); + sendParticle(serverLevel, ParticleTypes.LARGE_SMOKE, x, y + 1, z, 80, 0.4, 1, 0.4, 0.02, true); + sendParticle(serverLevel, ParticleTypes.CAMPFIRE_COSY_SMOKE, x, y, z, 80, 2, 0.001, 2, 0.01, true); + sendParticle(serverLevel, TargetModParticleTypes.FIRE_STAR.get(), x, y, z, 80, 0, 0, 0, 0.2, true); + } + + } }