Search in sources :

Example 1 with IGreenhouseLimits

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

the class GreenhouseController method createLimits.

private IGreenhouseLimits createLimits() {
    BlockPos centerTop = getTopCenterCoord();
    centerPos = centerTop.up(CENTER_HEIGHT);
    BlockPos max = getMaximumCoord();
    BlockPos min = getMinimumCoord();
    int sizeNorthSouth = Math.abs(max.getZ() - min.getZ()) + 1;
    int sizeEastWest = Math.abs(max.getX() - min.getX()) + 1;
    int height = (Math.abs(max.getY() - min.getY()) + 2) * Config.greenhouseSize;
    int lengthEastWest = sizeEastWest * Config.greenhouseSize;
    int lengthNorthSouth = sizeNorthSouth * Config.greenhouseSize;
    return new GreenhouseLimits(new Position2D(lengthEastWest, lengthNorthSouth), new Position2D(-lengthEastWest, -lengthNorthSouth), height, REGION_DEPTH);
}
Also used : IGreenhouseLimits(forestry.greenhouse.api.greenhouse.IGreenhouseLimits) Position2D(forestry.greenhouse.api.greenhouse.Position2D) BlockPos(net.minecraft.util.math.BlockPos)

Example 2 with IGreenhouseLimits

use of forestry.greenhouse.api.greenhouse.IGreenhouseLimits 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)

Aggregations

IGreenhouseLimits (forestry.greenhouse.api.greenhouse.IGreenhouseLimits)2 Position2D (forestry.greenhouse.api.greenhouse.Position2D)2 BlockPos (net.minecraft.util.math.BlockPos)2 IGreenhouseProvider (forestry.greenhouse.api.greenhouse.IGreenhouseProvider)1 IGreenhouseControllerInternal (forestry.greenhouse.multiblock.IGreenhouseControllerInternal)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 ItemStack (net.minecraft.item.ItemStack)1 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)1 World (net.minecraft.world.World)1 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)1