Search in sources :

Example 1 with CraftBlockState

use of org.bukkit.craftbukkit.v.block.CraftBlockState in project Arclight by IzzelAliz.

the class SpongeBlockMixin method absorb.

/**
 * @author IzzelAliz
 * @reason
 */
@SuppressWarnings("unchecked")
@Overwrite
private boolean absorb(World worldIn, BlockPos pos) {
    Queue<Tuple<BlockPos, Integer>> queue = Lists.newLinkedList();
    queue.add(new Tuple<>(pos, 0));
    int i = 0;
    BlockStateListPopulator blockList = new BlockStateListPopulator(worldIn);
    while (!queue.isEmpty()) {
        Tuple<BlockPos, Integer> tuple = queue.poll();
        BlockPos blockpos = tuple.getA();
        int j = tuple.getB();
        for (Direction direction : Direction.values()) {
            BlockPos blockpos1 = blockpos.offset(direction);
            BlockState blockstate = blockList.getBlockState(blockpos1);
            IFluidState ifluidstate = blockList.getFluidState(blockpos1);
            Material material = blockstate.getMaterial();
            if (ifluidstate.isTagged(FluidTags.WATER)) {
                if (blockstate.getBlock() instanceof IBucketPickupHandler && ((IBucketPickupHandler) blockstate.getBlock()).pickupFluid(worldIn, blockpos1, blockstate) != Fluids.EMPTY) {
                    ++i;
                    if (j < 6) {
                        queue.add(new Tuple<>(blockpos1, j + 1));
                    }
                } else if (blockstate.getBlock() instanceof FlowingFluidBlock) {
                    worldIn.setBlockState(blockpos1, Blocks.AIR.getDefaultState(), 3);
                    ++i;
                    if (j < 6) {
                        queue.add(new Tuple<>(blockpos1, j + 1));
                    }
                } else if (material == Material.OCEAN_PLANT || material == Material.SEA_GRASS) {
                    // TileEntity tileentity = blockstate.getBlock().hasTileEntity() ? worldIn.getTileEntity(blockpos1) : null;
                    // Block.spawnDrops(blockstate, worldIn, blockpos1, tileentity);
                    blockList.setBlockState(blockpos1, Blocks.AIR.getDefaultState(), 3);
                    ++i;
                    if (j < 6) {
                        queue.add(new Tuple<>(blockpos1, j + 1));
                    }
                }
            }
        }
        if (i > 64) {
            break;
        }
    }
    // Is a clone
    List<CraftBlockState> blocks = blockList.getList();
    if (!blocks.isEmpty()) {
        final org.bukkit.block.Block bblock = CraftBlock.at(worldIn, pos);
        SpongeAbsorbEvent event = new SpongeAbsorbEvent(bblock, (List<org.bukkit.block.BlockState>) (List) blocks);
        Bukkit.getPluginManager().callEvent(event);
        if (event.isCancelled()) {
            return false;
        }
        for (CraftBlockState block : blocks) {
            BlockPos blockposition2 = block.getPosition();
            BlockState iblockdata = worldIn.getBlockState(blockposition2);
            IFluidState fluid = worldIn.getFluidState(blockposition2);
            Material material = iblockdata.getMaterial();
            if (fluid.isTagged(FluidTags.WATER)) {
                if (iblockdata.getBlock() instanceof IBucketPickupHandler && ((IBucketPickupHandler) iblockdata.getBlock()).pickupFluid(blockList, blockposition2, iblockdata) != Fluids.EMPTY) {
                // NOP
                } else if (iblockdata.getBlock() instanceof FlowingFluidBlock) {
                // NOP
                } else if (material == Material.OCEAN_PLANT || material == Material.SEA_GRASS) {
                    TileEntity tileentity = iblockdata.getBlock().hasTileEntity(iblockdata) ? worldIn.getTileEntity(blockposition2) : null;
                    Block.spawnDrops(iblockdata, worldIn, blockposition2, tileentity);
                }
            }
            worldIn.setBlockState(blockposition2, block.getHandle(), block.getFlag());
        }
    }
    return i > 0;
}
Also used : IBucketPickupHandler(net.minecraft.block.IBucketPickupHandler) FlowingFluidBlock(net.minecraft.block.FlowingFluidBlock) SpongeAbsorbEvent(org.bukkit.event.block.SpongeAbsorbEvent) BlockStateListPopulator(org.bukkit.craftbukkit.v.util.BlockStateListPopulator) Material(net.minecraft.block.material.Material) Direction(net.minecraft.util.Direction) TileEntity(net.minecraft.tileentity.TileEntity) CraftBlockState(org.bukkit.craftbukkit.v.block.CraftBlockState) CraftBlockState(org.bukkit.craftbukkit.v.block.CraftBlockState) BlockState(net.minecraft.block.BlockState) BlockPos(net.minecraft.util.math.BlockPos) List(java.util.List) Tuple(net.minecraft.util.Tuple) IFluidState(net.minecraft.fluid.IFluidState) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Example 2 with CraftBlockState

