优化线程,准星,音效,特效,修复靶子

This commit is contained in:
Atsuihsio 2024-05-25 18:34:59 +08:00
parent 16fe722935
commit a863e9a0c2
35 changed files with 224 additions and 206 deletions

View file

@ -35,7 +35,7 @@ public class CrossHairOverlay {
return;
}
double spread = entity.getAttribute(TargetModAttributes.SPREAD.get()).getBaseValue();
double spread = entity.getPersistentData().getDouble("crosshair");
RenderSystem.disableDepthTest();
RenderSystem.depthMask(false);

View file

@ -69,7 +69,7 @@ public class GunGrenadeEntity extends ThrowableItemProjectile {
if (this.getPersistentData().getInt("fuse") > 0) {
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()), 4.5f, Level.ExplosionInteraction.NONE);
if (!entity.level().isClientSide()) {
ParticleTool.spawnMediumExplosionParticles(this.level(), this.position());
}
@ -128,7 +128,7 @@ public class GunGrenadeEntity extends ThrowableItemProjectile {
super.onHitBlock(blockHitResult);
if (this.getPersistentData().getInt("fuse") > 0) {
if (this.level() instanceof ServerLevel) {
this.level().explode(this, this.getX(), this.getY(), this.getZ(), 5.5f, Level.ExplosionInteraction.NONE);
this.level().explode(this, this.getX(), this.getY(), this.getZ(), 4.5f, Level.ExplosionInteraction.NONE);
ParticleTool.spawnMediumExplosionParticles(this.level(), this.position());
}
}
@ -147,7 +147,11 @@ public class GunGrenadeEntity extends ThrowableItemProjectile {
1, 0, 0, 0, 0.02, true);
}
if (this.tickCount > 200) {
if (this.tickCount > 200 || this.isInWater()) {
if (this.level() instanceof ServerLevel) {
this.level().explode(this, this.getX(), this.getY(), this.getZ(), 4.5f, Level.ExplosionInteraction.NONE);
ParticleTool.spawnMediumExplosionParticles(this.level(), this.position());
}
this.discard();
}
}

View file

