修改Vector Burst Fire实现

This commit is contained in:
Light_Quanta 2024-05-11 03:13:17 +08:00
parent 2452434531
commit ceba5abbea
No known key found for this signature in database
GPG key ID: 11A39A1B8C890959
2 changed files with 44 additions and 57 deletions

View file

@ -5,6 +5,8 @@ import com.google.common.collect.Multimap;
import net.mcreator.target.TargetMod;
import net.mcreator.target.client.renderer.item.VectorItemRenderer;
import net.mcreator.target.init.TargetModItems;
import net.mcreator.target.init.TargetModSounds;
import net.mcreator.target.init.TargetModTags;
import net.mcreator.target.item.AnimatedItem;
import net.mcreator.target.procedures.VectorWuPinZaiBeiBaoZhongShiMeiKeFaShengProcedure;
import net.mcreator.target.tools.GunsTool;
@ -13,7 +15,9 @@ import net.minecraft.client.Minecraft;
import net.minecraft.client.model.HumanoidModel;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.client.renderer.BlockEntityWithoutLevelRenderer;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component;
import net.minecraft.sounds.SoundSource;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EquipmentSlot;
@ -24,6 +28,9 @@ import net.minecraft.world.entity.ai.attributes.Attributes;
import net.minecraft.world.item.*;
import net.minecraft.world.level.Level;
import net.minecraftforge.client.extensions.common.IClientItemExtensions;
import net.minecraftforge.event.TickEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import software.bernie.geckolib.animatable.GeoItem;
import software.bernie.geckolib.core.animatable.instance.AnimatableInstanceCache;
import software.bernie.geckolib.core.animation.AnimatableManager;
@ -37,6 +44,7 @@ import java.util.List;
import java.util.UUID;
import java.util.function.Consumer;
@Mod.EventBusSubscriber
public class VectorItem extends GunItem implements GeoItem, AnimatedItem {
private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);
public String animationProcedure = "empty";
@ -73,7 +81,6 @@ public class VectorItem extends GunItem implements GeoItem, AnimatedItem {
ItemStack stack = player.getMainHandItem();
if (this.animationProcedure.equals("empty")) {
if (stack.getOrCreateTag().getDouble("drawtime") < 11) {
return event.setAndContinue(RawAnimation.begin().thenLoop("animation.vec.draw"));
}
@ -182,4 +189,40 @@ public class VectorItem extends GunItem implements GeoItem, AnimatedItem {
public void setAnimationProcedure(String procedure) {
this.animationProcedure = procedure;
}
@SubscribeEvent
public static void handleBurstFire(TickEvent.PlayerTickEvent event) {
if (event.phase != TickEvent.Phase.END) return;
var player = event.player;
ItemStack mainHandItem = player.getMainHandItem();
CompoundTag tag = mainHandItem.getOrCreateTag();
if (mainHandItem.is(TargetModTags.Items.GUN)) {
if (tag.getDouble("firemode") == 1) {
player.getPersistentData().putDouble("firing", 0);
}
if (tag.getDouble("ammo") == 0) {
tag.putDouble("burst", 0);
}
}
Item item = mainHandItem.getItem();
if (item == TargetModItems.VECTOR.get()
&& tag.getDouble("reloading") == 0
&& tag.getDouble("ammo") > 0
&& !player.getCooldowns().isOnCooldown(item)
&& tag.getDouble("burst") > 0
) {
player.getCooldowns().addCooldown(item, tag.getDouble("burst") == 1 ? 5 : 1);
tag.putDouble("burst", tag.getDouble("burst") - 1);
tag.putDouble("fireanim", 2);
tag.putDouble("ammo", (tag.getDouble("ammo") - 1));
GunsTool.spawnBullet(player);
player.level().playSound(null, player.blockPosition(), TargetModSounds.VECTOR_FIRE_1P.get(), SoundSource.PLAYERS, 2, 1);
player.level().playSound(null, player.blockPosition(), TargetModSounds.VECTOR_FIRE_1P.get(), SoundSource.PLAYERS, 4, 1);
player.level().playSound(null, player.blockPosition(), TargetModSounds.VECTOR_FAR.get(), SoundSource.PLAYERS, 6, 1);
player.level().playSound(null, player.blockPosition(), TargetModSounds.VECTOR_VERYFAR.get(), SoundSource.PLAYERS, 12, 1);
}
}
}

View file

@ -1,56 +0,0 @@
package net.mcreator.target.procedures;
import net.mcreator.target.init.TargetModItems;
import net.mcreator.target.tools.GunsTool;
import net.minecraft.commands.CommandSource;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.tags.ItemTags;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraftforge.event.TickEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
@Mod.EventBusSubscriber
public class VecBurstFireProcedure {
@SubscribeEvent
public static void onPlayerTick(TickEvent.PlayerTickEvent event) {
if (event.phase == TickEvent.Phase.END) {
execute(event.player);
}
}
private static void execute(Player player) {
ItemStack usehand;
usehand = player.getMainHandItem();
if (usehand.is(ItemTags.create(new ResourceLocation("target:gun")))) {
if (usehand.getOrCreateTag().getDouble("firemode") == 1) {
player.getPersistentData().putDouble("firing", 0);
}
if (usehand.getOrCreateTag().getDouble("ammo") == 0) {
usehand.getOrCreateTag().putDouble("burst", 0);
}
}
if (usehand.getItem() == TargetModItems.VECTOR.get() && usehand.getOrCreateTag().getDouble("reloading") == 0 && usehand.getOrCreateTag().getDouble("ammo") > 0
&& !(player.getCooldowns().isOnCooldown(usehand.getItem())) && usehand.getOrCreateTag().getDouble("burst") > 0) {
player.getCooldowns().addCooldown(usehand.getItem(), usehand.getOrCreateTag().getDouble("burst") == 1 ? 5 : 1);
usehand.getOrCreateTag().putDouble("burst", (usehand.getOrCreateTag().getDouble("burst") - 1));
GunsTool.spawnBullet(player);
if (!player.level().isClientSide() && player.getServer() != null) {
player.getServer().getCommands().performPrefixedCommand(new CommandSourceStack(CommandSource.NULL, player.position(), player.getRotationVector(), (ServerLevel) player.level(), 4,
player.getName().getString(), player.getDisplayName(), player.level().getServer(), player), "playsound target:vector_fire_1p player @a ~ ~ ~ 2 1");
player.getServer().getCommands().performPrefixedCommand(new CommandSourceStack(CommandSource.NULL, player.position(), player.getRotationVector(), (ServerLevel) player.level(), 4,
player.getName().getString(), player.getDisplayName(), player.level().getServer(), player), "playsound target:vector_fire_1p player @s ~ ~ ~ 4 1");
player.getServer().getCommands().performPrefixedCommand(new CommandSourceStack(CommandSource.NULL, player.position(), player.getRotationVector(), (ServerLevel) player.level(), 4,
player.getName().getString(), player.getDisplayName(), player.level().getServer(), player), "playsound target:vector_far player @a ~ ~ ~ 6 1");
player.getServer().getCommands().performPrefixedCommand(new CommandSourceStack(CommandSource.NULL, player.position(), player.getRotationVector(), (ServerLevel) player.level(), 4,
player.getName().getString(), player.getDisplayName(), player.level().getServer(), player), "playsound target:vector_veryfar player @a ~ ~ ~ 12 1");
}
usehand.getOrCreateTag().putDouble("fireanim", 2);
usehand.getOrCreateTag().putDouble("ammo", (usehand.getOrCreateTag().getDouble("ammo") - 1));
}
}
}