优化霰弹枪换弹方法
This commit is contained in:
parent
e3052a1b10
commit
b7d6209fd1
3 changed files with 38 additions and 69 deletions
|
@ -9,10 +9,7 @@ import net.minecraft.world.item.ItemStack;
|
||||||
|
|
||||||
public class Aa12WuPinZaiBeiBaoZhongShiMeiKeFaShengProcedure {
|
public class Aa12WuPinZaiBeiBaoZhongShiMeiKeFaShengProcedure {
|
||||||
public static void execute(Entity entity, ItemStack itemstack) {
|
public static void execute(Entity entity, ItemStack itemstack) {
|
||||||
if (entity == null)
|
double id = itemstack.getOrCreateTag().getDouble("id");
|
||||||
return;
|
|
||||||
double id = 0;
|
|
||||||
id = itemstack.getOrCreateTag().getDouble("id");
|
|
||||||
if ((entity instanceof LivingEntity _livEnt ? _livEnt.getMainHandItem() : ItemStack.EMPTY).getOrCreateTag().getDouble("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("emptyreload", 0);
|
||||||
itemstack.getOrCreateTag().putDouble("reloading", 0);
|
itemstack.getOrCreateTag().putDouble("reloading", 0);
|
||||||
|
@ -39,7 +36,9 @@ public class Aa12WuPinZaiBeiBaoZhongShiMeiKeFaShengProcedure {
|
||||||
itemstack.getOrCreateTag().putDouble("reloadtime", 0);
|
itemstack.getOrCreateTag().putDouble("reloadtime", 0);
|
||||||
}
|
}
|
||||||
if (itemstack.getOrCreateTag().getDouble("reloadtime") == 1 && (entity instanceof LivingEntity _livEnt ? _livEnt.getMainHandItem() : ItemStack.EMPTY).getOrCreateTag().getDouble("id") == id) {
|
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) {
|
} else if (itemstack.getOrCreateTag().getDouble("reloading") == 1 && itemstack.getOrCreateTag().getDouble("ammo") > 0) {
|
||||||
if (itemstack.getOrCreateTag().getDouble("reloadtime") == 41) {
|
if (itemstack.getOrCreateTag().getDouble("reloadtime") == 41) {
|
||||||
|
@ -62,7 +61,9 @@ public class Aa12WuPinZaiBeiBaoZhongShiMeiKeFaShengProcedure {
|
||||||
itemstack.getOrCreateTag().putDouble("reloadtime", 0);
|
itemstack.getOrCreateTag().putDouble("reloadtime", 0);
|
||||||
}
|
}
|
||||||
if (itemstack.getOrCreateTag().getDouble("reloadtime") == 1 && (entity instanceof LivingEntity _livEnt ? _livEnt.getMainHandItem() : ItemStack.EMPTY).getOrCreateTag().getDouble("id") == id) {
|
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);
|
WeaponDrawProcedure.execute(entity, itemstack);
|
||||||
|
|
|
@ -1,40 +1,26 @@
|
||||||
package net.mcreator.target.procedures;
|
package net.mcreator.target.procedures;
|
||||||
|
|
||||||
import net.mcreator.target.network.TargetModVariables;
|
import net.mcreator.target.network.TargetModVariables;
|
||||||
import net.minecraft.world.entity.Entity;
|
|
||||||
import net.minecraft.world.entity.LivingEntity;
|
import net.minecraft.world.entity.LivingEntity;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
|
|
||||||
public class ShotgunReload1Procedure {
|
public class ShotgunReload1Procedure {
|
||||||
public static void execute(Entity entity) {
|
public static void execute(LivingEntity entity) {
|
||||||
if (entity == null)
|
ItemStack stack = entity.getMainHandItem();
|
||||||
return;
|
double mag = stack.getOrCreateTag().getDouble("mag");
|
||||||
double ammo1 = 0;
|
double ammo = stack.getOrCreateTag().getDouble("ammo");
|
||||||
ItemStack stack = ItemStack.EMPTY;
|
|
||||||
stack = (entity instanceof LivingEntity _livEnt ? _livEnt.getMainHandItem() : ItemStack.EMPTY);
|
double empty = mag - ammo;
|
||||||
ammo1 = stack.getOrCreateTag().getDouble("mag") - stack.getOrCreateTag().getDouble("ammo");
|
double shotgunAmmo = entity.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new TargetModVariables.PlayerVariables()).shotgunammo;
|
||||||
if ((entity.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new TargetModVariables.PlayerVariables())).shotgunammo >= ammo1) {
|
|
||||||
{
|
stack.getOrCreateTag().putDouble("ammo", ammo + Math.min(empty, shotgunAmmo));
|
||||||
double _setval = (entity.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new TargetModVariables.PlayerVariables())).shotgunammo - ammo1;
|
|
||||||
entity.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
|
entity.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
|
||||||
capability.shotgunammo = _setval;
|
capability.shotgunammo = shotgunAmmo >= empty ? shotgunAmmo - empty : 0;
|
||||||
capability.syncPlayerVariables(entity);
|
capability.syncPlayerVariables(entity);
|
||||||
});
|
});
|
||||||
}
|
|
||||||
stack.getOrCreateTag().putDouble("ammo", (stack.getOrCreateTag().getDouble("ammo") + ammo1));
|
stack.getOrCreateTag().putDouble("reloading", 0);
|
||||||
stack.getOrCreateTag().putDouble("reloading", 0);
|
stack.getOrCreateTag().putDouble("emptyreload", 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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,41 +1,23 @@
|
||||||
package net.mcreator.target.procedures;
|
package net.mcreator.target.procedures;
|
||||||
|
|
||||||
import net.mcreator.target.network.TargetModVariables;
|
import net.mcreator.target.network.TargetModVariables;
|
||||||
import net.minecraft.world.entity.Entity;
|
|
||||||
import net.minecraft.world.entity.LivingEntity;
|
import net.minecraft.world.entity.LivingEntity;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
|
|
||||||
public class ShotgunReload2Procedure {
|
public class ShotgunReload2Procedure {
|
||||||
public static void execute(Entity entity) {
|
public static void execute(LivingEntity entity) {
|
||||||
if (entity == null)
|
ItemStack stack = entity.getMainHandItem();
|
||||||
return;
|
double mag = stack.getOrCreateTag().getDouble("mag");
|
||||||
ItemStack stack = ItemStack.EMPTY;
|
double ammo = stack.getOrCreateTag().getDouble("ammo");
|
||||||
double ammo2 = 0;
|
double ammo2 = mag + 1 - ammo;
|
||||||
double ammo1 = 0;
|
double shotgunAmmo = (entity.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new TargetModVariables.PlayerVariables())).shotgunammo;
|
||||||
stack = (entity instanceof LivingEntity _livEnt ? _livEnt.getMainHandItem() : ItemStack.EMPTY);
|
|
||||||
ammo2 = (stack.getOrCreateTag().getDouble("mag") + 1) - stack.getOrCreateTag().getDouble("ammo");
|
stack.getOrCreateTag().putDouble("ammo", ammo + Math.min(ammo2, shotgunAmmo));
|
||||||
if ((entity.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new TargetModVariables.PlayerVariables())).shotgunammo >= ammo2) {
|
entity.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
|
||||||
{
|
capability.shotgunammo = shotgunAmmo >= ammo2 ? shotgunAmmo - ammo2 : 0;
|
||||||
double _setval = (entity.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new TargetModVariables.PlayerVariables())).shotgunammo - ammo2;
|
capability.syncPlayerVariables(entity);
|
||||||
entity.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
|
});
|
||||||
capability.shotgunammo = _setval;
|
stack.getOrCreateTag().putDouble("reloading", 0);
|
||||||
capability.syncPlayerVariables(entity);
|
stack.getOrCreateTag().putDouble("emptyreload", 0);
|
||||||
});
|
|
||||||
}
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue