优化换弹流程
This commit is contained in:
parent
f3c0f173eb
commit
b730ae4b0b
13 changed files with 59 additions and 100 deletions
|
@ -39,7 +39,7 @@ public class AK47WuPinZaiBeiBaoZhongShiMeiKeFaShengProcedure {
|
|||
itemstack.getOrCreateTag().putDouble("reloadtime", 0);
|
||||
}
|
||||
if (itemstack.getOrCreateTag().getDouble("reloadtime") == 1 && (entity instanceof LivingEntity _livEnt ? _livEnt.getMainHandItem() : ItemStack.EMPTY).getOrCreateTag().getDouble("id") == id) {
|
||||
Reload1Procedure.execute(entity);
|
||||
RifleReloadProcedure.execute(entity);
|
||||
}
|
||||
} else if (itemstack.getOrCreateTag().getDouble("reloading") == 1 && itemstack.getOrCreateTag().getDouble("ammo") > 0) {
|
||||
if (itemstack.getOrCreateTag().getDouble("reloadtime") == 41) {
|
||||
|
@ -62,7 +62,7 @@ public class AK47WuPinZaiBeiBaoZhongShiMeiKeFaShengProcedure {
|
|||
itemstack.getOrCreateTag().putDouble("reloadtime", 0);
|
||||
}
|
||||
if (itemstack.getOrCreateTag().getDouble("reloadtime") == 1 && (entity instanceof LivingEntity _livEnt ? _livEnt.getMainHandItem() : ItemStack.EMPTY).getOrCreateTag().getDouble("id") == id) {
|
||||
Reload2Procedure.execute(entity);
|
||||
RifleReloadProcedure.execute(entity, true);
|
||||
}
|
||||
}
|
||||
WeaponDrawProcedure.execute(entity, itemstack);
|
||||
|
|
|
@ -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) {
|
||||
ShotgunReloadProcedure.execute((LivingEntity) entity, false);
|
||||
ShotgunReloadProcedure.execute((LivingEntity) entity);
|
||||
}
|
||||
}
|
||||
} else if (itemstack.getOrCreateTag().getDouble("reloading") == 1 && itemstack.getOrCreateTag().getDouble("ammo") > 0) {
|
||||
|
|
|
@ -39,7 +39,7 @@ public class DevotionWuPinZaiBeiBaoZhongShiMeiKeFaShengProcedure {
|
|||
itemstack.getOrCreateTag().putDouble("reloadtime", 0);
|
||||
}
|
||||
if (itemstack.getOrCreateTag().getDouble("reloadtime") == 1 && (entity instanceof LivingEntity _livEnt ? _livEnt.getMainHandItem() : ItemStack.EMPTY).getOrCreateTag().getDouble("id") == id) {
|
||||
Reload1Procedure.execute(entity);
|
||||
RifleReloadProcedure.execute(entity);
|
||||
}
|
||||
} else if (itemstack.getOrCreateTag().getDouble("reloading") == 1 && itemstack.getOrCreateTag().getDouble("ammo") > 0) {
|
||||
if (itemstack.getOrCreateTag().getDouble("reloadtime") == 51) {
|
||||
|
@ -63,7 +63,7 @@ public class DevotionWuPinZaiBeiBaoZhongShiMeiKeFaShengProcedure {
|
|||
itemstack.getOrCreateTag().putDouble("reloadtime", 0);
|
||||
}
|
||||
if (itemstack.getOrCreateTag().getDouble("reloadtime") == 1 && (entity instanceof LivingEntity _livEnt ? _livEnt.getMainHandItem() : ItemStack.EMPTY).getOrCreateTag().getDouble("id") == id) {
|
||||
Reload2Procedure.execute(entity);
|
||||
RifleReloadProcedure.execute(entity, true);
|
||||
}
|
||||
}
|
||||
WeaponDrawProcedure.execute(entity, itemstack);
|
||||
|
|
|
@ -39,7 +39,7 @@ public class Hk416WuPinZaiBeiBaoZhongShiMeiKeFaShengProcedure {
|
|||
itemstack.getOrCreateTag().putDouble("reloadtime", 0);
|
||||
}
|
||||
if (itemstack.getOrCreateTag().getDouble("reloadtime") == 1 && (entity instanceof LivingEntity _livEnt ? _livEnt.getMainHandItem() : ItemStack.EMPTY).getOrCreateTag().getDouble("id") == id) {
|
||||
Reload1Procedure.execute(entity);
|
||||
RifleReloadProcedure.execute(entity);
|
||||
}
|
||||
} else if (itemstack.getOrCreateTag().getDouble("reloading") == 1 && itemstack.getOrCreateTag().getDouble("ammo") > 0) {
|
||||
if (itemstack.getOrCreateTag().getDouble("reloadtime") == 41) {
|
||||
|
@ -62,7 +62,7 @@ public class Hk416WuPinZaiBeiBaoZhongShiMeiKeFaShengProcedure {
|
|||
itemstack.getOrCreateTag().putDouble("reloadtime", 0);
|
||||
}
|
||||
if (itemstack.getOrCreateTag().getDouble("reloadtime") == 1 && (entity instanceof LivingEntity _livEnt ? _livEnt.getMainHandItem() : ItemStack.EMPTY).getOrCreateTag().getDouble("id") == id) {
|
||||
Reload2Procedure.execute(entity);
|
||||
RifleReloadProcedure.execute(entity, true);
|
||||
}
|
||||
}
|
||||
WeaponDrawProcedure.execute(entity, itemstack);
|
||||
|
|
|
@ -39,7 +39,7 @@ public class M4WuPinZaiBeiBaoZhongShiMeiKeFaShengProcedure {
|
|||
itemstack.getOrCreateTag().putDouble("reloadtime", 0);
|
||||
}
|
||||
if (itemstack.getOrCreateTag().getDouble("reloadtime") == 1 && (entity instanceof LivingEntity _livEnt ? _livEnt.getMainHandItem() : ItemStack.EMPTY).getOrCreateTag().getDouble("id") == id) {
|
||||
Reload1Procedure.execute(entity);
|
||||
RifleReloadProcedure.execute(entity);
|
||||
}
|
||||
} else if (itemstack.getOrCreateTag().getDouble("reloading") == 1 && itemstack.getOrCreateTag().getDouble("ammo") > 0) {
|
||||
if (itemstack.getOrCreateTag().getDouble("reloadtime") == 41) {
|
||||
|
@ -62,7 +62,7 @@ public class M4WuPinZaiBeiBaoZhongShiMeiKeFaShengProcedure {
|
|||
itemstack.getOrCreateTag().putDouble("reloadtime", 0);
|
||||
}
|
||||
if (itemstack.getOrCreateTag().getDouble("reloadtime") == 1 && (entity instanceof LivingEntity _livEnt ? _livEnt.getMainHandItem() : ItemStack.EMPTY).getOrCreateTag().getDouble("id") == id) {
|
||||
Reload2Procedure.execute(entity);
|
||||
RifleReloadProcedure.execute(entity, true);
|
||||
}
|
||||
}
|
||||
WeaponDrawProcedure.execute(entity, itemstack);
|
||||
|
|
|
@ -42,7 +42,7 @@ public class M60WuPinZaiBeiBaoZhongShiMeiKeFaShengProcedure {
|
|||
itemstack.getOrCreateTag().putDouble("reloadtime", 0);
|
||||
}
|
||||
if (itemstack.getOrCreateTag().getDouble("reloadtime") == 1 && (entity instanceof LivingEntity _livEnt ? _livEnt.getMainHandItem() : ItemStack.EMPTY).getOrCreateTag().getDouble("id") == id) {
|
||||
Reload1Procedure.execute(entity);
|
||||
RifleReloadProcedure.execute(entity);
|
||||
}
|
||||
} else if (itemstack.getOrCreateTag().getDouble("reloading") == 1 && itemstack.getOrCreateTag().getDouble("ammo") > 0) {
|
||||
if (itemstack.getOrCreateTag().getDouble("reloadtime") == 111) {
|
||||
|
@ -65,7 +65,7 @@ public class M60WuPinZaiBeiBaoZhongShiMeiKeFaShengProcedure {
|
|||
itemstack.getOrCreateTag().putDouble("reloadtime", 0);
|
||||
}
|
||||
if (itemstack.getOrCreateTag().getDouble("reloadtime") == 1 && (entity instanceof LivingEntity _livEnt ? _livEnt.getMainHandItem() : ItemStack.EMPTY).getOrCreateTag().getDouble("id") == id) {
|
||||
Reload1Procedure.execute(entity);
|
||||
RifleReloadProcedure.execute(entity);
|
||||
}
|
||||
}
|
||||
WeapondrawhaveyProcedure.execute(entity, itemstack);
|
||||
|
|
|
@ -42,7 +42,7 @@ public class Mk14WuPinZaiBeiBaoZhongShiMeiKeFaShengProcedure {
|
|||
itemstack.getOrCreateTag().putDouble("gj", 0);
|
||||
}
|
||||
if (itemstack.getOrCreateTag().getDouble("reloadtime") == 1 && (entity instanceof LivingEntity _livEnt ? _livEnt.getMainHandItem() : ItemStack.EMPTY).getOrCreateTag().getDouble("id") == id) {
|
||||
Reload1Procedure.execute(entity);
|
||||
RifleReloadProcedure.execute(entity);
|
||||
}
|
||||
} else if (itemstack.getOrCreateTag().getDouble("reloading") == 1 && itemstack.getOrCreateTag().getDouble("ammo") > 0) {
|
||||
if (itemstack.getOrCreateTag().getDouble("reloadtime") == 45) {
|
||||
|
@ -65,7 +65,7 @@ public class Mk14WuPinZaiBeiBaoZhongShiMeiKeFaShengProcedure {
|
|||
itemstack.getOrCreateTag().putDouble("reloadtime", 0);
|
||||
}
|
||||
if (itemstack.getOrCreateTag().getDouble("reloadtime") == 1 && (entity instanceof LivingEntity _livEnt ? _livEnt.getMainHandItem() : ItemStack.EMPTY).getOrCreateTag().getDouble("id") == id) {
|
||||
Reload2Procedure.execute(entity);
|
||||
RifleReloadProcedure.execute(entity, true);
|
||||
}
|
||||
}
|
||||
WeaponDrawProcedure.execute(entity, itemstack);
|
||||
|
|
|
@ -1,40 +0,0 @@
|
|||
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 Reload1Procedure {
|
||||
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())).rifleAmmo >= ammo1) {
|
||||
{
|
||||
double _setval = (entity.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new TargetModVariables.PlayerVariables())).rifleAmmo - ammo1;
|
||||
entity.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
|
||||
capability.rifleAmmo = _setval;
|
||||
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())).rifleAmmo));
|
||||
{
|
||||
double _setval = 0;
|
||||
entity.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
|
||||
capability.rifleAmmo = _setval;
|
||||
capability.syncPlayerVariables(entity);
|
||||
});
|
||||
}
|
||||
stack.getOrCreateTag().putDouble("reloading", 0);
|
||||
stack.getOrCreateTag().putDouble("emptyreload", 0);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,41 +0,0 @@
|
|||
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 Reload2Procedure {
|
||||
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())).rifleAmmo >= ammo2) {
|
||||
{
|
||||
double _setval = (entity.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new TargetModVariables.PlayerVariables())).rifleAmmo - ammo2;
|
||||
entity.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
|
||||
capability.rifleAmmo = _setval;
|
||||
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())).rifleAmmo));
|
||||
{
|
||||
double _setval = 0;
|
||||
entity.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
|
||||
capability.rifleAmmo = _setval;
|
||||
capability.syncPlayerVariables(entity);
|
||||
});
|
||||
}
|
||||
stack.getOrCreateTag().putDouble("reloading", 0);
|
||||
stack.getOrCreateTag().putDouble("emptyreload", 0);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
package net.mcreator.target.procedures;
|
||||
|
||||
import net.mcreator.target.network.TargetModVariables;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
|
||||
public class RifleReloadProcedure {
|
||||
public static void execute(Entity entity) {
|
||||
execute(entity, false);
|
||||
}
|
||||
|
||||
public static void execute(Entity entity, boolean extraOne) {
|
||||
if (entity == null) return;
|
||||
|
||||
ItemStack stack = (entity instanceof LivingEntity living ? living.getMainHandItem() : ItemStack.EMPTY);
|
||||
|
||||
CompoundTag tag = stack.getOrCreateTag();
|
||||
|
||||
double mag = tag.getDouble("mag");
|
||||
double ammo = tag.getDouble("ammo");
|
||||
double rifleAmmo = entity.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).map(c -> c.rifleAmmo).orElse(0d);
|
||||
|
||||
double ammo1 = mag - ammo + (extraOne ? 1 : 0);
|
||||
|
||||
tag.putDouble("ammo", ammo + Math.min(ammo1, rifleAmmo));
|
||||
entity.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
|
||||
capability.rifleAmmo = Math.max(0, rifleAmmo - ammo1);
|
||||
capability.syncPlayerVariables(entity);
|
||||
});
|
||||
|
||||
tag.putDouble("reloading", 0);
|
||||
tag.putDouble("emptyreload", 0);
|
||||
}
|
||||
}
|
|
@ -35,7 +35,7 @@ public class RpkWuPinZaiBeiBaoZhongShiMeiKeFaShengProcedure {
|
|||
itemstack.getOrCreateTag().putDouble("reloadtime", 0);
|
||||
}
|
||||
if (itemstack.getOrCreateTag().getDouble("reloadtime") == 1 && (entity instanceof LivingEntity _livEnt ? _livEnt.getMainHandItem() : ItemStack.EMPTY).getOrCreateTag().getDouble("id") == id) {
|
||||
Reload1Procedure.execute(entity);
|
||||
RifleReloadProcedure.execute(entity);
|
||||
}
|
||||
} else if (itemstack.getOrCreateTag().getDouble("reloading") == 1 && itemstack.getOrCreateTag().getDouble("ammo") > 0) {
|
||||
if (itemstack.getOrCreateTag().getDouble("reloadtime") == 41) {
|
||||
|
@ -56,7 +56,7 @@ public class RpkWuPinZaiBeiBaoZhongShiMeiKeFaShengProcedure {
|
|||
itemstack.getOrCreateTag().putDouble("reloadtime", 0);
|
||||
}
|
||||
if (itemstack.getOrCreateTag().getDouble("reloadtime") == 1 && (entity instanceof LivingEntity _livEnt ? _livEnt.getMainHandItem() : ItemStack.EMPTY).getOrCreateTag().getDouble("id") == id) {
|
||||
Reload2Procedure.execute(entity);
|
||||
RifleReloadProcedure.execute(entity, true);
|
||||
}
|
||||
}
|
||||
WeaponDrawProcedure.execute(entity, itemstack);
|
||||
|
|
|
@ -5,12 +5,16 @@ import net.minecraft.nbt.CompoundTag;
|
|||
import net.minecraft.world.entity.LivingEntity;
|
||||
|
||||
public class ShotgunReloadProcedure {
|
||||
public static void execute(LivingEntity entity, boolean plusOne) {
|
||||
public static void execute(LivingEntity entity) {
|
||||
execute(entity, false);
|
||||
}
|
||||
|
||||
public static void execute(LivingEntity entity, boolean extraOne) {
|
||||
CompoundTag tag = entity.getMainHandItem().getOrCreateTag();
|
||||
double mag = tag.getDouble("mag");
|
||||
double ammo = tag.getDouble("ammo");
|
||||
|
||||
double empty = mag - ammo + (plusOne ? 1 : 0);
|
||||
double empty = mag - ammo + (extraOne ? 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));
|
||||
|
|
|
@ -43,7 +43,7 @@ public class SksWuPinZaiBeiBaoZhongShiMeiKeFaShengProcedure {
|
|||
itemstack.getOrCreateTag().putDouble("gj", 0);
|
||||
}
|
||||
if (itemstack.getOrCreateTag().getDouble("reloadtime") == 1 && (entity instanceof LivingEntity _livEnt ? _livEnt.getMainHandItem() : ItemStack.EMPTY).getOrCreateTag().getDouble("id") == id) {
|
||||
Reload1Procedure.execute(entity);
|
||||
RifleReloadProcedure.execute(entity);
|
||||
}
|
||||
} else if (itemstack.getOrCreateTag().getDouble("reloading") == 1 && itemstack.getOrCreateTag().getDouble("ammo") > 0) {
|
||||
if (itemstack.getOrCreateTag().getDouble("reloadtime") == 41) {
|
||||
|
@ -67,7 +67,7 @@ public class SksWuPinZaiBeiBaoZhongShiMeiKeFaShengProcedure {
|
|||
itemstack.getOrCreateTag().putDouble("reloadtime", 0);
|
||||
}
|
||||
if (itemstack.getOrCreateTag().getDouble("reloadtime") == 1 && (entity instanceof LivingEntity _livEnt ? _livEnt.getMainHandItem() : ItemStack.EMPTY).getOrCreateTag().getDouble("id") == id) {
|
||||
Reload2Procedure.execute(entity);
|
||||
RifleReloadProcedure.execute(entity, true);
|
||||
}
|
||||
}
|
||||
WeaponDrawProcedure.execute(entity, itemstack);
|
||||
|
|
Loading…
Add table
Reference in a new issue