移除冗余指令

This commit is contained in:
17146 2024-05-19 23:13:17 +08:00
parent dbe0c91f89
commit 3d1baac24c
4 changed files with 49 additions and 78 deletions

View file

@ -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;
}));
}
}

View file

@ -5,8 +5,8 @@ import net.mcreator.target.headshot.IHeadshotBox;
import net.mcreator.target.init.TargetModEntities; import net.mcreator.target.init.TargetModEntities;
import net.mcreator.target.init.TargetModSounds; import net.mcreator.target.init.TargetModSounds;
import net.mcreator.target.network.TargetModVariables; import net.mcreator.target.network.TargetModVariables;
import net.minecraft.commands.CommandSource; import net.mcreator.target.tools.ParticleTool;
import net.minecraft.commands.CommandSourceStack; import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.network.protocol.Packet; import net.minecraft.network.protocol.Packet;
import net.minecraft.network.protocol.game.ClientGamePacketListener; import net.minecraft.network.protocol.game.ClientGamePacketListener;
import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerLevel;
@ -89,9 +89,8 @@ public class GunGrenadeEntity extends AbstractArrow implements ItemSupplier {
if (this.level() instanceof ServerLevel level) { if (this.level() instanceof ServerLevel level) {
level.explode(this, (this.getX()), (this.getY()), (this.getZ()), 5.5f, Level.ExplosionInteraction.NONE); level.explode(this, (this.getX()), (this.getY()), (this.getZ()), 5.5f, Level.ExplosionInteraction.NONE);
if (!entity.level().isClientSide() && entity.getServer() != null) { if (!entity.level().isClientSide()) {
entity.getServer().getCommands().performPrefixedCommand(new CommandSourceStack(CommandSource.NULL, entity.position(), entity.getRotationVector(), (ServerLevel) entity.level(), 4, ParticleTool.spawnMediumExplosionParticles(this.level(), this.position());
entity.getName().getString(), entity.getDisplayName(), entity.getServer(), entity), "target:mediumexp");
} }
this.discard(); this.discard();
} }
@ -155,15 +154,13 @@ public class GunGrenadeEntity extends AbstractArrow implements ItemSupplier {
this.getPersistentData().putInt("fuse", this.getPersistentData().getInt("fuse") + 1); this.getPersistentData().putInt("fuse", this.getPersistentData().getInt("fuse") + 1);
// TODO 修改为正确的粒子效果添加 if (!this.level().isClientSide() && this.level() instanceof ServerLevel serverLevel) {
if (!this.level().isClientSide() && this.getServer() != null) { ParticleTool.sendParticle(serverLevel, ParticleTypes.CAMPFIRE_COSY_SMOKE, this.getX(), this.getY(), this.getZ(),
this.getServer().getCommands().performPrefixedCommand(new CommandSourceStack(CommandSource.NULL, this.position(), this.getRotationVector(), this.level() instanceof ServerLevel ? (ServerLevel) this.level() : null, 4, 1, 0, 0, 0, 0.02, true);
this.getName().getString(), this.getDisplayName(), this.level().getServer(), this), "particle minecraft:campfire_cosy_smoke ~ ~ ~ 0 0 0 0 1 force");
} }
if (this.inGround) { if (this.inGround) {
if (!this.level().isClientSide() && this.getServer() != null) { if (!this.level().isClientSide()) {
this.getServer().getCommands().performPrefixedCommand(new CommandSourceStack(CommandSource.NULL, this.position(), this.getRotationVector(), this.level() instanceof ServerLevel ? (ServerLevel) this.level() : null, 4, ParticleTool.spawnMediumExplosionParticles(this.level(), this.position());
this.getName().getString(), this.getDisplayName(), this.level().getServer(), this), "target:mediumexp");
} }
this.discard(); this.discard();
} }

View file

@ -1,8 +1,8 @@
package net.mcreator.target.entity; package net.mcreator.target.entity;
import net.mcreator.target.init.TargetModEntities; import net.mcreator.target.init.TargetModEntities;
import net.minecraft.commands.CommandSource; import net.mcreator.target.tools.ParticleTool;
import net.minecraft.commands.CommandSourceStack; import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.network.protocol.Packet; import net.minecraft.network.protocol.Packet;
import net.minecraft.network.protocol.game.ClientGamePacketListener; import net.minecraft.network.protocol.game.ClientGamePacketListener;
import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerLevel;
@ -71,8 +71,7 @@ public class MortarShellEntity extends AbstractArrow implements ItemSupplier {
if (this.level() instanceof ServerLevel level) { if (this.level() instanceof ServerLevel level) {
level.explode(this, (this.getX()), (this.getY()), (this.getZ()), 10, Level.ExplosionInteraction.NONE); level.explode(this, (this.getX()), (this.getY()), (this.getZ()), 10, Level.ExplosionInteraction.NONE);
if (!entity.level().isClientSide() && entity.getServer() != null) { if (!entity.level().isClientSide() && entity.getServer() != null) {
entity.getServer().getCommands().performPrefixedCommand(new CommandSourceStack(CommandSource.NULL, entity.position(), entity.getRotationVector(), (ServerLevel) entity.level(), 4, ParticleTool.spawnMediumExplosionParticles(level, entity.position());
entity.getName().getString(), entity.getDisplayName(), entity.getServer(), entity), "target:mediumexp");
} }
} }
this.discard(); this.discard();
@ -81,23 +80,21 @@ public class MortarShellEntity extends AbstractArrow implements ItemSupplier {
@Override @Override
public void onHitBlock(BlockHitResult blockHitResult) { public void onHitBlock(BlockHitResult blockHitResult) {
super.onHitBlock(blockHitResult); super.onHitBlock(blockHitResult);
if (this.level() instanceof ServerLevel level) { if (this.level() instanceof ServerLevel level) {
level.explode(this, this.getX(), this.getY(), this.getZ(), 10, Level.ExplosionInteraction.NONE); level.explode(this, this.getX(), this.getY(), this.getZ(), 10, Level.ExplosionInteraction.NONE);
} }
} }
@Override @Override
public void tick() { public void tick() {
super.tick(); super.tick();
if (this.getServer() != null) { if (this.level() instanceof ServerLevel serverLevel) {
// TODO 修改为正确的粒子效果播放方法 ParticleTool.sendParticle(serverLevel, ParticleTypes.CAMPFIRE_COSY_SMOKE, this.getX(), this.getY(), this.getZ(),
this.getServer().getCommands().performPrefixedCommand(new CommandSourceStack(CommandSource.NULL, this.position(), this.getRotationVector(), this.level() instanceof ServerLevel ? (ServerLevel) this.level() : null, 4, 2, 0, 0, 0, 0.02, true);
this.getName().getString(), this.getDisplayName(), this.level().getServer(), this), "particle minecraft:campfire_cosy_smoke ~ ~ ~ 0 0 0 0 2 force");
} }
if (this.inGround) { if (this.inGround) {
if (!this.level().isClientSide() && this.getServer() != null) { 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, ParticleTool.spawnMediumExplosionParticles(this.level(), this.position());
this.getName().getString(), this.getDisplayName(), this.level().getServer(), this), "target:mediumexp");
} }
this.discard(); this.discard();
} }

View file

@ -1,8 +1,15 @@
package net.mcreator.target.tools; 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.ParticleOptions;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer; 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 class ParticleTool {
public static <T extends ParticleOptions> void sendParticle(ServerLevel level, T particle, double x, double y, double z, int count, public static <T extends ParticleOptions> 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); 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);
}
}
} }