重构附魔逻辑
This commit is contained in:
parent
39b5fbce1a
commit
eac02b58e0
7 changed files with 150 additions and 76 deletions
|
@ -1,13 +1,15 @@
|
||||||
package net.mcreator.superbwarfare.enchantment;
|
package net.mcreator.superbwarfare.enchantment;
|
||||||
|
|
||||||
|
import net.mcreator.superbwarfare.init.ModTags;
|
||||||
import net.mcreator.superbwarfare.tools.EnchantmentCategoryTool;
|
import net.mcreator.superbwarfare.tools.EnchantmentCategoryTool;
|
||||||
import net.minecraft.world.entity.EquipmentSlot;
|
import net.minecraft.world.entity.EquipmentSlot;
|
||||||
|
import net.minecraft.world.item.ItemStack;
|
||||||
import net.minecraft.world.item.enchantment.Enchantment;
|
import net.minecraft.world.item.enchantment.Enchantment;
|
||||||
|
|
||||||
public class HealClip extends Enchantment {
|
public class HealClip extends Enchantment {
|
||||||
|
|
||||||
public HealClip() {
|
public HealClip() {
|
||||||
super(Rarity.RARE, EnchantmentCategoryTool.GUN, new EquipmentSlot[]{EquipmentSlot.MAINHAND});
|
super(Rarity.RARE, EnchantmentCategoryTool.CAN_RELOAD, new EquipmentSlot[]{EquipmentSlot.MAINHAND});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -25,4 +27,9 @@ public class HealClip extends Enchantment {
|
||||||
return getMinCost(pLevel) + 10;
|
return getMinCost(pLevel) + 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canApplyAtEnchantingTable(ItemStack itemstack) {
|
||||||
|
return itemstack.is(ModTags.Items.CAN_RELOAD);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,13 +1,15 @@
|
||||||
package net.mcreator.superbwarfare.enchantment;
|
package net.mcreator.superbwarfare.enchantment;
|
||||||
|
|
||||||
|
import net.mcreator.superbwarfare.init.ModTags;
|
||||||
import net.mcreator.superbwarfare.tools.EnchantmentCategoryTool;
|
import net.mcreator.superbwarfare.tools.EnchantmentCategoryTool;
|
||||||
import net.minecraft.world.entity.EquipmentSlot;
|
import net.minecraft.world.entity.EquipmentSlot;
|
||||||
|
import net.minecraft.world.item.ItemStack;
|
||||||
import net.minecraft.world.item.enchantment.Enchantment;
|
import net.minecraft.world.item.enchantment.Enchantment;
|
||||||
|
|
||||||
public class KillClip extends Enchantment {
|
public class KillClip extends Enchantment {
|
||||||
|
|
||||||
public KillClip() {
|
public KillClip() {
|
||||||
super(Rarity.UNCOMMON, EnchantmentCategoryTool.GUN, new EquipmentSlot[]{EquipmentSlot.MAINHAND});
|
super(Rarity.UNCOMMON, EnchantmentCategoryTool.CAN_RELOAD, new EquipmentSlot[]{EquipmentSlot.MAINHAND});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -24,4 +26,10 @@ public class KillClip extends Enchantment {
|
||||||
public int getMaxCost(int pLevel) {
|
public int getMaxCost(int pLevel) {
|
||||||
return getMinCost(pLevel) + 10;
|
return getMinCost(pLevel) + 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canApplyAtEnchantingTable(ItemStack itemstack) {
|
||||||
|
return itemstack.is(ModTags.Items.CAN_RELOAD);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,10 @@ package net.mcreator.superbwarfare.event;
|
||||||
import net.mcreator.superbwarfare.ModUtils;
|
import net.mcreator.superbwarfare.ModUtils;
|
||||||
import net.mcreator.superbwarfare.entity.ProjectileEntity;
|
import net.mcreator.superbwarfare.entity.ProjectileEntity;
|
||||||
import net.mcreator.superbwarfare.event.modevent.ReloadEvent;
|
import net.mcreator.superbwarfare.event.modevent.ReloadEvent;
|
||||||
import net.mcreator.superbwarfare.init.*;
|
import net.mcreator.superbwarfare.init.ModEnchantments;
|
||||||
|
import net.mcreator.superbwarfare.init.ModItems;
|
||||||
|
import net.mcreator.superbwarfare.init.ModSounds;
|
||||||
|
import net.mcreator.superbwarfare.init.ModTags;
|
||||||
import net.mcreator.superbwarfare.network.ModVariables;
|
import net.mcreator.superbwarfare.network.ModVariables;
|
||||||
import net.mcreator.superbwarfare.network.message.ZoomMessage;
|
import net.mcreator.superbwarfare.network.message.ZoomMessage;
|
||||||
import net.mcreator.superbwarfare.tools.GunInfo;
|
import net.mcreator.superbwarfare.tools.GunInfo;
|
||||||
|
@ -28,7 +31,6 @@ import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||||
import net.minecraftforge.fml.common.Mod;
|
import net.minecraftforge.fml.common.Mod;
|
||||||
import net.minecraftforge.registries.ForgeRegistries;
|
import net.minecraftforge.registries.ForgeRegistries;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
@Mod.EventBusSubscriber
|
@Mod.EventBusSubscriber
|
||||||
|
@ -52,43 +54,6 @@ public class GunEventHandler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@SubscribeEvent
|
|
||||||
public static void onPreReload(ReloadEvent.Pre event) {
|
|
||||||
Player player = event.player;
|
|
||||||
ItemStack stack = event.stack;
|
|
||||||
if (player == null || !stack.is(ModTags.Items.GUN)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (player.level().isClientSide) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
System.out.println("Pre Reload: " + stack);
|
|
||||||
|
|
||||||
handleHealClipPre(stack);
|
|
||||||
handleKillClipPre(stack);
|
|
||||||
}
|
|
||||||
|
|
||||||
@SubscribeEvent
|
|
||||||
public static void onPostReload(ReloadEvent.Post event) {
|
|
||||||
Player player = event.player;
|
|
||||||
ItemStack stack = event.stack;
|
|
||||||
if (player == null || !stack.is(ModTags.Items.GUN)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (player.level().isClientSide) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
System.out.println("Post Reload: " + stack);
|
|
||||||
System.out.println();
|
|
||||||
|
|
||||||
handleHealClipPost(player, stack);
|
|
||||||
handleKillClipPost(stack);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 通用的武器开火流程
|
* 通用的武器开火流程
|
||||||
*/
|
*/
|
||||||
|
@ -841,35 +806,4 @@ public class GunEventHandler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void handleHealClipPre(ItemStack stack) {
|
|
||||||
int time = stack.getOrCreateTag().getInt("HealClipTime");
|
|
||||||
if (time > 0) {
|
|
||||||
stack.getOrCreateTag().putInt("HealClipTime", 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void handleHealClipPost(Player player, ItemStack stack) {
|
|
||||||
int healClipLevel = EnchantmentHelper.getTagEnchantmentLevel(ModEnchantments.HEAL_CLIP.get(), stack);
|
|
||||||
if (healClipLevel == 0) {
|
|
||||||
healClipLevel = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
player.heal(12.0f * (0.8f + 0.2f * healClipLevel));
|
|
||||||
List<Player> players = player.level().getEntitiesOfClass(Player.class, player.getBoundingBox().inflate(5))
|
|
||||||
.stream().filter(p -> p.isAlliedTo(player)).toList();
|
|
||||||
int finalHealClipLevel = healClipLevel;
|
|
||||||
players.forEach(p -> p.heal(6.0f * (0.8f + 0.2f * finalHealClipLevel)));
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void handleKillClipPre(ItemStack stack) {
|
|
||||||
int time = stack.getOrCreateTag().getInt("KillClipReloadTime");
|
|
||||||
if (time > 0) {
|
|
||||||
stack.getOrCreateTag().putInt("KillClipReloadTime", 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void handleKillClipPost(ItemStack stack) {
|
|
||||||
int level = EnchantmentHelper.getTagEnchantmentLevel(ModEnchantments.KILL_CLIP.get(), stack);
|
|
||||||
stack.getOrCreateTag().putInt("KillClipTime", 90 + 10 * level);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,95 @@
|
||||||
|
package net.mcreator.superbwarfare.event;
|
||||||
|
|
||||||
|
import net.mcreator.superbwarfare.event.modevent.ReloadEvent;
|
||||||
|
import net.mcreator.superbwarfare.init.ModEnchantments;
|
||||||
|
import net.mcreator.superbwarfare.init.ModTags;
|
||||||
|
import net.minecraft.world.entity.player.Player;
|
||||||
|
import net.minecraft.world.item.ItemStack;
|
||||||
|
import net.minecraft.world.item.enchantment.EnchantmentHelper;
|
||||||
|
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||||
|
import net.minecraftforge.fml.common.Mod;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Mod.EventBusSubscriber
|
||||||
|
public class ReloadEventHandler {
|
||||||
|
|
||||||
|
@SubscribeEvent
|
||||||
|
public static void onPreReload(ReloadEvent.Pre event) {
|
||||||
|
Player player = event.player;
|
||||||
|
ItemStack stack = event.stack;
|
||||||
|
if (player == null || !stack.is(ModTags.Items.GUN)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (player.level().isClientSide) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
handleHealClipPre(stack);
|
||||||
|
handleKillClipPre(stack);
|
||||||
|
}
|
||||||
|
|
||||||
|
@SubscribeEvent
|
||||||
|
public static void onPostReload(ReloadEvent.Post event) {
|
||||||
|
Player player = event.player;
|
||||||
|
ItemStack stack = event.stack;
|
||||||
|
if (player == null || !stack.is(ModTags.Items.GUN)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (player.level().isClientSide) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
handleHealClipPost(player, stack);
|
||||||
|
handleKillClipPost(stack);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void handleHealClipPre(ItemStack stack) {
|
||||||
|
int time = stack.getOrCreateTag().getInt("HealClipTime");
|
||||||
|
if (time > 0) {
|
||||||
|
stack.getOrCreateTag().putInt("HealClipTime", 0);
|
||||||
|
stack.getOrCreateTag().putBoolean("HealClip", true);
|
||||||
|
} else {
|
||||||
|
stack.getOrCreateTag().putBoolean("HealClip", false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void handleHealClipPost(Player player, ItemStack stack) {
|
||||||
|
if (!stack.getOrCreateTag().getBoolean("HealClip")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int healClipLevel = EnchantmentHelper.getTagEnchantmentLevel(ModEnchantments.HEAL_CLIP.get(), stack);
|
||||||
|
if (healClipLevel == 0) {
|
||||||
|
healClipLevel = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
player.heal(12.0f * (0.8f + 0.2f * healClipLevel));
|
||||||
|
List<Player> players = player.level().getEntitiesOfClass(Player.class, player.getBoundingBox().inflate(5))
|
||||||
|
.stream().filter(p -> p.isAlliedTo(player)).toList();
|
||||||
|
int finalHealClipLevel = healClipLevel;
|
||||||
|
players.forEach(p -> p.heal(6.0f * (0.8f + 0.2f * finalHealClipLevel)));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void handleKillClipPre(ItemStack stack) {
|
||||||
|
int time = stack.getOrCreateTag().getInt("KillClipReloadTime");
|
||||||
|
if (time > 0) {
|
||||||
|
stack.getOrCreateTag().putInt("KillClipReloadTime", 0);
|
||||||
|
stack.getOrCreateTag().putBoolean("KillClip", true);
|
||||||
|
} else {
|
||||||
|
stack.getOrCreateTag().putBoolean("KillClip", false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void handleKillClipPost(ItemStack stack) {
|
||||||
|
if (!stack.getOrCreateTag().getBoolean("KillClip")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int level = EnchantmentHelper.getTagEnchantmentLevel(ModEnchantments.KILL_CLIP.get(), stack);
|
||||||
|
stack.getOrCreateTag().putInt("KillClipTime", 90 + 10 * level);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -20,6 +20,7 @@ public class ModTags {
|
||||||
public static final TagKey<Item> LEGENDARY_GUN = tag("legendary_gun");
|
public static final TagKey<Item> LEGENDARY_GUN = tag("legendary_gun");
|
||||||
public static final TagKey<Item> SPECIAL_GUN = tag("special_gun");
|
public static final TagKey<Item> SPECIAL_GUN = tag("special_gun");
|
||||||
public static final TagKey<Item> OPEN_BOLT = tag("open_bolt");
|
public static final TagKey<Item> OPEN_BOLT = tag("open_bolt");
|
||||||
|
public static final TagKey<Item> CAN_RELOAD = tag("can_reload");
|
||||||
|
|
||||||
private static TagKey<Item> tag(String name) {
|
private static TagKey<Item> tag(String name) {
|
||||||
return ItemTags.create(new ResourceLocation(ModUtils.MODID, name));
|
return ItemTags.create(new ResourceLocation(ModUtils.MODID, name));
|
||||||
|
|
|
@ -1,12 +1,15 @@
|
||||||
package net.mcreator.superbwarfare.tools;
|
package net.mcreator.superbwarfare.tools;
|
||||||
|
|
||||||
|
import net.mcreator.superbwarfare.init.ModTags;
|
||||||
import net.mcreator.superbwarfare.item.gun.GunItem;
|
import net.mcreator.superbwarfare.item.gun.GunItem;
|
||||||
import net.mcreator.superbwarfare.item.gun.Taser;
|
import net.mcreator.superbwarfare.item.gun.Taser;
|
||||||
import net.minecraft.world.item.enchantment.EnchantmentCategory;
|
import net.minecraft.world.item.enchantment.EnchantmentCategory;
|
||||||
|
|
||||||
public class EnchantmentCategoryTool {
|
public class EnchantmentCategoryTool {
|
||||||
public static final EnchantmentCategory TASER = EnchantmentCategory.create("superbwarfare:taser", item -> item instanceof Taser);
|
public static final EnchantmentCategory TASER = EnchantmentCategory.create("superbwarfare:taser",
|
||||||
|
item -> item instanceof Taser);
|
||||||
public static final EnchantmentCategory GUN = EnchantmentCategory.create("superbwarfare:gun", item -> item instanceof GunItem && !(item instanceof Taser));
|
public static final EnchantmentCategory GUN = EnchantmentCategory.create("superbwarfare:gun",
|
||||||
|
item -> item instanceof GunItem && !(item instanceof Taser));
|
||||||
|
public static final EnchantmentCategory CAN_RELOAD = EnchantmentCategory.create("superbwarfare:can_reload",
|
||||||
|
item -> item.getDefaultInstance().is(ModTags.Items.CAN_RELOAD));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,26 @@
|
||||||
|
{
|
||||||
|
"replace": false,
|
||||||
|
"values": [
|
||||||
|
"superbwarfare:trachelium",
|
||||||
|
"superbwarfare:hunting_rifle",
|
||||||
|
"superbwarfare:m_79",
|
||||||
|
"superbwarfare:abekiri",
|
||||||
|
"superbwarfare:devotion",
|
||||||
|
"superbwarfare:m_4",
|
||||||
|
"superbwarfare:aa_12",
|
||||||
|
"superbwarfare:hk_416",
|
||||||
|
"superbwarfare:rpk",
|
||||||
|
"superbwarfare:sks",
|
||||||
|
"superbwarfare:ntw_20",
|
||||||
|
"superbwarfare:vector",
|
||||||
|
"superbwarfare:mk_14",
|
||||||
|
"superbwarfare:sentinel",
|
||||||
|
"superbwarfare:m_60",
|
||||||
|
"superbwarfare:svd",
|
||||||
|
"superbwarfare:marlin",
|
||||||
|
"superbwarfare:m_870",
|
||||||
|
"superbwarfare:m_98b",
|
||||||
|
"superbwarfare:ak_47",
|
||||||
|
"superbwarfare:rpg"
|
||||||
|
]
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue