use of forestry.greenhouse.multiblock.IGreenhouseControllerInternal 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.multiblock.IGreenhouseControllerInternal in project ForestryMC by ForestryMC.
the class ClimateSourceClimatiser method canWork.
@Override
public boolean canWork(IClimateState currentState, ClimateSourceType oppositeType) {
IClimateHousing region = container.getParent();
if (region instanceof IGreenhouseControllerInternal) {
IGreenhouseControllerInternal controller = (IGreenhouseControllerInternal) region;
IErrorLogic errorLogic = owner.getErrorLogic();
EnergyManager energyManager = controller.getEnergyManager();
if (energyManager.extractEnergy((int) (ENERGY_PER_OPERATION * getEnergyModifier(currentState, oppositeType)), true) > 0) {
owner.setActive(true);
errorLogic.setCondition(false, EnumErrorCode.NO_POWER);
return true;
} else {
owner.setActive(false);
errorLogic.setCondition(true, EnumErrorCode.NO_POWER);
return false;
}
}
if (owner.isActive()) {
owner.setActive(false);
}
return false;
}
use of forestry.greenhouse.multiblock.IGreenhouseControllerInternal 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.multiblock.IGreenhouseControllerInternal in project ForestryMC by ForestryMC.
the class ClimateSourceClimatiser method removeResources.
@Override
protected void removeResources(IClimateState currentState, ClimateSourceType oppositeType) {
IClimateHousing region = container.getParent();
if (region instanceof IGreenhouseControllerInternal) {
IGreenhouseControllerInternal controller = (IGreenhouseControllerInternal) region;
EnergyManager energyManager = controller.getEnergyManager();
energyManager.extractEnergy((int) (ENERGY_PER_OPERATION * getEnergyModifier(currentState, oppositeType)), false);
}
}
use of forestry.greenhouse.multiblock.IGreenhouseControllerInternal in project ForestryMC by ForestryMC.
the class ItemGreenhouseScreen method isValid.
public static boolean isValid(ItemStack stack, World world) {
BlockPos pos = getGreenhousePos(stack);
boolean isValid = true;
if (pos == null || world == null || !world.isBlockLoaded(pos)) {
isValid = false;
} else {
IGreenhouseControllerInternal controller = MultiblockUtil.getController(world, pos, IGreenhouseComponent.class);
if (controller == null || !controller.isAssembled()) {
isValid = false;
}
}
return isValid;
}
Aggregations