Skip to content

Commit

Permalink
Fix Injection issue in block_entity_ticking.support_cache
Browse files Browse the repository at this point in the history
  • Loading branch information
2No2Name committed Jun 23, 2024
1 parent dcd47fb commit fa16438
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 12 deletions.
2 changes: 1 addition & 1 deletion lithium-mixin-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ Optimizations that technically deviate from vanilla behavior, but must not affec
Speed up finding empty spaces mobs fit into. This speeds up entity pose checks and nether portal positioning for colliding mobs (This code is vanilla's nether portal horse suffocation fix). If certain block collision surfaces have coordinates that are different but within 1e-7 of each other, this optimization may cause entities coming from nether portals or changing pose to be placed in a different position or pose than vanilla. This effect only occurs when the decision whether the entity fits into a space depends on a difference in the magnitude of 1e-7 blocks.

### `mixin.minimal_nonvanilla.world.block_entity_ticking.support_cache`
(default: `false`)
(default: `true`)
BlockEntity ticking caches whether the BlockEntity can exist in the BlockState at the same location. This deviates from vanilla in the case of placing a hopper in a powered location, immediately updating the cached BlockState (which is incorrect in vanilla). This most likely does not affect your gameplay, as this deviation only affects hoppers, and in vanilla, hoppers never use the cached state information anyway.
Requirements:
- `mixin.world.block_entity_ticking=true`
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
package me.jellysquid.mods.lithium.mixin.minimal_nonvanilla.world.block_entity_ticking.support_cache;

import net.minecraft.block.Block;
import com.llamalad7.mixinextras.sugar.Local;
import net.minecraft.block.BlockEntityProvider;
import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.chunk.ChunkSection;
import net.minecraft.world.chunk.WorldChunk;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;

/**
* Fix {@link net.minecraft.block.AbstractBlock.AbstractBlockState#onBlockAdded(World, BlockPos, BlockState, boolean)}
Expand Down Expand Up @@ -46,14 +44,13 @@ private BlockEntity createBlockEntityWithCachedStateFix(BlockEntityProvider bloc
value = "INVOKE",
target = "Lnet/minecraft/block/entity/BlockEntity;setCachedState(Lnet/minecraft/block/BlockState;)V",
shift = At.Shift.AFTER
),
locals = LocalCapture.CAPTURE_FAILHARD
)
)
private void fixCachedState(BlockPos pos, BlockState state, boolean moved, CallbackInfoReturnable<BlockState> cir, int i, ChunkSection chunkSection, boolean bl, int j, int k, int l, BlockState blockState, Block block, BlockEntity blockEntity) {
BlockState blockState1 = this.getBlockState(pos);
if (blockState1 != state) {
private void fixCachedState(BlockPos pos, BlockState state, boolean moved, CallbackInfoReturnable<BlockState> cir, @Local BlockEntity blockEntity) {
BlockState updatedBlockState = this.getBlockState(pos);
if (updatedBlockState != state) {
//noinspection deprecation
blockEntity.setCachedState(blockState1);
blockEntity.setCachedState(updatedBlockState);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
" This deviates from vanilla in the case of placing a hopper in a powered location, immediately updating the" +
" cached BlockState (which is incorrect in vanilla). This most likely does not affect your gameplay, as this" +
" deviation only affects hoppers, and in vanilla, hoppers never use the cached state information anyway.",
depends = @MixinConfigDependency(dependencyPath = "mixin.world.block_entity_ticking"),
enabled = false //Lots of mod incompatibilities, TODO: analysis -> change the mixins or suggest changes to carpet & world edit
depends = @MixinConfigDependency(dependencyPath = "mixin.world.block_entity_ticking")
)
package me.jellysquid.mods.lithium.mixin.minimal_nonvanilla.world.block_entity_ticking.support_cache;

Expand Down

0 comments on commit fa16438

Please sign in to comment.