Search in sources :

Example 6 with IMultiblockController

use of forestry.api.multiblock.IMultiblockController in project ForestryMC by ForestryMC.

the class BlockGreenhouse method getCamouflageBlock.

@Override
public ItemStack getCamouflageBlock(IBlockAccess world, BlockPos pos) {
    if (world == null || pos == null) {
        return ItemStack.EMPTY;
    }
    TileEntity tile = TileUtil.getTile(world, pos, TileEntity.class);
    if (tile instanceof ICamouflagedTile) {
        ICamouflagedTile block = (ICamouflagedTile) tile;
        ItemStack camouflageStack = ItemStack.EMPTY;
        if (tile instanceof ICamouflageHandler) {
            ICamouflageHandler tileHandler = (ICamouflageHandler) tile;
            ItemStack tileCamouflageStack = tileHandler.getCamouflageBlock();
            ItemStack defaultCamouflageStack = tileHandler.getDefaultCamouflageBlock();
            if (!ItemStackUtil.isIdenticalItem(tileCamouflageStack, defaultCamouflageStack)) {
                camouflageStack = tileCamouflageStack;
            }
        }
        if (camouflageStack.isEmpty() && tile instanceof IMultiblockComponent) {
            IMultiblockComponent component = (IMultiblockComponent) tile;
            IMultiblockController controller = component.getMultiblockLogic().getController();
            if (controller instanceof ICamouflageHandler) {
                ICamouflageHandler multiblockHandler = (ICamouflageHandler) controller;
                camouflageStack = multiblockHandler.getCamouflageBlock();
            }
            if (!controller.isAssembled()) {
                camouflageStack = ItemStack.EMPTY;
            }
        }
        return camouflageStack;
    }
    return ItemStack.EMPTY;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IMultiblockController(forestry.api.multiblock.IMultiblockController) ICamouflagedTile(forestry.api.core.ICamouflagedTile) ICamouflageHandler(forestry.api.core.ICamouflageHandler) IMultiblockComponent(forestry.api.multiblock.IMultiblockComponent) ItemStack(net.minecraft.item.ItemStack)

Example 7 with IMultiblockController

use of forestry.api.multiblock.IMultiblockController in project ForestryMC by ForestryMC.

the class CamouflageUtil method getCamouflageHandler.

@Nullable
public static ICamouflageHandler getCamouflageHandler(IBlockAccess world, BlockPos pos) {
    TileEntity tile = TileUtil.getTile(world, pos, TileEntity.class);
    if (tile instanceof ICamouflagedTile) {
        ICamouflagedTile block = (ICamouflagedTile) tile;
        ICamouflageHandler handler = null;
        if (tile instanceof ICamouflageHandler) {
            handler = (ICamouflageHandler) tile;
        }
        if ((handler == null || handler.getCamouflageBlock().isEmpty()) && tile instanceof IMultiblockComponent) {
            IMultiblockComponent component = (IMultiblockComponent) tile;
            IMultiblockController controller = component.getMultiblockLogic().getController();
            if (controller instanceof ICamouflageHandler) {
                handler = (ICamouflageHandler) controller;
            }
        }
        return handler;
    }
    return null;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IMultiblockController(forestry.api.multiblock.IMultiblockController) ICamouflagedTile(forestry.api.core.ICamouflagedTile) ICamouflageHandler(forestry.api.core.ICamouflageHandler) IMultiblockComponent(forestry.api.multiblock.IMultiblockComponent) Nullable(javax.annotation.Nullable)

Example 8 with IMultiblockController

use of forestry.api.multiblock.IMultiblockController in project ForestryMC by ForestryMC.

the class CamouflageUtil method getCamouflageBlock.

public static ItemStack getCamouflageBlock(@Nullable IBlockAccess world, @Nullable BlockPos pos) {
    if (world == null || pos == null) {
        return ItemStack.EMPTY;
    }
    TileEntity tile = TileUtil.getTile(world, pos, TileEntity.class);
    if (tile instanceof ICamouflagedTile) {
        ICamouflagedTile block = (ICamouflagedTile) tile;
        ItemStack camouflageStack = ItemStack.EMPTY;
        if (tile instanceof ICamouflageHandler) {
            ICamouflageHandler tileHandler = (ICamouflageHandler) tile;
            ItemStack tileCamouflageStack = tileHandler.getCamouflageBlock();
            ItemStack defaultCamouflageStack = tileHandler.getDefaultCamouflageBlock();
            if (!ItemStackUtil.isIdenticalItem(tileCamouflageStack, defaultCamouflageStack)) {
                camouflageStack = tileCamouflageStack;
            }
        }
        if (camouflageStack.isEmpty() && tile instanceof IMultiblockComponent) {
            IMultiblockComponent component = (IMultiblockComponent) tile;
            IMultiblockController controller = component.getMultiblockLogic().getController();
            if (controller.isAssembled() && controller instanceof ICamouflageHandler) {
                ICamouflageHandler multiblockHandler = (ICamouflageHandler) controller;
                camouflageStack = multiblockHandler.getCamouflageBlock();
            }
        }
        return camouflageStack;
    }
    return ItemStack.EMPTY;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IMultiblockController(forestry.api.multiblock.IMultiblockController) ICamouflagedTile(forestry.api.core.ICamouflagedTile) ICamouflageHandler(forestry.api.core.ICamouflageHandler) IMultiblockComponent(forestry.api.multiblock.IMultiblockComponent) ItemStack(net.minecraft.item.ItemStack)

Aggregations

IMultiblockController (forestry.api.multiblock.IMultiblockController)8 ICamouflageHandler (forestry.api.core.ICamouflageHandler)4 ICamouflagedTile (forestry.api.core.ICamouflagedTile)4 IMultiblockComponent (forestry.api.multiblock.IMultiblockComponent)4 ItemStack (net.minecraft.item.ItemStack)4 TileEntity (net.minecraft.tileentity.TileEntity)4 MultiblockTileEntityForestry (forestry.core.multiblock.MultiblockTileEntityForestry)2 TextComponentString (net.minecraft.util.text.TextComponentString)2 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)2 Nullable (javax.annotation.Nullable)1 Minecraft (net.minecraft.client.Minecraft)1 ScaledResolution (net.minecraft.client.gui.ScaledResolution)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)1 BlockPos (net.minecraft.util.math.BlockPos)1 RayTraceResult (net.minecraft.util.math.RayTraceResult)1 TextComponentTranslation (net.minecraft.util.text.TextComponentTranslation)1 World (net.minecraft.world.World)1