Skip to content

Commit

Permalink
support leaf blocks that use the LEAVES block tag provided they still…
Browse files Browse the repository at this point in the history
… call LeavesBlock.randomDisplayTick,

this applies to ExtendedLeavesBlock from Terraform (Terrestria/Traverse) and we could extend this to blocks calling Block.randomDisplayTick as well in the future
  • Loading branch information
Fourmisain committed Jan 27, 2021
1 parent 1a81cfc commit ce13332
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
11 changes: 6 additions & 5 deletions src/main/java/randommcsomethin/fallingleaves/init/Leaves.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class Leaves {
public static DefaultParticleType FALLING_LEAF;
public static DefaultParticleType FALLING_CONIFER_LEAF;

private static boolean partiallyLoadedRegisteredLeafBlocks = false;
private static boolean preLoadedRegisteredLeafBlocks = false;

public static void init() {
LOGGER.debug("Registering leaf particles.");
Expand All @@ -52,12 +52,13 @@ private static void registerReloadListener() {
ResourceManagerHelper.get(ResourceType.CLIENT_RESOURCES).registerReloadListener(new SimpleSynchronousResourceReloadListener() {
@Override
public void apply(ResourceManager resourceManager) {
// This is a pretty good point to load registered leaf blocks, it may be good enough to replace LoadWorldMixin
if (!partiallyLoadedRegisteredLeafBlocks) {
for (Map.Entry<Identifier, LeafSettingsEntry> registered : LeafUtil.getRegisteredLeafBlocks().entrySet())
// This is called before the integrated server is started and block tags are useable,
// so we'll get an incomplete list of leaf blocks, but that's fine
if (!preLoadedRegisteredLeafBlocks) {
for (Map.Entry<Identifier, LeafSettingsEntry> registered : LeafUtil.getRegisteredLeafBlocks(false).entrySet())
CONFIG.leafSettings.computeIfAbsent(registered.getKey(), k -> registered.getValue());

partiallyLoadedRegisteredLeafBlocks = true;
preLoadedRegisteredLeafBlocks = true;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ public abstract class LoadWorldMixin {
protected void loadWorld(CallbackInfo ci) {
LOGGER.info("Loading all registered leaf blocks.");

// At this point it has to be guaranteed that all modded blocks are registered,
// so we add all leaf blocks that weren't already read from the config file
for (Map.Entry<Identifier, LeafSettingsEntry> registered : LeafUtil.getRegisteredLeafBlocks().entrySet())
// At this point it has to be guaranteed that all modded blocks are registered and block tags are useable
// (This is actually pretty much the earliest point in time where we can use block tags)
// So we add all leaf blocks that weren't already read from the config file or preloaded in our ReloadListener
for (Map.Entry<Identifier, LeafSettingsEntry> registered : LeafUtil.getRegisteredLeafBlocks(true).entrySet())
CONFIG.leafSettings.computeIfAbsent(registered.getKey(), k -> registered.getValue());

Config.save();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import net.minecraft.client.render.model.BakedQuad;
import net.minecraft.client.texture.Sprite;
import net.minecraft.resource.Resource;
import net.minecraft.tag.BlockTags;
import net.minecraft.tag.Tag;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Box;
Expand Down Expand Up @@ -112,13 +114,14 @@ private static boolean shouldSpawnParticle(World world, BlockPos pos, double x,
return !world.getBlockCollisions(null, collisionBox).findAny().isPresent();
}

public static Map<Identifier, LeafSettingsEntry> getRegisteredLeafBlocks() {
/** Block tags can only be used once the integrated server is started */
public static Map<Identifier, LeafSettingsEntry> getRegisteredLeafBlocks(boolean useBlockTags) {
return Registry.BLOCK
.getIds()
.stream()
.filter(entry -> {
Block block = Registry.BLOCK.get(entry);
return (block instanceof LeavesBlock);
return (block instanceof LeavesBlock) || (useBlockTags && block.isIn(BlockTags.LEAVES));
})
.collect(Collectors.toMap(
Function.identity(),
Expand Down

0 comments on commit ce13332

Please sign in to comment.