Search in sources :

Example 1 with CakeBlock

use of net.minecraft.block.CakeBlock in project Arclight by IzzelAliz.

the class PlayerInteractionManagerMixin_1_15 method func_219441_a.

/**
 * @author IzzelAliz
 * @reason
 */
@Overwrite
public ActionResultType func_219441_a(PlayerEntity playerIn, World worldIn, ItemStack stackIn, Hand handIn, BlockRayTraceResult blockRaytraceResultIn) {
    BlockPos blockpos = blockRaytraceResultIn.getPos();
    BlockState blockstate = worldIn.getBlockState(blockpos);
    ActionResultType resultType = ActionResultType.PASS;
    boolean cancelledBlock = false;
    if (this.gameType == GameType.SPECTATOR) {
        INamedContainerProvider provider = blockstate.getContainer(worldIn, blockpos);
        cancelledBlock = !(provider instanceof INamedContainerProvider);
    }
    if (playerIn.getCooldownTracker().hasCooldown(stackIn.getItem())) {
        cancelledBlock = true;
    }
    PlayerInteractEvent bukkitEvent = CraftEventFactory.callPlayerInteractEvent(playerIn, Action.RIGHT_CLICK_BLOCK, blockpos, blockRaytraceResultIn.getFace(), stackIn, cancelledBlock, handIn);
    bridge$setFiredInteract(true);
    bridge$setInteractResult(bukkitEvent.useItemInHand() == Event.Result.DENY);
    if (bukkitEvent.useInteractedBlock() == Event.Result.DENY) {
        if (blockstate.getBlock() instanceof DoorBlock) {
            boolean bottom = blockstate.get(DoorBlock.HALF) == DoubleBlockHalf.LOWER;
            ((ServerPlayerEntity) playerIn).connection.sendPacket(new SChangeBlockPacket(this.world, bottom ? blockpos.up() : blockpos.down()));
        } else if (blockstate.getBlock() instanceof CakeBlock) {
            ((ServerPlayerEntityBridge) playerIn).bridge$getBukkitEntity().sendHealthUpdate();
        }
        ((ServerPlayerEntityBridge) playerIn).bridge$getBukkitEntity().updateInventory();
        resultType = ((bukkitEvent.useItemInHand() != Event.Result.ALLOW) ? ActionResultType.SUCCESS : ActionResultType.PASS);
    } else if (this.gameType == GameType.SPECTATOR) {
        INamedContainerProvider inamedcontainerprovider = blockstate.getContainer(worldIn, blockpos);
        if (inamedcontainerprovider != null) {
            playerIn.openContainer(inamedcontainerprovider);
            return ActionResultType.SUCCESS;
        } else {
            return ActionResultType.PASS;
        }
    } else {
        net.minecraftforge.event.entity.player.PlayerInteractEvent.RightClickBlock event = ForgeHooks.onRightClickBlock(playerIn, handIn, blockpos, blockRaytraceResultIn.getFace());
        if (event.isCanceled())
            return event.getCancellationResult();
        ItemUseContext itemusecontext = new ItemUseContext(playerIn, handIn, blockRaytraceResultIn);
        if (event.getUseItem() != net.minecraftforge.eventbus.api.Event.Result.DENY) {
            ActionResultType result = stackIn.onItemUseFirst(itemusecontext);
            if (result != ActionResultType.PASS)
                return result;
        }
        boolean flag = !playerIn.getHeldItemMainhand().isEmpty() || !playerIn.getHeldItemOffhand().isEmpty();
        boolean flag1 = (playerIn.isSecondaryUseActive() && flag) && !(playerIn.getHeldItemMainhand().doesSneakBypassUse(worldIn, blockpos, playerIn) && playerIn.getHeldItemOffhand().doesSneakBypassUse(worldIn, blockpos, playerIn));
        if (event.getUseBlock() != net.minecraftforge.eventbus.api.Event.Result.DENY && !flag1) {
            resultType = blockstate.onBlockActivated(worldIn, playerIn, handIn, blockRaytraceResultIn);
            if (resultType.isSuccessOrConsume()) {
                return resultType;
            }
        }
        if (!stackIn.isEmpty() && resultType != ActionResultType.SUCCESS && !bridge$getInteractResult()) {
            if (event.getUseItem() == net.minecraftforge.eventbus.api.Event.Result.DENY) {
                return ActionResultType.PASS;
            }
            if (this.isCreative()) {
                int i = stackIn.getCount();
                resultType = stackIn.onItemUse(itemusecontext);
                stackIn.setCount(i);
                return resultType;
            } else {
                return stackIn.onItemUse(itemusecontext);
            }
        } else {
            return resultType;
        }
    }
    return resultType;
}
Also used : ItemUseContext(net.minecraft.item.ItemUseContext) ActionResultType(net.minecraft.util.ActionResultType) SChangeBlockPacket(net.minecraft.network.play.server.SChangeBlockPacket) PlayerInteractEvent(org.bukkit.event.player.PlayerInteractEvent) INamedContainerProvider(net.minecraft.inventory.container.INamedContainerProvider) ServerPlayerEntityBridge(io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge) CakeBlock(net.minecraft.block.CakeBlock) BlockState(net.minecraft.block.BlockState) BlockPos(net.minecraft.util.math.BlockPos) DoorBlock(net.minecraft.block.DoorBlock) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Example 2 with CakeBlock

use of net.minecraft.block.CakeBlock in project Arclight by IzzelAliz.

the class PlayerInteractionManagerMixin_1_14 method func_219441_a.

/**
 * @author IzzelAliz
 * @reason
 */
