Search in sources :

Example 1 with Position2D

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

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

the class ClimateSourceWorldManager method removeSource.

public void removeSource(IClimateSourceOwner owner) {
    BlockPos pos = owner.getCoordinates();
    Position2D position = new Position2D(pos);
    Map<Integer, IClimateSourceOwner> positionedOwners = owners.computeIfAbsent(position, k -> new HashMap<>());
    positionedOwners.remove(pos.getY());
}
Also used : IClimateSourceOwner(forestry.greenhouse.api.climate.IClimateSourceOwner) Position2D(forestry.greenhouse.api.greenhouse.Position2D) BlockPos(net.minecraft.util.math.BlockPos)

Example 3 with Position2D

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

the class ClimateSourceWorldManager method addSource.

public void addSource(IClimateSourceOwner owner) {
    BlockPos pos = owner.getCoordinates();
    Position2D position = new Position2D(pos);
    Map<Integer, IClimateSourceOwner> positionedOwners = owners.computeIfAbsent(position, k -> new HashMap<>());
    positionedOwners.put(pos.getY(), owner);
}
Also used : IClimateSourceOwner(forestry.greenhouse.api.climate.IClimateSourceOwner) Position2D(forestry.greenhouse.api.greenhouse.Position2D) BlockPos(net.minecraft.util.math.BlockPos)

Example 4 with Position2D

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

the class WallBlock method onCreate.

@Override
public void onCreate() {
    IClimateContainer container = provider.getClimateContainer();
    for (IClimateSourceOwner sourceOwner : GreenhouseManager.climateManager.getSources(provider.getWorld(), new Position2D(pos))) {
        IClimateSource source = sourceOwner.getClimateSource();
        sources.add(source);
        container.addClimateSource(source);
        source.onAdded(container);
    }
}
Also used : IClimateSourceOwner(forestry.greenhouse.api.climate.IClimateSourceOwner) IClimateContainer(forestry.greenhouse.api.climate.IClimateContainer) Position2D(forestry.greenhouse.api.greenhouse.Position2D) IClimateSource(forestry.greenhouse.api.climate.IClimateSource)

Example 5 with Position2D

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

Position2D (forestry.greenhouse.api.greenhouse.Position2D)10 BlockPos (net.minecraft.util.math.BlockPos)6 IGreenhouseBlock (forestry.greenhouse.api.greenhouse.IGreenhouseBlock)4 IClimateSourceOwner (forestry.greenhouse.api.climate.IClimateSourceOwner)3 IGreenhouseController (forestry.api.multiblock.IGreenhouseController)2 IBlankBlock (forestry.greenhouse.api.greenhouse.IBlankBlock)2 IGreenhouseLimits (forestry.greenhouse.api.greenhouse.IGreenhouseLimits)2 IErrorLogic (forestry.api.core.IErrorLogic)1 IErrorState (forestry.api.core.IErrorState)1 IClimateHousing (forestry.api.greenhouse.IClimateHousing)1 IClimateContainer (forestry.greenhouse.api.climate.IClimateContainer)1 IClimateSource (forestry.greenhouse.api.climate.IClimateSource)1 IGreenhouseBlockHandler (forestry.greenhouse.api.greenhouse.IGreenhouseBlockHandler)1 IGreenhouseChunk (forestry.greenhouse.api.greenhouse.IGreenhouseChunk)1 IGreenhouseProvider (forestry.greenhouse.api.greenhouse.IGreenhouseProvider)1 GreenhouseLimitsBuilder (forestry.greenhouse.multiblock.GreenhouseLimitsBuilder)1 IGreenhouseControllerInternal (forestry.greenhouse.multiblock.IGreenhouseControllerInternal)1 LinkedList (java.util.LinkedList)1 Stack (java.util.Stack)1 Nullable (javax.annotation.Nullable)1