Search in sources :

Example 1 with MultiblockData

use of mekanism.common.lib.multiblock.MultiblockData in project Mekanism by mekanism.

the class TileEntityStructuralMultiblock method onActivate.

@Override
public ActionResultType onActivate(PlayerEntity player, Hand hand, ItemStack stack) {
    for (Map.Entry<MultiblockManager<?>, Structure> entry : structures.entrySet()) {
        Structure structure = entry.getValue();
        IMultiblock<?> master = structure.getController();
        if (master != null) {
            MultiblockData data = getMultiblockData(structure);
            if (data.isFormed() && structuralGuiAccessAllowed(entry.getKey().getNameLower())) {
                // make sure this block is on the structure first
                if (data.getBounds().getRelativeLocation(getBlockPos()).isWall()) {
                    return master.onActivate(player, hand, stack);
                }
            }
        }
    }
    return ActionResultType.PASS;
}
Also used : MultiblockManager(mekanism.common.lib.multiblock.MultiblockManager) Structure(mekanism.common.lib.multiblock.Structure) MultiblockData(mekanism.common.lib.multiblock.MultiblockData) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with MultiblockData

use of mekanism.common.lib.multiblock.MultiblockData in project Mekanism by mekanism.

the class LookingAtUtils method addInfo.

public static void addInfo(LookingAtHelper info, @Nonnull TileEntity tile, boolean displayTanks, boolean displayFluidTanks) {
    MultiblockData structure = getMultiblock(tile);
    Optional<IStrictEnergyHandler> energyCapability = CapabilityUtils.getCapability(tile, Capabilities.STRICT_ENERGY_CAPABILITY, null).resolve();
    if (energyCapability.isPresent()) {
        displayEnergy(info, energyCapability.get());
    } else if (structure != null && structure.isFormed()) {
        // Special handling to allow viewing the energy of multiblock's when looking at things other than the ports
        displayEnergy(info, structure);
    }
    if (displayTanks) {
        // Fluid - only add it to our own tiles in which we disable the default display for
        if (displayFluidTanks && tile instanceof TileEntityUpdateable) {
            Optional<IFluidHandler> fluidCapability = CapabilityUtils.getCapability(tile, CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, null).resolve();
            if (fluidCapability.isPresent()) {
                displayFluid(info, fluidCapability.get());
            } else if (structure != null && structure.isFormed()) {
                // Special handling to allow viewing the fluid in a multiblock when looking at things other than the ports
                displayFluid(info, structure);
            }
        }
        // Chemicals
        addInfo(tile, structure, Capabilities.GAS_HANDLER_CAPABILITY, multiblock -> multiblock.getGasTanks(null), info, MekanismLang.GAS, Current.GAS, CurrentType.GAS);
        addInfo(tile, structure, Capabilities.INFUSION_HANDLER_CAPABILITY, multiblock -> multiblock.getInfusionTanks(null), info, MekanismLang.INFUSE_TYPE, Current.INFUSION, CurrentType.INFUSION);
        addInfo(tile, structure, Capabilities.PIGMENT_HANDLER_CAPABILITY, multiblock -> multiblock.getPigmentTanks(null), info, MekanismLang.PIGMENT, Current.PIGMENT, CurrentType.PIGMENT);
        addInfo(tile, structure, Capabilities.SLURRY_HANDLER_CAPABILITY, multiblock -> multiblock.getSlurryTanks(null), info, MekanismLang.SLURRY, Current.SLURRY, CurrentType.SLURRY);
    }
}
Also used : IStrictEnergyHandler(mekanism.api.energy.IStrictEnergyHandler) TileEntityUpdateable(mekanism.common.tile.base.TileEntityUpdateable) MultiblockData(mekanism.common.lib.multiblock.MultiblockData) IFluidHandler(net.minecraftforge.fluids.capability.IFluidHandler)

Example 3 with MultiblockData

use of mekanism.common.lib.multiblock.MultiblockData 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

MultiblockData (mekanism.common.lib.multiblock.MultiblockData)3 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Coord4D (mekanism.api.Coord4D)1 IStrictEnergyHandler (mekanism.api.energy.IStrictEnergyHandler)1 AttributeTier (mekanism.common.block.attribute.AttributeTier)1 ItemGaugeDropper (mekanism.common.item.ItemGaugeDropper)1 MultiblockManager (mekanism.common.lib.multiblock.MultiblockManager)1 Structure (mekanism.common.lib.multiblock.Structure)1 TileEntityMekanism (mekanism.common.tile.base.TileEntityMekanism)1 TileEntityUpdateable (mekanism.common.tile.base.TileEntityUpdateable)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 ItemStack (net.minecraft.item.ItemStack)1 IFluidHandler (net.minecraftforge.fluids.capability.IFluidHandler)1