移除新的procedure
This commit is contained in:
parent
aab783e319
commit
457e5b4345
8 changed files with 131 additions and 210 deletions
|
@ -1,14 +1,19 @@
|
|||
package net.mcreator.target.event;
|
||||
|
||||
import net.mcreator.target.init.TargetModAttributes;
|
||||
import net.mcreator.target.init.TargetModItems;
|
||||
import net.mcreator.target.init.TargetModTags;
|
||||
import net.mcreator.target.network.TargetModVariables;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.tags.ItemTags;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.Items;
|
||||
import net.minecraft.world.level.ClipContext;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import net.minecraftforge.event.TickEvent;
|
||||
import net.minecraftforge.event.entity.player.PlayerEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
|
@ -54,9 +59,15 @@ public class PlayerEventHandler {
|
|||
handleGround(player);
|
||||
handlePrepareZoom(player);
|
||||
handleSpecialWeaponAmmo(player);
|
||||
handleChangeFireRate(player);
|
||||
handleDistantRange(player);
|
||||
handleGunsDev(player);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断玩家是否趴下
|
||||
*/
|
||||
private static void handlePlayerProne(Player player) {
|
||||
Level level = player.level();
|
||||
|
||||
|
@ -81,6 +92,9 @@ public class PlayerEventHandler {
|
|||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断玩家是否在奔跑
|
||||
*/
|
||||
private static void handlePlayerSprint(Player player) {
|
||||
if (player.getMainHandItem().getOrCreateTag().getDouble("fireanim") > 0) {
|
||||
player.getPersistentData().putDouble("noRun", 20);
|
||||
|
@ -99,6 +113,9 @@ public class PlayerEventHandler {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理武器等级
|
||||
*/
|
||||
private static void handleWeaponLevel(Player player) {
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
if (stack.is(TargetModTags.Items.GUN)) {
|
||||
|
@ -172,26 +189,26 @@ public class PlayerEventHandler {
|
|||
if (stack.getItem() == TargetModItems.MINIGUN.get()) {
|
||||
return new java.text.DecimalFormat("##").format((player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new TargetModVariables.PlayerVariables())).rifleammo) + " " + firemode;
|
||||
}
|
||||
if (stack.is(ItemTags.create(new ResourceLocation("target:rifle")))) {
|
||||
if (stack.is(TargetModTags.Items.RIFLE)) {
|
||||
stack.getOrCreateTag().putDouble("maxammo",
|
||||
((player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new TargetModVariables.PlayerVariables())).rifleammo));
|
||||
return (new java.text.DecimalFormat("##").format(stack.getOrCreateTag().getDouble("ammo"))) + "/"
|
||||
+ new java.text.DecimalFormat("##").format((player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new TargetModVariables.PlayerVariables())).rifleammo) + " " + firemode;
|
||||
}
|
||||
if (stack.is(ItemTags.create(new ResourceLocation("target:handgun")))
|
||||
if (stack.is(TargetModTags.Items.HANDGUN)
|
||||
|| stack.is(ItemTags.create(new ResourceLocation("target:smg")))) {
|
||||
stack.getOrCreateTag().putDouble("maxammo",
|
||||
((player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new TargetModVariables.PlayerVariables())).handgunammo));
|
||||
return (new java.text.DecimalFormat("##").format(stack.getOrCreateTag().getDouble("ammo"))) + "/"
|
||||
+ new java.text.DecimalFormat("##").format((player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new TargetModVariables.PlayerVariables())).handgunammo) + " " + firemode;
|
||||
}
|
||||
if (stack.is(ItemTags.create(new ResourceLocation("target:shotgun")))) {
|
||||
if (stack.is(TargetModTags.Items.SHOTGUN)) {
|
||||
stack.getOrCreateTag().putDouble("maxammo",
|
||||
((player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new TargetModVariables.PlayerVariables())).shotgunammo));
|
||||
return (new java.text.DecimalFormat("##").format(stack.getOrCreateTag().getDouble("ammo"))) + "/"
|
||||
+ new java.text.DecimalFormat("##").format((player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new TargetModVariables.PlayerVariables())).shotgunammo) + " " + firemode;
|
||||
}
|
||||
if (stack.is(ItemTags.create(new ResourceLocation("target:sniperrifle")))) {
|
||||
if (stack.is(TargetModTags.Items.SNIPER_RIFLE)) {
|
||||
stack.getOrCreateTag().putDouble("maxammo",
|
||||
((player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new TargetModVariables.PlayerVariables())).sniperammo));
|
||||
return (new java.text.DecimalFormat("##").format(stack.getOrCreateTag().getDouble("ammo"))) + "/"
|
||||
|
@ -250,11 +267,11 @@ public class PlayerEventHandler {
|
|||
capability.syncPlayerVariables(player);
|
||||
});
|
||||
|
||||
if (player.getPersistentData().getDouble("miaozhunshijian") < 10) {
|
||||
player.getPersistentData().putDouble("miaozhunshijian", (player.getPersistentData().getDouble("miaozhunshijian") + 1));
|
||||
if (player.getPersistentData().getDouble("zoom_time") < 10) {
|
||||
player.getPersistentData().putDouble("zoom_time", (player.getPersistentData().getDouble("zoom_time") + 1));
|
||||
}
|
||||
} else {
|
||||
player.getPersistentData().putDouble("miaozhunshijian", 0);
|
||||
player.getPersistentData().putDouble("zoom_time", 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -270,4 +287,102 @@ public class PlayerEventHandler {
|
|||
stack.getOrCreateTag().putDouble("empty", 0);
|
||||
}
|
||||
}
|
||||
|
||||
private static void handleChangeFireRate(Player player) {
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
if (stack.is(TargetModTags.Items.GUN)) {
|
||||
if (stack.getOrCreateTag().getDouble("cg") > 0) {
|
||||
stack.getOrCreateTag().putDouble("cg", (stack.getOrCreateTag().getDouble("cg") - 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 望远镜瞄准时显示距离
|
||||
*/
|
||||
private static void handleDistantRange(Player player) {
|
||||
ItemStack stack = player.getUseItem();
|
||||
if (stack.getItem() == Items.SPYGLASS) {
|
||||
if (player.position().distanceTo((Vec3.atLowerCornerOf(player.level().clip(
|
||||
new ClipContext(player.getEyePosition(), player.getEyePosition().add(player.getLookAngle().scale(1024)),
|
||||
ClipContext.Block.OUTLINE, ClipContext.Fluid.NONE, player)).getBlockPos()))) <= 512) {
|
||||
if (!player.level().isClientSide())
|
||||
player.displayClientMessage(Component.literal((new java.text.DecimalFormat("##.#")
|
||||
.format(player.position().distanceTo((Vec3.atLowerCornerOf(
|
||||
player.level().clip(new ClipContext(player.getEyePosition(), player.getEyePosition().add(player.getLookAngle().scale(768)), ClipContext.Block.OUTLINE, ClipContext.Fluid.NONE, player)).getBlockPos()))))
|
||||
+ "M")), true);
|
||||
} else {
|
||||
if (player.level().isClientSide())
|
||||
player.displayClientMessage(Component.literal("---M"), true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void handleGunsDev(Player player) {
|
||||
double[] recoilTimer = {0};
|
||||
double totalTime = 20;
|
||||
int sleepTime = 2;
|
||||
double recoilDuration = totalTime / sleepTime;
|
||||
|
||||
Runnable recoilRunnable = () -> {
|
||||
while (recoilTimer[0] < recoilDuration) {
|
||||
if (player == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
|
||||
double basic = stack.getOrCreateTag().getDouble("dev");
|
||||
|
||||
double sprint = player.isSprinting() ? 0.5 * basic : 0;
|
||||
double sneaking = player.isShiftKeyDown() ? (-0.25) * basic : 0;
|
||||
double prone = player.getPersistentData().getDouble("prone") > 0 ? (-0.5) * basic : 0;
|
||||
double jump = player.onGround() ? 0 : 1.5 * basic;
|
||||
double fire = stack.getOrCreateTag().getDouble("fireanim") > 0 ? 0.5 * basic : 0;
|
||||
double ride = player.isPassenger() ? (-0.5) * basic : 0;
|
||||
|
||||
double walk;
|
||||
if (player.getPersistentData().getDouble("qian") == 1 || player.getPersistentData().getDouble("tui") == 1 ||
|
||||
player.getPersistentData().getDouble("mover") == 1 || player.getPersistentData().getDouble("movel") == 1) {
|
||||
walk = 0.2 * basic;
|
||||
} else {
|
||||
walk = 0;
|
||||
}
|
||||
|
||||
double zoom;
|
||||
if (player.getPersistentData().getDouble("zoom_time") > 4) {
|
||||
if (stack.is(TargetModTags.Items.SNIPER_RIFLE)) {
|
||||
zoom = 0.0001;
|
||||
} else if (stack.is(TargetModTags.Items.SHOTGUN)) {
|
||||
zoom = 0.9;
|
||||
} else {
|
||||
zoom = 0.0001;
|
||||
}
|
||||
} else {
|
||||
zoom = 1;
|
||||
}
|
||||
|
||||
double index = zoom * (basic + walk + sprint + sneaking + prone + jump + fire + ride);
|
||||
|
||||
if (player.getAttributeBaseValue(TargetModAttributes.SPREAD.get()) < index) {
|
||||
player.getAttribute(TargetModAttributes.SPREAD.get())
|
||||
.setBaseValue(player.getAttributeBaseValue(TargetModAttributes.SPREAD.get()) + 0.0125 * Math.pow(index - player.getAttributeBaseValue(TargetModAttributes.SPREAD.get()), 2));
|
||||
} else {
|
||||
player.getAttribute(TargetModAttributes.SPREAD.get())
|
||||
.setBaseValue(player.getAttributeBaseValue(TargetModAttributes.SPREAD.get()) - 0.0125 * Math.pow(index - player.getAttributeBaseValue(TargetModAttributes.SPREAD.get()), 2));
|
||||
}
|
||||
|
||||
recoilTimer[0]++;
|
||||
|
||||
try {
|
||||
Thread.sleep(sleepTime);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Thread recoilThread = new Thread(recoilRunnable);
|
||||
recoilThread.start();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,6 +11,14 @@ public class TargetModTags {
|
|||
|
||||
public static class Items {
|
||||
public static final TagKey<Item> GUN = tag("gun");
|
||||
public static final TagKey<Item> HANDGUN = tag("handgun");
|
||||
public static final TagKey<Item> RIFLE = tag("rifle");
|
||||
public static final TagKey<Item> SHOTGUN = tag("shotgun");
|
||||
public static final TagKey<Item> SNIPER_RIFLE = tag("sniper_rifle");
|
||||
public static final TagKey<Item> SMG = tag("smg");
|
||||
public static final TagKey<Item> NORMAL_MAG_GUN = tag("normal_mag_gun");
|
||||
public static final TagKey<Item> LEGENDARY_GUN = tag("legendary_gun");
|
||||
public static final TagKey<Item> SPECIAL_GUN = tag("special_gun");
|
||||
|
||||
private static TagKey<Item> tag(String name) {
|
||||
return ItemTags.create(new ResourceLocation(TargetMod.MODID, name));
|
||||
|
|
|
@ -58,7 +58,7 @@ public class ZoomMessage {
|
|||
capability.zooming = false;
|
||||
capability.syncPlayerVariables(entity);
|
||||
});
|
||||
entity.getPersistentData().putDouble("miaozhunshijian", 0);
|
||||
entity.getPersistentData().putDouble("zoom_time", 0);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,38 +0,0 @@
|
|||
package net.mcreator.target.procedures;
|
||||
|
||||
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 ChangefirerateProcedure {
|
||||
@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 instanceof LivingEntity _livEnt ? _livEnt.getMainHandItem() : ItemStack.EMPTY).getOrCreateTag().getDouble("cg") > 0) {
|
||||
(entity instanceof LivingEntity _livEnt ? _livEnt.getMainHandItem() : ItemStack.EMPTY).getOrCreateTag().putDouble("cg",
|
||||
((entity instanceof LivingEntity _livEnt ? _livEnt.getMainHandItem() : ItemStack.EMPTY).getOrCreateTag().getDouble("cg") - 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,50 +0,0 @@
|
|||
package net.mcreator.target.procedures;
|
||||
|
||||
import net.minecraft.network.chat.Component;
|
||||
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.minecraft.world.item.Items;
|
||||
import net.minecraft.world.level.ClipContext;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
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 DistantRangeProcedure {
|
||||
@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 _entUseItem0 ? _entUseItem0.getUseItem() : ItemStack.EMPTY).getItem() == Items.SPYGLASS) {
|
||||
if ((entity.position()).distanceTo((Vec3
|
||||
.atLowerCornerOf(entity.level().clip(new ClipContext(entity.getEyePosition(), entity.getEyePosition().add(entity.getLookAngle().scale(1024)), ClipContext.Block.OUTLINE, ClipContext.Fluid.NONE, entity)).getBlockPos()))) <= 512) {
|
||||
if (entity instanceof Player _player && !_player.level().isClientSide())
|
||||
_player.displayClientMessage(
|
||||
Component.literal((new java.text.DecimalFormat("##.#")
|
||||
.format((entity.position()).distanceTo((Vec3.atLowerCornerOf(
|
||||
entity.level().clip(new ClipContext(entity.getEyePosition(), entity.getEyePosition().add(entity.getLookAngle().scale(768)), ClipContext.Block.OUTLINE, ClipContext.Fluid.NONE, entity)).getBlockPos()))))
|
||||
+ "M")),
|
||||
true);
|
||||
} else {
|
||||
if (entity instanceof Player _player && !_player.level().isClientSide())
|
||||
_player.displayClientMessage(Component.literal("---M"), true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,114 +0,0 @@
|
|||
package net.mcreator.target.procedures;
|
||||
|
||||
import net.mcreator.target.init.TargetModAttributes;
|
||||
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 GunsDevProcedure {
|
||||
@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 = 20;
|
||||
int sleepTime = 2;
|
||||
double recoilDuration = totalTime / sleepTime;
|
||||
Runnable recoilRunnable = () -> {
|
||||
while (recoilTimer[0] < recoilDuration) {
|
||||
if (entity == null)
|
||||
return;
|
||||
double walk;
|
||||
double sprint;
|
||||
double qianxing;
|
||||
double basicdev;
|
||||
double prone;
|
||||
double jump;
|
||||
double xishu;
|
||||
double zoom;
|
||||
double fire;
|
||||
double ride;
|
||||
basicdev = (entity instanceof LivingEntity _livEnt ? _livEnt.getMainHandItem() : ItemStack.EMPTY).getOrCreateTag().getDouble("dev");
|
||||
if (entity.getPersistentData().getDouble("qian") == 1 || entity.getPersistentData().getDouble("tui") == 1 || entity.getPersistentData().getDouble("mover") == 1 || entity.getPersistentData().getDouble("movel") == 1) {
|
||||
walk = 0.2 * basicdev;
|
||||
} else {
|
||||
walk = 0;
|
||||
}
|
||||
if (entity.isSprinting()) {
|
||||
sprint = 0.5 * basicdev;
|
||||
} else {
|
||||
sprint = 0;
|
||||
}
|
||||
if (entity.isShiftKeyDown()) {
|
||||
qianxing = (-0.25) * basicdev;
|
||||
} else {
|
||||
qianxing = 0;
|
||||
}
|
||||
if (entity.getPersistentData().getDouble("prone") > 0) {
|
||||
prone = (-0.5) * basicdev;
|
||||
} else {
|
||||
prone = 0;
|
||||
}
|
||||
if (entity.onGround()) {
|
||||
jump = 0;
|
||||
} else {
|
||||
jump = 1.5 * basicdev;
|
||||
}
|
||||
if (entity.getPersistentData().getDouble("miaozhunshijian") > 4) {
|
||||
if ((entity instanceof LivingEntity _livEnt ? _livEnt.getMainHandItem() : ItemStack.EMPTY).getOrCreateTag().getDouble("sniperguns") == 1) {
|
||||
zoom = 0.0001;
|
||||
} else if ((entity instanceof LivingEntity _livEnt ? _livEnt.getMainHandItem() : ItemStack.EMPTY).getOrCreateTag().getDouble("shotgun") == 1) {
|
||||
zoom = 0.9;
|
||||
} else {
|
||||
zoom = 0.0001;
|
||||
}
|
||||
} else {
|
||||
zoom = 1;
|
||||
}
|
||||
if ((entity instanceof LivingEntity _livEnt ? _livEnt.getMainHandItem() : ItemStack.EMPTY).getOrCreateTag().getDouble("fireanim") > 0) {
|
||||
fire = 0.5 * basicdev;
|
||||
} else {
|
||||
fire = 0;
|
||||
}
|
||||
if (entity.isPassenger()) {
|
||||
ride = (-0.5) * basicdev;
|
||||
} else {
|
||||
ride = 0;
|
||||
}
|
||||
xishu = zoom * (basicdev + walk + sprint + qianxing + prone + jump + fire + ride);
|
||||
if (((LivingEntity) entity).getAttribute(TargetModAttributes.SPREAD.get()).getBaseValue() < xishu) {
|
||||
((LivingEntity) entity).getAttribute(TargetModAttributes.SPREAD.get())
|
||||
.setBaseValue((((LivingEntity) entity).getAttribute(TargetModAttributes.SPREAD.get()).getBaseValue() + 0.0125 * Math.pow(xishu - ((LivingEntity) entity).getAttribute(TargetModAttributes.SPREAD.get()).getBaseValue(), 2)));
|
||||
} else {
|
||||
((LivingEntity) entity).getAttribute(TargetModAttributes.SPREAD.get())
|
||||
.setBaseValue((((LivingEntity) entity).getAttribute(TargetModAttributes.SPREAD.get()).getBaseValue() - 0.0125 * Math.pow(xishu - ((LivingEntity) entity).getAttribute(TargetModAttributes.SPREAD.get()).getBaseValue(), 2)));
|
||||
}
|
||||
|
||||
recoilTimer[0]++;
|
||||
try {
|
||||
Thread.sleep(sleepTime);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
};
|
||||
Thread recoilThread = new Thread(recoilRunnable);
|
||||
recoilThread.start();
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue