Skip to content

Commit ab392f0

Browse files
authored
Use Minecraft registries instead of Forge's (#773)
1 parent 203bc27 commit ab392f0

File tree

1 file changed

+19
-17
lines changed

1 file changed

+19
-17
lines changed

forge/src/main/java/fr/rakambda/fallingtree/forge/common/FallingTreeCommonsImpl.java

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
import net.minecraft.core.BlockPos;
2929
import net.minecraft.core.Direction;
3030
import net.minecraft.core.Holder;
31+
import net.minecraft.core.Registry;
32+
import net.minecraft.core.registries.BuiltInRegistries;
3133
import net.minecraft.core.registries.Registries;
3234
import net.minecraft.network.chat.Component;
3335
import net.minecraft.resources.ResourceLocation;
@@ -42,8 +44,6 @@
4244
import net.minecraft.world.level.block.state.BlockState;
4345
import net.minecraftforge.common.MinecraftForge;
4446
import net.minecraftforge.eventbus.api.IEventBus;
45-
import net.minecraftforge.registries.ForgeRegistries;
46-
import net.minecraftforge.registries.IForgeRegistry;
4747
import org.jetbrains.annotations.NotNull;
4848
import java.util.Arrays;
4949
import java.util.HashMap;
@@ -110,9 +110,9 @@ public Stream<IBlock> getBlock(@NotNull String name){
110110
var resourceLocation = idExternal(name);
111111
if(isTag){
112112
var tag = TagKey.create(Registries.BLOCK, resourceLocation);
113-
return getRegistryTagContent(ForgeRegistries.BLOCKS, tag).map(BlockWrapper::new);
113+
return getRegistryTagContent(BuiltInRegistries.BLOCK, tag).map(BlockWrapper::new);
114114
}
115-
return getRegistryElement(ForgeRegistries.BLOCKS, resourceLocation).stream().map(BlockWrapper::new);
115+
return getRegistryElement(BuiltInRegistries.BLOCK, resourceLocation).stream().map(BlockWrapper::new);
116116
}
117117
catch(Exception e){
118118
return empty();
@@ -130,9 +130,9 @@ public Stream<IItem> getItem(@NotNull String name){
130130
var resourceLocation = idExternal(name);
131131
if(isTag){
132132
var tag = TagKey.create(Registries.ITEM, resourceLocation);
133-
return getRegistryTagContent(ForgeRegistries.ITEMS, tag).map(ItemWrapper::new);
133+
return getRegistryTagContent(BuiltInRegistries.ITEM, tag).map(ItemWrapper::new);
134134
}
135-
return getRegistryElement(ForgeRegistries.ITEMS, resourceLocation).stream().map(ItemWrapper::new);
135+
return getRegistryElement(BuiltInRegistries.ITEM, resourceLocation).stream().map(ItemWrapper::new);
136136
}
137137
catch(Exception e){
138138
return empty();
@@ -141,7 +141,7 @@ public Stream<IItem> getItem(@NotNull String name){
141141

142142
@Override
143143
public boolean isLeafBlock(@NotNull IBlock block){
144-
var isAllowedBlock = registryTagContains(ForgeRegistries.BLOCKS, BlockTags.LEAVES, (Block) block.getRaw())
144+
var isAllowedBlock = registryTagContains(BuiltInRegistries.BLOCK, BlockTags.LEAVES, (Block) block.getRaw())
145145
|| getConfiguration().getTrees().getAllowedLeaveBlocks(this).stream().anyMatch(leaf -> leaf.equals(block));
146146
if(isAllowedBlock){
147147
var isDeniedBlock = getConfiguration().getTrees().getDeniedLeaveBlocks(this).stream().anyMatch(leaf -> leaf.equals(block));
@@ -152,7 +152,7 @@ public boolean isLeafBlock(@NotNull IBlock block){
152152

153153
@Override
154154
public boolean isLogBlock(@NotNull IBlock block){
155-
var isAllowedBlock = getConfiguration().getTrees().getDefaultLogsBlocks(this).stream().anyMatch(log -> log.equals(block))
155+
var isAllowedBlock = getConfiguration().getTrees().getDefaultLogsBlocks(this).stream().anyMatch(log -> log.equals(block))
156156
|| getConfiguration().getTrees().getAllowedLogBlocks(this).stream().anyMatch(log -> log.equals(block));
157157
if(isAllowedBlock){
158158
var isDeniedBlock = getConfiguration().getTrees().getDeniedLogBlocks(this).stream().anyMatch(log -> log.equals(block));
@@ -164,11 +164,12 @@ public boolean isLogBlock(@NotNull IBlock block){
164164
@Override
165165
@NotNull
166166
public Set<IBlock> getAllNonStrippedLogsBlocks(){
167-
return getRegistryTagContent(ForgeRegistries.BLOCKS, BlockTags.LOGS)
168-
.filter(block -> !Optional.ofNullable(ForgeRegistries.BLOCKS.getKey(block))
167+
return getRegistryTagContent(BuiltInRegistries.BLOCK, BlockTags.LOGS)
168+
.filter(block -> !Optional.of(BuiltInRegistries.BLOCK.getKey(block))
169169
.map(ResourceLocation::getPath)
170170
.map(name -> name.startsWith("stripped"))
171-
.orElse(false))
171+
.orElse(false)
172+
)
172173
.map(BlockWrapper::new)
173174
.collect(Collectors.toSet());
174175
}
@@ -187,7 +188,7 @@ public Direction asDirection(@NotNull DirectionCompat dir){
187188

188189
@Override
189190
public boolean isNetherWartOrShroomlight(@NotNull IBlock block){
190-
return registryTagContains(ForgeRegistries.BLOCKS, BlockTags.WART_BLOCKS, (Block) block.getRaw())
191+
return registryTagContains(BuiltInRegistries.BLOCK, BlockTags.WART_BLOCKS, (Block) block.getRaw())
191192
|| Blocks.SHROOMLIGHT.equals(block.getRaw());
192193
}
193194

@@ -208,16 +209,17 @@ public IItemStack getEmptyItemStack(){
208209
}
209210

210211
@NotNull
211-
private <T> Optional<T> getRegistryElement(IForgeRegistry<T> registryKey, ResourceLocation identifier){
212-
return registryKey.getHolder(identifier).map(Holder::value);
212+
private <T> Optional<T> getRegistryElement(Registry<T> registryKey, ResourceLocation identifier){
213+
return registryKey.get(identifier).map(Holder::value);
213214
}
214215

215216
@NotNull
216-
private <T> Stream<T> getRegistryTagContent(@NotNull IForgeRegistry<T> registry, @NotNull TagKey<T> tag){
217-
return registry.tags().getTag(tag).stream();
217+
private <T> Stream<T> getRegistryTagContent(@NotNull Registry<T> registry, @NotNull TagKey<T> tag){
218+
return registry.get(tag).stream()
219+
.flatMap(a -> a.stream().map(Holder::value));
218220
}
219221

220-
private <T> boolean registryTagContains(@NotNull IForgeRegistry<T> registry, @NotNull TagKey<T> tag, @NotNull T element){
222+
private <T> boolean registryTagContains(@NotNull Registry<T> registry, @NotNull TagKey<T> tag, @NotNull T element){
221223
return getRegistryTagContent(registry, tag).anyMatch(element::equals);
222224
}
223225

0 commit comments

Comments
 (0)