Search in sources :

Example 1 with IGreenhouseProvider

use of forestry.greenhouse.api.greenhouse.IGreenhouseProvider in project ForestryMC by ForestryMC.

the class BlockGreenhouse method colorMultiplier.

@Override
@SideOnly(Side.CLIENT)
@SuppressWarnings("deprecation")
public int colorMultiplier(IBlockState blockState, @Nullable IBlockAccess world, @Nullable BlockPos pos, int tintIndex) {
    if (pos == null || world == null) {
        return 16777215;
    }
    ItemStack camouflageStack = getCamouflageBlock(world, pos);
    if (tintIndex == ModelCamouflaged.OVERLAY_COLOR_INDEX + 1) {
        BlockGreenhouseType type = getGreenhouseType(blockState);
        if (type == BlockGreenhouseType.SCREEN) {
            IGreenhouseControllerInternal controller = MultiblockUtil.getController(world, pos, IGreenhouseComponent.class);
            if (controller == null || !controller.isAssembled()) {
                return 16777215;
            }
            IClimateContainer container = controller.getClimateContainer();
            IClimateState state = container.getState();
            return ClimateUtil.getColor(EnumTemperature.getFromValue(state.getTemperature()));
        } else if (type == BlockGreenhouseType.BORDER_CENTER) {
            boolean isClosed = true;
            IGreenhouseControllerInternal controller = MultiblockUtil.getController(world, pos, IGreenhouseComponent.class);
            if (controller == null || !controller.isAssembled()) {
                isClosed = false;
            } else {
                IGreenhouseProvider manager = controller.getProvider();
                isClosed = manager.isClosed();
            }
            return isClosed ? 1356406 : 12197655;
        }
    } else if (tintIndex < ModelCamouflaged.OVERLAY_COLOR_INDEX && !camouflageStack.isEmpty()) {
        Block block = Block.getBlockFromItem(camouflageStack.getItem());
        if (block != Blocks.AIR) {
            IBlockState camouflageState = block.getStateFromMeta(camouflageStack.getItemDamage());
            BlockColors blockColors = Minecraft.getMinecraft().getBlockColors();
            int color = blockColors.colorMultiplier(camouflageState, world, pos, tintIndex);
            if (color != -1) {
                return color;
            }
        }
    }
    return 16777215;
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) IClimateContainer(forestry.greenhouse.api.climate.IClimateContainer) Block(net.minecraft.block.Block) IColoredBlock(forestry.core.blocks.IColoredBlock) IGreenhouseControllerInternal(forestry.greenhouse.multiblock.IGreenhouseControllerInternal) IClimateState(forestry.api.climate.IClimateState) IGreenhouseProvider(forestry.greenhouse.api.greenhouse.IGreenhouseProvider) ItemStack(net.minecraft.item.ItemStack) BlockColors(net.minecraft.client.renderer.color.BlockColors) IGreenhouseComponent(forestry.api.multiblock.IGreenhouseComponent) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 2 with IGreenhouseProvider

use of forestry.greenhouse.api.greenhouse.IGreenhouseProvider in project ForestryMC by ForestryMC.

the class ChunkManager method unload.

public void unload(int x, int z) {
    long pos = ChunkPos.asLong(x, z);
    GreenhouseChunk chunk = id2ChunkMap.remove(pos);
    if (chunk != null) {
        for (IGreenhouseProvider manager : chunk.getProviders()) {
            manager.onUnloadChunk(pos);
        }
    }
}
Also used : IGreenhouseProvider(forestry.greenhouse.api.greenhouse.IGreenhouseProvider) GreenhouseChunk(forestry.greenhouse.multiblock.blocks.storage.GreenhouseChunk)

Example 3 with IGreenhouseProvider

use of forestry.greenhouse.api.greenhouse.IGreenhouseProvider in project ForestryMC by ForestryMC.

the class GreenhouseBlockManager method markBlockDirty.

