Search in sources :

Example 1 with IToolDrop

use of reborncore.api.IToolDrop in project RebornCore by TechReborn.

the class BlockMachineBase method onBlockActivated.

/* 
	 *  Right-click should open GUI for all non-wrench items
	 *  Shift-Right-click should apply special action, like fill\drain bucket, install upgrade, etc.
	 */
@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
    if (fillBlockWithFluid(worldIn, pos, playerIn)) {
        return true;
    }
    ItemStack stack = playerIn.getHeldItem(EnumHand.MAIN_HAND);
    TileEntity tileEntity = worldIn.getTileEntity(pos);
    // We extended BlockTileBase. Thus we should always have tile entity. I hope.
    if (tileEntity == null) {
        return false;
    }
    if (!stack.isEmpty()) {
        if (ToolManager.INSTANCE.canHandleTool(stack)) {
            if (ToolManager.INSTANCE.handleTool(stack, pos, worldIn, playerIn, side, false)) {
                if (playerIn.isSneaking()) {
                    if (tileEntity instanceof IToolDrop) {
                        ItemStack drop = ((IToolDrop) tileEntity).getToolDrop(playerIn);
                        if (drop == null) {
                            return false;
                        }
                        if (!drop.isEmpty()) {
                            spawnAsEntity(worldIn, pos, drop);
                        }
                        if (!worldIn.isRemote) {
                            worldIn.setBlockState(pos, Blocks.AIR.getDefaultState(), 2);
                        }
                        return true;
                    }
                } else {
                    rotateBlock(worldIn, pos, side);
                    return true;
                }
            }
        } else if (stack.getItem() instanceof IUpgrade && tileEntity instanceof IUpgradeable) {
            IUpgradeable upgradeableEntity = (IUpgradeable) tileEntity;
            if (upgradeableEntity.canBeUpgraded()) {
                if (InventoryHelper.testInventoryInsertion(upgradeableEntity.getUpgradeInvetory(), stack, null) > 0) {
                    InventoryHelper.insertItemIntoInventory(upgradeableEntity.getUpgradeInvetory(), stack);
                    playerIn.setHeldItem(EnumHand.MAIN_HAND, stack);
                    return true;
                }
            }
        }
    }
    if (getGui() != null && !playerIn.isSneaking()) {
        getGui().open(playerIn, pos, worldIn);
        return true;
    }
    return super.onBlockActivated(worldIn, pos, state, playerIn, hand, side, hitX, hitY, hitZ);
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IUpgrade(reborncore.api.tile.IUpgrade) IToolDrop(reborncore.api.IToolDrop) IUpgradeable(reborncore.api.tile.IUpgradeable) ItemStack(net.minecraft.item.ItemStack)

Example 2 with IToolDrop

use of reborncore.api.IToolDrop in project TechReborn by TechReborn.

the class BlockPlayerDetector method onBlockActivated.

@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
    ItemStack stack = playerIn.getHeldItem(EnumHand.MAIN_HAND);
    TileEntity tileEntity = worldIn.getTileEntity(pos);
    if (tileEntity == null) {
        return super.onBlockActivated(worldIn, pos, state, playerIn, hand, side, hitX, hitY, hitZ);
    }
    String type = state.getValue(TYPE);
    String newType = type;
    TextFormatting color = TextFormatting.GREEN;
    if (!stack.isEmpty() && ToolManager.INSTANCE.canHandleTool(stack)) {
        if (ToolManager.INSTANCE.handleTool(stack, pos, worldIn, playerIn, side, false)) {
            if (playerIn.isSneaking()) {
                if (tileEntity instanceof IToolDrop) {
                    ItemStack drop = ((IToolDrop) tileEntity).getToolDrop(playerIn);
                    if (drop == null) {
                        return false;
                    }
                    if (!drop.isEmpty()) {
                        spawnAsEntity(worldIn, pos, drop);
                    }
                    if (!worldIn.isRemote) {
                        worldIn.setBlockState(pos, Blocks.AIR.getDefaultState(), 2);
                    }
                    return true;
                }
            } else {
                if (type.equals("all")) {
                    newType = "others";
                    color = TextFormatting.RED;
                } else if (type.equals("others")) {
                    newType = "you";
                    color = TextFormatting.BLUE;
                } else if (type.equals("you")) {
                    newType = "all";
                }
                worldIn.setBlockState(pos, state.withProperty(TYPE, newType));
            }
        }
    }
    if (worldIn.isRemote) {
        ChatUtils.sendNoSpamMessages(MessageIDs.playerDetectorID, new TextComponentString(TextFormatting.GRAY + I18n.format("techreborn.message.detects") + " " + color + StringUtils.toFirstCapital(newType)));
    }
    return true;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IToolDrop(reborncore.api.IToolDrop) TextFormatting(net.minecraft.util.text.TextFormatting) TextComponentString(net.minecraft.util.text.TextComponentString) PropertyString(reborncore.common.blocks.PropertyString) ItemStack(net.minecraft.item.ItemStack) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 3 with IToolDrop

