Search in sources :

Example 1 with IPlayerInteraction

use of blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IPlayerInteraction in project Immersive-Tech by FerroO2000.

the class BlockITTileProvider method onBlockActivated.

@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
    ItemStack heldItem = player.getHeldItem(hand);
    TileEntity tile = world.getTileEntity(pos);
    if (tile instanceof IConfigurableSides && Utils.isHammer(heldItem) && !world.isRemote) {
        int iSide = player.isSneaking() ? side.getOpposite().ordinal() : side.ordinal();
        if (((IConfigurableSides) tile).toggleSide(iSide, player))
            return true;
    }
    if (tile instanceof IDirectionalTile && Utils.isHammer(heldItem) && ((IDirectionalTile) tile).canHammerRotate(side, hitX, hitY, hitZ, player) && !world.isRemote) {
        EnumFacing f = ((IDirectionalTile) tile).getFacing();
        int limit = ((IDirectionalTile) tile).getFacingLimitation();
        if (limit == 0)
            f = EnumFacing.VALUES[(f.ordinal() + 1) % EnumFacing.VALUES.length];
        else if (limit == 1)
            f = player.isSneaking() ? f.rotateAround(side.getAxis()).getOpposite() : f.rotateAround(side.getAxis());
        else if (limit == 2 || limit == 5)
            f = player.isSneaking() ? f.rotateYCCW() : f.rotateY();
        ((IDirectionalTile) tile).setFacing(f);
        tile.markDirty();
        world.notifyBlockUpdate(pos, state, state, 3);
        world.addBlockEvent(tile.getPos(), tile.getBlockType(), 255, 0);
        return true;
    }
    if (tile instanceof IHammerInteraction && Utils.isHammer(heldItem) && !world.isRemote) {
        boolean b = ((IHammerInteraction) tile).hammerUseSide(side, player, hitX, hitY, hitZ);
        if (b)
            return b;
    }
    if (tile instanceof IPlayerInteraction) {
        boolean b = ((IPlayerInteraction) tile).interact(side, player, hand, heldItem, hitX, hitY, hitZ);
        if (b)
            return b;
    }
    if (tile instanceof IGuiTile && hand == EnumHand.MAIN_HAND && !player.isSneaking()) {
        TileEntity master = ((IGuiTile) tile).getGuiMaster();
        if (((IGuiTile) tile).canOpenGui(player)) {
            if (!world.isRemote && master != null)
                CommonProxy.openGuiForTile(player, (TileEntity & IGuiTile) master);
            return true;
        }
    }
    return false;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IHammerInteraction(blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IHammerInteraction) IGuiTile(blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IGuiTile) EnumFacing(net.minecraft.util.EnumFacing) IConfigurableSides(blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IConfigurableSides) IPlayerInteraction(blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IPlayerInteraction) ItemStack(net.minecraft.item.ItemStack) IDirectionalTile(blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IDirectionalTile)

Aggregations

IConfigurableSides (blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IConfigurableSides)1 IDirectionalTile (blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IDirectionalTile)1 IGuiTile (blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IGuiTile)1 IHammerInteraction (blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IHammerInteraction)1 IPlayerInteraction (blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IPlayerInteraction)1 ItemStack (net.minecraft.item.ItemStack)1 TileEntity (net.minecraft.tileentity.TileEntity)1 EnumFacing (net.minecraft.util.EnumFacing)1