@Nullable
public synchronized void markBlockDirty(World world, BlockPos pos) {
    long position = ChunkPos.asLong(pos.getX() >> 4, pos.getZ() >> 4);
    GreenhouseChunk chunk = getChunk(world, position);
    if (chunk != null) {
        IGreenhouseBlock block = chunk.get(pos);
        if (block != null) {
            IGreenhouseProvider provider = block.getProvider();
            provider.onBlockChange();
        // markChunkDirty(world, position);
        // chunk.markProviderDirty(pos);
        }
    }
}
Also used : IGreenhouseProvider(forestry.greenhouse.api.greenhouse.IGreenhouseProvider) IGreenhouseChunk(forestry.greenhouse.api.greenhouse.IGreenhouseChunk) GreenhouseChunk(forestry.greenhouse.multiblock.blocks.storage.GreenhouseChunk) IGreenhouseBlock(forestry.greenhouse.api.greenhouse.IGreenhouseBlock) Nullable(javax.annotation.Nullable)

Example 4 with IGreenhouseProvider

use of forestry.greenhouse.api.greenhouse.IGreenhouseProvider in project ForestryMC by ForestryMC.

the class GreenhouseEventHandler method onWorldRenderLast.

@SubscribeEvent
public void onWorldRenderLast(RenderWorldLastEvent event) {
    try {
        float partialTicks = event.getPartialTicks();
        EntityPlayer player = Minecraft.getMinecraft().player;
        World world = player.world;
        long tick = world.getTotalWorldTime();
        if (tick > previousCheckTick + 50) {
            greenhousePositions.clear();
            for (ItemStack itemStack : getClimateScreen(player.inventory)) {
                if (!itemStack.isEmpty()) {
                    BlockPos position = ItemGreenhouseScreen.getGreenhousePos(itemStack);
                    IGreenhouseControllerInternal controller = MultiblockUtil.getController(world, position, IGreenhouseComponent.class);
                    if (controller == null || !controller.isAssembled()) {
                        return;
                    }
                    position = controller.getCenterCoordinates();
                    double distance = MathHelper.sqrt(player.getDistanceSqToCenter(position));
                    if (distance > 64F) {
                        return;
                    }
                    greenhousePositions.add(position);
                }
            }
            previousCheckTick = tick;
        }
        for (BlockPos position : greenhousePositions) {
            IGreenhouseControllerInternal controller = MultiblockUtil.getController(world, position, IGreenhouseComponent.class);
            if (controller == null || !controller.isAssembled()) {
                continue;
            }
            IGreenhouseProvider provider = controller.getProvider();
            position = controller.getCenterCoordinates();
            double distance = MathHelper.sqrt(player.getDistanceSqToCenter(position));
            if (distance > 64F) {
                return;
            }
            double playerX = player.lastTickPosX + (player.posX - player.lastTickPosX) * partialTicks;
            double playerY = player.lastTickPosY + (player.posY - player.lastTickPosY) * partialTicks;
            double playerZ = player.lastTickPosZ + (player.posZ - player.lastTickPosZ) * partialTicks;
            GlStateManager.pushMatrix();
            GlStateManager.translate(-playerX, -playerY, -playerZ);
            GlStateManager.enableBlend();
            GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
            GlStateManager.disableTexture2D();
            GlStateManager.glLineWidth(2.5F);
            // Draw center position
            BlockPos offset = provider.getCenterPos();
            AxisAlignedBB testBlockBB = Block.FULL_BLOCK_AABB.offset(offset);
            RenderGlobal.drawSelectionBoundingBox(testBlockBB, 0.0F, 0.0F, 0.0F, 0.5F);
            IGreenhouseLimits limits = provider.getUsedLimits();
            if (limits != null) {
                Position2D minEdge = limits.getMinimumCoordinates();
                Position2D maxEdge = limits.getMaximumCoordinates();
                AxisAlignedBB greenhouseBB = new AxisAlignedBB(minEdge.getX(), limits.getDepth(), minEdge.getZ(), maxEdge.getX() + 1, limits.getHeight() + 1, maxEdge.getZ() + 1);
                RenderGlobal.drawSelectionBoundingBox(greenhouseBB, 0.0F, 0.0F, 0.0F, 0.5F);
            }
            GlStateManager.enableTexture2D();
            GlStateManager.disableBlend();
            GlStateManager.popMatrix();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) IGreenhouseProvider(forestry.greenhouse.api.greenhouse.IGreenhouseProvider) World(net.minecraft.world.World) IGreenhouseLimits(forestry.greenhouse.api.greenhouse.IGreenhouseLimits) EntityPlayer(net.minecraft.entity.player.EntityPlayer) Position2D(forestry.greenhouse.api.greenhouse.Position2D) BlockPos(net.minecraft.util.math.BlockPos) IGreenhouseControllerInternal(forestry.greenhouse.multiblock.IGreenhouseControllerInternal) ItemStack(net.minecraft.item.ItemStack) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 5 with IGreenhouseProvider

use of forestry.greenhouse.api.greenhouse.IGreenhouseProvider in project ForestryMC by ForestryMC.

the class WallBlockHandler method onCheckPosition.

@Override
public boolean onCheckPosition(IGreenhouseBlockStorage storage, IBlankBlock rootBlock, BlockPos position, EnumFacing facing, IGreenhouseBlock block, List<IGreenhouseBlock> newBlocksToCheck) {
    IGreenhouseProvider provider = storage.getProvider();
    if (block == null && isValidWallBlock(provider.getWorld(), position)) {
        for (IGreenhouseProviderListener listener : provider.getListeners()) {
            listener.onCheckPosition(position);
        }
        IWallBlock wallBlock = createBlock(storage, rootBlock, facing, position);
        storage.setBlock(position, wallBlock);
        rootBlock.setFaceTested(facing, true);
        rootBlock.setNearWall(true);
        return true;
    }
    return false;
}
Also used : IGreenhouseProviderListener(forestry.greenhouse.api.greenhouse.IGreenhouseProviderListener) IGreenhouseProvider(forestry.greenhouse.api.greenhouse.IGreenhouseProvider) IWallBlock(forestry.greenhouse.api.greenhouse.IWallBlock)

Aggregations

IGreenhouseProvider (forestry.greenhouse.api.greenhouse.IGreenhouseProvider)7 GreenhouseChunk (forestry.greenhouse.multiblock.blocks.storage.GreenhouseChunk)3 IGreenhouseBlock (forestry.greenhouse.api.greenhouse.IGreenhouseBlock)2 IGreenhouseControllerInternal (forestry.greenhouse.multiblock.IGreenhouseControllerInternal)2 ItemStack (net.minecraft.item.ItemStack)2 BlockPos (net.minecraft.util.math.BlockPos)2 IClimateState (forestry.api.climate.IClimateState)1 IErrorState (forestry.api.core.IErrorState)1 IGreenhouseComponent (forestry.api.multiblock.IGreenhouseComponent)1 IColoredBlock (forestry.core.blocks.IColoredBlock)1 IClimateContainer (forestry.greenhouse.api.climate.IClimateContainer)1 IGreenhouseBlockHandler (forestry.greenhouse.api.greenhouse.IGreenhouseBlockHandler)1 IGreenhouseChunk (forestry.greenhouse.api.greenhouse.IGreenhouseChunk)1 IGreenhouseLimits (forestry.greenhouse.api.greenhouse.IGreenhouseLimits)1 IGreenhouseProviderListener (forestry.greenhouse.api.greenhouse.IGreenhouseProviderListener)1 IWallBlock (forestry.greenhouse.api.greenhouse.IWallBlock)1 Position2D (forestry.greenhouse.api.greenhouse.Position2D)1 Nullable (javax.annotation.Nullable)1 Block (net.minecraft.block.Block)1 IBlockState (net.minecraft.block.state.IBlockState)1