Skip to content

Commit 9d88579

Browse files
committed
Fix initialization of cached block info not working on neoforge
Broken since 1.21.2+
1 parent cd3e2dc commit 9d88579

File tree

16 files changed

+127
-87
lines changed

16 files changed

+127
-87
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ Make sure to take a backup of your world before using the mod and please report
1212

1313
## Fixes
1414
- Fix entity explosion exposure optimization not using the entity collision context
15+
- Fix initialization of cached block info not working on neoforge

build.gradle.kts

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ plugins {
1010
// Fabric: https://fabricmc.net/develop/
1111
// Neoforge: https://neoforged.net/
1212
val MINECRAFT_VERSION by extra { "1.21.4" } //MUST manually update fabric.mod.json and neoforge.mods.toml
13-
val NEOFORGE_VERSION by extra { "21.4.109-beta" }
13+
val NEOFORGE_VERSION by extra { "21.4.115-beta" }
1414
val FABRIC_LOADER_VERSION by extra { "0.16.9" }
1515
val FABRIC_API_VERSION by extra { "0.110.5+1.21.4" }
1616

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package net.caffeinemc.mods.lithium.common.initialization;
2+
3+
import net.caffeinemc.mods.lithium.common.ai.pathing.BlockStatePathingCache;
4+
import net.caffeinemc.mods.lithium.common.block.BlockStateFlagHolder;
5+
import net.minecraft.world.level.block.Block;
6+
import net.minecraft.world.level.block.state.BlockState;
7+
8+
public class BlockInfoInitializer {
9+
10+
// Initialize the block info.
11+
// This is called before burn times are set in the minecraft server, but we don't care about the updated burn times.
12+
// But burn times are updated after block tags etc. are modified, so it is a good hook
13+
public static void initializeBlockInfo() {
14+
if (BlockStatePathingCache.class.isAssignableFrom(BlockState.class)) {
15+
// Initialize / Reinitialize the cached path node types.
16+
for (BlockState blockState : Block.BLOCK_STATE_REGISTRY) {
17+
((BlockStatePathingCache) blockState).lithium$initializePathNodeTypeCache();
18+
}
19+
}
20+
21+
if (BlockStateFlagHolder.class.isAssignableFrom(BlockState.class)) {
22+
// Initialize / Reinitialize the cached block flags.
23+
for (BlockState blockState : Block.BLOCK_STATE_REGISTRY) {
24+
((BlockStateFlagHolder) blockState).lithium$initializeFlags();
25+
}
26+
}
27+
}
28+
}

common/src/main/java/net/caffeinemc/mods/lithium/mixin/ai/pathing/FuelValuesMixin.java

-32
This file was deleted.

common/src/main/java/net/caffeinemc/mods/lithium/mixin/ai/pathing/package-info.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
A faster code path is used for determining what kind of path-finding node type is associated with a
44
given block. Additionally, a faster chunk cache will be used for accessing blocks while evaluating
55
paths.""",
6-
depends = @MixinConfigDependency(
7-
dependencyPath = "mixin.util.chunk_access"
8-
)
6+
depends = {
7+
@MixinConfigDependency(dependencyPath = "mixin.util.chunk_access"),
8+
@MixinConfigDependency(dependencyPath = "mixin.util.initialization")
9+
}
910
)
1011
package net.caffeinemc.mods.lithium.mixin.ai.pathing;
1112

common/src/main/java/net/caffeinemc/mods/lithium/mixin/util/block_tracking/BlockStateBaseMixin.java

+6-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
@Mixin(value = BlockBehaviour.BlockStateBase.class, priority = 1010)
1212
public class BlockStateBaseMixin implements BlockStateFlagHolder {
1313
@Unique
14-
private int flags;
14+
private int flags = -1;
1515

1616
@Override
1717
public void lithium$initializeFlags() {
@@ -31,6 +31,10 @@ public class BlockStateBaseMixin implements BlockStateFlagHolder {
3131

3232
@Override
3333
public int lithium$getAllFlags() {
34-
return this.flags;
34+
int blockStateFlags = this.flags;
35+
if (blockStateFlags == -1) {
36+
throw new IllegalStateException("Tried to get uninitialized block state flags!");
37+
}
38+
return blockStateFlags;
3539
}
3640
}

common/src/main/java/net/caffeinemc/mods/lithium/mixin/util/block_tracking/FuelValuesMixin.java

-32
This file was deleted.

common/src/main/java/net/caffeinemc/mods/lithium/mixin/util/block_tracking/package-info.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
" certain blocks being placed or broken.",
55
depends = {
66
@MixinConfigDependency(dependencyPath = "mixin.util.data_storage"),
7-
@MixinConfigDependency(dependencyPath = "mixin.util.chunk_status_tracking")
7+
@MixinConfigDependency(dependencyPath = "mixin.util.chunk_status_tracking"),
8+
@MixinConfigDependency(dependencyPath = "mixin.util.initialization")
89
}
910
)
1011
package net.caffeinemc.mods.lithium.mixin.util.block_tracking;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
@MixinConfigOption(description = "Platform dependent initialization hooks.")
2+
package net.caffeinemc.mods.lithium.mixin.util.initialization;
3+
4+
import net.caffeinemc.gradle.MixinConfigOption;

common/src/main/resources/lithium.mixins.json

-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
"mixins" : [
1010
"ai.pathing.BlockStateBaseMixin",
1111
"ai.pathing.FlyNodeEvaluatorMixin",
12-
"ai.pathing.FuelValuesMixin",
1312
"ai.pathing.PathfindingContextAccessor",
1413
"ai.pathing.PathfindingContextMixin",
1514
"ai.pathing.PathNavigationRegionMixin",
@@ -181,7 +180,6 @@
181180
"util.accessors.ServerLevelAccessor",
182181
"util.block_entity_retrieval.LevelMixin",
183182
"util.block_tracking.BlockStateBaseMixin",
184-
"util.block_tracking.FuelValuesMixin",
185183
"util.block_tracking.LevelChunkSectionMixin",
186184
"util.chunk_access.LevelReaderMixin",
187185
"util.chunk_access.PathNavigationRegionMixin",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package net.caffeinemc.mods.lithium.fabric.mixin.util.initialization;
2+
3+
import net.caffeinemc.mods.lithium.common.initialization.BlockInfoInitializer;
4+
import net.minecraft.core.HolderLookup;
5+
import net.minecraft.world.flag.FeatureFlagSet;
6+
import net.minecraft.world.level.block.entity.FuelValues;
7+
import org.spongepowered.asm.mixin.Mixin;
8+
import org.spongepowered.asm.mixin.injection.At;
9+
import org.spongepowered.asm.mixin.injection.Inject;
10+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
11+
12+
/**
13+
* Hook into the initialization of fuel values, because those are always updated after block tags are modified,
14+
* and we must among others, update our cache path node information which is also based on block tags.
15+
*/
16+
@Mixin(FuelValues.class)
17+
public class FuelValuesMixin {
18+
19+
@Inject(
20+
method = "vanillaBurnTimes(Lnet/minecraft/core/HolderLookup$Provider;Lnet/minecraft/world/flag/FeatureFlagSet;I)Lnet/minecraft/world/level/block/entity/FuelValues;",
21+
at = @At(value = "RETURN")
22+
)
23+
private static void initializeBlockInfo(HolderLookup.Provider provider, FeatureFlagSet featureFlagSet, int i, CallbackInfoReturnable<FuelValues> cir) {
24+
BlockInfoInitializer.initializeBlockInfo();
25+
}
26+
}
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,24 @@
11
{
2-
"package": "net.caffeinemc.mods.lithium.fabric.mixin",
3-
"required": true,
4-
"compatibilityLevel": "JAVA_21",
5-
"plugin": "net.caffeinemc.mods.lithium.mixin.LithiumMixinPlugin",
6-
"injectors": {
7-
"defaultRequire": 1
2+
"package" : "net.caffeinemc.mods.lithium.fabric.mixin",
3+
"required" : true,
4+
"compatibilityLevel" : "JAVA_21",
5+
"plugin" : "net.caffeinemc.mods.lithium.mixin.LithiumMixinPlugin",
6+
"injectors" : {
7+
"defaultRequire" : 1
88
},
9-
"overwrites": {
10-
"conformVisibility": true
9+
"overwrites" : {
10+
"conformVisibility" : true
1111
},
12-
"mixins": [
12+
"mixins" : [
1313
"block.hopper.LevelMixin",
1414
"collections.poi_types.PoiTypesMixin",
1515
"compat.worldedit.LevelChunkMixin",
1616
"entity.collisions.fluid.EntityMixin",
1717
"experimental.entity.block_caching.fluid_pushing.EntityMixin",
18+
"util.initialization.FuelValuesMixin",
1819
"util.inventory_change_listening.BlockEntityMixin",
1920
"util.inventory_change_listening.ChestBlockEntityMixin"
2021
],
21-
"client": [
22+
"client" : [
2223
]
2324
}

lithium-fabric-mixin-config.md

+8-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ A faster code path is used for determining what kind of path-finding node type i
2626
given block. Additionally, a faster chunk cache will be used for accessing blocks while evaluating
2727
paths.
2828
Requirements:
29-
- `mixin.util.chunk_access=true`
29+
- `mixin.util.chunk_access=true`
30+
- `mixin.util.initialization=true`
3031

3132
### `mixin.ai.poi`
3233
(default: `true`)
@@ -511,7 +512,8 @@ Allows access to existing BlockEntities without creating new ones
511512
Chunk sections count certain blocks inside them and provide a method to quickly check whether a chunk contains any of these blocks. Furthermore, chunk sections can notify registered listeners about certain blocks being placed or broken.
512513
Requirements:
513514
- `mixin.util.data_storage=true`
514-
- `mixin.util.chunk_status_tracking=true`
515+
- `mixin.util.chunk_status_tracking=true`
516+
- `mixin.util.initialization=true`
515517

516518
### `mixin.util.chunk_access`
517519
(default: `true`)
@@ -542,6 +544,10 @@ Requirements:
542544
(default: `true`)
543545
Entity sections store their position
544546

547+
### `mixin.util.initialization`
548+
(default: `true`)
549+
Platform dependent initialization hooks.
550+
545551
### `mixin.util.inventory_change_listening`
546552
(default: `true`)
547553
Certain BlockEntity Inventories emit updates to their listeners when their stack list is changed or the inventory becomes invalid

lithium-neoforge-mixin-config.md

+8-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ A faster code path is used for determining what kind of path-finding node type i
2626
given block. Additionally, a faster chunk cache will be used for accessing blocks while evaluating
2727
paths.
2828
Requirements:
29-
- `mixin.util.chunk_access=true`
29+
- `mixin.util.chunk_access=true`
30+
- `mixin.util.initialization=true`
3031

3132
### `mixin.ai.poi`
3233
(default: `true`)
@@ -492,7 +493,8 @@ Allows access to existing BlockEntities without creating new ones
492493
Chunk sections count certain blocks inside them and provide a method to quickly check whether a chunk contains any of these blocks. Furthermore, chunk sections can notify registered listeners about certain blocks being placed or broken.
493494
Requirements:
494495
- `mixin.util.data_storage=true`
495-
- `mixin.util.chunk_status_tracking=true`
496+
- `mixin.util.chunk_status_tracking=true`
497+
- `mixin.util.initialization=true`
496498

497499
### `mixin.util.chunk_access`
498500
(default: `true`)
@@ -523,6 +525,10 @@ Requirements:
523525
(default: `true`)
524526
Entity sections store their position
525527

528+
### `mixin.util.initialization`
529+
(default: `true`)
530+
Platform dependent initialization hooks.
531+
526532
### `mixin.util.inventory_change_listening`
527533
(default: `true`)
528534
Certain BlockEntity Inventories emit updates to their listeners when their stack list is changed or the inventory becomes invalid
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package net.caffeinemc.mods.lithium.neoforge.mixin.util.initialization;
2+
3+
import net.caffeinemc.mods.lithium.common.initialization.BlockInfoInitializer;
4+
import net.minecraft.core.RegistryAccess;
5+
import net.minecraft.world.flag.FeatureFlagSet;
6+
import net.minecraft.world.level.block.entity.FuelValues;
7+
import net.neoforged.neoforge.common.DataMapHooks;
8+
import org.spongepowered.asm.mixin.Mixin;
9+
import org.spongepowered.asm.mixin.injection.At;
10+
import org.spongepowered.asm.mixin.injection.Inject;
11+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
12+
13+
/**
14+
* Hook into the initialization of fuel values, because those are always updated after block tags are modified,
15+
* and we must among others, update our cache path node information which is also based on block tags.
16+
*/
17+
@Mixin(DataMapHooks.class)
18+
public class DataMapHooksMixin {
19+
20+
@Inject(
21+
method = "populateFuelValues",
22+
at = @At(value = "RETURN")
23+
)
24+
private static void initializeCachedBlockData(RegistryAccess lookupProvider, FeatureFlagSet features, CallbackInfoReturnable<FuelValues> cir) {
25+
BlockInfoInitializer.initializeBlockInfo();
26+
}
27+
}

neoforge/src/main/resources/lithium-neoforge.mixins.json

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"mixins" : [
1313
"block.hopper.HopperBlockEntityMixin",
1414
"block.hopper.LevelMixin",
15+
"util.initialization.DataMapHooksMixin",
1516
"util.inventory_change_listening.ChestBlockEntityMixin"
1617
],
1718
"client" : [

0 commit comments

Comments
 (0)