调整音效,优化武器切换动画流程
This commit is contained in:
parent
14bb0ac8a8
commit
e759939003
19 changed files with 54 additions and 34 deletions
|
@ -140,9 +140,34 @@ public class LivingEntityEventHandler {
|
||||||
if (oldStack.getItem() instanceof GunItem oldGun && player.level() instanceof ServerLevel serverLevel) {
|
if (oldStack.getItem() instanceof GunItem oldGun && player.level() instanceof ServerLevel serverLevel) {
|
||||||
if (newStack.getItem() != oldStack.getItem()) {
|
if (newStack.getItem() != oldStack.getItem()) {
|
||||||
stopGunReloadSound(serverLevel, oldGun);
|
stopGunReloadSound(serverLevel, oldGun);
|
||||||
|
|
||||||
|
newStack.getOrCreateTag().putDouble("drawtime", 0);
|
||||||
|
player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
|
||||||
|
capability.zoom = false;
|
||||||
|
capability.syncPlayerVariables(player);
|
||||||
|
});
|
||||||
|
player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
|
||||||
|
capability.zooming = false;
|
||||||
|
capability.syncPlayerVariables(player);
|
||||||
|
});
|
||||||
|
player.getPersistentData().putDouble("zoompos", 0);
|
||||||
|
player.getPersistentData().putDouble("zoom_time", 0);
|
||||||
|
|
||||||
} else if (!newStack.getOrCreateTag().hasUUID("gun_uuid") || !oldStack.getOrCreateTag().hasUUID("gun_uuid") ||
|
} else if (!newStack.getOrCreateTag().hasUUID("gun_uuid") || !oldStack.getOrCreateTag().hasUUID("gun_uuid") ||
|
||||||
!newStack.getOrCreateTag().getUUID("gun_uuid").equals(oldStack.getOrCreateTag().getUUID("gun_uuid"))) {
|
!newStack.getOrCreateTag().getUUID("gun_uuid").equals(oldStack.getOrCreateTag().getUUID("gun_uuid"))) {
|
||||||
stopGunReloadSound(serverLevel, oldGun);
|
stopGunReloadSound(serverLevel, oldGun);
|
||||||
|
|
||||||
|
newStack.getOrCreateTag().putDouble("drawtime", 0);
|
||||||
|
player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
|
||||||
|
capability.zoom = false;
|
||||||
|
capability.syncPlayerVariables(player);
|
||||||
|
});
|
||||||
|
player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
|
||||||
|
capability.zooming = false;
|
||||||
|
capability.syncPlayerVariables(player);
|
||||||
|
});
|
||||||
|
player.getPersistentData().putDouble("zoompos", 0);
|
||||||
|
player.getPersistentData().putDouble("zoom_time", 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,8 +17,12 @@ import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.model.HumanoidModel;
|
import net.minecraft.client.model.HumanoidModel;
|
||||||
import net.minecraft.client.player.LocalPlayer;
|
import net.minecraft.client.player.LocalPlayer;
|
||||||
import net.minecraft.client.renderer.BlockEntityWithoutLevelRenderer;
|
import net.minecraft.client.renderer.BlockEntityWithoutLevelRenderer;
|
||||||
|
import net.minecraft.core.Holder;
|
||||||
import net.minecraft.nbt.CompoundTag;
|
import net.minecraft.nbt.CompoundTag;
|
||||||
import net.minecraft.network.chat.Component;
|
import net.minecraft.network.chat.Component;
|
||||||
|
import net.minecraft.network.protocol.game.ClientboundSoundPacket;
|
||||||
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
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;
|
||||||
import net.minecraft.world.InteractionHand;
|
import net.minecraft.world.InteractionHand;
|
||||||
|
@ -34,6 +38,7 @@ import net.minecraftforge.client.extensions.common.IClientItemExtensions;
|
||||||
import net.minecraftforge.event.TickEvent;
|
import net.minecraftforge.event.TickEvent;
|
||||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||||
import net.minecraftforge.fml.common.Mod;
|
import net.minecraftforge.fml.common.Mod;
|
||||||
|
import net.minecraftforge.registries.ForgeRegistries;
|
||||||
import software.bernie.geckolib.animatable.GeoItem;
|
import software.bernie.geckolib.animatable.GeoItem;
|
||||||
import software.bernie.geckolib.core.animatable.instance.AnimatableInstanceCache;
|
import software.bernie.geckolib.core.animatable.instance.AnimatableInstanceCache;
|
||||||
import software.bernie.geckolib.core.animation.AnimatableManager;
|
import software.bernie.geckolib.core.animation.AnimatableManager;
|
||||||
|
@ -170,7 +175,11 @@ public class VectorItem extends GunItem implements GeoItem, AnimatedItem {
|
||||||
if (tag.getDouble("reloading") == 1 && tag.getDouble("ammo") == 0) {
|
if (tag.getDouble("reloading") == 1 && tag.getDouble("ammo") == 0) {
|
||||||
if (tag.getDouble("reloadtime") == 61) {
|
if (tag.getDouble("reloadtime") == 61) {
|
||||||
entity.getPersistentData().putDouble("id", id);
|
entity.getPersistentData().putDouble("id", id);
|
||||||
entity.level().playSound(null, entity.blockPosition(), TargetModSounds.VECTOR_RELOAD_EMPTY.get(), SoundSource.PLAYERS, 100, 1);
|
if (entity instanceof ServerPlayer serverPlayer) {
|
||||||
|
serverPlayer.connection.send(new ClientboundSoundPacket(new Holder.Direct<>(ForgeRegistries.SOUND_EVENTS.getValue(new ResourceLocation("target:vector_reload_empty"))),
|
||||||
|
SoundSource.PLAYERS, serverPlayer.getX(), serverPlayer.getY(), serverPlayer.getZ(), 10f, 1f, serverPlayer.level().random.nextLong()));
|
||||||
|
}
|
||||||
|
// entity.level().playSound(null, entity.blockPosition(), TargetModSounds.VECTOR_RELOAD_EMPTY.get(), SoundSource.PLAYERS, 100, 1);
|
||||||
}
|
}
|
||||||
if (mainHandItem.getItem() == itemStack.getItem()
|
if (mainHandItem.getItem() == itemStack.getItem()
|
||||||
&& mainHandItem.getOrCreateTag().getDouble("id") == id
|
&& mainHandItem.getOrCreateTag().getDouble("id") == id
|
||||||
|
@ -187,7 +196,11 @@ public class VectorItem extends GunItem implements GeoItem, AnimatedItem {
|
||||||
} else if (tag.getDouble("reloading") == 1 && tag.getDouble("ammo") > 0) {
|
} else if (tag.getDouble("reloading") == 1 && tag.getDouble("ammo") > 0) {
|
||||||
if (tag.getDouble("reloadtime") == 47) {
|
if (tag.getDouble("reloadtime") == 47) {
|
||||||
entity.getPersistentData().putDouble("id", id);
|
entity.getPersistentData().putDouble("id", id);
|
||||||
entity.level().playSound(null, entity.blockPosition(), TargetModSounds.VECTOR_RELOAD_NORMAL.get(), SoundSource.PLAYERS, 100, 1);
|
if (entity instanceof ServerPlayer serverPlayer) {
|
||||||
|
serverPlayer.connection.send(new ClientboundSoundPacket(new Holder.Direct<>(ForgeRegistries.SOUND_EVENTS.getValue(new ResourceLocation("target:vector_reload_normal"))),
|
||||||
|
SoundSource.PLAYERS, serverPlayer.getX(), serverPlayer.getY(), serverPlayer.getZ(), 10f, 1f, serverPlayer.level().random.nextLong()));
|
||||||
|
}
|
||||||
|
// entity.level().playSound(null, entity.blockPosition(), TargetModSounds.VECTOR_RELOAD_NORMAL.get(), SoundSource.PLAYERS, 100, 1);
|
||||||
}
|
}
|
||||||
if (mainHandItem.getItem() == itemStack.getItem()
|
if (mainHandItem.getItem() == itemStack.getItem()
|
||||||
&& mainHandItem.getOrCreateTag().getDouble("id") == id
|
&& mainHandItem.getOrCreateTag().getDouble("id") == id
|
||||||
|
|
|
@ -3,9 +3,14 @@ package net.mcreator.target.network;
|
||||||
import net.mcreator.target.TargetMod;
|
import net.mcreator.target.TargetMod;
|
||||||
import net.mcreator.target.init.TargetModItems;
|
import net.mcreator.target.init.TargetModItems;
|
||||||
import net.mcreator.target.init.TargetModSounds;
|
import net.mcreator.target.init.TargetModSounds;
|
||||||
|
import net.minecraft.core.Holder;
|
||||||
import net.minecraft.nbt.CompoundTag;
|
import net.minecraft.nbt.CompoundTag;
|
||||||
import net.minecraft.network.FriendlyByteBuf;
|
import net.minecraft.network.FriendlyByteBuf;
|
||||||
import net.minecraft.network.chat.Component;
|
import net.minecraft.network.chat.Component;
|
||||||
|
import net.minecraft.network.protocol.game.ClientboundSoundPacket;
|
||||||
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
|
import net.minecraft.sounds.SoundEvent;
|
||||||
import net.minecraft.sounds.SoundSource;
|
import net.minecraft.sounds.SoundSource;
|
||||||
import net.minecraft.util.Mth;
|
import net.minecraft.util.Mth;
|
||||||
import net.minecraft.util.RandomSource;
|
import net.minecraft.util.RandomSource;
|
||||||
|
@ -16,6 +21,7 @@ import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||||
import net.minecraftforge.fml.common.Mod;
|
import net.minecraftforge.fml.common.Mod;
|
||||||
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
|
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
|
||||||
import net.minecraftforge.network.NetworkEvent;
|
import net.minecraftforge.network.NetworkEvent;
|
||||||
|
import net.minecraftforge.registries.ForgeRegistries;
|
||||||
|
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
|
@ -63,8 +69,10 @@ public class FireModeMessage {
|
||||||
default -> "";
|
default -> "";
|
||||||
};
|
};
|
||||||
|
|
||||||
player.displayClientMessage(Component.literal(text), true);
|
if (player instanceof ServerPlayer serverPlayer) {
|
||||||
player.level().playSound(null, player.blockPosition(), TargetModSounds.FIRERATE.get(), SoundSource.PLAYERS, 10, 1);
|
serverPlayer.connection.send(new ClientboundSoundPacket(new Holder.Direct<>(ForgeRegistries.SOUND_EVENTS.getValue(new ResourceLocation("target:firerate"))),
|
||||||
|
SoundSource.PLAYERS, serverPlayer.getX(), serverPlayer.getY(), serverPlayer.getZ(), 1f, 1f, serverPlayer.level().random.nextLong()));
|
||||||
|
}
|
||||||
|
|
||||||
tag.putDouble("firemode", mode);
|
tag.putDouble("firemode", mode);
|
||||||
tag.putDouble("cg", 10);
|
tag.putDouble("cg", 10);
|
||||||
|
|
|
@ -10,14 +10,7 @@ public class WeaponDrawLightProcedure {
|
||||||
public static void execute(Entity entity, ItemStack itemstack) {
|
public static void execute(Entity entity, ItemStack itemstack) {
|
||||||
if (entity == null)
|
if (entity == null)
|
||||||
return;
|
return;
|
||||||
if ((entity instanceof LivingEntity _livEnt ? _livEnt.getMainHandItem() : ItemStack.EMPTY).getItem() == itemstack.getItem()) {
|
if (itemstack.getOrCreateTag().getDouble("drawtime") == 1) {
|
||||||
if (itemstack.getOrCreateTag().getDouble("draw") < 2) {
|
|
||||||
itemstack.getOrCreateTag().putDouble("draw", (itemstack.getOrCreateTag().getDouble("draw") + 1));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
itemstack.getOrCreateTag().putDouble("draw", 0);
|
|
||||||
}
|
|
||||||
if (itemstack.getOrCreateTag().getDouble("draw") == 1) {
|
|
||||||
{
|
{
|
||||||
boolean _setval = false;
|
boolean _setval = false;
|
||||||
entity.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
|
entity.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
|
||||||
|
@ -35,8 +28,6 @@ public class WeaponDrawLightProcedure {
|
||||||
if (itemstack.getOrCreateTag().getDouble("drawtime") < 11) {
|
if (itemstack.getOrCreateTag().getDouble("drawtime") < 11) {
|
||||||
itemstack.getOrCreateTag().putDouble("drawtime", (itemstack.getOrCreateTag().getDouble("drawtime") + 1));
|
itemstack.getOrCreateTag().putDouble("drawtime", (itemstack.getOrCreateTag().getDouble("drawtime") + 1));
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
itemstack.getOrCreateTag().putDouble("drawtime", 0);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,14 +14,8 @@ public class WeaponDrawProcedure {
|
||||||
if (entity == null) return;
|
if (entity == null) return;
|
||||||
CompoundTag tag = itemStack.getOrCreateTag();
|
CompoundTag tag = itemStack.getOrCreateTag();
|
||||||
Item mainHandItem = (entity instanceof LivingEntity _livEnt ? _livEnt.getMainHandItem() : ItemStack.EMPTY).getItem();
|
Item mainHandItem = (entity instanceof LivingEntity _livEnt ? _livEnt.getMainHandItem() : ItemStack.EMPTY).getItem();
|
||||||
if (mainHandItem == itemStack.getItem()) {
|
|
||||||
if (tag.getDouble("draw") < 2) {
|
if (tag.getDouble("drawtime") == 1) {
|
||||||
tag.putDouble("draw", (tag.getDouble("draw") + 1));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
tag.putDouble("draw", 0);
|
|
||||||
}
|
|
||||||
if (tag.getDouble("draw") == 1) {
|
|
||||||
entity.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
|
entity.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
|
||||||
capability.zooming = false;
|
capability.zooming = false;
|
||||||
capability.syncPlayerVariables(entity);
|
capability.syncPlayerVariables(entity);
|
||||||
|
@ -39,8 +33,6 @@ public class WeaponDrawProcedure {
|
||||||
if (tag.getDouble("drawtime") < 16) {
|
if (tag.getDouble("drawtime") < 16) {
|
||||||
tag.putDouble("drawtime", (tag.getDouble("drawtime") + 1));
|
tag.putDouble("drawtime", (tag.getDouble("drawtime") + 1));
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
tag.putDouble("drawtime", 0);
|
|
||||||
}
|
}
|
||||||
if (tag.getDouble("fireanim") > 0) {
|
if (tag.getDouble("fireanim") > 0) {
|
||||||
tag.putDouble("fireanim", (tag.getDouble("fireanim") - 1));
|
tag.putDouble("fireanim", (tag.getDouble("fireanim") - 1));
|
||||||
|
|
|
@ -12,14 +12,7 @@ public class WeapondrawhaveyProcedure {
|
||||||
public static void execute(Entity entity, ItemStack itemstack) {
|
public static void execute(Entity entity, ItemStack itemstack) {
|
||||||
if (entity == null)
|
if (entity == null)
|
||||||
return;
|
return;
|
||||||
if ((entity instanceof LivingEntity _livEnt ? _livEnt.getMainHandItem() : ItemStack.EMPTY).getItem() == itemstack.getItem()) {
|
if (itemstack.getOrCreateTag().getDouble("drawtime") == 1) {
|
||||||
if (itemstack.getOrCreateTag().getDouble("draw") < 2) {
|
|
||||||
itemstack.getOrCreateTag().putDouble("draw", (itemstack.getOrCreateTag().getDouble("draw") + 1));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
itemstack.getOrCreateTag().putDouble("draw", 0);
|
|
||||||
}
|
|
||||||
if (itemstack.getOrCreateTag().getDouble("draw") == 1) {
|
|
||||||
{
|
{
|
||||||
boolean _setval = false;
|
boolean _setval = false;
|
||||||
entity.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
|
entity.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
|
||||||
|
@ -37,8 +30,6 @@ public class WeapondrawhaveyProcedure {
|
||||||
if (itemstack.getOrCreateTag().getDouble("drawtime") < 29) {
|
if (itemstack.getOrCreateTag().getDouble("drawtime") < 29) {
|
||||||
itemstack.getOrCreateTag().putDouble("drawtime", (itemstack.getOrCreateTag().getDouble("drawtime") + 1));
|
itemstack.getOrCreateTag().putDouble("drawtime", (itemstack.getOrCreateTag().getDouble("drawtime") + 1));
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
itemstack.getOrCreateTag().putDouble("drawtime", 0);
|
|
||||||
}
|
}
|
||||||
if (itemstack.getOrCreateTag().getDouble("fireanim") > 0) {
|
if (itemstack.getOrCreateTag().getDouble("fireanim") > 0) {
|
||||||
itemstack.getOrCreateTag().putDouble("fireanim", (itemstack.getOrCreateTag().getDouble("fireanim") - 1));
|
itemstack.getOrCreateTag().putDouble("fireanim", (itemstack.getOrCreateTag().getDouble("fireanim") - 1));
|
||||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Add table
Reference in a new issue