优化AA12换弹写法

This commit is contained in:
Light_Quanta 2024-05-12 14:25:39 +08:00
parent 042c1750df
commit bd647f2a4e
No known key found for this signature in database
GPG key ID: 11A39A1B8C890959
4 changed files with 28 additions and 51 deletions

View file

@ -0,0 +1,26 @@
package net.mcreator.target.procedures;
import net.mcreator.target.network.TargetModVariables;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.entity.LivingEntity;
public class AA12ReloadProcedure {
public static void execute(LivingEntity entity, boolean plusOne) {
CompoundTag tag = entity.getMainHandItem().getOrCreateTag();
double mag = tag.getDouble("mag");
double ammo = tag.getDouble("ammo");
double empty = mag - ammo + (plusOne ? 1 : 0);
double shotgunAmmo = entity.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).map(c -> c.shotgunammo).orElse(0d);
tag.putDouble("ammo", ammo + Math.min(empty, shotgunAmmo));
entity.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
capability.shotgunammo = Math.max(0, shotgunAmmo - empty);
capability.syncPlayerVariables(entity);
});
tag.putDouble("reloading", 0);
tag.putDouble("emptyreload", 0);
}
}

View file

@ -37,7 +37,7 @@ public class Aa12WuPinZaiBeiBaoZhongShiMeiKeFaShengProcedure {
}
if (itemstack.getOrCreateTag().getDouble("reloadtime") == 1 && (entity instanceof LivingEntity _livEnt ? _livEnt.getMainHandItem() : ItemStack.EMPTY).getOrCreateTag().getDouble("id") == id) {
if (entity instanceof LivingEntity) {
ShotgunReload1Procedure.execute((LivingEntity) entity);
AA12ReloadProcedure.execute((LivingEntity) entity, false);
}
}
} else if (itemstack.getOrCreateTag().getDouble("reloading") == 1 && itemstack.getOrCreateTag().getDouble("ammo") > 0) {
@ -62,7 +62,7 @@ public class Aa12WuPinZaiBeiBaoZhongShiMeiKeFaShengProcedure {
}
if (itemstack.getOrCreateTag().getDouble("reloadtime") == 1 && (entity instanceof LivingEntity _livEnt ? _livEnt.getMainHandItem() : ItemStack.EMPTY).getOrCreateTag().getDouble("id") == id) {
if (entity instanceof LivingEntity) {
ShotgunReload2Procedure.execute((LivingEntity) entity);
AA12ReloadProcedure.execute((LivingEntity) entity, true);
}
}
}

View file

@ -1,26 +0,0 @@
package net.mcreator.target.procedures;
import net.mcreator.target.network.TargetModVariables;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.item.ItemStack;
public class ShotgunReload1Procedure {
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 = shotgunAmmo >= empty ? shotgunAmmo - empty : 0;
capability.syncPlayerVariables(entity);
});
stack.getOrCreateTag().putDouble("reloading", 0);
stack.getOrCreateTag().putDouble("emptyreload", 0);
}
}

View file

@ -1,23 +0,0 @@
package net.mcreator.target.procedures;
import net.mcreator.target.network.TargetModVariables;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.item.ItemStack;
public class ShotgunReload2Procedure {
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 = shotgunAmmo >= ammo2 ? shotgunAmmo - ammo2 : 0;
capability.syncPlayerVariables(entity);
});
stack.getOrCreateTag().putDouble("reloading", 0);
stack.getOrCreateTag().putDouble("emptyreload", 0);
}
}