@Overwrite
public ActionResultType func_219441_a(PlayerEntity playerIn, World worldIn, ItemStack stackIn, Hand handIn, BlockRayTraceResult blockRaytraceResultIn) {
    BlockPos blockpos = blockRaytraceResultIn.getPos();
    BlockState blockstate = worldIn.getBlockState(blockpos);
    ActionResultType resultType = ActionResultType.PASS;
    boolean cancelledBlock = false;
    if (this.gameType == GameType.SPECTATOR) {
        INamedContainerProvider provider = blockstate.getContainer(worldIn, blockpos);
        cancelledBlock = !(provider instanceof INamedContainerProvider);
    }
    if (playerIn.getCooldownTracker().hasCooldown(stackIn.getItem())) {
        cancelledBlock = true;
    }
    PlayerInteractEvent bukkitEvent = CraftEventFactory.callPlayerInteractEvent(playerIn, Action.RIGHT_CLICK_BLOCK, blockpos, blockRaytraceResultIn.getFace(), stackIn, cancelledBlock, handIn);
    bridge$setFiredInteract(true);
    bridge$setInteractResult(bukkitEvent.useItemInHand() == Event.Result.DENY);
    if (bukkitEvent.useInteractedBlock() == Event.Result.DENY) {
        if (blockstate.getBlock() instanceof DoorBlock) {
            boolean bottom = blockstate.get(DoorBlock.HALF) == DoubleBlockHalf.LOWER;
            ((ServerPlayerEntity) playerIn).connection.sendPacket(new SChangeBlockPacket(this.world, bottom ? blockpos.up() : blockpos.down()));
        } else if (blockstate.getBlock() instanceof CakeBlock) {
            ((ServerPlayerEntityBridge) playerIn).bridge$getBukkitEntity().sendHealthUpdate();
        }
        ((ServerPlayerEntityBridge) playerIn).bridge$getBukkitEntity().updateInventory();
        resultType = ((bukkitEvent.useItemInHand() != Event.Result.ALLOW) ? ActionResultType.SUCCESS : ActionResultType.PASS);
    } else if (this.gameType == GameType.SPECTATOR) {
        INamedContainerProvider inamedcontainerprovider = blockstate.getContainer(worldIn, blockpos);
        if (inamedcontainerprovider != null) {
            playerIn.openContainer(inamedcontainerprovider);
            return ActionResultType.SUCCESS;
        } else {
            return ActionResultType.PASS;
        }
    } else {
        net.minecraftforge.event.entity.player.PlayerInteractEvent.RightClickBlock event = ForgeHooks.onRightClickBlock(playerIn, handIn, blockpos, blockRaytraceResultIn.getFace());
        if (event.isCanceled())
            return event.getCancellationResult();
        ItemUseContext itemusecontext = new ItemUseContext(playerIn, handIn, blockRaytraceResultIn);
        if (event.getUseItem() != net.minecraftforge.eventbus.api.Event.Result.DENY) {
            ActionResultType result = stackIn.onItemUseFirst(itemusecontext);
            if (result != ActionResultType.PASS)
                return result;
        }
        boolean flag = !playerIn.getHeldItemMainhand().isEmpty() || !playerIn.getHeldItemOffhand().isEmpty();
        boolean flag1 = !(playerIn.isSneaking() && flag) || (playerIn.getHeldItemMainhand().doesSneakBypassUse(worldIn, blockpos, playerIn) && playerIn.getHeldItemOffhand().doesSneakBypassUse(worldIn, blockpos, playerIn));
        boolean flag2 = blockstate.onBlockActivated(worldIn, playerIn, handIn, blockRaytraceResultIn);
        if (event.getUseBlock() != net.minecraftforge.eventbus.api.Event.Result.DENY && flag1 && flag2) {
            return ActionResultType.SUCCESS;
        } else {
            if (flag1) {
                resultType = flag2 ? ActionResultType.SUCCESS : ActionResultType.FAIL;
            }
            if (!stackIn.isEmpty() && resultType != ActionResultType.SUCCESS && !bridge$getInteractResult()) {
                if (event.getUseItem() == net.minecraftforge.eventbus.api.Event.Result.DENY) {
                    return ActionResultType.PASS;
                }
                if (this.isCreative()) {
                    int i = stackIn.getCount();
                    resultType = stackIn.onItemUse(itemusecontext);
                    stackIn.setCount(i);
                    return resultType;
                } else {
                    return stackIn.onItemUse(itemusecontext);
                }
            } else {
                return resultType;
            }
        }
    }
    return resultType;
}
Also used : ItemUseContext(net.minecraft.item.ItemUseContext) ActionResultType(net.minecraft.util.ActionResultType) SChangeBlockPacket(net.minecraft.network.play.server.SChangeBlockPacket) PlayerInteractEvent(org.bukkit.event.player.PlayerInteractEvent) INamedContainerProvider(net.minecraft.inventory.container.INamedContainerProvider) ServerPlayerEntityBridge(io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge) CakeBlock(net.minecraft.block.CakeBlock) BlockState(net.minecraft.block.BlockState) BlockPos(net.minecraft.util.math.BlockPos) DoorBlock(net.minecraft.block.DoorBlock) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Aggregations

ServerPlayerEntityBridge (io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge)2 BlockState (net.minecraft.block.BlockState)2 CakeBlock (net.minecraft.block.CakeBlock)2 DoorBlock (net.minecraft.block.DoorBlock)2 INamedContainerProvider (net.minecraft.inventory.container.INamedContainerProvider)2 ItemUseContext (net.minecraft.item.ItemUseContext)2 SChangeBlockPacket (net.minecraft.network.play.server.SChangeBlockPacket)2 ActionResultType (net.minecraft.util.ActionResultType)2 BlockPos (net.minecraft.util.math.BlockPos)2 PlayerInteractEvent (org.bukkit.event.player.PlayerInteractEvent)2 Overwrite (org.spongepowered.asm.mixin.Overwrite)2