use of reborncore.api.IToolDrop in project TechReborn by TechReborn.

the class BlockEnergyStorage 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 heldStack = player.getHeldItem(hand);
    if (ToolManager.INSTANCE.canHandleTool(heldStack)) {
        if (ToolManager.INSTANCE.handleTool(heldStack, pos, world, player, side, true)) {
            if (player.isSneaking()) {
                TileEntity tileEntity = world.getTileEntity(pos);
                if (tileEntity instanceof IToolDrop) {
                    ItemStack drop = ((IToolDrop) tileEntity).getToolDrop(player);
                    if (drop == null) {
                        return false;
                    }
                    if (!drop.isEmpty()) {
                        spawnAsEntity(world, pos, drop);
                    }
                    world.playSound(null, player.posX, player.posY, player.posZ, ModSounds.BLOCK_DISMANTLE, SoundCategory.BLOCKS, 0.6F, 1F);
                    if (!world.isRemote) {
                        world.setBlockState(pos, Blocks.AIR.getDefaultState(), 2);
                    }
                    return true;
                }
            } else {
                EnumFacing facing2 = state.getValue(BlockEnergyStorage.FACING);
                if (facing2.getOpposite() == side) {
                    facing2 = side;
                } else {
                    facing2 = side.getOpposite();
                }
                world.setBlockState(pos, state.withProperty(BlockEnergyStorage.FACING, facing2));
                return true;
            }
        }
    } else if (!player.isSneaking()) {
        player.openGui(Core.INSTANCE, guiID, world, pos.getX(), pos.getY(), pos.getZ());
        return true;
    }
    return super.onBlockActivated(world, pos, state, player, hand, side, hitX, hitY, hitZ);
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IToolDrop(reborncore.api.IToolDrop) EnumFacing(net.minecraft.util.EnumFacing) ItemStack(net.minecraft.item.ItemStack)

Example 4 with IToolDrop

use of reborncore.api.IToolDrop in project TechReborn by TechReborn.

the class BlockTransformer 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 stack = player.getHeldItem(EnumHand.MAIN_HAND);
    if (!stack.isEmpty() && ToolManager.INSTANCE.canHandleTool(stack) && !world.isRemote) {
        if (ToolManager.INSTANCE.handleTool(stack, pos, world, player, side, true) && state.getBlock() instanceof BlockTransformer) {
            if (player.isSneaking()) {
                TileEntity tileEntity = world.getTileEntity(pos);
                if (tileEntity instanceof IToolDrop) {
                    ItemStack drop = ((IToolDrop) tileEntity).getToolDrop(player);
                    if (drop == null) {
                        return false;
                    }
                    if (!drop.isEmpty()) {
                        spawnAsEntity(world, pos, drop);
                    }
                    world.playSound(null, player.posX, player.posY, player.posZ, ModSounds.BLOCK_DISMANTLE, SoundCategory.BLOCKS, 0.6F, 1F);
                    if (!world.isRemote) {
                        world.setBlockState(pos, Blocks.AIR.getDefaultState(), 2);
                    }
                    return true;
                }
            } else {
                EnumFacing facing2 = state.getValue(BlockTransformer.FACING);
                if (facing2.getOpposite() == side) {
                    facing2 = side;
                } else {
                    facing2 = side.getOpposite();
                }
                world.setBlockState(pos, state.withProperty(BlockTransformer.FACING, facing2));
                return true;
            }
        }
    }
    return super.onBlockActivated(world, pos, state, player, hand, side, hitX, hitY, hitZ);
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IToolDrop(reborncore.api.IToolDrop) EnumFacing(net.minecraft.util.EnumFacing) ItemStack(net.minecraft.item.ItemStack)

Aggregations

ItemStack (net.minecraft.item.ItemStack)4 TileEntity (net.minecraft.tileentity.TileEntity)4 IToolDrop (reborncore.api.IToolDrop)4 EnumFacing (net.minecraft.util.EnumFacing)2 TextComponentString (net.minecraft.util.text.TextComponentString)1 TextFormatting (net.minecraft.util.text.TextFormatting)1 IUpgrade (reborncore.api.tile.IUpgrade)1 IUpgradeable (reborncore.api.tile.IUpgradeable)1 PropertyString (reborncore.common.blocks.PropertyString)1