@ -54,7 +54,7 @@ public class MortarShellEntity extends ThrowableItemProjectile {
entity.hurt(this.level().damageSources().thrown(this, this.getOwner()), this.damage);
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()), 11, Level.ExplosionInteraction.NONE);
if (!entity.level().isClientSide() && entity.getServer() != null) {
ParticleTool.spawnMediumExplosionParticles(level, entity.position());
}
@ -66,7 +66,7 @@ public class MortarShellEntity extends ThrowableItemProjectile {
public void onHitBlock(BlockHitResult blockHitResult) {
super.onHitBlock(blockHitResult);
if (!this.level().isClientSide() && 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(), 11, Level.ExplosionInteraction.NONE);
ParticleTool.spawnMediumExplosionParticles(this.level(), this.position());
}
this.discard();
@ -79,8 +79,11 @@ public class MortarShellEntity extends ThrowableItemProjectile {
ParticleTool.sendParticle(serverLevel, ParticleTypes.CAMPFIRE_COSY_SMOKE, this.getX(), this.getY(), this.getZ(),
2, 0, 0, 0, 0.02, true);
}
if (this.tickCount >= 600) {
this.level().explode(this, this.getX(), this.getY(), this.getZ(), 10, Level.ExplosionInteraction.NONE);
if (this.tickCount > 600 || this.isInWater()) {
if (this.level() instanceof ServerLevel) {
this.level().explode(this, this.getX(), this.getY(), this.getZ(), 11f, Level.ExplosionInteraction.NONE);
ParticleTool.spawnMediumExplosionParticles(this.level(), this.position());
}
this.discard();
}
}

View file

@ -68,7 +68,7 @@ public class RpgRocketEntity extends ThrowableItemProjectile {
}
if (this.level() instanceof ServerLevel level) {
level.explode(this, this.getX(), this.getY(), this.getZ(), 4, Level.ExplosionInteraction.NONE);
level.explode(this, this.getX(), this.getY(), this.getZ(), 5, Level.ExplosionInteraction.NONE);
if (!entity.level().isClientSide()) {
ParticleTool.spawnMediumExplosionParticles(this.level(), this.position());
@ -132,7 +132,7 @@ public class RpgRocketEntity extends ThrowableItemProjectile {
super.onHitBlock(blockHitResult);
if (this.level() instanceof ServerLevel level) {
level.explode(this, this.getX(), this.getY(), this.getZ(), 6, Level.ExplosionInteraction.NONE);
level.explode(this, this.getX(), this.getY(), this.getZ(), 5, Level.ExplosionInteraction.NONE);
ParticleTool.spawnMediumExplosionParticles(this.level(), this.position());
}
@ -157,8 +157,9 @@ public class RpgRocketEntity extends ThrowableItemProjectile {
}
}
if (this.tickCount >= 90) {
if (!this.level().isClientSide()) {
if (this.tickCount > 100 || this.isInWater()) {
if (this.level() instanceof ServerLevel) {
this.level().explode(this, this.getX(), this.getY(), this.getZ(), 5f, Level.ExplosionInteraction.NONE);
ParticleTool.spawnMediumExplosionParticles(this.level(), this.position());
}
this.discard();

View file

@ -4,6 +4,7 @@ import net.mcreator.target.init.TargetModEntities;
import net.mcreator.target.init.TargetModItems;
import net.mcreator.target.init.TargetModSounds;
import net.mcreator.target.network.TargetModVariables;
import net.mcreator.target.tools.SoundTool;
import net.minecraft.commands.arguments.EntityAnchorArgument;
import net.minecraft.core.BlockPos;
import net.minecraft.nbt.CompoundTag;
@ -104,16 +105,17 @@ public class Target1Entity extends PathfinderMob implements GeoEntity, AnimatedE
@Override
public boolean hurt(DamageSource source, float amount) {
if (this.getPersistentData().getDouble("target_down") > 0) {
return false;
}
if (!this.level().isClientSide()) {
this.level().playSound(null, BlockPos.containing(this.getX(), this.getY(), this.getZ()), TargetModSounds.HIT.get(), SoundSource.BLOCKS, 2, 1);
} else {
this.level().playLocalSound(this.getX(), this.getY(), this.getZ(), TargetModSounds.HIT.get(), SoundSource.BLOCKS, 2, 1, false);
}
if (this.getPersistentData().getDouble("targetdown") > 0) {
return false;
}
if (source.is(DamageTypes.IN_FIRE))
return false;
if (source.getDirectEntity() instanceof ThrownPotion || source.getDirectEntity() instanceof AreaEffectCloud)
@ -164,8 +166,7 @@ public class Target1Entity extends PathfinderMob implements GeoEntity, AnimatedE
@SubscribeEvent
public static void onTarget1Down(LivingDeathEvent event) {
if (event.getEntity() == null) return;
event.setCanceled(true);
var entity = event.getEntity();
var sourceEntity = event.getSource().getEntity();
@ -174,12 +175,11 @@ public class Target1Entity extends PathfinderMob implements GeoEntity, AnimatedE
if (entity instanceof Target1Entity target1) {
target1.setHealth(target1.getMaxHealth());
sourceEntity.level().playLocalSound(sourceEntity.blockPosition(), TargetModSounds.TARGET_DOWN.get(), SoundSource.PLAYERS, 100, 1, false);
if (sourceEntity instanceof Player player)
if (sourceEntity instanceof Player player) {
player.displayClientMessage(Component.literal(("Target Down " + new java.text.DecimalFormat("##.#").format((entity.position()).distanceTo((sourceEntity.position()))) + "M")), true);
entity.getPersistentData().putDouble("target_down", 201);
event.setCanceled(true);
SoundTool.playLocalSound(player, TargetModSounds.TARGET_DOWN.get(), 100, 1);
entity.getPersistentData().putDouble("target_down", 100);
}
}
}
@ -215,53 +215,29 @@ public class Target1Entity extends PathfinderMob implements GeoEntity, AnimatedE
@Override
public void baseTick() {
super.baseTick();
this.setCustomName(Component.literal("HP:" + new DecimalFormat("##.##").format(this.getHealth()) + "/"
+ new DecimalFormat("##.##").format(this.getMaxHealth())));
double[] recoilTimer = {0};
double totalTime = 6;
int sleepTime = 2;
double recoilDuration = totalTime / sleepTime;
Runnable recoilRunnable = () -> {
while (recoilTimer[0] < recoilDuration) {
if (this.getPersistentData().getDouble("target_down") > -1) {
this.getPersistentData().putDouble("target_down", this.getPersistentData().getDouble("target_down") - 1);
}
if (this.getPersistentData().getDouble("target_down") > 195) {
this.setYRot(this.getYRot());
this.setXRot((float) (201 - this.getPersistentData().getDouble("target_down")) * -18);
this.setYBodyRot(this.getYRot());
this.setYHeadRot(this.getYRot());
this.yRotO = this.getYRot();
this.xRotO = this.getXRot();
this.yBodyRotO = this.getYRot();
this.yHeadRotO = this.getYRot();
}
if (this.getPersistentData().getDouble("target_down") < 20 && this.getPersistentData().getDouble("target_down") > -1) {
this.setYRot(this.getYRot());
this.setXRot((float) (-90 + 20 - this.getPersistentData().getDouble("target_down")) * 5.14f);
this.setYBodyRot(this.getYRot());
this.setYHeadRot(this.getYRot());
this.yRotO = this.getYRot();
this.xRotO = this.getXRot();
this.yBodyRotO = this.getYRot();
this.yHeadRotO = this.getYRot();
}
recoilTimer[0]++;
try {
Thread.sleep(sleepTime);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
};
Thread recoilThread = new Thread(recoilRunnable);
recoilThread.start();
this.refreshDimensions();
if (this.getPersistentData().getDouble("target_down") > 0) {
this.getPersistentData().putDouble("target_down", this.getPersistentData().getDouble("target_down") - 1);
}
if (this.getPersistentData().getDouble("target_down") >= 98) {
this.setYRot(this.getYRot());
this.setXRot((float) (100 - this.getPersistentData().getDouble("target_down")) * -45f);
this.setYBodyRot(this.getYRot());
this.setYHeadRot(this.getYRot());
this.yRotO = this.getYRot();
this.xRotO = this.getXRot();
this.yBodyRotO = this.getYRot();
this.yHeadRotO = this.getYRot();
}
if (this.getPersistentData().getDouble("target_down") <= 5 && this.getPersistentData().getDouble("target_down") > 0) {
this.setYRot(this.getYRot());
this.setXRot((float) (-90 + (5 - this.getPersistentData().getDouble("target_down")) * 18f * 1.25f));
this.setYBodyRot(this.getYRot());
this.setYHeadRot(this.getYRot());
this.yRotO = this.getYRot();
this.xRotO = this.getXRot();
this.yBodyRotO = this.getYRot();
this.yHeadRotO = this.getYRot();
}
}
@ -331,9 +307,9 @@ public class Target1Entity extends PathfinderMob implements GeoEntity, AnimatedE
@Override
protected void tickDeath() {
++this.deathTime;
if (this.deathTime == 100) {
this.remove(Target1Entity.RemovalReason.KILLED);
this.dropExperience();
if (this.deathTime == 114514) {
// this.remove(Target1Entity.RemovalReason.KILLED);
// this.dropExperience();
}
}

View file

@ -1,5 +1,6 @@
package net.mcreator.target.event;
import net.mcreator.target.init.TargetModAttributes;
import net.mcreator.target.init.TargetModMobEffects;
import net.mcreator.target.init.TargetModTags;
import net.mcreator.target.network.TargetModVariables;
@ -28,6 +29,7 @@ public class ClientEventHandler {
ClientLevel level = Minecraft.getInstance().level;
Entity entity = event.getCamera().getEntity();
if (level != null && entity instanceof LivingEntity living) {
handleWeaponCrosshair(living);
handleWeaponSway(living);
handleWeaponMove(living);
handleWeaponZoom(living);
@ -38,6 +40,24 @@ public class ClientEventHandler {
}
}
private static void handleWeaponCrosshair(LivingEntity entity) {
if (entity.getMainHandItem().is(TargetModTags.Items.GUN)) {
float fps = Minecraft.getInstance().getFps();
if (fps <= 30) {
fps = 30f;
}
float times = 90f / fps;
var data = entity.getPersistentData();
double spread = entity.getAttribute(TargetModAttributes.SPREAD.get()).getBaseValue();
if (data.getDouble("crosshair") > spread){
data.putDouble("crosshair",data.getDouble("crosshair") - 0.05 *Math.pow(spread - data.getDouble("crosshair"), 2) * times);
} else {
data.putDouble("crosshair",data.getDouble("crosshair") + 0.05 *Math.pow(spread - data.getDouble("crosshair"), 2) * times);
}
}
}
private static void handleWeaponSway(LivingEntity entity) {
if (entity.getMainHandItem().is(TargetModTags.Items.GUN)) {
float fps = Minecraft.getInstance().getFps();

View file

@ -42,71 +42,51 @@ public class GunEventHandler {
}
private static void handleGunsDev(Player player) {
double[] recoilTimer = {0};
double totalTime = 20;
int sleepTime = 2;
double recoilDuration = totalTime / sleepTime;
if (player == null) {
return;
}
Runnable recoilRunnable = () -> {
while (recoilTimer[0] < recoilDuration) {
if (player == null) {
return;
}
ItemStack stack = player.getMainHandItem();
ItemStack stack = player.getMainHandItem();
double basic = stack.getOrCreateTag().getDouble("dev");
double basic = stack.getOrCreateTag().getDouble("dev");
double sprint = player.isSprinting() ? 0.5 * basic : 0;
double sneaking = player.isShiftKeyDown() ? (-0.25) * basic : 0;
double prone = player.getPersistentData().getDouble("prone") > 0 ? (-0.5) * basic : 0;
double jump = player.onGround() ? 0 : 1.5 * basic;
double fire = stack.getOrCreateTag().getInt("fire_animation") > 0 ? 0.5 * basic : 0;
double ride = player.isPassenger() ? (-0.5) * basic : 0;
double sprint = player.isSprinting() ? 0.5 * basic : 0;
double sneaking = player.isShiftKeyDown() ? (-0.25) * basic : 0;
double prone = player.getPersistentData().getDouble("prone") > 0 ? (-0.5) * basic : 0;
double jump = player.onGround() ? 0 : 1.5 * basic;
double fire = stack.getOrCreateTag().getInt("fire_animation") > 0 ? 0.5 * basic : 0;
double ride = player.isPassenger() ? (-0.5) * basic : 0;
double walk;
if (player.getPersistentData().getDouble("move_forward") == 1 || player.getPersistentData().getDouble("move_backward") == 1 ||
player.getPersistentData().getDouble("move_left") == 1 || player.getPersistentData().getDouble("move_right") == 1) {
walk = 0.2 * basic;
} else {
walk = 0;
}
double walk;
if (player.getPersistentData().getDouble("move_forward") == 1 || player.getPersistentData().getDouble("move_backward") == 1 ||
player.getPersistentData().getDouble("move_left") == 1 || player.getPersistentData().getDouble("move_right") == 1) {
walk = 0.2 * basic;
} else {
walk = 0;
}
double zoom;
if (player.getPersistentData().getDouble("zoom_animation_time") > 4) {
if (stack.is(TargetModTags.Items.SNIPER_RIFLE)) {
zoom = 0.0001;
} else if (stack.is(TargetModTags.Items.SHOTGUN)) {
zoom = 0.9;
} else {
zoom = 0.0001;
}
} else {
zoom = 1;
}
double index = zoom * (basic + walk + sprint + sneaking + prone + jump + fire + ride);
if (player.getAttributeBaseValue(TargetModAttributes.SPREAD.get()) < index) {
player.getAttribute(TargetModAttributes.SPREAD.get())
.setBaseValue(player.getAttributeBaseValue(TargetModAttributes.SPREAD.get()) + 0.0125 * Math.pow(index - player.getAttributeBaseValue(TargetModAttributes.SPREAD.get()), 2));
} else {
player.getAttribute(TargetModAttributes.SPREAD.get())
.setBaseValue(player.getAttributeBaseValue(TargetModAttributes.SPREAD.get()) - 0.0125 * Math.pow(index - player.getAttributeBaseValue(TargetModAttributes.SPREAD.get()), 2));
}
recoilTimer[0]++;
try {
Thread.sleep(sleepTime);
} catch (InterruptedException e) {
e.printStackTrace();
}
double zoom;
if (player.getPersistentData().getDouble("zoom_animation_time") > 4) {
if (stack.is(TargetModTags.Items.SNIPER_RIFLE)) {
zoom = 0.0001;
} else if (stack.is(TargetModTags.Items.SHOTGUN)) {
zoom = 0.9;
} else {
zoom = 0.0001;
}
};
} else {
zoom = 1;
}
Thread recoilThread = new Thread(recoilRunnable);
recoilThread.start();
double index = zoom * (basic + walk + sprint + sneaking + prone + jump + fire + ride);
if (player.getAttributeBaseValue(TargetModAttributes.SPREAD.get()) < index) {
player.getAttribute(TargetModAttributes.SPREAD.get())
.setBaseValue(player.getAttributeBaseValue(TargetModAttributes.SPREAD.get()) + 0.125 * Math.pow(index - player.getAttributeBaseValue(TargetModAttributes.SPREAD.get()), 2));
} else {
player.getAttribute(TargetModAttributes.SPREAD.get())
.setBaseValue(player.getAttributeBaseValue(TargetModAttributes.SPREAD.get()) - 0.125 * Math.pow(index - player.getAttributeBaseValue(TargetModAttributes.SPREAD.get()), 2));
}
}
/**

View file

@ -2,15 +2,14 @@ package net.mcreator.target.event;
import net.mcreator.target.TargetMod;
import net.mcreator.target.entity.ClaymoreEntity;
import net.mcreator.target.init.TargetModDamageTypes;
import net.mcreator.target.init.TargetModItems;
import net.mcreator.target.init.TargetModSounds;
import net.mcreator.target.init.TargetModTags;
import net.mcreator.target.entity.Target1Entity;
import net.mcreator.target.init.*;
import net.mcreator.target.item.gun.GunItem;
import net.mcreator.target.network.TargetModVariables;
import net.mcreator.target.network.message.ClientIndicatorMessage;
import net.mcreator.target.network.message.PlayerGunKillMessage;
import net.mcreator.target.tools.SoundTool;
import net.minecraft.network.chat.Component;
import net.minecraft.network.protocol.game.ClientboundStopSoundPacket;
import net.minecraft.resources.ResourceKey;
import net.minecraft.server.level.ServerPlayer;
@ -95,6 +94,10 @@ public class LivingEventHandler {
}
event.setAmount((float) damage);
stack.getOrCreateTag().putDouble("damagetotal", stack.getOrCreateTag().getDouble("damagetotal") + damage);
if (entity instanceof Target1Entity && sourceentity instanceof Player player) {
player.displayClientMessage(Component.literal("Damage:" + new java.text.DecimalFormat("##.#").format(damage) + " Distance:" + new java.text.DecimalFormat("##.#").format((entity.position()).distanceTo((sourceentity.position()))) + "M"), false);
}
}
}

View file

@ -173,12 +173,7 @@ public class PlayerEventHandler {
if (player == null) {
return;
}
if ((player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new TargetModVariables.PlayerVariables())).firing > 0) {
player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
capability.firing = (player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new TargetModVariables.PlayerVariables())).firing - 0.5;
capability.syncPlayerVariables(player);
});
}
}
private static void handleGround(Player player) {
@ -294,16 +289,28 @@ public class PlayerEventHandler {
float recoilX = (float) tag.getDouble("recoil_x");
float recoilY = (float) tag.getDouble("recoil_y");
var capability = player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null);
float recoilYaw = capability.map(c -> c.recoilHorizon).orElse(0d).floatValue();
float recoilYaw = player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).map(c -> c.recoilHorizon).orElse(0d).floatValue();
double[] recoilTimer = {0};
double totalTime = 10;
double totalTime = 20;
int sleepTime = 2;
double recoilDuration = totalTime / sleepTime;
Runnable recoilRunnable = () -> {
while (recoilTimer[0] < recoilDuration) {
if ((player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new TargetModVariables.PlayerVariables())).firing > 0) {
player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
capability.firing = (player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new TargetModVariables.PlayerVariables())).firing - 0.1;
capability.syncPlayerVariables(player);
});
} else {
player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
capability.firing = 0;
capability.syncPlayerVariables(player);
});
}
float rx, ry;
if (player.isShiftKeyDown() && player.getBbHeight() >= 1 && player.getPersistentData().getDouble("prone") == 0) {
rx = 0.7f;
@ -321,26 +328,26 @@ public class PlayerEventHandler {
ry = 1f;
}
double recoil = capability.map(c -> c.recoil).orElse(0d);
double recoil = player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).map(c -> c.recoil).orElse(0d);
if (recoil >= 1) recoil = 0d;
if (recoil > 0) {
recoil += 0.02;
recoil += 0.01;
double sinRes = Math.sin(2 * Math.PI * (1.03f * recoil - 0.032047110911)) + 0.2;
float newPitch = ((float) (player.getXRot() - 15f * recoilY * ry * sinRes));
float newPitch = ((float) (player.getXRot() - 7.5f * recoilY * ry * sinRes));
player.setXRot(newPitch);
player.xRotO = player.getXRot();
float newYaw = ((float) (player.getYRot() - 10f * recoilYaw * recoilX * rx * sinRes));
float newYaw = ((float) (player.getYRot() - 5f * recoilYaw * recoilX * rx * sinRes));
player.setYRot(newYaw);
player.yRotO = player.getYRot();
}
double finalRecoil = recoil;
capability.ifPresent(c -> {
player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(c -> {
c.recoil = finalRecoil;
c.syncPlayerVariables(player);
});

View file

@ -26,9 +26,10 @@ public class TargetModSounds {
public static final RegistryObject<SoundEvent> INDICATION = REGISTRY.register("indication", () -> SoundEvent.createVariableRangeEvent(new ResourceLocation("target", "indication")));
public static final RegistryObject<SoundEvent> JUMP = REGISTRY.register("jump", () -> SoundEvent.createVariableRangeEvent(new ResourceLocation("target", "jump")));
public static final RegistryObject<SoundEvent> DOUBLE_JUMP = REGISTRY.register("doublejump", () -> SoundEvent.createVariableRangeEvent(new ResourceLocation("target", "doublejump")));
public static final RegistryObject<SoundEvent> EXPLOSION = REGISTRY.register("exp", () -> SoundEvent.createVariableRangeEvent(new ResourceLocation("target", "exp")));
public static final RegistryObject<SoundEvent> EXPLOSION_FAR = REGISTRY.register("expfar", () -> SoundEvent.createVariableRangeEvent(new ResourceLocation("target", "expfar")));
public static final RegistryObject<SoundEvent> EXPLOSION_VERY_FAR = REGISTRY.register("expveryfar", () -> SoundEvent.createVariableRangeEvent(new ResourceLocation("target", "expveryfar")));
public static final RegistryObject<SoundEvent> EXPLOSION_CLOSE = REGISTRY.register("explosion_close", () -> SoundEvent.createVariableRangeEvent(new ResourceLocation("target", "explosion_close")));
public static final RegistryObject<SoundEvent> EXPLOSION_FAR = REGISTRY.register("explosion_far", () -> SoundEvent.createVariableRangeEvent(new ResourceLocation("target", "explosion_far")));
public static final RegistryObject<SoundEvent> EXPLOSION_VERY_FAR = REGISTRY.register("explosion_very_far", () -> SoundEvent.createVariableRangeEvent(new ResourceLocation("target", "explosion_very_far")));
public static final RegistryObject<SoundEvent> EXPLOSION_WATER = REGISTRY.register("explosion_water", () -> SoundEvent.createVariableRangeEvent(new ResourceLocation("target", "explosion_water")));
public static final RegistryObject<SoundEvent> HUNTING_RIFLE_FIRE_1P = REGISTRY.register("hunting_rifle_fire_1p", () -> SoundEvent.createVariableRangeEvent(new ResourceLocation("target", "hunting_rifle_fire_1p")));
public static final RegistryObject<SoundEvent> HUNTING_RIFLE_FIRE_3P = REGISTRY.register("hunting_rifle_fire_3p", () -> SoundEvent.createVariableRangeEvent(new ResourceLocation("target", "hunting_rifle_fire_3p")));
public static final RegistryObject<SoundEvent> HUNTING_RIFLE_FAR = REGISTRY.register("hunting_rifle_far", () -> SoundEvent.createVariableRangeEvent(new ResourceLocation("target", "hunting_rifle_far")));

View file

@ -1,6 +1,8 @@
package net.mcreator.target.network.message;
import net.mcreator.target.entity.BocekArrowEntity;
import net.mcreator.target.entity.ProjectileEntity;
import net.mcreator.target.init.TargetModAttributes;
import net.mcreator.target.init.TargetModEntities;
import net.mcreator.target.init.TargetModItems;
import net.mcreator.target.init.TargetModSounds;
@ -10,6 +12,7 @@ import net.mcreator.target.tools.GunsTool;
import net.mcreator.target.tools.SoundTool;
import net.minecraft.commands.CommandSource;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.entity.player.Player;
@ -109,7 +112,7 @@ public class FireMessage {
}
} else {
for (int index0 = 0; index0 < 10; index0++) {
GunsTool.spawnBullet(player);
spawnBullet(player);
}
if (!player.level().isClientSide() && player.getServer() != null) {
@ -135,4 +138,34 @@ public class FireMessage {
}
}
}
public static void spawnBullet(Player player) {
ItemStack heldItem = player.getMainHandItem();
player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
capability.recoilHorizon = Math.random() < 0.5 ? -1 : 1;
capability.recoil = 0.1;
capability.firing = 1;
capability.syncPlayerVariables(player);
});
if (player.level().isClientSide()) return;
CompoundTag tag = heldItem.getOrCreateTag();
double damage;
float headshot = (float) tag.getDouble("headshot");
float velocity = 4 * (float) tag.getDouble("speed");
var projectile = new ProjectileEntity(player.level())
.shooter(player)
.headShot(headshot);
if (tag.getBoolean("beast")) {
projectile.beast();
}
projectile.setPos(player.getX() - 0.1 * player.getLookAngle().x, player.getEyeY() - 0.1 - 0.1 * player.getLookAngle().y, player.getZ() + -0.1 * player.getLookAngle().z);
damage = 0.008333333 * tag.getDouble("damage") * tag.getDouble("speed") * tag.getDouble("damageadd");
projectile.shoot(player.getLookAngle().x, player.getLookAngle().y, player.getLookAngle().z, velocity, 2.5f);
projectile.damage((float) damage);
player.level().addFreshEntity(projectile);
}
}

View file

@ -92,44 +92,5 @@ public class GunsTool {
initJsonData(event.getServer().getResourceManager());
}
public static void spawnBullet(Player player) {
ItemStack heldItem = player.getMainHandItem();
player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
capability.recoilHorizon = Math.random() < 0.5 ? -1 : 1;
capability.recoil = 0.1;
capability.firing = 1;
capability.syncPlayerVariables(player);
});
if (player.level().isClientSide()) return;
CompoundTag tag = heldItem.getOrCreateTag();
double damage;
float headshot = (float) tag.getDouble("headshot");
float velocity = 4 * (float) tag.getDouble("speed");
var projectile = new ProjectileEntity(player.level())
.shooter(player)
.headShot(headshot);
if (tag.getBoolean("beast")) {
projectile.beast();
}
projectile.setPos(player.getX() - 0.1 * player.getLookAngle().x, player.getEyeY() - 0.1 - 0.1 * player.getLookAngle().y, player.getZ() + -0.1 * player.getLookAngle().z);
if (heldItem.getItem() == TargetModItems.BOCEK.get()) {
damage = 0.008333333 * tag.getDouble("damage") * tag.getDouble("speed") * tag.getDouble("damageadd");
projectile.shoot(player.getLookAngle().x, player.getLookAngle().y, player.getLookAngle().z, velocity, 2.5f);
} else {
damage = tag.getDouble("damage") + tag.getDouble("add_damage") * tag.getDouble("damageadd");
projectile.shoot(player.getLookAngle().x,
player.getLookAngle().y,
player.getLookAngle().z,
(float) tag.getDouble("velocity"),
(float) player.getAttribute(TargetModAttributes.SPREAD.get()).getBaseValue());
}
projectile.damage((float) damage);
player.level().addFreshEntity(projectile);
}
}

View file

@ -2,6 +2,7 @@ package net.mcreator.target.tools;
import net.mcreator.target.init.TargetModParticleTypes;
import net.mcreator.target.init.TargetModSounds;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.core.BlockPos;
import net.minecraft.core.particles.ParticleOptions;
import net.minecraft.core.particles.ParticleTypes;
@ -30,16 +31,28 @@ public class ParticleTool {
double z = pos.z;
if (!level.isClientSide()) {
level.playSound(null, BlockPos.containing(x, y + 1, z), TargetModSounds.EXPLOSION.get(), SoundSource.BLOCKS, 8, 1);
if ((level.getBlockState(BlockPos.containing(x, y, z))).getBlock() == Blocks.WATER) {
level.playSound(null, BlockPos.containing(x, y + 1, z), TargetModSounds.EXPLOSION_WATER.get(), SoundSource.BLOCKS, 3, 1);
}
level.playSound(null, BlockPos.containing(x, y + 1, z), TargetModSounds.EXPLOSION_CLOSE.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);
} else {
if ((level.getBlockState(BlockPos.containing(x, y, z))).getBlock() == Blocks.WATER) {
level.playLocalSound(x, (y + 1), z, TargetModSounds.EXPLOSION_WATER.get(), SoundSource.BLOCKS, 3, 1, false);
}
level.playLocalSound(x, (y + 1), z, TargetModSounds.EXPLOSION_CLOSE.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) {
if ((level.getBlockState(BlockPos.containing(x, y, z))).getBlock() == Blocks.WATER) {
sendParticle(serverLevel, ParticleTypes.CLOUD, x, y + 3, z, 200, 1, 3, 1, 0.01, true);
sendParticle(serverLevel, ParticleTypes.CLOUD, x, y + 3, z, 300, 2, 1, 2, 0.01, true);
sendParticle(serverLevel, ParticleTypes.FALLING_WATER, x, y + 3, z, 600, 1.5, 4, 1.5, 1, true);
sendParticle(serverLevel, ParticleTypes.BUBBLE_COLUMN_UP, x, y, z, 1000, 3, 0.5, 3, 0.1, true);
}
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);

View file

@ -1287,46 +1287,62 @@
}
]
},
"exp": {
"explosion_close": {
"sounds": [
{
"name": "target:explosion/exp",
"name": "target:explosion/explosion_close",
"stream": false
},
{
"name": "target:explosion/exp2",
"name": "target:explosion/explosion_close2",
"stream": false
},
{
"name": "target:explosion/exp3",
"name": "target:explosion/explosion_close3",
"stream": false
}
]
},
"expfar": {
"explosion_far": {
"sounds": [
{
"name": "target:explosion/far",
"name": "target:explosion/explosion_far",
"stream": false
},
{
"name": "target:explosion/far2",
"name": "target:explosion/explosion_far2",
"stream": false
},
{
"name": "target:explosion/far3",
"name": "target:explosion/explosion_far3",
"stream": false
}
]
},
"expveryfar": {
"explosion_very_far": {
"sounds": [
{
"name": "target:explosion/veryfar",
"name": "target:explosion/explosion_very_far",
"stream": false
},
{
"name": "target:explosion/veryfar2",
"name": "target:explosion/explosion_very_far2",
"stream": false
}
]
},
"explosion_water": {
"sounds": [
{
"name": "target:explosion/explosion_water",
"stream": false
},
{
"name": "target:explosion/explosion_water2",
"stream": false
},
{
"name": "target:explosion/explosion_water3",
"stream": false
}
]