From ab392f0dda224e92cdd46a1ea353494660975b48 Mon Sep 17 00:00:00 2001 From: Thomas <1688389+Rakambda@users.noreply.github.com> Date: Mon, 4 Nov 2024 15:38:42 +0100 Subject: [PATCH] Use Minecraft registries instead of Forge's (#773) --- .../forge/common/FallingTreeCommonsImpl.java | 36 ++++++++++--------- 1 file changed, 19 insertions(+), 17 deletions(-) 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 6920e4c4..b1452d6d 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 @@ -28,6 +28,8 @@ import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.core.Holder; +import net.minecraft.core.Registry; +import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.core.registries.Registries; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; @@ -42,8 +44,6 @@ import net.minecraft.world.level.block.state.BlockState; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.eventbus.api.IEventBus; -import net.minecraftforge.registries.ForgeRegistries; -import net.minecraftforge.registries.IForgeRegistry; import org.jetbrains.annotations.NotNull; import java.util.Arrays; import java.util.HashMap; @@ -110,9 +110,9 @@ public Stream getBlock(@NotNull String name){ var resourceLocation = idExternal(name); if(isTag){ var tag = TagKey.create(Registries.BLOCK, resourceLocation); - return getRegistryTagContent(ForgeRegistries.BLOCKS, tag).map(BlockWrapper::new); + return getRegistryTagContent(BuiltInRegistries.BLOCK, tag).map(BlockWrapper::new); } - return getRegistryElement(ForgeRegistries.BLOCKS, resourceLocation).stream().map(BlockWrapper::new); + return getRegistryElement(BuiltInRegistries.BLOCK, resourceLocation).stream().map(BlockWrapper::new); } catch(Exception e){ return empty(); @@ -130,9 +130,9 @@ public Stream getItem(@NotNull String name){ var resourceLocation = idExternal(name); if(isTag){ var tag = TagKey.create(Registries.ITEM, resourceLocation); - return getRegistryTagContent(ForgeRegistries.ITEMS, tag).map(ItemWrapper::new); + return getRegistryTagContent(BuiltInRegistries.ITEM, tag).map(ItemWrapper::new); } - return getRegistryElement(ForgeRegistries.ITEMS, resourceLocation).stream().map(ItemWrapper::new); + return getRegistryElement(BuiltInRegistries.ITEM, resourceLocation).stream().map(ItemWrapper::new); } catch(Exception e){ return empty(); @@ -141,7 +141,7 @@ public Stream getItem(@NotNull String name){ @Override public boolean isLeafBlock(@NotNull IBlock block){ - var isAllowedBlock = registryTagContains(ForgeRegistries.BLOCKS, BlockTags.LEAVES, (Block) block.getRaw()) + var isAllowedBlock = registryTagContains(BuiltInRegistries.BLOCK, BlockTags.LEAVES, (Block) block.getRaw()) || getConfiguration().getTrees().getAllowedLeaveBlocks(this).stream().anyMatch(leaf -> leaf.equals(block)); if(isAllowedBlock){ var isDeniedBlock = getConfiguration().getTrees().getDeniedLeaveBlocks(this).stream().anyMatch(leaf -> leaf.equals(block)); @@ -152,7 +152,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)) + var isAllowedBlock = getConfiguration().getTrees().getDefaultLogsBlocks(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)); @@ -164,11 +164,12 @@ public boolean isLogBlock(@NotNull IBlock block){ @Override @NotNull public Set getAllNonStrippedLogsBlocks(){ - return getRegistryTagContent(ForgeRegistries.BLOCKS, BlockTags.LOGS) - .filter(block -> !Optional.ofNullable(ForgeRegistries.BLOCKS.getKey(block)) + return getRegistryTagContent(BuiltInRegistries.BLOCK, BlockTags.LOGS) + .filter(block -> !Optional.of(BuiltInRegistries.BLOCK.getKey(block)) .map(ResourceLocation::getPath) .map(name -> name.startsWith("stripped")) - .orElse(false)) + .orElse(false) + ) .map(BlockWrapper::new) .collect(Collectors.toSet()); } @@ -187,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()) + return registryTagContains(BuiltInRegistries.BLOCK, BlockTags.WART_BLOCKS, (Block) block.getRaw()) || Blocks.SHROOMLIGHT.equals(block.getRaw()); } @@ -208,16 +209,17 @@ public IItemStack getEmptyItemStack(){ } @NotNull - private Optional getRegistryElement(IForgeRegistry registryKey, ResourceLocation identifier){ - return registryKey.getHolder(identifier).map(Holder::value); + private Optional getRegistryElement(Registry registryKey, ResourceLocation identifier){ + return registryKey.get(identifier).map(Holder::value); } @NotNull - private Stream getRegistryTagContent(@NotNull IForgeRegistry registry, @NotNull TagKey tag){ - return registry.tags().getTag(tag).stream(); + private Stream getRegistryTagContent(@NotNull Registry registry, @NotNull TagKey tag){ + return registry.get(tag).stream() + .flatMap(a -> a.stream().map(Holder::value)); } - private boolean registryTagContains(@NotNull IForgeRegistry registry, @NotNull TagKey tag, @NotNull T element){ + private boolean registryTagContains(@NotNull Registry registry, @NotNull TagKey tag, @NotNull T element){ return getRegistryTagContent(registry, tag).anyMatch(element::equals); }