Skip to content

Commit

Permalink
Check Beehive obstruction first on exit
Browse files Browse the repository at this point in the history
  • Loading branch information
2No2Name committed Mar 1, 2024
1 parent b8f2818 commit 3a32d72
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lithium-mixin-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@ NBT tags use a fastutil hashmap instead of a standard HashMap
(default: `true`)
Optimizations related to blocks

### `mixin.block.beehive`
(default: `true`)
Beehives check if they are obstructed before performing expensive nbt copy operations for each exit attempt.

### `mixin.block.flatten_states`
(default: `true`)
FluidStates store directly whether they are empty
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package me.jellysquid.mods.lithium.mixin.block.beehive;

import net.minecraft.block.BeehiveBlock;
import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BeehiveBlockEntity;
import net.minecraft.entity.Entity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.world.World;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Coerce;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import java.util.List;

@Mixin(BeehiveBlockEntity.class)
public class BeehiveBlockEntityMixin {

@Inject(
method = "releaseBee",
at = @At(value = "INVOKE", shift = At.Shift.BEFORE, target = "Lnet/minecraft/nbt/NbtCompound;copy()Lnet/minecraft/nbt/NbtCompound;"),
cancellable = true
)
private static void exitEarlyIfHiveObstructed(World world, BlockPos pos, BlockState state, @Coerce Object bee, @Nullable List<Entity> entities, BeehiveBlockEntity.BeeState beeState, @Nullable BlockPos flowerPos, CallbackInfoReturnable<Boolean> cir) {
Direction direction = state.get(BeehiveBlock.FACING);
BlockPos blockPos = pos.offset(direction);

if (beeState != BeehiveBlockEntity.BeeState.EMERGENCY && !world.getBlockState(blockPos).getCollisionShape(world, blockPos).isEmpty()) {
cir.setReturnValue(false);
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@MixinConfigOption(description = "Beehives check if they are obstructed before performing expensive nbt copy operations for each exit attempt.")
package me.jellysquid.mods.lithium.mixin.block.beehive;

import net.caffeinemc.gradle.MixinConfigOption;
1 change: 1 addition & 0 deletions src/main/resources/lithium.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"alloc.explosion_behavior.EntityExplosionBehaviorMixin",
"alloc.nbt.NbtCompoundMixin",
"alloc.nbt.NbtCompoundMixin$Type",
"block.beehive.BeehiveBlockEntityMixin",
"block.flatten_states.FluidStateMixin",
"block.hopper.AbstractMinecartEntityMixin",
"block.hopper.ChestBoatEntityMixin",
Expand Down

0 comments on commit 3a32d72

Please sign in to comment.