use of org.bukkit.craftbukkit.v.block.CraftBlockState in project Arclight by IzzelAliz.

the class FireBlockMixin method arclight$blockFade.

@Redirect(method = "updatePostPlacement", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/Block;getDefaultState()Lnet/minecraft/block/BlockState;"))
public BlockState arclight$blockFade(net.minecraft.block.Block block, BlockState stateIn, Direction facing, BlockState facingState, IWorld worldIn, BlockPos currentPos, BlockPos facingPos) {
    CraftBlockState blockState = CraftBlockState.getBlockState(worldIn, currentPos);
    blockState.setData(Blocks.AIR.getDefaultState());
    BlockFadeEvent event = new BlockFadeEvent(blockState.getBlock(), blockState);
    Bukkit.getPluginManager().callEvent(event);
    if (event.isCancelled()) {
        return this.getStateForPlacement(worldIn, currentPos).with(FireBlock.AGE, stateIn.get(FireBlock.AGE));
    } else {
        return blockState.getHandle();
    }
}
Also used : CraftBlockState(org.bukkit.craftbukkit.v.block.CraftBlockState) BlockFadeEvent(org.bukkit.event.block.BlockFadeEvent) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Example 3 with CraftBlockState

use of org.bukkit.craftbukkit.v.block.CraftBlockState in project Arclight by IzzelAliz.

the class ConcretePowderBlockMixin method arclight$blockForm.

@Redirect(method = "updatePostPlacement", at = @At(value = "FIELD", target = "Lnet/minecraft/block/ConcretePowderBlock;solidifiedState:Lnet/minecraft/block/BlockState;"))
public BlockState arclight$blockForm(@Coerce ConcretePowderBlockMixin block, BlockState stateIn, Direction facing, BlockState facingState, IWorld worldIn, BlockPos currentPos, BlockPos facingPos) {
    CraftBlockState blockState = CraftBlockState.getBlockState(worldIn, currentPos);
    blockState.setData(this.solidifiedState);
    BlockFormEvent event = new BlockFormEvent(blockState.getBlock(), blockState);
    Bukkit.getPluginManager().callEvent(event);
    if (!event.isCancelled()) {
        return blockState.getHandle();
    }
    return super.updatePostPlacement(stateIn, facing, facingState, worldIn, currentPos, facingPos);
}
Also used : CraftBlockState(org.bukkit.craftbukkit.v.block.CraftBlockState) BlockFormEvent(org.bukkit.event.block.BlockFormEvent) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Example 4 with CraftBlockState

use of org.bukkit.craftbukkit.v.block.CraftBlockState in project Arclight by IzzelAliz.

the class MaterialMixin method setupBlockStateFunc.

private void setupBlockStateFunc() {
    if (arclight$spec.blockStateClass != null) {
        try {
            Class<?> cl = Class.forName(arclight$spec.blockStateClass);
            if (!CraftBlockState.class.isAssignableFrom(cl)) {
                throw LocalizedException.checked("registry.block-state.not-subclass", cl, CraftBlockState.class);
            }
            for (Constructor<?> constructor : cl.getDeclaredConstructors()) {
                if (constructor.getParameterTypes().length == 1 && org.bukkit.block.Block.class.isAssignableFrom(constructor.getParameterTypes()[0])) {
                    constructor.setAccessible(true);
                    this.arclight$stateFunc = b -> {
                        try {
                            return (BlockState) constructor.newInstance(b);
                        } catch (Exception e) {
                            throw new RuntimeException(e);
                        }
                    };
                }
            }
        } catch (Exception e) {
            if (e instanceof LocalizedException) {
                ArclightMod.LOGGER.warn(((LocalizedException) e).node(), ((LocalizedException) e).args());
            } else {
                ArclightMod.LOGGER.warn("registry.block-state.error", this, arclight$spec.blockStateClass, e);
            }
        }
        if (this.arclight$stateFunc == null) {
            ArclightMod.LOGGER.warn("registry.block-state.no-candidate", this, arclight$spec.blockStateClass);
        }
    }
    if (this.arclight$stateFunc == null) {
        this.arclight$stateFunc = b -> {
            TileEntity tileEntity = b.getCraftWorld().getHandle().getTileEntity(b.getPosition());
            return tileEntity == null ? new CraftBlockState(b) : new CraftBlockEntityState<>(b, tileEntity.getClass());
        };
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) CraftBlockState(org.bukkit.craftbukkit.v.block.CraftBlockState) LocalizedException(io.izzel.arclight.i18n.LocalizedException) CraftBlockState(org.bukkit.craftbukkit.v.block.CraftBlockState) BlockState(org.bukkit.block.BlockState) CraftMetaBlockState(org.bukkit.craftbukkit.v.inventory.CraftMetaBlockState) Block(net.minecraft.block.Block) CraftBlock(org.bukkit.craftbukkit.v.block.CraftBlock) FallingBlock(net.minecraft.block.FallingBlock) LocalizedException(io.izzel.arclight.i18n.LocalizedException)

Example 5 with CraftBlockState

use of org.bukkit.craftbukkit.v.block.CraftBlockState in project Arclight by IzzelAliz.

the class ConcretePowderBlockMixin method arclight$blockForm.

@Redirect(method = "getStateForPlacement", at = @At(value = "FIELD", target = "Lnet/minecraft/block/ConcretePowderBlock;solidifiedState:Lnet/minecraft/block/BlockState;"))
public BlockState arclight$blockForm(@Coerce ConcretePowderBlockMixin block, BlockItemUseContext context) {
    World world = context.getWorld();
    BlockPos blockPos = context.getPos();
    CraftBlockState blockState = CraftBlockState.getBlockState(world, blockPos);
    blockState.setData(this.solidifiedState);
    BlockFormEvent event = new BlockFormEvent(blockState.getBlock(), blockState);
    Bukkit.getPluginManager().callEvent(event);
    if (!event.isCancelled()) {
        return blockState.getHandle();
    }
    return super.getStateForPlacement(context);
}
Also used : CraftBlockState(org.bukkit.craftbukkit.v.block.CraftBlockState) BlockFormEvent(org.bukkit.event.block.BlockFormEvent) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World) IWorld(net.minecraft.world.IWorld) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Aggregations

CraftBlockState (org.bukkit.craftbukkit.v.block.CraftBlockState)6 BlockPos (net.minecraft.util.math.BlockPos)3 Redirect (org.spongepowered.asm.mixin.injection.Redirect)3 TileEntity (net.minecraft.tileentity.TileEntity)2 BlockFormEvent (org.bukkit.event.block.BlockFormEvent)2 WorldBridge (io.izzel.arclight.common.bridge.world.WorldBridge)1 LocalizedException (io.izzel.arclight.i18n.LocalizedException)1 List (java.util.List)1 Block (net.minecraft.block.Block)1 BlockState (net.minecraft.block.BlockState)1 FallingBlock (net.minecraft.block.FallingBlock)1 FlowingFluidBlock (net.minecraft.block.FlowingFluidBlock)1 IBucketPickupHandler (net.minecraft.block.IBucketPickupHandler)1 Material (net.minecraft.block.material.Material)1 IFluidState (net.minecraft.fluid.IFluidState)1 Direction (net.minecraft.util.Direction)1 Tuple (net.minecraft.util.Tuple)1 IWorld (net.minecraft.world.IWorld)1 World (net.minecraft.world.World)1 BlockState (org.bukkit.block.BlockState)1