Search in sources :

Example 1 with IUpgradeable

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

the class GuiBase method drawGuiContainerBackgroundLayer.

@Override
protected void drawGuiContainerBackgroundLayer(float p_146976_1_, int mouseX, int mouseY) {
    GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
    builder.drawDefaultBackground(this, guiLeft, guiTop, xSize, ySize);
    if (drawPlayerSlots()) {
        builder.drawPlayerSlots(this, guiLeft + xSize / 2, guiTop + 93, true);
    }
    if (tryAddUpgrades() && tile instanceof IUpgradeable) {
        IUpgradeable upgradeable = (IUpgradeable) tile;
        if (upgradeable.canBeUpgraded()) {
            builder.drawUpgrades(this, upgradeable, guiLeft, guiTop);
            upgrades = true;
        }
    }
    builder.drawSlotTab(this, guiLeft, guiTop, mouseX, mouseY, upgrades);
}
Also used : IUpgradeable(reborncore.api.tile.IUpgradeable)

Example 2 with IUpgradeable

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

the class PacketSyncSideConfig method processData.

@Override
public void processData(PacketSyncSideConfig message, MessageContext context) {
    TileEntity tileEntity = context.getServerHandler().player.world.getTileEntity(message.pos);
    if (tileEntity instanceof IUpgradeable) {
        ItemStack stack = ((IUpgradeable) tileEntity).getUpgradeInvetory().getStackInSlot(message.slotID);
        ItemNBTHelper.setInt(stack, "side", message.side);
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IUpgradeable(reborncore.api.tile.IUpgradeable) ItemStack(net.minecraft.item.ItemStack)

Example 3 with IUpgradeable

use of reborncore.api.tile.IUpgradeable 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 4 with IUpgradeable

use of reborncore.api.tile.IUpgradeable in project RebornCore by TechReborn.

the class BlockMachineBase method dropInventory.

protected void dropInventory(World world, BlockPos pos) {
    TileEntity tileEntity = world.getTileEntity(pos);
    if (tileEntity == null) {
        return;
    }
    if (!(tileEntity instanceof IInventory)) {
        return;
    }
    IInventory inventory = (IInventory) tileEntity;
    List<ItemStack> items = new ArrayList<ItemStack>();
    addItemsToList(inventory, items);
    if (tileEntity instanceof IUpgradeable) {
        addItemsToList(((IUpgradeable) tileEntity).getUpgradeInvetory(), items);
    }
    WorldUtils.dropItems(items, world, pos);
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IInventory(net.minecraft.inventory.IInventory) ArrayList(java.util.ArrayList) IUpgradeable(reborncore.api.tile.IUpgradeable) ItemStack(net.minecraft.item.ItemStack)

Example 5 with IUpgradeable

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

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