移除瞄准相关procedure

This commit is contained in:
17146 2024-05-07 23:26:02 +08:00
parent 3392193d7a
commit 64de84a32b
4 changed files with 62 additions and 148 deletions

View file

@ -48,6 +48,9 @@ public class PlayerEventHandler {
handleWeaponLevel(player);
handleWeaponSway(player);
handleAmmoCount(player);
handleFireTime(player);
handleGround(player);
handlePrepareZoom(player);
}
}
@ -194,4 +197,63 @@ public class PlayerEventHandler {
return (new java.text.DecimalFormat("##").format(stack.getOrCreateTag().getDouble("ammo"))) + "/"
+ (new java.text.DecimalFormat("##").format(stack.getOrCreateTag().getDouble("maxammo"))) + " " + firemode;
}
private static void handleFireTime(Player player) {
double[] recoilTimer = {0};
double totalTime = 50;
int sleepTime = 2;
double recoilDuration = totalTime / sleepTime;
Runnable recoilRunnable = () -> {
while (recoilTimer[0] < recoilDuration) {
if (player == null) {
return;
}
if ((player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new TargetModVariables.PlayerVariables())).firing > 0) {
player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
capability.firing = (player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new TargetModVariables.PlayerVariables())).firing - 0.05;
capability.syncPlayerVariables(player);
});
}
recoilTimer[0]++;
try {
Thread.sleep(sleepTime);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
};
Thread recoilThread = new Thread(recoilRunnable);
recoilThread.start();
}
private static void handleGround(Player player) {
if (player.onGround()) {
player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
capability.playerdoublejump = false;
capability.syncPlayerVariables(player);
});
}
}
private static void handlePrepareZoom(Player player) {
ItemStack stack = player.getMainHandItem();
if (stack.is(TargetModTags.Items.GUN) && stack.getOrCreateTag().getDouble("reloading") != 1 && !player.isSpectator()) {
if (player.getMainHandItem().getItem() != TargetModItems.MINIGUN.get()) {
if ((player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new TargetModVariables.PlayerVariables())).zoom) {
player.setSprinting(false);
player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
capability.zooming = true;
capability.syncPlayerVariables(player);
});
if (player.getPersistentData().getDouble("miaozhunshijian") < 10) {
player.getPersistentData().putDouble("miaozhunshijian", (player.getPersistentData().getDouble("miaozhunshijian") + 1));
}
} else {
player.getPersistentData().putDouble("miaozhunshijian", 0);
}
}
}
}
}

View file

@ -1,57 +0,0 @@
package net.mcreator.target.procedures;
import net.mcreator.target.network.TargetModVariables;
import net.minecraft.world.entity.Entity;
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 FiretimeProcedure {
@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) {
double[] recoilTimer = {0};
double totalTime = 50;
int sleepTime = 2;
double recoilDuration = totalTime / sleepTime;
Runnable recoilRunnable = () -> {
while (recoilTimer[0] < recoilDuration) {
if (entity == null)
return;
if ((entity.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new TargetModVariables.PlayerVariables())).firing > 0) {
{
double _setval = (entity.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new TargetModVariables.PlayerVariables())).firing - 0.05;
entity.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
capability.firing = _setval;
capability.syncPlayerVariables(entity);
});
}
}
recoilTimer[0]++;
try {
Thread.sleep(sleepTime);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
};
Thread recoilThread = new Thread(recoilRunnable);
recoilThread.start();
}
}

View file

@ -1,38 +0,0 @@
package net.mcreator.target.procedures;
import net.mcreator.target.network.TargetModVariables;
import net.minecraft.world.entity.Entity;
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 GroundProcedure {
@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.onGround()) {
{
boolean _setval = false;
entity.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
capability.playerdoublejump = _setval;
capability.syncPlayerVariables(entity);
});
}
}
}
}

View file

@ -1,53 +0,0 @@
package net.mcreator.target.procedures;
import net.mcreator.target.init.TargetModItems;
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.entity.player.Player;
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 PrepareToZoomProcedure {
@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")))
&& !((entity instanceof LivingEntity _livEnt ? _livEnt.getMainHandItem() : ItemStack.EMPTY).getOrCreateTag().getDouble("reloading") == 1) &&
entity instanceof Player player && !player.isSpectator()) {
if (!(player.getMainHandItem().getItem() == TargetModItems.MINIGUN.get())) {
if ((entity.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new TargetModVariables.PlayerVariables())).zoom) {
entity.setSprinting(false);
entity.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
capability.zooming = true;
capability.syncPlayerVariables(entity);
});
if (entity.getPersistentData().getDouble("miaozhunshijian") < 10) {
entity.getPersistentData().putDouble("miaozhunshijian", (entity.getPersistentData().getDouble("miaozhunshijian") + 1));
}
} else {
entity.getPersistentData().putDouble("miaozhunshijian", 0);
}
}
}
}
}