添加粒子工具类
This commit is contained in:
parent
cdd6d457ee
commit
dbe0c91f89
5 changed files with 66 additions and 49 deletions
|
@ -5,6 +5,7 @@ import net.mcreator.target.headshot.IHeadshotBox;
|
||||||
import net.mcreator.target.init.*;
|
import net.mcreator.target.init.*;
|
||||||
import net.mcreator.target.network.TargetModVariables;
|
import net.mcreator.target.network.TargetModVariables;
|
||||||
import net.mcreator.target.tools.ExtendedEntityRayTraceResult;
|
import net.mcreator.target.tools.ExtendedEntityRayTraceResult;
|
||||||
|
import net.mcreator.target.tools.ParticleTool;
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.core.Direction;
|
import net.minecraft.core.Direction;
|
||||||
import net.minecraft.core.Holder;
|
import net.minecraft.core.Holder;
|
||||||
|
@ -258,11 +259,10 @@ public class ProjectileEntity extends Entity implements IEntityAdditionalSpawnDa
|
||||||
protected void onHitBlock(Vec3 location) {
|
protected void onHitBlock(Vec3 location) {
|
||||||
if (this.level() instanceof ServerLevel serverLevel) {
|
if (this.level() instanceof ServerLevel serverLevel) {
|
||||||
if (this.beast) {
|
if (this.beast) {
|
||||||
serverLevel.sendParticles(ParticleTypes.END_ROD, location.x, location.y, location.z, 15, 0.1, 0.1, 0.1, 0.05);
|
ParticleTool.sendParticle(serverLevel, ParticleTypes.END_ROD, location.x, location.y, location.z, 15, 0.1, 0.1, 0.1, 0.05, true);
|
||||||
} else {
|
} else {
|
||||||
serverLevel.sendParticles(TargetModParticleTypes.BULLET_HOLE.get(), location.x, location.y, location.z, 1, 0, 0, 0, 0);
|
ParticleTool.sendParticle(serverLevel, TargetModParticleTypes.BULLET_HOLE.get(), location.x, location.y, location.z, 1, 0, 0, 0, 0, true);
|
||||||
serverLevel.sendParticles(ParticleTypes.SMOKE, location.x, location.y, location.z, 3, 0, 0.1, 0, 0.01);
|
ParticleTool.sendParticle(serverLevel, ParticleTypes.SMOKE, location.x, location.y, location.z, 3, 0, 0.1, 0, 0.01, true);
|
||||||
serverLevel.sendParticles(TargetModParticleTypes.BULLET_HOLE.get(), location.x, location.y, location.z, 1, 0, 0, 0, 0);
|
|
||||||
|
|
||||||
this.discard();
|
this.discard();
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,7 @@ import net.minecraft.resources.ResourceLocation;
|
||||||
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.SoundEvent;
|
import net.minecraft.sounds.SoundEvent;
|
||||||
|
import net.minecraft.sounds.SoundSource;
|
||||||
import net.minecraft.world.InteractionHand;
|
import net.minecraft.world.InteractionHand;
|
||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
|
@ -173,11 +174,7 @@ public class GunEventHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (player.getMainHandItem().getItem() == TargetModItems.SENTINEL.get()) {
|
if (player.getMainHandItem().getItem() == TargetModItems.SENTINEL.get()) {
|
||||||
if ((player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new TargetModVariables.PlayerVariables())).zooming) {
|
stack.getOrCreateTag().putBoolean("zoom_fire", (player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new TargetModVariables.PlayerVariables())).zooming);
|
||||||
stack.getOrCreateTag().putBoolean("zoom_fire", true);
|
|
||||||
} else {
|
|
||||||
stack.getOrCreateTag().putBoolean("zoom_fire", false);
|
|
||||||
}
|
|
||||||
if (stack.getOrCreateTag().getDouble("power") > 20) {
|
if (stack.getOrCreateTag().getDouble("power") > 20) {
|
||||||
stack.getOrCreateTag().putDouble("power", (stack.getOrCreateTag().getDouble("power") - 20));
|
stack.getOrCreateTag().putDouble("power", (stack.getOrCreateTag().getDouble("power") - 20));
|
||||||
} else {
|
} else {
|
||||||
|
@ -232,7 +229,7 @@ public class GunEventHandler {
|
||||||
|
|
||||||
SoundEvent sound3p = ForgeRegistries.SOUND_EVENTS.getValue(new ResourceLocation(TargetMod.MODID, name + "v_fire_3p"));
|
SoundEvent sound3p = ForgeRegistries.SOUND_EVENTS.getValue(new ResourceLocation(TargetMod.MODID, name + "v_fire_3p"));
|
||||||
if (sound3p != null) {
|
if (sound3p != null) {
|
||||||
player.playSound(sound3p, 4f, 1f);
|
player.level().playSound(null, player.getOnPos(), sound3p, SoundSource.PLAYERS, 4f, 1f);
|
||||||
}
|
}
|
||||||
|
|
||||||
SoundEvent soundFar = ForgeRegistries.SOUND_EVENTS.getValue(new ResourceLocation(TargetMod.MODID, name + "_charge_far"));
|
SoundEvent soundFar = ForgeRegistries.SOUND_EVENTS.getValue(new ResourceLocation(TargetMod.MODID, name + "_charge_far"));
|
||||||
|
@ -252,7 +249,7 @@ public class GunEventHandler {
|
||||||
|
|
||||||
SoundEvent sound3p = ForgeRegistries.SOUND_EVENTS.getValue(new ResourceLocation(TargetMod.MODID, name + "_fire_3p"));
|
SoundEvent sound3p = ForgeRegistries.SOUND_EVENTS.getValue(new ResourceLocation(TargetMod.MODID, name + "_fire_3p"));
|
||||||
if (sound3p != null) {
|
if (sound3p != null) {
|
||||||
player.playSound(sound3p, 4f, 1f);
|
player.level().playSound(null, player.getOnPos(), sound3p, SoundSource.PLAYERS, 4f, 1f);
|
||||||
}
|
}
|
||||||
|
|
||||||
SoundEvent soundFar = ForgeRegistries.SOUND_EVENTS.getValue(new ResourceLocation(TargetMod.MODID, name + "_far"));
|
SoundEvent soundFar = ForgeRegistries.SOUND_EVENTS.getValue(new ResourceLocation(TargetMod.MODID, name + "_far"));
|
||||||
|
|
|
@ -7,10 +7,8 @@ import net.mcreator.target.init.TargetModItems;
|
||||||
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.mcreator.target.tools.SoundTool;
|
import net.mcreator.target.tools.SoundTool;
|
||||||
import net.minecraft.commands.CommandSource;
|
|
||||||
import net.minecraft.commands.CommandSourceStack;
|
|
||||||
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.entity.Entity;
|
import net.minecraft.world.entity.Entity;
|
||||||
import net.minecraft.world.entity.LivingEntity;
|
import net.minecraft.world.entity.LivingEntity;
|
||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
|
@ -24,45 +22,43 @@ public class TaserfireProcedure {
|
||||||
if (entity == null) return;
|
if (entity == null) return;
|
||||||
if (entity instanceof Player player && !player.isSpectator()) {
|
if (entity instanceof Player player && !player.isSpectator()) {
|
||||||
ItemStack usehand = player.getMainHandItem();
|
ItemStack usehand = player.getMainHandItem();
|
||||||
if (usehand.getItem() == TargetModItems.TASER.get() && !usehand.getOrCreateTag().getBoolean("reloading") && !(entity instanceof Player _plrCldCheck4 && _plrCldCheck4.getCooldowns().isOnCooldown(usehand.getItem()))
|
if (usehand.getItem() == TargetModItems.TASER.get() && !usehand.getOrCreateTag().getBoolean("reloading")) {
|
||||||
&& usehand.getOrCreateTag().getInt("ammo") > 0) {
|
Player _plrCldCheck4 = (Player) entity;
|
||||||
|
if (!_plrCldCheck4.getCooldowns().isOnCooldown(usehand.getItem()) && usehand.getOrCreateTag().getInt("ammo") > 0) {
|
||||||
|
|
||||||
entity.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
|
entity.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
|
||||||
capability.recoilHorizon = Math.random() < 0.5 ? -1 : 1;
|
capability.recoilHorizon = Math.random() < 0.5 ? -1 : 1;
|
||||||
capability.recoil = 0.1;
|
capability.recoil = 0.1;
|
||||||
capability.firing = 1;
|
capability.firing = 1;
|
||||||
capability.syncPlayerVariables(entity);
|
capability.syncPlayerVariables(entity);
|
||||||
});
|
});
|
||||||
player.getCooldowns().addCooldown(usehand.getItem(), 5);
|
player.getCooldowns().addCooldown(usehand.getItem(), 5);
|
||||||
|
|
||||||
if (entity instanceof ServerPlayer serverPlayer) {
|
if (entity instanceof ServerPlayer serverPlayer) {
|
||||||
SoundTool.playLocalSound(serverPlayer, TargetModSounds.TASER_FIRE_1P.get(), 1, 1);
|
SoundTool.playLocalSound(serverPlayer, TargetModSounds.TASER_FIRE_1P.get(), 1, 1);
|
||||||
serverPlayer.playSound(TargetModSounds.TASER_FIRE_3P.get(), 1, 1);
|
serverPlayer.level().playSound(null, serverPlayer.getOnPos(), TargetModSounds.TASER_FIRE_3P.get(), SoundSource.PLAYERS, 1, 1);
|
||||||
|
}
|
||||||
|
|
||||||
// TODO 重写stopsound
|
Level projectileLevel = entity.level();
|
||||||
entity.getServer().getCommands().performPrefixedCommand(new CommandSourceStack(CommandSource.NULL, entity.position(), entity.getRotationVector(), entity.level() instanceof ServerLevel ? (ServerLevel) entity.level() : null, 4,
|
if (!projectileLevel.isClientSide()) {
|
||||||
entity.getName().getString(), entity.getDisplayName(), entity.level().getServer(), entity), "stopsound @s player target:taser_fire_3p");
|
Projectile _entityToSpawn = new Object() {
|
||||||
|
public Projectile getArrow(Level level, Entity shooter, float damage, int knockback) {
|
||||||
|
AbstractArrow entityToSpawn = new TaserBulletProjectileEntity(TargetModEntities.TASER_BULLET_PROJECTILE.get(), level);
|
||||||
|
entityToSpawn.setOwner(shooter);
|
||||||
|
entityToSpawn.setBaseDamage(damage);
|
||||||
|
entityToSpawn.setKnockback(knockback);
|
||||||
|
entityToSpawn.setSilent(true);
|
||||||
|
return entityToSpawn;
|
||||||
|
}
|
||||||
|
}.getArrow(projectileLevel, entity, (float) (usehand.getOrCreateTag().getDouble("damage") / usehand.getOrCreateTag().getDouble("velocity")), 0);
|
||||||
|
_entityToSpawn.setPos(entity.getX(), entity.getEyeY() - 0.1, entity.getZ());
|
||||||
|
_entityToSpawn.shoot(entity.getLookAngle().x, entity.getLookAngle().y, entity.getLookAngle().z, (float) usehand.getOrCreateTag().getDouble("velocity"),
|
||||||
|
(float) ((LivingEntity) entity).getAttribute(TargetModAttributes.SPREAD.get()).getBaseValue());
|
||||||
|
projectileLevel.addFreshEntity(_entityToSpawn);
|
||||||
|
}
|
||||||
|
usehand.getOrCreateTag().putInt("fire_animation", 4);
|
||||||
|
usehand.getOrCreateTag().putInt("ammo", (usehand.getOrCreateTag().getInt("ammo") - 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
Level projectileLevel = entity.level();
|
|
||||||
if (!projectileLevel.isClientSide()) {
|
|
||||||
Projectile _entityToSpawn = new Object() {
|
|
||||||
public Projectile getArrow(Level level, Entity shooter, float damage, int knockback) {
|
|
||||||
AbstractArrow entityToSpawn = new TaserBulletProjectileEntity(TargetModEntities.TASER_BULLET_PROJECTILE.get(), level);
|
|
||||||
entityToSpawn.setOwner(shooter);
|
|
||||||
entityToSpawn.setBaseDamage(damage);
|
|
||||||
entityToSpawn.setKnockback(knockback);
|
|
||||||
entityToSpawn.setSilent(true);
|
|
||||||
return entityToSpawn;
|
|
||||||
}
|
|
||||||
}.getArrow(projectileLevel, entity, (float) (usehand.getOrCreateTag().getDouble("damage") / usehand.getOrCreateTag().getDouble("velocity")), 0);
|
|
||||||
_entityToSpawn.setPos(entity.getX(), entity.getEyeY() - 0.1, entity.getZ());
|
|
||||||
_entityToSpawn.shoot(entity.getLookAngle().x, entity.getLookAngle().y, entity.getLookAngle().z, (float) usehand.getOrCreateTag().getDouble("velocity"),
|
|
||||||
(float) ((LivingEntity) entity).getAttribute(TargetModAttributes.SPREAD.get()).getBaseValue());
|
|
||||||
projectileLevel.addFreshEntity(_entityToSpawn);
|
|
||||||
}
|
|
||||||
usehand.getOrCreateTag().putInt("fire_animation", 4);
|
|
||||||
usehand.getOrCreateTag().putInt("ammo", (usehand.getOrCreateTag().getInt("ammo") - 1));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
14
src/main/java/net/mcreator/target/tools/ParticleTool.java
Normal file
14
src/main/java/net/mcreator/target/tools/ParticleTool.java
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
package net.mcreator.target.tools;
|
||||||
|
|
||||||
|
import net.minecraft.core.particles.ParticleOptions;
|
||||||
|
import net.minecraft.server.level.ServerLevel;
|
||||||
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
|
|
||||||
|
public class ParticleTool {
|
||||||
|
public static <T extends ParticleOptions> void sendParticle(ServerLevel level, T particle, double x, double y, double z, int count,
|
||||||
|
double xOffset, double yOffset, double zOffset, double speed, boolean force) {
|
||||||
|
for (ServerPlayer serverPlayer : level.players()) {
|
||||||
|
level.sendParticles(serverPlayer, particle, force, x, y, z, count, xOffset, yOffset, zOffset, speed);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,6 +2,8 @@ package net.mcreator.target.tools;
|
||||||
|
|
||||||
import net.minecraft.core.Holder;
|
import net.minecraft.core.Holder;
|
||||||
import net.minecraft.network.protocol.game.ClientboundSoundPacket;
|
import net.minecraft.network.protocol.game.ClientboundSoundPacket;
|
||||||
|
import net.minecraft.network.protocol.game.ClientboundStopSoundPacket;
|
||||||
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.server.level.ServerPlayer;
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
import net.minecraft.sounds.SoundEvent;
|
import net.minecraft.sounds.SoundEvent;
|
||||||
import net.minecraft.sounds.SoundSource;
|
import net.minecraft.sounds.SoundSource;
|
||||||
|
@ -30,4 +32,12 @@ public class SoundTool {
|
||||||
player.connection.send(new ClientboundSoundPacket(new Holder.Direct<>(sound),
|
player.connection.send(new ClientboundSoundPacket(new Holder.Direct<>(sound),
|
||||||
source, player.getX(), player.getY(), player.getZ(), volume, pitch, player.level().random.nextLong()));
|
source, player.getX(), player.getY(), player.getZ(), volume, pitch, player.level().random.nextLong()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void stopSound(ServerPlayer player, ResourceLocation sound) {
|
||||||
|
stopSound(player, sound, SoundSource.PLAYERS);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void stopSound(ServerPlayer player, ResourceLocation sound, SoundSource source) {
|
||||||
|
player.connection.send(new ClientboundStopSoundPacket(sound, source));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue