添加事不过四附魔

This commit is contained in:
17146 2024-08-03 13:26:21 +08:00
parent acc6215fd2
commit dd973afa71
7 changed files with 100 additions and 12 deletions

View file

@ -0,0 +1,39 @@
package net.mcreator.superbwarfare.enchantment;
import net.mcreator.superbwarfare.init.ModTags;
import net.mcreator.superbwarfare.tools.EnchantmentCategoryTool;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.enchantment.Enchantment;
public class FourthTimesCharm extends Enchantment {
public FourthTimesCharm() {
super(Rarity.VERY_RARE, EnchantmentCategoryTool.GUN, new EquipmentSlot[]{EquipmentSlot.MAINHAND});
}
@Override
public int getMaxLevel() {
return super.getMaxLevel();
}
@Override
public boolean isTreasureOnly() {
return true;
}
@Override
public int getMinCost(int pLevel) {
return 20 + 5 * pLevel;
}
@Override
public int getMaxCost(int pLevel) {
return getMinCost(pLevel) + 20;
}
@Override
public boolean canApplyAtEnchantingTable(ItemStack itemstack) {
return itemstack.is(ModTags.Items.CAN_SHOOT_BULLET);
}
}

View file

@ -288,6 +288,10 @@ public class LivingEventHandler {
if (source.is(ModDamageTypes.GUN_FIRE) || source.is(ModDamageTypes.GUN_FIRE_HEADSHOT)) { if (source.is(ModDamageTypes.GUN_FIRE) || source.is(ModDamageTypes.GUN_FIRE_HEADSHOT)) {
handleKillingTallyDamage(stack, event); handleKillingTallyDamage(stack, event);
} }
if (source.is(ModDamageTypes.GUN_FIRE_HEADSHOT)) {
handleFourthTimesCharm(stack);
}
} }
private static void handleGunEnchantmentsWhenDeath(LivingDeathEvent event) { private static void handleGunEnchantmentsWhenDeath(LivingDeathEvent event) {
@ -374,4 +378,22 @@ public class LivingEventHandler {
} }
} }
private static void handleFourthTimesCharm(ItemStack stack) {
int level = EnchantmentHelper.getTagEnchantmentLevel(ModEnchantments.FOURTH_TIMES_CHARM.get(), stack);
if (level == 0) {
return;
}
int fourthTimesCharmTick = stack.getOrCreateTag().getInt("FourthTimesCharmTick");
if (fourthTimesCharmTick <= 0) {
stack.getOrCreateTag().putInt("FourthTimesCharmTick", 60);
stack.getOrCreateTag().putInt("FourthTimesCharmCount", 1);
} else {
int count = stack.getOrCreateTag().getInt("FourthTimesCharmCount");
if (count < 4) {
stack.getOrCreateTag().putInt("FourthTimesCharmCount", Math.min(4, count + 1));
}
}
}
} }

View file

@ -19,4 +19,5 @@ public class ModEnchantments {
public static final RegistryObject<Enchantment> KILL_CLIP = REGISTRY.register("kill_clip", KillClip::new); public static final RegistryObject<Enchantment> KILL_CLIP = REGISTRY.register("kill_clip", KillClip::new);
public static final RegistryObject<Enchantment> GUTSHOT_STRAIGHT = REGISTRY.register("gutshot_straight", GutshotStraight::new); public static final RegistryObject<Enchantment> GUTSHOT_STRAIGHT = REGISTRY.register("gutshot_straight", GutshotStraight::new);
public static final RegistryObject<Enchantment> KILLING_TALLY = REGISTRY.register("killing_tally", KillingTally::new); public static final RegistryObject<Enchantment> KILLING_TALLY = REGISTRY.register("killing_tally", KillingTally::new);
public static final RegistryObject<Enchantment> FOURTH_TIMES_CHARM = REGISTRY.register("fourth_times_charm", FourthTimesCharm::new);
} }

View file

@ -1,6 +1,7 @@
package net.mcreator.superbwarfare.item.gun; package net.mcreator.superbwarfare.item.gun;
import net.mcreator.superbwarfare.ModUtils; import net.mcreator.superbwarfare.ModUtils;
import net.mcreator.superbwarfare.init.ModEnchantments;
import net.mcreator.superbwarfare.init.ModItems; import net.mcreator.superbwarfare.init.ModItems;
import net.mcreator.superbwarfare.init.ModTags; import net.mcreator.superbwarfare.init.ModTags;
import net.mcreator.superbwarfare.network.ModVariables; import net.mcreator.superbwarfare.network.ModVariables;
@ -19,6 +20,7 @@ import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.TooltipFlag; import net.minecraft.world.item.TooltipFlag;
import net.minecraft.world.item.enchantment.Enchantment; import net.minecraft.world.item.enchantment.Enchantment;
import net.minecraft.world.item.enchantment.EnchantmentHelper;
import net.minecraft.world.level.Level; import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.minecraftforge.event.entity.player.EntityItemPickupEvent; import net.minecraftforge.event.entity.player.EntityItemPickupEvent;
@ -87,17 +89,7 @@ public abstract class GunItem extends Item {
itemstack.getOrCreateTag().putDouble("flash_time", (itemstack.getOrCreateTag().getDouble("flash_time") - 1)); itemstack.getOrCreateTag().putDouble("flash_time", (itemstack.getOrCreateTag().getDouble("flash_time") - 1));
} }
if (itemstack.getOrCreateTag().getInt("HealClipTime") > 0) { handleEnchantments(itemstack);
itemstack.getOrCreateTag().putInt("HealClipTime", Math.max(0, itemstack.getOrCreateTag().getInt("HealClipTime") - 1));
}
if (itemstack.getOrCreateTag().getInt("KillClipReloadTime") > 0) {
itemstack.getOrCreateTag().putInt("KillClipReloadTime", Math.max(0, itemstack.getOrCreateTag().getInt("KillClipReloadTime") - 1));
}
if (itemstack.getOrCreateTag().getInt("KillClipTime") > 0) {
itemstack.getOrCreateTag().putInt("KillClipTime", Math.max(0, itemstack.getOrCreateTag().getInt("KillClipTime") - 1));
}
} }
} }
@ -154,4 +146,34 @@ public abstract class GunItem extends Item {
public boolean canApplyAtEnchantingTable(ItemStack stack, Enchantment enchantment) { public boolean canApplyAtEnchantingTable(ItemStack stack, Enchantment enchantment) {
return enchantment.category == EnchantmentCategoryTool.GUN; return enchantment.category == EnchantmentCategoryTool.GUN;
} }
private void handleEnchantments(ItemStack stack) {
if (stack.getOrCreateTag().getInt("HealClipTime") > 0) {
stack.getOrCreateTag().putInt("HealClipTime", Math.max(0, stack.getOrCreateTag().getInt("HealClipTime") - 1));
}
if (stack.getOrCreateTag().getInt("KillClipReloadTime") > 0) {
stack.getOrCreateTag().putInt("KillClipReloadTime", Math.max(0, stack.getOrCreateTag().getInt("KillClipReloadTime") - 1));
}
if (stack.getOrCreateTag().getInt("KillClipTime") > 0) {
stack.getOrCreateTag().putInt("KillClipTime", Math.max(0, stack.getOrCreateTag().getInt("KillClipTime") - 1));
}
if (stack.getOrCreateTag().getInt("FourthTimesCharmTick") > 0) {
stack.getOrCreateTag().putInt("FourthTimesCharmTick",
Math.max(0, stack.getOrCreateTag().getInt("FourthTimesCharmTick") - 1));
}
if (EnchantmentHelper.getTagEnchantmentLevel(ModEnchantments.FOURTH_TIMES_CHARM.get(), stack) > 0) {
int count = stack.getOrCreateTag().getInt("FourthTimesCharmCount");
if (count >= 4) {
stack.getOrCreateTag().putInt("FourthTimesCharmTick", 0);
stack.getOrCreateTag().putInt("FourthTimesCharmCount", 0);
int mag = stack.getOrCreateTag().getInt("mag");
stack.getOrCreateTag().putInt("ammo", Math.min(mag, stack.getOrCreateTag().getInt("ammo") + 2));
}
}
}
} }

View file

@ -47,7 +47,7 @@ public class GunsTool {
reader.endObject(); reader.endObject();
reader.close(); reader.close();
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); ModUtils.LOGGER.error(e.getMessage());
} }
} }
} }

View file

@ -257,6 +257,8 @@
"enchantment.superbwarfare.gutshot_straight.desc": "Aiming down sights increases body shot damage", "enchantment.superbwarfare.gutshot_straight.desc": "Aiming down sights increases body shot damage",
"enchantment.superbwarfare.killing_tally": "Killing Tally", "enchantment.superbwarfare.killing_tally": "Killing Tally",
"enchantment.superbwarfare.killing_tally.desc": "Kill increases the weapon's damage until it is stowed or reloaded", "enchantment.superbwarfare.killing_tally.desc": "Kill increases the weapon's damage until it is stowed or reloaded",
"enchantment.superbwarfare.fourth_times_charm": "Fourth Time's The Charm",
"enchantment.superbwarfare.fourth_times_charm.desc": "Rapidly landing precision hits will return two rounds to the magazine",
"des.superbwarfare.sensitivity": "Current Sensitivity of This Gun: %1$s", "des.superbwarfare.sensitivity": "Current Sensitivity of This Gun: %1$s",
"des.superbwarfare.need_bolt_action": "[ Need Bolt Action ]", "des.superbwarfare.need_bolt_action": "[ Need Bolt Action ]",

View file

@ -257,6 +257,8 @@
"enchantment.superbwarfare.gutshot_straight.desc": "瞄准时增加身体射击伤害", "enchantment.superbwarfare.gutshot_straight.desc": "瞄准时增加身体射击伤害",
"enchantment.superbwarfare.killing_tally": "击杀记录", "enchantment.superbwarfare.killing_tally": "击杀记录",
"enchantment.superbwarfare.killing_tally.desc": "完成击杀可提高此武器的伤害,效果持续至切换或填装武器", "enchantment.superbwarfare.killing_tally.desc": "完成击杀可提高此武器的伤害,效果持续至切换或填装武器",
"enchantment.superbwarfare.fourth_times_charm": "事不过四",
"enchantment.superbwarfare.fourth_times_charm.desc": "快速精准命中目标会向弹匣中返还两枚弹药",
"des.superbwarfare.sensitivity": "当前枪械的灵敏度为:%1$s", "des.superbwarfare.sensitivity": "当前枪械的灵敏度为:%1$s",
"des.superbwarfare.need_bolt_action": "【需要拉栓】", "des.superbwarfare.need_bolt_action": "【需要拉栓】",