重制哨兵充能

This commit is contained in:
Atsuihsio 2024-07-08 12:51:45 +08:00
parent 99aa83927a
commit 02d09cbc61
5 changed files with 55 additions and 2 deletions

View file

@ -41,6 +41,7 @@ public class GunEventHandler {
handleMiniGunFire(player);
handleGunReload(player);
handleGunSingleReload(player);
handleSentinelCharge(player);
}
}
@ -754,4 +755,36 @@ public class GunEventHandler {
}
}
}
/**
* 哨兵充能
*/
private static void handleSentinelCharge(Player player) {
ItemStack stack = player.getMainHandItem();
CompoundTag tag = stack.getOrCreateTag();
//启动换弹
if (tag.getBoolean("start_sentinel_charge")) {
tag.putInt("sentinel_charge_time", 127);
stack.getOrCreateTag().putBoolean("sentinel_is_charging", true);
SoundEvent sound1p = ForgeRegistries.SOUND_EVENTS.getValue(new ResourceLocation(TargetMod.MODID, "sentinel_charge"));
if (sound1p != null && player instanceof ServerPlayer serverPlayer) {
SoundTool.playLocalSound(serverPlayer, sound1p, 2f, 1f);
}
tag.putBoolean("start_sentinel_charge", false);
}
if (tag.getInt("sentinel_charge_time") > 0) {
tag.putInt("sentinel_charge_time", tag.getInt("sentinel_charge_time") - 1);
}
if (tag.getInt("sentinel_charge_time") == 1) {
tag.putDouble("power",100);
tag.putBoolean("sentinel_is_charging", false);
}
}
}

View file

@ -173,6 +173,9 @@ public class LivingEventHandler {
oldTags.putDouble("prepare_load", 0);
oldTags.putDouble("iterative", 0);
oldTags.putDouble("finish", 0);
oldTags.putBoolean("sentinel_is_charging", false);
oldTags.putInt("sentinel_charge_time", 0);
}
if (newStack.getItem() instanceof GunItem) {
@ -193,6 +196,9 @@ public class LivingEventHandler {
newStack.getOrCreateTag().putDouble("iterative", 0);
newStack.getOrCreateTag().putDouble("finish", 0);
newStack.getOrCreateTag().putBoolean("sentinel_is_charging", false);
newStack.getOrCreateTag().putInt("sentinel_charge_time", 0);
double weight = newStack.getOrCreateTag().getDouble("weight");
if (weight == 0) {

View file

@ -125,7 +125,7 @@ public class SentinelItem extends GunItem implements GeoItem, AnimatedItem {
}
if (stack.getOrCreateTag().getDouble("charging_time") < 127 && stack.getOrCreateTag().getDouble("charging_time") > 0 && stack.getOrCreateTag().getBoolean("charging")) {
if (stack.getOrCreateTag().getDouble("sentinel_charge_time") < 127 && stack.getOrCreateTag().getDouble("sentinel_charge_time") > 0 && stack.getOrCreateTag().getBoolean("sentinel_is_charging")) {
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.sentinel.charge"));
}

View file

@ -1,7 +1,9 @@
package net.mcreator.target.network.message;
import net.mcreator.target.init.TargetModItems;
import net.mcreator.target.init.TargetModSounds;
import net.mcreator.target.init.TargetModTags;
import net.mcreator.target.network.TargetModVariables;
import net.minecraft.core.Holder;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.FriendlyByteBuf;
@ -94,6 +96,18 @@ public class FireModeMessage {
setFireMode(player, tag);
}
}
var capability = player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new TargetModVariables.PlayerVariables());
if (mainHandItem.getItem() == TargetModItems.SENTINEL.get()
&& !player.isSpectator()
&& !capability.zooming
&& !(player.getCooldowns().isOnCooldown(mainHandItem.getItem()))
&& mainHandItem.getOrCreateTag().getInt("gun_reloading_time") == 0
&& !mainHandItem.getOrCreateTag().getBoolean("sentinel_is_charging")){
tag.putBoolean("start_sentinel_charge", true);
}
}
}
}

View file

@ -50,7 +50,7 @@ public class ReloadMessage {
&& stack.is(TargetModTags.Items.GUN)
&& !capability.zooming
&& !(player.getCooldowns().isOnCooldown(stack.getItem()))
&& (stack.getOrCreateTag().getInt("gun_reloading_time") == 0)
&& stack.getOrCreateTag().getInt("gun_reloading_time") == 0
) {
CompoundTag tag = stack.getOrCreateTag();