Search in sources :

Example 1 with ICamouflagedTile

use of forestry.api.core.ICamouflagedTile in project ForestryMC by ForestryMC.

the class GreenhouseController method setCamouflageBlock.

@Override
public boolean setCamouflageBlock(ItemStack camouflageBlock, boolean sendClientUpdate) {
    if (!ItemStackUtil.isIdenticalItem(camouflageBlock, camouflage)) {
        camouflage = camouflageBlock;
        if (sendClientUpdate && world.isRemote) {
            for (IMultiblockComponent comp : connectedParts) {
                if (comp instanceof ICamouflagedTile) {
                    ICamouflagedTile camBlock = (ICamouflagedTile) comp;
                    BlockPos coordinates = camBlock.getCoordinates();
                    world.markBlockRangeForRenderUpdate(coordinates, coordinates);
                }
            }
            NetworkUtil.sendToServer(new PacketCamouflageSelectionServer(this, CamouflageHandlerType.STRUCTURE));
        }
        return true;
    }
    return false;
}
Also used : ICamouflagedTile(forestry.api.core.ICamouflagedTile) BlockPos(net.minecraft.util.math.BlockPos) IMultiblockComponent(forestry.api.multiblock.IMultiblockComponent) PacketCamouflageSelectionServer(forestry.greenhouse.network.packets.PacketCamouflageSelectionServer)

Example 2 with ICamouflagedTile

use of forestry.api.core.ICamouflagedTile in project ForestryMC by ForestryMC.

the class BlockGreenhouse method getCamouflageHandler.

@Override
public 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)

Example 3 with ICamouflagedTile

use of forestry.api.core.ICamouflagedTile 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 4 with ICamouflagedTile

use of forestry.api.core.ICamouflagedTile 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 5 with ICamouflagedTile

use of forestry.api.core.ICamouflagedTile 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

ICamouflagedTile (forestry.api.core.ICamouflagedTile)6 IMultiblockComponent (forestry.api.multiblock.IMultiblockComponent)6 ICamouflageHandler (forestry.api.core.ICamouflageHandler)4 IMultiblockController (forestry.api.multiblock.IMultiblockController)4 TileEntity (net.minecraft.tileentity.TileEntity)4 ItemStack (net.minecraft.item.ItemStack)2 PacketCamouflageSelectionServer (forestry.greenhouse.network.packets.PacketCamouflageSelectionServer)1 Nullable (javax.annotation.Nullable)1 BlockPos (net.minecraft.util.math.BlockPos)1