From 470abab9cb4f2844e9d59b8956e94beef25cd872 Mon Sep 17 00:00:00 2001 From: Thomas Couchoud <1688389+Rakambda@users.noreply.github.com> Date: Sat, 15 Jun 2024 21:57:43 +0200 Subject: [PATCH] Forge & NeoForge --- README.md | 1 + .../fallingtree/forge/FallingTree.java | 26 +++--- .../fallingtree/forge/FallingTreeUtils.java | 16 ++++ .../forge/common/FallingTreeCommonsImpl.java | 86 ++++++++++--------- .../common/wrapper/EnchantmentWrapper.java | 34 -------- .../common/wrapper/ItemStackWrapper.java | 36 +++----- .../forge/enchant/ChopperEnchantment.java | 50 ----------- .../forge/event/FallingTreeEnchantments.java | 37 -------- .../forge/network/ForgePacketHandler.java | 5 +- forge/src/main/resources/META-INF/mods.toml | 6 +- forge/src/main/resources/pack.mcmeta | 2 +- gradle.properties | 4 +- gradle/libs.versions.toml | 6 +- .../fallingtree/neoforge/FallingTree.java | 1 - .../neoforge/FallingTreeUtils.java | 16 ++++ .../client/cloth/ClothConfigHook.java | 21 ----- .../common/FallingTreeCommonsImpl.java | 58 +++++-------- .../common/wrapper/EnchantmentWrapper.java | 33 ------- .../common/wrapper/ItemStackWrapper.java | 38 +++----- .../neoforge/enchant/ChopperEnchantment.java | 50 ----------- .../event/FallingTreeBlockBreakEvent.java | 5 -- .../event/FallingTreeEnchantments.java | 37 -------- .../network/FallingTreeConfigPacket.java | 5 +- .../resources/META-INF/neoforge.mods.toml | 6 +- 24 files changed, 150 insertions(+), 429 deletions(-) create mode 100644 forge/src/main/java/fr/rakambda/fallingtree/forge/FallingTreeUtils.java delete mode 100644 forge/src/main/java/fr/rakambda/fallingtree/forge/common/wrapper/EnchantmentWrapper.java delete mode 100644 forge/src/main/java/fr/rakambda/fallingtree/forge/enchant/ChopperEnchantment.java delete mode 100644 forge/src/main/java/fr/rakambda/fallingtree/forge/event/FallingTreeEnchantments.java create mode 100644 neoforge/src/main/java/fr/rakambda/fallingtree/neoforge/FallingTreeUtils.java delete mode 100644 neoforge/src/main/java/fr/rakambda/fallingtree/neoforge/common/wrapper/EnchantmentWrapper.java delete mode 100644 neoforge/src/main/java/fr/rakambda/fallingtree/neoforge/enchant/ChopperEnchantment.java delete mode 100644 neoforge/src/main/java/fr/rakambda/fallingtree/neoforge/event/FallingTreeEnchantments.java diff --git a/README.md b/README.md index e5b91a7a..bea03e9e 100644 --- a/README.md +++ b/README.md @@ -27,5 +27,6 @@ Check out the [wiki](https://github.com/Rakambda/FallingTree/wiki) for some more * For Fabric users, **Fabric API** is required. * For Neoforge/Forge users, **Cloth Config API** is optional on the client and allows you to have a config GUI in game. + Starting Minecraft 1.21, enchantments needs to be added separately through a datapack [available here](https://modrinth.com/datapack/fallingtree-enchantments). NOTE: On servers this mod can be server-side only, client isn't required (except if you use the change speed feature and/or enchants configurations). \ No newline at end of file diff --git a/forge/src/main/java/fr/rakambda/fallingtree/forge/FallingTree.java b/forge/src/main/java/fr/rakambda/fallingtree/forge/FallingTree.java index b049f683..4c874a8d 100644 --- a/forge/src/main/java/fr/rakambda/fallingtree/forge/FallingTree.java +++ b/forge/src/main/java/fr/rakambda/fallingtree/forge/FallingTree.java @@ -4,7 +4,6 @@ import lombok.Getter; import lombok.extern.log4j.Log4j2; import net.minecraftforge.common.MinecraftForge; -import net.minecraftforge.fml.ModList; import net.minecraftforge.fml.common.Mod; @Log4j2 @@ -15,20 +14,19 @@ public class FallingTree{ private static final FallingTreeCommonsImpl mod = new FallingTreeCommonsImpl(); public FallingTree(){ - if(ModList.get().isLoaded("cloth_config")){ - // try{ - // Class.forName("fr.rakambda.fallingtree.forge.client.cloth.ClothConfigHook") - // .asSubclass(ClothConfigHook.class) - // .getConstructor(FallingTreeCommon.class) - // .newInstance(mod) - // .load(); - // } - // catch(ClassNotFoundException | IllegalAccessException | InstantiationException | NoSuchMethodException | InvocationTargetException e){ - // log.error("Failed to hook into ClothConfig", e); - // } - } + // if(ModList.get().isLoaded("cloth_config")){ + // try{ + // Class.forName("fr.rakambda.fallingtree.forge.client.cloth.ClothConfigHook") + // .asSubclass(ClothConfigHook.class) + // .getConstructor(FallingTreeCommon.class) + // .newInstance(mod) + // .load(); + // } + // catch(ClassNotFoundException | IllegalAccessException | InstantiationException | NoSuchMethodException | InvocationTargetException e){ + // log.error("Failed to hook into ClothConfig", e); + // } + // } - mod.registerEnchant(); mod.registerForge(MinecraftForge.EVENT_BUS); } } diff --git a/forge/src/main/java/fr/rakambda/fallingtree/forge/FallingTreeUtils.java b/forge/src/main/java/fr/rakambda/fallingtree/forge/FallingTreeUtils.java new file mode 100644 index 00000000..12a03104 --- /dev/null +++ b/forge/src/main/java/fr/rakambda/fallingtree/forge/FallingTreeUtils.java @@ -0,0 +1,16 @@ +package fr.rakambda.fallingtree.forge; + +import net.minecraft.resources.ResourceLocation; +import org.jetbrains.annotations.NotNull; + +public class FallingTreeUtils{ + @NotNull + public static ResourceLocation id(@NotNull String name){ + return ResourceLocation.fromNamespaceAndPath(FallingTree.MOD_ID, name); + } + + @NotNull + public static ResourceLocation idExternal(@NotNull String fullName){ + return ResourceLocation.parse(fullName); + } +} diff --git a/forge/src/main/java/fr/rakambda/fallingtree/forge/common/FallingTreeCommonsImpl.java b/forge/src/main/java/fr/rakambda/fallingtree/forge/common/FallingTreeCommonsImpl.java index 19e2038a..6920e4c4 100644 --- a/forge/src/main/java/fr/rakambda/fallingtree/forge/common/FallingTreeCommonsImpl.java +++ b/forge/src/main/java/fr/rakambda/fallingtree/forge/common/FallingTreeCommonsImpl.java @@ -1,12 +1,27 @@ package fr.rakambda.fallingtree.forge.common; import fr.rakambda.fallingtree.common.FallingTreeCommon; +import fr.rakambda.fallingtree.common.config.enums.BreakMode; import fr.rakambda.fallingtree.common.leaf.LeafBreakingHandler; import fr.rakambda.fallingtree.common.network.ServerPacketHandler; -import fr.rakambda.fallingtree.common.wrapper.*; +import fr.rakambda.fallingtree.common.wrapper.DirectionCompat; +import fr.rakambda.fallingtree.common.wrapper.IBlock; +import fr.rakambda.fallingtree.common.wrapper.IBlockPos; +import fr.rakambda.fallingtree.common.wrapper.IBlockState; +import fr.rakambda.fallingtree.common.wrapper.IComponent; +import fr.rakambda.fallingtree.common.wrapper.IItem; +import fr.rakambda.fallingtree.common.wrapper.IItemStack; +import fr.rakambda.fallingtree.common.wrapper.ILevel; +import fr.rakambda.fallingtree.common.wrapper.IPlayer; import fr.rakambda.fallingtree.forge.client.event.PlayerLeaveListener; -import fr.rakambda.fallingtree.forge.common.wrapper.*; -import fr.rakambda.fallingtree.forge.event.*; +import fr.rakambda.fallingtree.forge.common.wrapper.BlockWrapper; +import fr.rakambda.fallingtree.forge.common.wrapper.ComponentWrapper; +import fr.rakambda.fallingtree.forge.common.wrapper.ItemStackWrapper; +import fr.rakambda.fallingtree.forge.common.wrapper.ItemWrapper; +import fr.rakambda.fallingtree.forge.event.BlockBreakListener; +import fr.rakambda.fallingtree.forge.event.FallingTreeBlockBreakEvent; +import fr.rakambda.fallingtree.forge.event.LeafBreakingListener; +import fr.rakambda.fallingtree.forge.event.ServerCommandRegistrationListener; import fr.rakambda.fallingtree.forge.network.ForgePacketHandler; import fr.rakambda.fallingtree.forge.network.PlayerJoinListener; import lombok.Getter; @@ -20,21 +35,25 @@ import net.minecraft.tags.TagKey; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.enchantment.Enchantment; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.state.BlockState; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.eventbus.api.IEventBus; -import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; import net.minecraftforge.registries.ForgeRegistries; import net.minecraftforge.registries.IForgeRegistry; import org.jetbrains.annotations.NotNull; - -import java.util.*; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; +import java.util.Optional; +import java.util.Set; import java.util.stream.Collectors; import java.util.stream.Stream; - +import static fr.rakambda.fallingtree.forge.FallingTreeUtils.id; +import static fr.rakambda.fallingtree.forge.FallingTreeUtils.idExternal; import static java.util.stream.Stream.empty; public class FallingTreeCommonsImpl extends FallingTreeCommon{ @@ -42,12 +61,22 @@ public class FallingTreeCommonsImpl extends FallingTreeCommon{ private final LeafBreakingHandler leafBreakingHandler; private final ForgePacketHandler packetHandler; @Getter - private Collection chopperEnchantments; + private final TagKey chopperEnchantmentTag; + @Getter + private final Map> breakModeChopperEnchantmentTag; public FallingTreeCommonsImpl(){ leafBreakingHandler = new LeafBreakingHandler(this); - chopperEnchantments = new ArrayList<>(); packetHandler = new ForgePacketHandler(this); + + chopperEnchantmentTag = TagKey.create(Registries.ENCHANTMENT, id("chopper_all")); + + breakModeChopperEnchantmentTag = new HashMap<>(); + breakModeChopperEnchantmentTag.put(BreakMode.FALL_ALL_BLOCK, TagKey.create(Registries.ENCHANTMENT, id("chopper_fall_all_block"))); + breakModeChopperEnchantmentTag.put(BreakMode.FALL_BLOCK, TagKey.create(Registries.ENCHANTMENT, id("chopper_fall_block"))); + breakModeChopperEnchantmentTag.put(BreakMode.FALL_ITEM, TagKey.create(Registries.ENCHANTMENT, id("chopper_fall_item"))); + breakModeChopperEnchantmentTag.put(BreakMode.INSTANTANEOUS, TagKey.create(Registries.ENCHANTMENT, id("chopper_instantaneous"))); + breakModeChopperEnchantmentTag.put(BreakMode.SHIFT_DOWN, TagKey.create(Registries.ENCHANTMENT, id("chopper_shift_down"))); } @Override @@ -78,7 +107,7 @@ public Stream getBlock(@NotNull String name){ if(isTag){ name = name.substring(1); } - var resourceLocation = new ResourceLocation(name); + var resourceLocation = idExternal(name); if(isTag){ var tag = TagKey.create(Registries.BLOCK, resourceLocation); return getRegistryTagContent(ForgeRegistries.BLOCKS, tag).map(BlockWrapper::new); @@ -98,7 +127,7 @@ public Stream getItem(@NotNull String name){ if(isTag){ name = name.substring(1); } - var resourceLocation = new ResourceLocation(name); + var resourceLocation = idExternal(name); if(isTag){ var tag = TagKey.create(Registries.ITEM, resourceLocation); return getRegistryTagContent(ForgeRegistries.ITEMS, tag).map(ItemWrapper::new); @@ -113,7 +142,7 @@ public Stream getItem(@NotNull String name){ @Override public boolean isLeafBlock(@NotNull IBlock block){ var isAllowedBlock = registryTagContains(ForgeRegistries.BLOCKS, BlockTags.LEAVES, (Block) block.getRaw()) - || getConfiguration().getTrees().getAllowedLeaveBlocks(this).stream().anyMatch(leaf -> leaf.equals(block)); + || getConfiguration().getTrees().getAllowedLeaveBlocks(this).stream().anyMatch(leaf -> leaf.equals(block)); if(isAllowedBlock){ var isDeniedBlock = getConfiguration().getTrees().getDeniedLeaveBlocks(this).stream().anyMatch(leaf -> leaf.equals(block)); return !isDeniedBlock; @@ -124,7 +153,7 @@ public boolean isLeafBlock(@NotNull IBlock block){ @Override public boolean isLogBlock(@NotNull IBlock block){ var isAllowedBlock = getConfiguration().getTrees().getDefaultLogsBlocks(this).stream().anyMatch(log -> log.equals(block)) - || getConfiguration().getTrees().getAllowedLogBlocks(this).stream().anyMatch(log -> log.equals(block)); + || getConfiguration().getTrees().getAllowedLogBlocks(this).stream().anyMatch(log -> log.equals(block)); if(isAllowedBlock){ var isDeniedBlock = getConfiguration().getTrees().getDeniedLogBlocks(this).stream().anyMatch(log -> log.equals(block)); return !isDeniedBlock; @@ -159,7 +188,7 @@ public Direction asDirection(@NotNull DirectionCompat dir){ @Override public boolean isNetherWartOrShroomlight(@NotNull IBlock block){ return registryTagContains(ForgeRegistries.BLOCKS, BlockTags.WART_BLOCKS, (Block) block.getRaw()) - || Blocks.SHROOMLIGHT.equals(block.getRaw()); + || Blocks.SHROOMLIGHT.equals(block.getRaw()); } @Override @@ -172,37 +201,12 @@ public boolean checkCanBreakBlock(@NotNull ILevel level, @NotNull IBlockPos bloc return !MinecraftForge.EVENT_BUS.post(new FallingTreeBlockBreakEvent((Level) level.getRaw(), (BlockPos) blockPos.getRaw(), (BlockState) blockState.getRaw(), (Player) player.getRaw())); } - @Override - protected void performDefaultEnchantRegister(){ - FallingTreeEnchantments.registerDefault(); - } - - @Override - protected void performSpecificEnchantRegister(){ - FallingTreeEnchantments.registerSpecific(); - } - - @Override - protected void performCommitEnchantRegister(){ - FallingTreeEnchantments.commit(FMLJavaModLoadingContext.get().getModEventBus()); - - Stream.of(FallingTreeEnchantments.CHOPPER_ENCHANTMENT, - FallingTreeEnchantments.CHOPPER_INSTANTANEOUS_ENCHANTMENT, - FallingTreeEnchantments.CHOPPER_FALL_BLOCK_ENCHANTMENT, - FallingTreeEnchantments.CHOPPER_FALL_ITEM_ENCHANTMENT, - FallingTreeEnchantments.CHOPPER_SHIFT_DOWN_ENCHANTMENT - ) - .filter(Objects::nonNull) - .map(EnchantmentWrapper::new) - .forEach(chopperEnchantments::add); - } - @Override @NotNull - public IItemStack getEmptyItemStack() { + public IItemStack getEmptyItemStack(){ return new ItemStackWrapper(ItemStack.EMPTY); } - + @NotNull private Optional getRegistryElement(IForgeRegistry registryKey, ResourceLocation identifier){ return registryKey.getHolder(identifier).map(Holder::value); diff --git a/forge/src/main/java/fr/rakambda/fallingtree/forge/common/wrapper/EnchantmentWrapper.java b/forge/src/main/java/fr/rakambda/fallingtree/forge/common/wrapper/EnchantmentWrapper.java deleted file mode 100644 index 8d7ba2f2..00000000 --- a/forge/src/main/java/fr/rakambda/fallingtree/forge/common/wrapper/EnchantmentWrapper.java +++ /dev/null @@ -1,34 +0,0 @@ -package fr.rakambda.fallingtree.forge.common.wrapper; - -import fr.rakambda.fallingtree.common.config.enums.BreakMode; -import fr.rakambda.fallingtree.common.enchant.IFallingTreeEnchantment; -import fr.rakambda.fallingtree.common.wrapper.IEnchantment; -import lombok.RequiredArgsConstructor; -import lombok.ToString; -import net.minecraft.world.item.enchantment.Enchantment; -import net.minecraftforge.registries.RegistryObject; -import org.jetbrains.annotations.NotNull; -import java.util.Optional; - -@RequiredArgsConstructor -@ToString -public class EnchantmentWrapper implements IEnchantment{ - @NotNull - private final RegistryObject raw; - - @Override - @NotNull - public Enchantment getRaw(){ - return raw.get(); - } - - - @Override - @NotNull - public Optional getBreakMode(){ - if(getRaw() instanceof IFallingTreeEnchantment ftEnchantment){ - return ftEnchantment.getBreakMode(); - } - return Optional.empty(); - } -} diff --git a/forge/src/main/java/fr/rakambda/fallingtree/forge/common/wrapper/ItemStackWrapper.java b/forge/src/main/java/fr/rakambda/fallingtree/forge/common/wrapper/ItemStackWrapper.java index 6da28601..8474b7d4 100644 --- a/forge/src/main/java/fr/rakambda/fallingtree/forge/common/wrapper/ItemStackWrapper.java +++ b/forge/src/main/java/fr/rakambda/fallingtree/forge/common/wrapper/ItemStackWrapper.java @@ -1,9 +1,10 @@ package fr.rakambda.fallingtree.forge.common.wrapper; -import fr.rakambda.fallingtree.common.wrapper.IEnchantment; +import fr.rakambda.fallingtree.common.config.enums.BreakMode; import fr.rakambda.fallingtree.common.wrapper.IItem; import fr.rakambda.fallingtree.common.wrapper.IItemStack; import fr.rakambda.fallingtree.common.wrapper.IPlayer; +import fr.rakambda.fallingtree.forge.FallingTree; import fr.rakambda.fallingtree.forge.compat.TetraCompat; import lombok.Getter; import lombok.RequiredArgsConstructor; @@ -11,12 +12,9 @@ import net.minecraft.world.entity.EquipmentSlot; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; -import net.minecraft.world.item.enchantment.Enchantment; import net.minecraft.world.item.enchantment.EnchantmentHelper; import net.minecraftforge.common.ToolActions; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import java.util.Collection; import java.util.Optional; @RequiredArgsConstructor @@ -52,7 +50,6 @@ public void damage(int amount, @NotNull IPlayer player){ raw.hurtAndBreak(amount, (Player) player.getRaw(), EquipmentSlot.MAINHAND); TetraCompat.tickHoningProgression(this, player); } - @Override @NotNull @@ -61,30 +58,19 @@ public IItem getItem(){ } @Override - public int getEnchantLevel(@Nullable IEnchantment enchantment){ - if(enchantment == null){ - return 0; - } - return raw.getEnchantmentLevel((Enchantment) enchantment.getRaw()); + public boolean hasChopperEnchant(){ + return EnchantmentHelper.hasTag(raw, FallingTree.getMod().getChopperEnchantmentTag()); } @Override - public boolean hasOneOfEnchantAtLeast(@NotNull Collection enchantments, int minLevel){ - for(var enchantment : enchantments){ - var key = (Enchantment) enchantment.getRaw(); - if(raw.getEnchantmentLevel(key) >= minLevel){ - return true; - } + public Optional getBreakModeFromEnchant(){ + if(!hasChopperEnchant()){ + return Optional.empty(); } - return false; - } - - @NotNull - public Optional getAnyEnchant(@NotNull Collection enchantments){ - for(var enchantment : enchantments){ - var key = (Enchantment) enchantment.getRaw(); - if(raw.getEnchantmentLevel(key) > 0){ - return Optional.of(enchantment); + var tags = FallingTree.getMod().getBreakModeChopperEnchantmentTag(); + for(var breakMode : tags.keySet()){ + if(EnchantmentHelper.hasTag(raw, tags.get(breakMode))){ + return Optional.of(breakMode); } } return Optional.empty(); diff --git a/forge/src/main/java/fr/rakambda/fallingtree/forge/enchant/ChopperEnchantment.java b/forge/src/main/java/fr/rakambda/fallingtree/forge/enchant/ChopperEnchantment.java deleted file mode 100644 index d9460395..00000000 --- a/forge/src/main/java/fr/rakambda/fallingtree/forge/enchant/ChopperEnchantment.java +++ /dev/null @@ -1,50 +0,0 @@ -package fr.rakambda.fallingtree.forge.enchant; - -import fr.rakambda.fallingtree.common.FallingTreeCommon; -import fr.rakambda.fallingtree.common.config.enums.BreakMode; -import fr.rakambda.fallingtree.common.enchant.IFallingTreeEnchantment; -import fr.rakambda.fallingtree.forge.common.wrapper.ItemStackWrapper; -import net.minecraft.tags.ItemTags; -import net.minecraft.world.entity.EquipmentSlot; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.item.enchantment.Enchantment; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import java.util.Optional; - -public class ChopperEnchantment extends Enchantment implements IFallingTreeEnchantment{ - private final FallingTreeCommon mod; - private final BreakMode breakMode; - - public ChopperEnchantment(@NotNull FallingTreeCommon mod, @Nullable BreakMode breakMode){ - super(Enchantment.definition(ItemTags.MINING_ENCHANTABLE, 1, 1, constantCost(1), constantCost(10), 1, EquipmentSlot.MAINHAND)); - this.mod = mod; - this.breakMode = breakMode; - } - - @Override - public boolean isTradeable(){ - return !mod.getConfiguration().getEnchantment().isHideEnchant(); - } - - @Override - public boolean isDiscoverable(){ - return !mod.getConfiguration().getEnchantment().isHideEnchant(); - } - - @Override - public boolean canApplyAtEnchantingTable(@NotNull ItemStack stack){ - return mod.isValidTool(new ItemStackWrapper(stack)); - } - - @Override - protected boolean checkCompatibility(@NotNull Enchantment enchantment){ - return super.checkCompatibility(enchantment) && !(enchantment instanceof IFallingTreeEnchantment); - } - - @Override - @NotNull - public Optional getBreakMode(){ - return Optional.ofNullable(breakMode); - } -} diff --git a/forge/src/main/java/fr/rakambda/fallingtree/forge/event/FallingTreeEnchantments.java b/forge/src/main/java/fr/rakambda/fallingtree/forge/event/FallingTreeEnchantments.java deleted file mode 100644 index 10e6db46..00000000 --- a/forge/src/main/java/fr/rakambda/fallingtree/forge/event/FallingTreeEnchantments.java +++ /dev/null @@ -1,37 +0,0 @@ -package fr.rakambda.fallingtree.forge.event; - -import fr.rakambda.fallingtree.common.config.enums.BreakMode; -import fr.rakambda.fallingtree.forge.enchant.ChopperEnchantment; -import fr.rakambda.fallingtree.forge.FallingTree; -import net.minecraft.world.item.enchantment.Enchantment; -import net.minecraftforge.eventbus.api.IEventBus; -import net.minecraftforge.registries.DeferredRegister; -import net.minecraftforge.registries.ForgeRegistries; -import net.minecraftforge.registries.RegistryObject; -import org.jetbrains.annotations.NotNull; - -public class FallingTreeEnchantments{ - private static final DeferredRegister ENCHANTMENTS = DeferredRegister.create(ForgeRegistries.ENCHANTMENTS, FallingTree.MOD_ID); - - public static RegistryObject CHOPPER_ENCHANTMENT; - public static RegistryObject CHOPPER_INSTANTANEOUS_ENCHANTMENT; - public static RegistryObject CHOPPER_FALL_BLOCK_ENCHANTMENT; - public static RegistryObject CHOPPER_FALL_ITEM_ENCHANTMENT; - public static RegistryObject CHOPPER_SHIFT_DOWN_ENCHANTMENT; - - public static void registerDefault(){ - CHOPPER_ENCHANTMENT = ENCHANTMENTS.register("chopper", () -> new ChopperEnchantment(FallingTree.getMod(), null)); - } - - public static void registerSpecific(){ - CHOPPER_INSTANTANEOUS_ENCHANTMENT = ENCHANTMENTS.register("chopper_instantaneous", () -> new ChopperEnchantment(FallingTree.getMod(), BreakMode.INSTANTANEOUS)); - CHOPPER_FALL_BLOCK_ENCHANTMENT = ENCHANTMENTS.register("chopper_fall_block", () -> new ChopperEnchantment(FallingTree.getMod(), BreakMode.FALL_BLOCK)); - CHOPPER_FALL_BLOCK_ENCHANTMENT = ENCHANTMENTS.register("chopper_fall_all_block", () -> new ChopperEnchantment(FallingTree.getMod(), BreakMode.FALL_ALL_BLOCK)); - CHOPPER_FALL_ITEM_ENCHANTMENT = ENCHANTMENTS.register("chopper_fall_item", () -> new ChopperEnchantment(FallingTree.getMod(), BreakMode.FALL_ITEM)); - CHOPPER_SHIFT_DOWN_ENCHANTMENT = ENCHANTMENTS.register("chopper_shift_down", () -> new ChopperEnchantment(FallingTree.getMod(), BreakMode.SHIFT_DOWN)); - } - - public static void commit(@NotNull IEventBus eventBus){ - ENCHANTMENTS.register(eventBus); - } -} diff --git a/forge/src/main/java/fr/rakambda/fallingtree/forge/network/ForgePacketHandler.java b/forge/src/main/java/fr/rakambda/fallingtree/forge/network/ForgePacketHandler.java index f8555c69..cfcda386 100644 --- a/forge/src/main/java/fr/rakambda/fallingtree/forge/network/ForgePacketHandler.java +++ b/forge/src/main/java/fr/rakambda/fallingtree/forge/network/ForgePacketHandler.java @@ -4,18 +4,17 @@ import fr.rakambda.fallingtree.common.network.ClientPacketHandler; import fr.rakambda.fallingtree.common.network.ConfigurationPacket; import fr.rakambda.fallingtree.common.network.ServerPacketHandler; -import fr.rakambda.fallingtree.forge.FallingTree; import fr.rakambda.fallingtree.forge.common.wrapper.FriendlyByteBufWrapper; import lombok.RequiredArgsConstructor; -import net.minecraft.resources.ResourceLocation; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.event.network.CustomPayloadEvent; import net.minecraftforge.fml.DistExecutor; import net.minecraftforge.network.SimpleChannel; +import static fr.rakambda.fallingtree.forge.FallingTreeUtils.id; @RequiredArgsConstructor public class ForgePacketHandler implements ClientPacketHandler, ServerPacketHandler{ - public static final SimpleChannel INSTANCE = net.minecraftforge.network.ChannelBuilder.named(new ResourceLocation(FallingTree.MOD_ID, "main")) + public static final SimpleChannel INSTANCE = net.minecraftforge.network.ChannelBuilder.named(id("main")) .optional() .simpleChannel(); diff --git a/forge/src/main/resources/META-INF/mods.toml b/forge/src/main/resources/META-INF/mods.toml index b383d674..bb11d7ec 100644 --- a/forge/src/main/resources/META-INF/mods.toml +++ b/forge/src/main/resources/META-INF/mods.toml @@ -1,5 +1,5 @@ modLoader = "javafml" -loaderVersion = "[50,)" +loaderVersion = "[51,)" issueTrackerURL = "https://github.com/${repoUser}/${repoName}/issues" license = "LGPL-3.0" @@ -15,7 +15,7 @@ authors = "Rakambda" [[dependencies.fallingtree]] modId = "forge" mandatory = true -versionRange = "[50,)" +versionRange = "[51,)" ordering = "NONE" side = "BOTH" [[dependencies.fallingtree]] @@ -27,6 +27,6 @@ side = "BOTH" [[dependencies.fallingtree]] modId = "cloth-config" mandatory = false -versionRange = "[14.0.0,)" +versionRange = "[15.0.0,)" ordering = "NONE" side = "CLIENT" diff --git a/forge/src/main/resources/pack.mcmeta b/forge/src/main/resources/pack.mcmeta index 63cb9600..2b9d3cb8 100644 --- a/forge/src/main/resources/pack.mcmeta +++ b/forge/src/main/resources/pack.mcmeta @@ -3,6 +3,6 @@ "description": { "text": "FallingTree" }, - "pack_format": 32 + "pack_format": 34 } } diff --git a/gradle.properties b/gradle.properties index bcef7537..b1068606 100644 --- a/gradle.properties +++ b/gradle.properties @@ -5,8 +5,8 @@ org.gradle.daemon=false modId=fallingtree modName=FallingTree includeFabric=true -includeForge=false -includeNeoForge=false +includeForge=true +includeNeoForge=true # Repository repoUser=Rakambda repoName=FallingTree diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 4408c704..e0958ea6 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -10,8 +10,8 @@ log4j2-version = "2.23.1" minecraftVersion = "1.21" fabric-loader-version = "0.15.11" fabric-api-version = "0.100.1+1.21" -forge-version = "1.20.6-50.0.19" -neoforge-version = "20.6.7-beta" +forge-version = "1.21-51.0.8" +neoforge-version = "21.0.8-beta" # Mod dependencies modmenu-version = "11.0.0-beta.1" @@ -23,7 +23,7 @@ curse-version = "1.4.0" modrinth-version = "2.8.7" names-version = "0.51.0" git-version-plugin-version = "3.1.0" -neoforge-plugin-version = "7.0.109" +neoforge-plugin-version = "7.0.143" [libraries] lombok = { group = "org.projectlombok", name = "lombok", version.ref = "lombok-version" } diff --git a/neoforge/src/main/java/fr/rakambda/fallingtree/neoforge/FallingTree.java b/neoforge/src/main/java/fr/rakambda/fallingtree/neoforge/FallingTree.java index 6d6e5d90..cd9e61f7 100644 --- a/neoforge/src/main/java/fr/rakambda/fallingtree/neoforge/FallingTree.java +++ b/neoforge/src/main/java/fr/rakambda/fallingtree/neoforge/FallingTree.java @@ -36,7 +36,6 @@ public FallingTree(@NotNull IEventBus modEventBus, @NotNull ModContainer modCont } } - mod.registerEnchant(); mod.registerForge(NeoForge.EVENT_BUS); } } diff --git a/neoforge/src/main/java/fr/rakambda/fallingtree/neoforge/FallingTreeUtils.java b/neoforge/src/main/java/fr/rakambda/fallingtree/neoforge/FallingTreeUtils.java new file mode 100644 index 00000000..2587b103 --- /dev/null +++ b/neoforge/src/main/java/fr/rakambda/fallingtree/neoforge/FallingTreeUtils.java @@ -0,0 +1,16 @@ +package fr.rakambda.fallingtree.neoforge; + +import net.minecraft.resources.ResourceLocation; +import org.jetbrains.annotations.NotNull; + +public class FallingTreeUtils{ + @NotNull + public static ResourceLocation id(@NotNull String name){ + return ResourceLocation.fromNamespaceAndPath(FallingTree.MOD_ID, name); + } + + @NotNull + public static ResourceLocation idExternal(@NotNull String fullName){ + return ResourceLocation.parse(fullName); + } +} diff --git a/neoforge/src/main/java/fr/rakambda/fallingtree/neoforge/client/cloth/ClothConfigHook.java b/neoforge/src/main/java/fr/rakambda/fallingtree/neoforge/client/cloth/ClothConfigHook.java index 3c2958e5..70e7c297 100644 --- a/neoforge/src/main/java/fr/rakambda/fallingtree/neoforge/client/cloth/ClothConfigHook.java +++ b/neoforge/src/main/java/fr/rakambda/fallingtree/neoforge/client/cloth/ClothConfigHook.java @@ -349,24 +349,6 @@ private void fillPlayerConfigScreen(@NotNull ConfigBuilder builder, @NotNull Pla @OnlyIn(Dist.CLIENT) private void fillEnchantmentConfigScreen(@NotNull ConfigBuilder builder, @NotNull EnchantmentConfiguration config){ - var registerEnchantEntry = builder.entryBuilder() - .startBooleanToggle(translatable(getFieldName("enchantment", "registerEnchant")), config.isRegisterEnchant()) - .setDefaultValue(false) - .setTooltip(getTooltips("enchantment", "registerEnchant")) - .setSaveConsumer(config::setRegisterEnchant) - .build(); - var registerSpecificEnchantEntry = builder.entryBuilder() - .startBooleanToggle(translatable(getFieldName("enchantment", "registerSpecificEnchant")), config.isRegisterSpecificEnchant()) - .setDefaultValue(false) - .setTooltip(getTooltips("enchantment", "registerSpecificEnchant")) - .setSaveConsumer(config::setRegisterSpecificEnchant) - .build(); - var hideEnchantEntry = builder.entryBuilder() - .startBooleanToggle(translatable(getFieldName("enchantment", "hideEnchant")), config.isHideEnchant()) - .setDefaultValue(false) - .setTooltip(getTooltips("enchantment", "hideEnchant")) - .setSaveConsumer(config::setHideEnchant) - .build(); var requireEnchantmentEntry = builder.entryBuilder() .startBooleanToggle(translatable(getFieldName("enchantment", "requireEnchantment")), config.isRequireEnchantment()) .setDefaultValue(false) @@ -375,9 +357,6 @@ private void fillEnchantmentConfigScreen(@NotNull ConfigBuilder builder, @NotNul .build(); var enchantment = builder.getOrCreateCategory(translatable("text.autoconfig.fallingtree.category.enchantment")); - enchantment.addEntry(registerEnchantEntry); - enchantment.addEntry(registerSpecificEnchantEntry); - enchantment.addEntry(hideEnchantEntry); enchantment.addEntry(requireEnchantmentEntry); } diff --git a/neoforge/src/main/java/fr/rakambda/fallingtree/neoforge/common/FallingTreeCommonsImpl.java b/neoforge/src/main/java/fr/rakambda/fallingtree/neoforge/common/FallingTreeCommonsImpl.java index 42c4f86f..e5e74d80 100644 --- a/neoforge/src/main/java/fr/rakambda/fallingtree/neoforge/common/FallingTreeCommonsImpl.java +++ b/neoforge/src/main/java/fr/rakambda/fallingtree/neoforge/common/FallingTreeCommonsImpl.java @@ -1,6 +1,7 @@ package fr.rakambda.fallingtree.neoforge.common; import fr.rakambda.fallingtree.common.FallingTreeCommon; +import fr.rakambda.fallingtree.common.config.enums.BreakMode; import fr.rakambda.fallingtree.common.leaf.LeafBreakingHandler; import fr.rakambda.fallingtree.common.network.ServerPacketHandler; import fr.rakambda.fallingtree.common.wrapper.DirectionCompat; @@ -8,7 +9,6 @@ import fr.rakambda.fallingtree.common.wrapper.IBlockPos; import fr.rakambda.fallingtree.common.wrapper.IBlockState; import fr.rakambda.fallingtree.common.wrapper.IComponent; -import fr.rakambda.fallingtree.common.wrapper.IEnchantment; import fr.rakambda.fallingtree.common.wrapper.IItem; import fr.rakambda.fallingtree.common.wrapper.IItemStack; import fr.rakambda.fallingtree.common.wrapper.ILevel; @@ -16,12 +16,10 @@ import fr.rakambda.fallingtree.neoforge.client.event.PlayerLeaveListener; import fr.rakambda.fallingtree.neoforge.common.wrapper.BlockWrapper; import fr.rakambda.fallingtree.neoforge.common.wrapper.ComponentWrapper; -import fr.rakambda.fallingtree.neoforge.common.wrapper.EnchantmentWrapper; import fr.rakambda.fallingtree.neoforge.common.wrapper.ItemStackWrapper; import fr.rakambda.fallingtree.neoforge.common.wrapper.ItemWrapper; import fr.rakambda.fallingtree.neoforge.event.BlockBreakListener; import fr.rakambda.fallingtree.neoforge.event.FallingTreeBlockBreakEvent; -import fr.rakambda.fallingtree.neoforge.event.FallingTreeEnchantments; import fr.rakambda.fallingtree.neoforge.event.LeafBreakingListener; import fr.rakambda.fallingtree.neoforge.event.ServerCommandRegistrationListener; import fr.rakambda.fallingtree.neoforge.network.NeoForgePacketHandler; @@ -38,22 +36,23 @@ import net.minecraft.tags.TagKey; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.enchantment.Enchantment; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.state.BlockState; import net.neoforged.bus.api.IEventBus; import net.neoforged.neoforge.common.NeoForge; -import net.neoforged.neoforge.registries.DeferredHolder; import org.jetbrains.annotations.NotNull; -import java.util.ArrayList; import java.util.Arrays; -import java.util.Collection; -import java.util.Objects; +import java.util.HashMap; +import java.util.Map; import java.util.Optional; import java.util.Set; import java.util.stream.Collectors; import java.util.stream.Stream; +import static fr.rakambda.fallingtree.neoforge.FallingTreeUtils.id; +import static fr.rakambda.fallingtree.neoforge.FallingTreeUtils.idExternal; import static java.util.stream.Stream.empty; public class FallingTreeCommonsImpl extends FallingTreeCommon{ @@ -62,14 +61,24 @@ public class FallingTreeCommonsImpl extends FallingTreeCommon{ private final LeafBreakingHandler leafBreakingHandler; private final NeoForgePacketHandler packetHandler; @Getter - private Collection chopperEnchantments; + private final TagKey chopperEnchantmentTag; + @Getter + private final Map> breakModeChopperEnchantmentTag; public FallingTreeCommonsImpl(@NotNull IEventBus modEventBus){ this.modEventBus = modEventBus; leafBreakingHandler = new LeafBreakingHandler(this); - chopperEnchantments = new ArrayList<>(); packetHandler = new NeoForgePacketHandler(this); + + chopperEnchantmentTag = TagKey.create(Registries.ENCHANTMENT, id("chopper_all")); + + breakModeChopperEnchantmentTag = new HashMap<>(); + breakModeChopperEnchantmentTag.put(BreakMode.FALL_ALL_BLOCK, TagKey.create(Registries.ENCHANTMENT, id("chopper_fall_all_block"))); + breakModeChopperEnchantmentTag.put(BreakMode.FALL_BLOCK, TagKey.create(Registries.ENCHANTMENT, id("chopper_fall_block"))); + breakModeChopperEnchantmentTag.put(BreakMode.FALL_ITEM, TagKey.create(Registries.ENCHANTMENT, id("chopper_fall_item"))); + breakModeChopperEnchantmentTag.put(BreakMode.INSTANTANEOUS, TagKey.create(Registries.ENCHANTMENT, id("chopper_instantaneous"))); + breakModeChopperEnchantmentTag.put(BreakMode.SHIFT_DOWN, TagKey.create(Registries.ENCHANTMENT, id("chopper_shift_down"))); } @Override @@ -100,7 +109,7 @@ public Stream getBlock(@NotNull String name){ if(isTag){ name = name.substring(1); } - var resourceLocation = new ResourceLocation(name); + var resourceLocation = idExternal(name); if(isTag){ var tag = TagKey.create(Registries.BLOCK, resourceLocation); return getRegistryTagContent(BuiltInRegistries.BLOCK, tag).map(BlockWrapper::new); @@ -120,7 +129,7 @@ public Stream getItem(@NotNull String name){ if(isTag){ name = name.substring(1); } - var resourceLocation = new ResourceLocation(name); + var resourceLocation = idExternal(name); if(isTag){ var tag = TagKey.create(Registries.ITEM, resourceLocation); return getRegistryTagContent(BuiltInRegistries.ITEM, tag).map(ItemWrapper::new); @@ -194,33 +203,6 @@ public boolean checkCanBreakBlock(@NotNull ILevel level, @NotNull IBlockPos bloc var event = NeoForge.EVENT_BUS.post(new FallingTreeBlockBreakEvent((Level) level.getRaw(), (BlockPos) blockPos.getRaw(), (BlockState) blockState.getRaw(), (Player) player.getRaw())); return !event.isCanceled(); } - - @Override - protected void performDefaultEnchantRegister(){ - FallingTreeEnchantments.registerDefault(); - } - - @Override - protected void performSpecificEnchantRegister(){ - FallingTreeEnchantments.registerSpecific(); - } - - @Override - protected void performCommitEnchantRegister(){ - FallingTreeEnchantments.commit(modEventBus); - - Stream.of(FallingTreeEnchantments.CHOPPER_ENCHANTMENT, - FallingTreeEnchantments.CHOPPER_INSTANTANEOUS_ENCHANTMENT, - FallingTreeEnchantments.CHOPPER_FALL_BLOCK_ENCHANTMENT, - FallingTreeEnchantments.CHOPPER_FALL_ITEM_ENCHANTMENT, - FallingTreeEnchantments.CHOPPER_SHIFT_DOWN_ENCHANTMENT - ) - .filter(Objects::nonNull) - .map(DeferredHolder::asOptional) - .flatMap(Optional::stream) - .map(EnchantmentWrapper::new) - .forEach(chopperEnchantments::add); - } @Override @NotNull diff --git a/neoforge/src/main/java/fr/rakambda/fallingtree/neoforge/common/wrapper/EnchantmentWrapper.java b/neoforge/src/main/java/fr/rakambda/fallingtree/neoforge/common/wrapper/EnchantmentWrapper.java deleted file mode 100644 index e8fd2548..00000000 --- a/neoforge/src/main/java/fr/rakambda/fallingtree/neoforge/common/wrapper/EnchantmentWrapper.java +++ /dev/null @@ -1,33 +0,0 @@ -package fr.rakambda.fallingtree.neoforge.common.wrapper; - -import fr.rakambda.fallingtree.common.config.enums.BreakMode; -import fr.rakambda.fallingtree.common.enchant.IFallingTreeEnchantment; -import fr.rakambda.fallingtree.common.wrapper.IEnchantment; -import lombok.RequiredArgsConstructor; -import lombok.ToString; -import net.minecraft.world.item.enchantment.Enchantment; -import org.jetbrains.annotations.NotNull; -import java.util.Optional; - -@RequiredArgsConstructor -@ToString -public class EnchantmentWrapper implements IEnchantment{ - @NotNull - private final Enchantment raw; - - @Override - @NotNull - public Enchantment getRaw(){ - return raw; - } - - - @Override - @NotNull - public Optional getBreakMode(){ - if(getRaw() instanceof IFallingTreeEnchantment ftEnchantment){ - return ftEnchantment.getBreakMode(); - } - return Optional.empty(); - } -} diff --git a/neoforge/src/main/java/fr/rakambda/fallingtree/neoforge/common/wrapper/ItemStackWrapper.java b/neoforge/src/main/java/fr/rakambda/fallingtree/neoforge/common/wrapper/ItemStackWrapper.java index 91b3981b..48f1d572 100644 --- a/neoforge/src/main/java/fr/rakambda/fallingtree/neoforge/common/wrapper/ItemStackWrapper.java +++ b/neoforge/src/main/java/fr/rakambda/fallingtree/neoforge/common/wrapper/ItemStackWrapper.java @@ -1,9 +1,10 @@ package fr.rakambda.fallingtree.neoforge.common.wrapper; -import fr.rakambda.fallingtree.common.wrapper.IEnchantment; +import fr.rakambda.fallingtree.common.config.enums.BreakMode; import fr.rakambda.fallingtree.common.wrapper.IItem; import fr.rakambda.fallingtree.common.wrapper.IItemStack; import fr.rakambda.fallingtree.common.wrapper.IPlayer; +import fr.rakambda.fallingtree.neoforge.FallingTree; import fr.rakambda.fallingtree.neoforge.compat.TetraCompat; import lombok.Getter; import lombok.RequiredArgsConstructor; @@ -11,11 +12,9 @@ import net.minecraft.world.entity.EquipmentSlot; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; -import net.minecraft.world.item.enchantment.Enchantment; +import net.minecraft.world.item.enchantment.EnchantmentHelper; import net.neoforged.neoforge.common.ToolActions; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import java.util.Collection; import java.util.Optional; @RequiredArgsConstructor @@ -59,30 +58,19 @@ public IItem getItem(){ } @Override - public int getEnchantLevel(@Nullable IEnchantment enchantment){ - if(enchantment == null){ - return 0; - } - return raw.getEnchantmentLevel((Enchantment) enchantment.getRaw()); - } - - @Override - public boolean hasOneOfEnchantAtLeast(@NotNull Collection enchantments, int minLevel){ - for(var enchantment : enchantments){ - var key = (Enchantment) enchantment.getRaw(); - if(raw.getEnchantmentLevel(key) >= minLevel){ - return true; - } - } - return false; + public boolean hasChopperEnchant(){ + return EnchantmentHelper.hasTag(raw, FallingTree.getMod().getChopperEnchantmentTag()); } @NotNull - public Optional getAnyEnchant(@NotNull Collection enchantments){ - for(var enchantment : enchantments){ - var key = (Enchantment) enchantment.getRaw(); - if(raw.getEnchantmentLevel(key) > 0){ - return Optional.of(enchantment); + public Optional getBreakModeFromEnchant(){ + if(!hasChopperEnchant()){ + return Optional.empty(); + } + var tags = FallingTree.getMod().getBreakModeChopperEnchantmentTag(); + for(var breakMode : tags.keySet()){ + if(EnchantmentHelper.hasTag(raw, tags.get(breakMode))){ + return Optional.of(breakMode); } } return Optional.empty(); diff --git a/neoforge/src/main/java/fr/rakambda/fallingtree/neoforge/enchant/ChopperEnchantment.java b/neoforge/src/main/java/fr/rakambda/fallingtree/neoforge/enchant/ChopperEnchantment.java deleted file mode 100644 index b2d0f094..00000000 --- a/neoforge/src/main/java/fr/rakambda/fallingtree/neoforge/enchant/ChopperEnchantment.java +++ /dev/null @@ -1,50 +0,0 @@ -package fr.rakambda.fallingtree.neoforge.enchant; - -import fr.rakambda.fallingtree.common.FallingTreeCommon; -import fr.rakambda.fallingtree.common.config.enums.BreakMode; -import fr.rakambda.fallingtree.common.enchant.IFallingTreeEnchantment; -import fr.rakambda.fallingtree.neoforge.common.wrapper.ItemStackWrapper; -import net.minecraft.tags.ItemTags; -import net.minecraft.world.entity.EquipmentSlot; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.item.enchantment.Enchantment; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import java.util.Optional; - -public class ChopperEnchantment extends Enchantment implements IFallingTreeEnchantment{ - private final FallingTreeCommon mod; - private final BreakMode breakMode; - - public ChopperEnchantment(@NotNull FallingTreeCommon mod, @Nullable BreakMode breakMode){ - super(Enchantment.definition(ItemTags.MINING_ENCHANTABLE, 1, 1, constantCost(1), constantCost(10), 1, EquipmentSlot.MAINHAND)); - this.mod = mod; - this.breakMode = breakMode; - } - - @Override - public boolean isTradeable(){ - return !mod.getConfiguration().getEnchantment().isHideEnchant(); - } - - @Override - public boolean isDiscoverable(){ - return !mod.getConfiguration().getEnchantment().isHideEnchant(); - } - - @Override - public boolean canApplyAtEnchantingTable(@NotNull ItemStack stack){ - return mod.isValidTool(new ItemStackWrapper(stack)); - } - - @Override - protected boolean checkCompatibility(@NotNull Enchantment enchantment){ - return super.checkCompatibility(enchantment) && !(enchantment instanceof IFallingTreeEnchantment); - } - - @Override - @NotNull - public Optional getBreakMode(){ - return Optional.ofNullable(breakMode); - } -} diff --git a/neoforge/src/main/java/fr/rakambda/fallingtree/neoforge/event/FallingTreeBlockBreakEvent.java b/neoforge/src/main/java/fr/rakambda/fallingtree/neoforge/event/FallingTreeBlockBreakEvent.java index e3b3eaf2..360f269d 100644 --- a/neoforge/src/main/java/fr/rakambda/fallingtree/neoforge/event/FallingTreeBlockBreakEvent.java +++ b/neoforge/src/main/java/fr/rakambda/fallingtree/neoforge/event/FallingTreeBlockBreakEvent.java @@ -10,9 +10,4 @@ public class FallingTreeBlockBreakEvent extends BlockEvent.BreakEvent{ public FallingTreeBlockBreakEvent(Level level, BlockPos pos, BlockState state, Player player){ super(level, pos, state, player); } - - @Override - public int getExpToDrop(){ - return 0; - } } diff --git a/neoforge/src/main/java/fr/rakambda/fallingtree/neoforge/event/FallingTreeEnchantments.java b/neoforge/src/main/java/fr/rakambda/fallingtree/neoforge/event/FallingTreeEnchantments.java deleted file mode 100644 index f149058a..00000000 --- a/neoforge/src/main/java/fr/rakambda/fallingtree/neoforge/event/FallingTreeEnchantments.java +++ /dev/null @@ -1,37 +0,0 @@ -package fr.rakambda.fallingtree.neoforge.event; - -import fr.rakambda.fallingtree.common.config.enums.BreakMode; -import fr.rakambda.fallingtree.neoforge.FallingTree; -import fr.rakambda.fallingtree.neoforge.enchant.ChopperEnchantment; -import net.minecraft.core.registries.BuiltInRegistries; -import net.minecraft.world.item.enchantment.Enchantment; -import net.neoforged.bus.api.IEventBus; -import net.neoforged.neoforge.registries.DeferredHolder; -import net.neoforged.neoforge.registries.DeferredRegister; -import org.jetbrains.annotations.NotNull; - -public class FallingTreeEnchantments{ - private static final DeferredRegister ENCHANTMENTS = DeferredRegister.create(BuiltInRegistries.ENCHANTMENT, FallingTree.MOD_ID); - - public static DeferredHolder CHOPPER_ENCHANTMENT; - public static DeferredHolder CHOPPER_INSTANTANEOUS_ENCHANTMENT; - public static DeferredHolder CHOPPER_FALL_BLOCK_ENCHANTMENT; - public static DeferredHolder CHOPPER_FALL_ITEM_ENCHANTMENT; - public static DeferredHolder CHOPPER_SHIFT_DOWN_ENCHANTMENT; - - public static void registerDefault(){ - CHOPPER_ENCHANTMENT = ENCHANTMENTS.register("chopper", () -> new ChopperEnchantment(FallingTree.getMod(), null)); - } - - public static void registerSpecific(){ - CHOPPER_INSTANTANEOUS_ENCHANTMENT = ENCHANTMENTS.register("chopper_instantaneous", () -> new ChopperEnchantment(FallingTree.getMod(), BreakMode.INSTANTANEOUS)); - CHOPPER_FALL_BLOCK_ENCHANTMENT = ENCHANTMENTS.register("chopper_fall_block", () -> new ChopperEnchantment(FallingTree.getMod(), BreakMode.FALL_BLOCK)); - CHOPPER_FALL_BLOCK_ENCHANTMENT = ENCHANTMENTS.register("chopper_fall_all_block", () -> new ChopperEnchantment(FallingTree.getMod(), BreakMode.FALL_ALL_BLOCK)); - CHOPPER_FALL_ITEM_ENCHANTMENT = ENCHANTMENTS.register("chopper_fall_item", () -> new ChopperEnchantment(FallingTree.getMod(), BreakMode.FALL_ITEM)); - CHOPPER_SHIFT_DOWN_ENCHANTMENT = ENCHANTMENTS.register("chopper_shift_down", () -> new ChopperEnchantment(FallingTree.getMod(), BreakMode.SHIFT_DOWN)); - } - - public static void commit(@NotNull IEventBus eventBus){ - ENCHANTMENTS.register(eventBus); - } -} diff --git a/neoforge/src/main/java/fr/rakambda/fallingtree/neoforge/network/FallingTreeConfigPacket.java b/neoforge/src/main/java/fr/rakambda/fallingtree/neoforge/network/FallingTreeConfigPacket.java index 84406dc3..cc288835 100644 --- a/neoforge/src/main/java/fr/rakambda/fallingtree/neoforge/network/FallingTreeConfigPacket.java +++ b/neoforge/src/main/java/fr/rakambda/fallingtree/neoforge/network/FallingTreeConfigPacket.java @@ -1,19 +1,18 @@ package fr.rakambda.fallingtree.neoforge.network; import fr.rakambda.fallingtree.common.network.ConfigurationPacket; -import fr.rakambda.fallingtree.neoforge.FallingTree; import fr.rakambda.fallingtree.neoforge.common.wrapper.FriendlyByteBufWrapper; import lombok.Getter; import lombok.RequiredArgsConstructor; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.network.codec.StreamCodec; import net.minecraft.network.protocol.common.custom.CustomPacketPayload; -import net.minecraft.resources.ResourceLocation; import org.jetbrains.annotations.NotNull; +import static fr.rakambda.fallingtree.neoforge.FallingTreeUtils.id; @RequiredArgsConstructor public class FallingTreeConfigPacket implements CustomPacketPayload{ - public static final Type TYPE = new Type<>(new ResourceLocation(FallingTree.MOD_ID, "configuration-packet")); + public static final Type TYPE = new Type<>(id("configuration-packet")); public static final StreamCodec CODEC = CustomPacketPayload.codec( FallingTreeConfigPacket::write, packet -> new FallingTreeConfigPacket(ConfigurationPacket.read(new FriendlyByteBufWrapper(packet)))); diff --git a/neoforge/src/main/resources/META-INF/neoforge.mods.toml b/neoforge/src/main/resources/META-INF/neoforge.mods.toml index fd3dbf92..331de651 100644 --- a/neoforge/src/main/resources/META-INF/neoforge.mods.toml +++ b/neoforge/src/main/resources/META-INF/neoforge.mods.toml @@ -1,5 +1,5 @@ modLoader="javafml" #mandatory -loaderVersion="[2,)" +loaderVersion="[4,)" license="LGPL-3.0" [[mods]] @@ -17,7 +17,7 @@ file="META-INF/neoforge.accesstransformer.cfg" [[dependencies.fallingtree]] modId="neoforge" type="required" -versionRange="[20.6,)" +versionRange="[21.0,)" ordering="NONE" side="BOTH" [[dependencies.fallingtree]] @@ -29,6 +29,6 @@ side="BOTH" [[dependencies.fallingtree]] modId = "cloth-config" type="optional" -versionRange = "[14.0.0,)" +versionRange = "[15.0.0,)" ordering = "NONE" side = "CLIENT"