Search in sources :

Example 1 with ItemGaugeDropper

use of mekanism.common.item.ItemGaugeDropper in project Mekanism by mekanism.

the class GuiTankGauge method mouseClicked.

@Override
public boolean mouseClicked(double mouseX, double mouseY, int button) {
    if (isMouseOver(mouseX, mouseY) && tankType != null) {
        ItemStack stack = minecraft.player.inventory.getCarried();
        if (gui() instanceof GuiMekanismTile && !stack.isEmpty() && stack.getItem() instanceof ItemGaugeDropper) {
            int index = infoHandler.getTankIndex();
            if (index != -1) {
                DropperAction action;
                if (button == 0) {
                    action = Screen.hasShiftDown() ? DropperAction.DUMP_TANK : DropperAction.FILL_DROPPER;
                } else {
                    action = DropperAction.DRAIN_DROPPER;
                }
                Mekanism.packetHandler.sendToServer(new PacketDropperUse(((GuiMekanismTile<?, ?>) gui()).getTileEntity().getBlockPos(), action, tankType, index));
            }
            return true;
        }
    }
    return super.mouseClicked(mouseX, mouseY, button);
}
Also used : DropperAction(mekanism.common.network.to_server.PacketDropperUse.DropperAction) PacketDropperUse(mekanism.common.network.to_server.PacketDropperUse) ItemGaugeDropper(mekanism.common.item.ItemGaugeDropper) ItemStack(net.minecraft.item.ItemStack) GuiMekanismTile(mekanism.client.gui.GuiMekanismTile)

Example 2 with ItemGaugeDropper

use of mekanism.common.item.ItemGaugeDropper in project Mekanism by mekanism.

the class GuiTankBar method mouseClicked.

@Override
public boolean mouseClicked(double mouseX, double mouseY, int button) {
    if (isMouseOver(mouseX, mouseY)) {
        ItemStack stack = Minecraft.getInstance().player.inventory.getCarried();
        if (gui() instanceof GuiMekanismTile && !stack.isEmpty() && stack.getItem() instanceof ItemGaugeDropper) {
            TankType tankType = getType(getHandler().getStack());
            if (tankType != null) {
                int index = getHandler().getTankIndex();
                if (index != -1) {
                    DropperAction action;
                    if (button == 0) {
                        action = Screen.hasShiftDown() ? DropperAction.DUMP_TANK : DropperAction.FILL_DROPPER;
                    } else {
                        action = DropperAction.DRAIN_DROPPER;
                    }
                    Mekanism.packetHandler.sendToServer(new PacketDropperUse(((GuiMekanismTile<?, ?>) gui()).getTileEntity().getBlockPos(), action, tankType, index));
                }
                return true;
            }
        }
    }
    return super.mouseClicked(mouseX, mouseY, button);
}
Also used : DropperAction(mekanism.common.network.to_server.PacketDropperUse.DropperAction) PacketDropperUse(mekanism.common.network.to_server.PacketDropperUse) ItemGaugeDropper(mekanism.common.item.ItemGaugeDropper) TankType(mekanism.common.network.to_server.PacketDropperUse.TankType) ItemStack(net.minecraft.item.ItemStack) GuiMekanismTile(mekanism.client.gui.GuiMekanismTile)

Example 3 with ItemGaugeDropper

use of mekanism.common.item.ItemGaugeDropper in project Mekanism by mekanism.

the class PacketDropperUse method handle.

@Override
public void handle(NetworkEvent.Context context) {
    PlayerEntity player = context.getSender();
    if (player == null || tankId < 0) {
        return;
    }
    ItemStack stack = player.inventory.getCarried();
    if (!stack.isEmpty() && stack.getItem() instanceof ItemGaugeDropper) {
        TileEntityMekanism tile = WorldUtils.getTileEntity(TileEntityMekanism.class, player.level, pos);
        if (tile != null) {
            if (tile instanceof TileEntityMultiblock) {
                MultiblockData structure = ((TileEntityMultiblock<?>) tile).getMultiblock();
                if (structure.isFormed()) {
                    handleTankType(structure, player, stack, new Coord4D(structure.getBounds().getCenter(), player.level));
                }
            } else {
                if (action == DropperAction.DUMP_TANK && !player.isCreative()) {
                    // If the dropper is being used to dump the tank and the player is not in creative
                    // check if the block the tank is in is a tiered block and if it is, and it is creative
                    // don't allow clearing the tank
                    Block block = tile.getBlockType();
                    if (Attribute.has(block, AttributeTier.class) && Attribute.get(block, AttributeTier.class).getTier().getBaseTier() == BaseTier.CREATIVE) {
                        return;
                    }
                }
                handleTankType(tile, player, stack, tile.getTileCoord());
            }
        }
    }
}
Also used : TileEntityMekanism(mekanism.common.tile.base.TileEntityMekanism) AttributeTier(mekanism.common.block.attribute.AttributeTier) ItemGaugeDropper(mekanism.common.item.ItemGaugeDropper) TileEntityMultiblock(mekanism.common.tile.prefab.TileEntityMultiblock) Coord4D(mekanism.api.Coord4D) Block(net.minecraft.block.Block) ItemStack(net.minecraft.item.ItemStack) MultiblockData(mekanism.common.lib.multiblock.MultiblockData) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity)

Aggregations

ItemGaugeDropper (mekanism.common.item.ItemGaugeDropper)3 ItemStack (net.minecraft.item.ItemStack)3 GuiMekanismTile (mekanism.client.gui.GuiMekanismTile)2 PacketDropperUse (mekanism.common.network.to_server.PacketDropperUse)2 DropperAction (mekanism.common.network.to_server.PacketDropperUse.DropperAction)2 Coord4D (mekanism.api.Coord4D)1 AttributeTier (mekanism.common.block.attribute.AttributeTier)1 MultiblockData (mekanism.common.lib.multiblock.MultiblockData)1 TankType (mekanism.common.network.to_server.PacketDropperUse.TankType)1 TileEntityMekanism (mekanism.common.tile.base.TileEntityMekanism)1 TileEntityMultiblock (mekanism.common.tile.prefab.TileEntityMultiblock)1 Block (net.minecraft.block.Block)1 PlayerEntity (net.minecraft.entity.player.PlayerEntity)1 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)1