优化音效和描述

This commit is contained in:
17146 2024-07-15 00:06:47 +08:00
parent 978d3c7ab0
commit f4a48c5aba
5 changed files with 32 additions and 22 deletions

View file

@ -25,6 +25,8 @@ import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.registries.ForgeRegistries; import net.minecraftforge.registries.ForgeRegistries;
import java.util.concurrent.atomic.AtomicBoolean;
@Mod.EventBusSubscriber @Mod.EventBusSubscriber
public class GunEventHandler { public class GunEventHandler {
@ -267,25 +269,33 @@ public class GunEventHandler {
String origin = stack.getItem().getDescriptionId(); String origin = stack.getItem().getDescriptionId();
String name = origin.substring(origin.lastIndexOf(".") + 1); String name = origin.substring(origin.lastIndexOf(".") + 1);
if (player.getMainHandItem().getItem() == TargetModItems.SENTINEL.get() && stack.getOrCreateTag().getDouble("power") > 0) { if (stack.getItem() == TargetModItems.SENTINEL.get()) {
SoundEvent sound1p = ForgeRegistries.SOUND_EVENTS.getValue(new ResourceLocation(TargetMod.MODID, "sentinel_charge_fire_1p")); AtomicBoolean charged = new AtomicBoolean(false);
if (sound1p != null && player instanceof ServerPlayer serverPlayer) {
SoundTool.playLocalSound(serverPlayer, sound1p, 2f, 1f);
}
SoundEvent sound3p = ForgeRegistries.SOUND_EVENTS.getValue(new ResourceLocation(TargetMod.MODID, "sentinel_charge_fire_3p")); stack.getCapability(ForgeCapabilities.ENERGY).ifPresent(
if (sound3p != null) { e -> charged.set(e.getEnergyStored() > 0)
player.level().playSound(null, player.getOnPos(), sound3p, SoundSource.PLAYERS, 4f, 1f); );
}
SoundEvent soundFar = ForgeRegistries.SOUND_EVENTS.getValue(new ResourceLocation(TargetMod.MODID, "sentinel_charge_far")); if (charged.get()) {
if (soundFar != null) { SoundEvent sound1p = ForgeRegistries.SOUND_EVENTS.getValue(new ResourceLocation(TargetMod.MODID, "sentinel_charge_fire_1p"));
player.playSound(soundFar, 12f, 1f); if (sound1p != null && player instanceof ServerPlayer serverPlayer) {
} SoundTool.playLocalSound(serverPlayer, sound1p, 2f, 1f);
}
SoundEvent soundVeryFar = ForgeRegistries.SOUND_EVENTS.getValue(new ResourceLocation(TargetMod.MODID, "sentinel_charge_veryfar")); SoundEvent sound3p = ForgeRegistries.SOUND_EVENTS.getValue(new ResourceLocation(TargetMod.MODID, "sentinel_charge_fire_3p"));
if (soundVeryFar != null) { if (sound3p != null) {
player.playSound(soundVeryFar, 24f, 1f); player.level().playSound(null, player.getOnPos(), sound3p, SoundSource.PLAYERS, 4f, 1f);
}
SoundEvent soundFar = ForgeRegistries.SOUND_EVENTS.getValue(new ResourceLocation(TargetMod.MODID, "sentinel_charge_far"));
if (soundFar != null) {
player.playSound(soundFar, 12f, 1f);
}
SoundEvent soundVeryFar = ForgeRegistries.SOUND_EVENTS.getValue(new ResourceLocation(TargetMod.MODID, "sentinel_charge_veryfar"));
if (soundVeryFar != null) {
player.playSound(soundVeryFar, 24f, 1f);
}
} }
} else { } else {
SoundEvent sound1p = ForgeRegistries.SOUND_EVENTS.getValue(new ResourceLocation(TargetMod.MODID, name + "_fire_1p")); SoundEvent sound1p = ForgeRegistries.SOUND_EVENTS.getValue(new ResourceLocation(TargetMod.MODID, name + "_fire_1p"));
@ -769,7 +779,6 @@ public class GunEventHandler {
CompoundTag tag = stack.getOrCreateTag(); CompoundTag tag = stack.getOrCreateTag();
//启动换弹 //启动换弹
if (tag.getBoolean("start_sentinel_charge")) { if (tag.getBoolean("start_sentinel_charge")) {
tag.putInt("sentinel_charge_time", 127); tag.putInt("sentinel_charge_time", 127);
stack.getOrCreateTag().putBoolean("sentinel_is_charging", true); stack.getOrCreateTag().putBoolean("sentinel_is_charging", true);
@ -790,7 +799,6 @@ public class GunEventHandler {
iEnergyStorage -> iEnergyStorage.receiveEnergy(24000, false) iEnergyStorage -> iEnergyStorage.receiveEnergy(24000, false)
); );
// tag.putDouble("power", Mth.clamp(tag.getDouble("power") + 24000,0,240000));
player.getInventory().clearOrCountMatchingItems(p -> p.getItem() == TargetModItems.SHIELD_CELL.get(), 1, player.inventoryMenu.getCraftSlots()); player.getInventory().clearOrCountMatchingItems(p -> p.getItem() == TargetModItems.SHIELD_CELL.get(), 1, player.inventoryMenu.getCraftSlots());
} }

View file

@ -43,7 +43,7 @@ public class TargetDeployer extends Item {
} }
} }
player.getInventory().clearOrCountMatchingItems(p -> TargetModItems.TARGET_DEPLOYER.get() == p.getItem(), 1, player.inventoryMenu.getCraftSlots()); context.getItemInHand().shrink(1);
player.swing(InteractionHand.MAIN_HAND, true); player.swing(InteractionHand.MAIN_HAND, true);
return InteractionResult.SUCCESS; return InteractionResult.SUCCESS;

View file

@ -207,8 +207,6 @@ public class SentinelItem extends GunItem implements GeoItem, AnimatedItem {
energy -> { energy -> {
int energyStored = energy.getEnergyStored(); int energyStored = energy.getEnergyStored();
System.out.println("Client:" + world.isClientSide + " " + energyStored);
if (energyStored > 0) { if (energyStored > 0) {
energy.extractEnergy(5, false); energy.extractEnergy(5, false);

View file

@ -169,7 +169,6 @@ public class FireMessage {
player.playSound(TargetModSounds.BOCEK_ZOOM_FIRE_3P.get(), 2, 1); player.playSound(TargetModSounds.BOCEK_ZOOM_FIRE_3P.get(), 2, 1);
} }
} else { } else {
stack.getOrCreateTag().putBoolean("shoot", true); stack.getOrCreateTag().putBoolean("shoot", true);
for (int index0 = 0; index0 < 10; index0++) { for (int index0 = 0; index0 < 10; index0++) {

View file

@ -4,6 +4,7 @@ import net.minecraft.ChatFormatting;
import net.minecraft.client.gui.screens.Screen; import net.minecraft.client.gui.screens.Screen;
import net.minecraft.network.chat.Component; import net.minecraft.network.chat.Component;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraftforge.common.capabilities.ForgeCapabilities;
import java.text.DecimalFormat; import java.text.DecimalFormat;
import java.util.List; import java.util.List;
@ -103,5 +104,9 @@ public class TooltipTool {
} }
addLevelTips(tooltip, stack); addLevelTips(tooltip, stack);
stack.getCapability(ForgeCapabilities.ENERGY).ifPresent(
e -> tooltip.add(Component.literal(e.getEnergyStored() + " / " + e.getMaxEnergyStored() + " FE").withStyle(ChatFormatting.GRAY))
);
} }
} }