Search in sources :

Example 1 with IUpgrade

use of reborncore.api.tile.IUpgrade 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 IUpgrade

use of reborncore.api.tile.IUpgrade in project TechReborn by TechReborn.

the class UpgradeSlot method handleRightClick.

@Override
public boolean handleRightClick(int slotID, EntityPlayer player, BuiltContainer container) {
    if (inventory instanceof Inventory) {
        Inventory inv = (Inventory) inventory;
        TileEntity tileEntity = inv.getTileBase();
        if (tileEntity instanceof IUpgradeable) {
            IUpgradeable upgradeable = (IUpgradeable) tileEntity;
            if (upgradeable.canBeUpgraded()) {
                ItemStack stack = upgradeable.getUpgradeInvetory().getStackInSlot(slotID);
                if (!stack.isEmpty() && stack.getItem() instanceof IUpgrade) {
                    if (player.world.isRemote) {
                        ((IUpgrade) stack.getItem()).handleRightClick(tileEntity, stack, container, slotID);
                    }
                }
            }
        }
    }
    return true;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IUpgrade(reborncore.api.tile.IUpgrade) IUpgradeable(reborncore.api.tile.IUpgradeable) ItemStack(net.minecraft.item.ItemStack) IInventory(net.minecraft.inventory.IInventory) Inventory(reborncore.common.util.Inventory)

Aggregations

ItemStack (net.minecraft.item.ItemStack)2 TileEntity (net.minecraft.tileentity.TileEntity)2 IUpgrade (reborncore.api.tile.IUpgrade)2 IUpgradeable (reborncore.api.tile.IUpgradeable)2 IInventory (net.minecraft.inventory.IInventory)1 IToolDrop (reborncore.api.IToolDrop)1 Inventory (reborncore.common.util.Inventory)1