优化霰弹枪换弹方法

This commit is contained in:
Light_Quanta 2024-05-11 14:15:31 +08:00
parent e3052a1b10
commit b7d6209fd1
No known key found for this signature in database
GPG key ID: 11A39A1B8C890959
3 changed files with 38 additions and 69 deletions

View file

@ -9,10 +9,7 @@ import net.minecraft.world.item.ItemStack;
public class Aa12WuPinZaiBeiBaoZhongShiMeiKeFaShengProcedure {
public static void execute(Entity entity, ItemStack itemstack) {
if (entity == null)
return;
double id = 0;
id = itemstack.getOrCreateTag().getDouble("id");
double id = itemstack.getOrCreateTag().getDouble("id");
if ((entity instanceof LivingEntity _livEnt ? _livEnt.getMainHandItem() : ItemStack.EMPTY).getOrCreateTag().getDouble("id") != itemstack.getOrCreateTag().getDouble("id")) {
itemstack.getOrCreateTag().putDouble("emptyreload", 0);
itemstack.getOrCreateTag().putDouble("reloading", 0);
@ -39,7 +36,9 @@ public class Aa12WuPinZaiBeiBaoZhongShiMeiKeFaShengProcedure {
itemstack.getOrCreateTag().putDouble("reloadtime", 0);
}
if (itemstack.getOrCreateTag().getDouble("reloadtime") == 1 && (entity instanceof LivingEntity _livEnt ? _livEnt.getMainHandItem() : ItemStack.EMPTY).getOrCreateTag().getDouble("id") == id) {
ShotgunReload1Procedure.execute(entity);
if (entity instanceof LivingEntity) {
ShotgunReload1Procedure.execute((LivingEntity) entity);
}
}
} else if (itemstack.getOrCreateTag().getDouble("reloading") == 1 && itemstack.getOrCreateTag().getDouble("ammo") > 0) {
if (itemstack.getOrCreateTag().getDouble("reloadtime") == 41) {
@ -62,7 +61,9 @@ public class Aa12WuPinZaiBeiBaoZhongShiMeiKeFaShengProcedure {
itemstack.getOrCreateTag().putDouble("reloadtime", 0);
}
if (itemstack.getOrCreateTag().getDouble("reloadtime") == 1 && (entity instanceof LivingEntity _livEnt ? _livEnt.getMainHandItem() : ItemStack.EMPTY).getOrCreateTag().getDouble("id") == id) {
ShotgunReload2Procedure.execute(entity);
if (entity instanceof LivingEntity) {
ShotgunReload2Procedure.execute((LivingEntity) entity);
}
}
}
WeaponDrawProcedure.execute(entity, itemstack);

View file

@ -1,40 +1,26 @@
package net.mcreator.target.procedures;
import net.mcreator.target.network.TargetModVariables;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.item.ItemStack;
public class ShotgunReload1Procedure {
public static void execute(Entity entity) {
if (entity == null)
return;
double ammo1 = 0;
ItemStack stack = ItemStack.EMPTY;
stack = (entity instanceof LivingEntity _livEnt ? _livEnt.getMainHandItem() : ItemStack.EMPTY);
ammo1 = stack.getOrCreateTag().getDouble("mag") - stack.getOrCreateTag().getDouble("ammo");
if ((entity.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new TargetModVariables.PlayerVariables())).shotgunammo >= ammo1) {
{
double _setval = (entity.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new TargetModVariables.PlayerVariables())).shotgunammo - ammo1;
public static void execute(LivingEntity entity) {
ItemStack stack = entity.getMainHandItem();
double mag = stack.getOrCreateTag().getDouble("mag");
double ammo = stack.getOrCreateTag().getDouble("ammo");
double empty = mag - ammo;
double shotgunAmmo = entity.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new TargetModVariables.PlayerVariables()).shotgunammo;
stack.getOrCreateTag().putDouble("ammo", ammo + Math.min(empty, shotgunAmmo));
entity.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
capability.shotgunammo = _setval;
capability.shotgunammo = shotgunAmmo >= empty ? shotgunAmmo - empty : 0;
capability.syncPlayerVariables(entity);
});
}
stack.getOrCreateTag().putDouble("ammo", (stack.getOrCreateTag().getDouble("ammo") + ammo1));
stack.getOrCreateTag().putDouble("reloading", 0);
stack.getOrCreateTag().putDouble("emptyreload", 0);
} else {
stack.getOrCreateTag().putDouble("ammo", (stack.getOrCreateTag().getDouble("ammo") + (entity.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new TargetModVariables.PlayerVariables())).shotgunammo));
{
double _setval = 0;
entity.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
capability.shotgunammo = _setval;
capability.syncPlayerVariables(entity);
});
}
stack.getOrCreateTag().putDouble("reloading", 0);
stack.getOrCreateTag().putDouble("emptyreload", 0);
}
}
}

View file

@ -1,41 +1,23 @@
package net.mcreator.target.procedures;
import net.mcreator.target.network.TargetModVariables;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.item.ItemStack;
public class ShotgunReload2Procedure {
public static void execute(Entity entity) {
if (entity == null)
return;
ItemStack stack = ItemStack.EMPTY;
double ammo2 = 0;
double ammo1 = 0;
stack = (entity instanceof LivingEntity _livEnt ? _livEnt.getMainHandItem() : ItemStack.EMPTY);
ammo2 = (stack.getOrCreateTag().getDouble("mag") + 1) - stack.getOrCreateTag().getDouble("ammo");
if ((entity.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new TargetModVariables.PlayerVariables())).shotgunammo >= ammo2) {
{
double _setval = (entity.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new TargetModVariables.PlayerVariables())).shotgunammo - ammo2;
public static void execute(LivingEntity entity) {
ItemStack stack = entity.getMainHandItem();
double mag = stack.getOrCreateTag().getDouble("mag");
double ammo = stack.getOrCreateTag().getDouble("ammo");
double ammo2 = mag + 1 - ammo;
double shotgunAmmo = (entity.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new TargetModVariables.PlayerVariables())).shotgunammo;
stack.getOrCreateTag().putDouble("ammo", ammo + Math.min(ammo2, shotgunAmmo));
entity.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
capability.shotgunammo = _setval;
capability.shotgunammo = shotgunAmmo >= ammo2 ? shotgunAmmo - ammo2 : 0;
capability.syncPlayerVariables(entity);
});
}
stack.getOrCreateTag().putDouble("ammo", (stack.getOrCreateTag().getDouble("ammo") + ammo2));
stack.getOrCreateTag().putDouble("reloading", 0);
stack.getOrCreateTag().putDouble("emptyreload", 0);
} else {
stack.getOrCreateTag().putDouble("ammo", (stack.getOrCreateTag().getDouble("ammo") + (entity.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new TargetModVariables.PlayerVariables())).shotgunammo));
{
double _setval = 0;
entity.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
capability.shotgunammo = _setval;
capability.syncPlayerVariables(entity);
});
}
stack.getOrCreateTag().putDouble("reloading", 0);
stack.getOrCreateTag().putDouble("emptyreload", 0);
}
}
}