修改瞄准流程
This commit is contained in:
parent
e33c02c21e
commit
2e5d9b75f6
2 changed files with 24 additions and 40 deletions
24
src/main/java/net/mcreator/target/event/AimingHandler.java
Normal file
24
src/main/java/net/mcreator/target/event/AimingHandler.java
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
package net.mcreator.target.event;
|
||||||
|
|
||||||
|
import net.mcreator.target.network.TargetModVariables;
|
||||||
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
import net.minecraft.tags.ItemTags;
|
||||||
|
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 AimingHandler {
|
||||||
|
|
||||||
|
@SubscribeEvent
|
||||||
|
public static void onPlayerTick(TickEvent.PlayerTickEvent event) {
|
||||||
|
if (event.phase == TickEvent.Phase.END && event.player != null) {
|
||||||
|
ItemStack itemstack = event.player.getMainHandItem();
|
||||||
|
|
||||||
|
if (itemstack.is(ItemTags.create(new ResourceLocation("target:gun")))) {
|
||||||
|
itemstack.getOrCreateTag().putBoolean("aiming", event.player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new TargetModVariables.PlayerVariables()).zooming);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,40 +0,0 @@
|
||||||
package net.mcreator.target.procedures;
|
|
||||||
|
|
||||||
import net.mcreator.target.network.TargetModVariables;
|
|
||||||
import net.minecraft.resources.ResourceLocation;
|
|
||||||
import net.minecraft.tags.ItemTags;
|
|
||||||
import net.minecraft.world.entity.Entity;
|
|
||||||
import net.minecraft.world.entity.LivingEntity;
|
|
||||||
import net.minecraft.world.item.ItemStack;
|
|
||||||
import net.minecraftforge.event.TickEvent;
|
|
||||||
import net.minecraftforge.eventbus.api.Event;
|
|
||||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
|
||||||
import net.minecraftforge.fml.common.Mod;
|
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
|
|
||||||
@Mod.EventBusSubscriber
|
|
||||||
public class AimingProcedure {
|
|
||||||
@SubscribeEvent
|
|
||||||
public static void onPlayerTick(TickEvent.PlayerTickEvent event) {
|
|
||||||
if (event.phase == TickEvent.Phase.END) {
|
|
||||||
execute(event, event.player);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void execute(Entity entity) {
|
|
||||||
execute(null, entity);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void execute(@Nullable Event event, Entity entity) {
|
|
||||||
if (entity == null)
|
|
||||||
return;
|
|
||||||
if ((entity instanceof LivingEntity _livEnt ? _livEnt.getMainHandItem() : ItemStack.EMPTY).is(ItemTags.create(new ResourceLocation("target:gun")))) {
|
|
||||||
if ((entity.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new TargetModVariables.PlayerVariables())).zooming) {
|
|
||||||
(entity instanceof LivingEntity _livEnt ? _livEnt.getMainHandItem() : ItemStack.EMPTY).getOrCreateTag().putBoolean("aiming", true);
|
|
||||||
} else {
|
|
||||||
(entity instanceof LivingEntity _livEnt ? _livEnt.getMainHandItem() : ItemStack.EMPTY).getOrCreateTag().putBoolean("aiming", false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Add table
Reference in a new issue