Skip to content

Commit

Permalink
Handle BlockTag changes for pathnode and block predicates
Browse files Browse the repository at this point in the history
Re-enable util.block_tracking and ai.pathing packages as they should work correctly now.
  • Loading branch information
2No2Name committed Dec 26, 2024
1 parent e4c2eac commit 337562b
Show file tree
Hide file tree
Showing 10 changed files with 81 additions and 62 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package net.caffeinemc.mods.lithium.mixin.ai.pathing;

import net.caffeinemc.mods.lithium.common.ai.pathing.BlockStatePathingCache;
import net.minecraft.core.HolderLookup;
import net.minecraft.world.flag.FeatureFlagSet;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.entity.FuelValues;
import net.minecraft.world.level.block.state.BlockState;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

/**
* Hook into the initialization of fuel values, because those are always updated after block tags are modified,
* and we must update our cache path node information which is also based on block tags.
*/
@Mixin(FuelValues.class)
public class FuelValuesMixin {

@Inject(
method = "vanillaBurnTimes(Lnet/minecraft/core/HolderLookup$Provider;Lnet/minecraft/world/flag/FeatureFlagSet;I)Lnet/minecraft/world/level/block/entity/FuelValues;",
at = @At(value = "RETURN")
)
private static void initializeCachedBlockData(HolderLookup.Provider provider, FeatureFlagSet featureFlagSet, int i, CallbackInfoReturnable<FuelValues> cir) {
// Initialize / Reinitialize the cached path node types.
// This is called before burn times are set in the minecraft server, but we don't care about the updated burn times
for (BlockState blockState : Block.BLOCK_STATE_REGISTRY) {
((BlockStatePathingCache) blockState).lithium$initializePathNodeTypeCache();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@
description = """
A faster code path is used for determining what kind of path-finding node type is associated with a
given block. Additionally, a faster chunk cache will be used for accessing blocks while evaluating
paths.
""",
paths.""",
depends = @MixinConfigDependency(
dependencyPath = "mixin.util.chunk_access"
),
enabled = false // TODO handle data pack tag changes etc. Just injecting into Bootstrap is not enough.
)
)
package net.caffeinemc.mods.lithium.mixin.ai.pathing;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
public abstract class EntityMixin implements BlockCacheProvider {
@Inject(
method = "checkInsideBlocks(Ljava/util/List;Ljava/util/Set;)V",
at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/Entity;getBoundingBox()Lnet/minecraft/world/phys/AABB;"), cancellable = true
at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/Entity;makeBoundingBox(Lnet/minecraft/world/phys/Vec3;)Lnet/minecraft/world/phys/AABB;"), cancellable = true
)
private void cancelIfSkippable(List<?> movementList, Set<BlockState> stateCollector, CallbackInfo ci) {
private void cancelIfSkippable(List<?> movementList, Set<BlockState> touchedBlocks, CallbackInfo ci) {
if (movementList.size() != 1) {
return; // If there are multiple movements, blocks far away, outside the cached range are queried.
// Not sure whether this special case is really needed, but it's here to be safe.
Expand All @@ -36,6 +36,12 @@ private void cancelIfSkippable(List<?> movementList, Set<BlockState> stateCollec
BlockCache bc = this.getUpdatedBlockCache((Entity) (Object) this);
if (bc.canSkipBlockTouching()) {
ci.cancel();
//TODO This could lead to mod compat issues with other mods, if they implement something similar to
// vanilla's FIRE / LAVA check. To work around this, other mods
// have to override the method where blocks interact with entities that touch it.
// Mojmap (1.21.4): entityInside . If mapping changed, look up how cactus damages entities, implement the same
// method on the modded block, even if it is empty.
// The method name is also defined at net.caffeinemc.mods.lithium.common.reflection.ReflectionUtil.REMAPPED_ON_ENTITY_COLLISION:
}
}
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package net.caffeinemc.mods.lithium.mixin.util.block_tracking;

import net.caffeinemc.mods.lithium.common.block.BlockStateFlagHolder;
import net.minecraft.core.HolderLookup;
import net.minecraft.world.flag.FeatureFlagSet;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.entity.FuelValues;
import net.minecraft.world.level.block.state.BlockState;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

/**
* Hook into the initialization of fuel values, because those are always updated after block tags are modified,
* and we must update our cache path node information which is also based on block tags.
*/
@Mixin(FuelValues.class)
public class FuelValuesMixin {

@Inject(
method = "vanillaBurnTimes(Lnet/minecraft/core/HolderLookup$Provider;Lnet/minecraft/world/flag/FeatureFlagSet;I)Lnet/minecraft/world/level/block/entity/FuelValues;",
at = @At(value = "RETURN")
)
private static void initializeCachedBlockData(HolderLookup.Provider provider, FeatureFlagSet featureFlagSet, int i, CallbackInfoReturnable<FuelValues> cir) {
// Initialize / Reinitialize the cached block flags.
// This is called before burn times are set in the minecraft server, but we don't care about the updated burn times
for (BlockState blockState : Block.BLOCK_STATE_REGISTRY) {
((BlockStateFlagHolder) blockState).lithium$initializeFlags();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
depends = {
@MixinConfigDependency(dependencyPath = "mixin.util.data_storage"),
@MixinConfigDependency(dependencyPath = "mixin.util.chunk_status_tracking")
},
enabled = false // TODO handle data pack tag changes etc. Just injecting into Bootstrap is not enough.
}
)
package net.caffeinemc.mods.lithium.mixin.util.block_tracking;

Expand Down
4 changes: 2 additions & 2 deletions common/src/main/resources/lithium.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
},
"mixins" : [
"ai.pathing.BlockStateBaseMixin",
"ai.pathing.BootstrapMixin",
"ai.pathing.FlyNodeEvaluatorMixin",
"ai.pathing.FuelValuesMixin",
"ai.pathing.PathfindingContextAccessor",
"ai.pathing.PathfindingContextMixin",
"ai.pathing.PathNavigationRegionMixin",
Expand Down Expand Up @@ -175,7 +175,7 @@
"util.accessors.ServerLevelAccessor",
"util.block_entity_retrieval.LevelMixin",
"util.block_tracking.BlockStateBaseMixin",
"util.block_tracking.BootstrapMixin",
"util.block_tracking.FuelValuesMixin",
"util.block_tracking.LevelChunkSectionMixin",
"util.chunk_access.LevelReaderMixin",
"util.chunk_access.PathNavigationRegionMixin",
Expand Down
7 changes: 3 additions & 4 deletions lithium-fabric-mixin-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,10 @@ mixin.gen.biome_noise_cache=false
Mob AI optimizations

### `mixin.ai.pathing`
(default: `false`)
(default: `true`)
A faster code path is used for determining what kind of path-finding node type is associated with a
given block. Additionally, a faster chunk cache will be used for accessing blocks while evaluating
paths.

paths.
Requirements:
- `mixin.util.chunk_access=true`

Expand Down Expand Up @@ -490,7 +489,7 @@ Allow accessing certain fields and functions that are normally inaccessible
Allows access to existing BlockEntities without creating new ones

### `mixin.util.block_tracking`
(default: `false`)
(default: `true`)
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.
Requirements:
- `mixin.util.data_storage=true`
Expand Down
3 changes: 1 addition & 2 deletions lithium-neoforge-mixin-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ Mob AI optimizations
(default: `true`)
A faster code path is used for determining what kind of path-finding node type is associated with a
given block. Additionally, a faster chunk cache will be used for accessing blocks while evaluating
paths.

paths.
Requirements:
- `mixin.util.chunk_access=true`

Expand Down

0 comments on commit 337562b

Please sign in to comment.