Search in sources :

Example 1 with TrackedBlockStatePredicate

use of me.jellysquid.mods.lithium.common.block.TrackedBlockStatePredicate in project lithium-fabric by CaffeineMC.

the class EntityMixin method tryShortcutFluidPushing.

@Inject(method = "updateMovementInFluid(Lnet/minecraft/tag/TagKey;D)Z", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;isPushedByFluids()Z", shift = At.Shift.BEFORE), cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD)
public void tryShortcutFluidPushing(TagKey<Fluid> tag, double speed, CallbackInfoReturnable<Boolean> cir, Box box, int x1, int x2, int y1, int y2, int z1, int z2, double zero) {
    TrackedBlockStatePredicate blockStateFlag;
    if (tag == FluidTags.WATER) {
        blockStateFlag = BlockStateFlags.WATER;
    } else if (tag == FluidTags.LAVA) {
        blockStateFlag = BlockStateFlags.LAVA;
    } else {
        return;
    }
    int chunkX1 = x1 >> 4;
    int chunkZ1 = z1 >> 4;
    int chunkX2 = ((x2 - 1) >> 4);
    int chunkZ2 = ((z2 - 1) >> 4);
    int chunkYIndex1 = Math.max(Pos.SectionYIndex.fromBlockCoord(this.world, y1), Pos.SectionYIndex.getMinYSectionIndex(this.world));
    int chunkYIndex2 = Math.min(Pos.SectionYIndex.fromBlockCoord(this.world, y2 - 1), Pos.SectionYIndex.getMaxYSectionIndexInclusive(this.world));
    for (int chunkX = chunkX1; chunkX <= chunkX2; chunkX++) {
        for (int chunkZ = chunkZ1; chunkZ <= chunkZ2; chunkZ++) {
            Chunk chunk = this.world.getChunk(chunkX, chunkZ);
            for (int chunkYIndex = chunkYIndex1; chunkYIndex <= chunkYIndex2; chunkYIndex++) {
                ChunkSection section = chunk.getSectionArray()[chunkYIndex];
                if (((BlockCountingSection) section).anyMatch(blockStateFlag)) {
                    // fluid found, cannot skip code
                    return;
                }
            }
        }
    }
    // side effects of not finding a fluid:
    this.fluidHeight.put(tag, 0.0);
    cir.setReturnValue(false);
}
Also used : TrackedBlockStatePredicate(me.jellysquid.mods.lithium.common.block.TrackedBlockStatePredicate) Chunk(net.minecraft.world.chunk.Chunk) ChunkSection(net.minecraft.world.chunk.ChunkSection) BlockCountingSection(me.jellysquid.mods.lithium.common.block.BlockCountingSection) Inject(org.spongepowered.asm.mixin.injection.Inject)

Aggregations

BlockCountingSection (me.jellysquid.mods.lithium.common.block.BlockCountingSection)1 TrackedBlockStatePredicate (me.jellysquid.mods.lithium.common.block.TrackedBlockStatePredicate)1 Chunk (net.minecraft.world.chunk.Chunk)1 ChunkSection (net.minecraft.world.chunk.ChunkSection)1 Inject (org.spongepowered.asm.mixin.injection.Inject)1