优化音效和描述

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.registries.ForgeRegistries;
import java.util.concurrent.atomic.AtomicBoolean;
@Mod.EventBusSubscriber
public class GunEventHandler {
@ -267,7 +269,14 @@ public class GunEventHandler {
String origin = stack.getItem().getDescriptionId();
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()) {
AtomicBoolean charged = new AtomicBoolean(false);
stack.getCapability(ForgeCapabilities.ENERGY).ifPresent(
e -> charged.set(e.getEnergyStored() > 0)
);
if (charged.get()) {
SoundEvent sound1p = ForgeRegistries.SOUND_EVENTS.getValue(new ResourceLocation(TargetMod.MODID, "sentinel_charge_fire_1p"));
if (sound1p != null && player instanceof ServerPlayer serverPlayer) {
SoundTool.playLocalSound(serverPlayer, sound1p, 2f, 1f);
@ -287,6 +296,7 @@ public class GunEventHandler {
if (soundVeryFar != null) {
player.playSound(soundVeryFar, 24f, 1f);
}
}
} else {
SoundEvent sound1p = ForgeRegistries.SOUND_EVENTS.getValue(new ResourceLocation(TargetMod.MODID, name + "_fire_1p"));
if (sound1p != null && player instanceof ServerPlayer serverPlayer) {
@ -769,7 +779,6 @@ public class GunEventHandler {
CompoundTag tag = stack.getOrCreateTag();
//启动换弹
if (tag.getBoolean("start_sentinel_charge")) {
tag.putInt("sentinel_charge_time", 127);
stack.getOrCreateTag().putBoolean("sentinel_is_charging", true);
@ -790,7 +799,6 @@ public class GunEventHandler {
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());
}

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);
return InteractionResult.SUCCESS;

View file

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

View file

@ -169,7 +169,6 @@ public class FireMessage {
player.playSound(TargetModSounds.BOCEK_ZOOM_FIRE_3P.get(), 2, 1);
}
} else {
stack.getOrCreateTag().putBoolean("shoot", true);
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.network.chat.Component;
import net.minecraft.world.item.ItemStack;
import net.minecraftforge.common.capabilities.ForgeCapabilities;
import java.text.DecimalFormat;
import java.util.List;
@ -103,5 +104,9 @@ public class TooltipTool {
}
addLevelTips(tooltip, stack);
stack.getCapability(ForgeCapabilities.ENERGY).ifPresent(
e -> tooltip.add(Component.literal(e.getEnergyStored() + " / " + e.getMaxEnergyStored() + " FE").withStyle(ChatFormatting.GRAY))
);
}
}