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;
}
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);
}
}
}
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);
}
}
}
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();
}
}
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;
}
Aggregations