use of forestry.api.multiblock.IMultiblockController in project ForestryMC by ForestryMC.
the class BlockStructure method onBlockActivated.
@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
if (playerIn.isSneaking()) {
return false;
}
MultiblockTileEntityForestry part = TileUtil.getTile(worldIn, pos, MultiblockTileEntityForestry.class);
if (part == null) {
return false;
}
IMultiblockController controller = part.getMultiblockLogic().getController();
ItemStack heldItem = playerIn.getHeldItem(hand);
// multiblock-debugging message if the machine is not assembled.
if (heldItem.isEmpty()) {
if (controller != null) {
if (!controller.isAssembled()) {
String validationError = controller.getLastValidationError();
if (validationError != null) {
long tick = worldIn.getTotalWorldTime();
if (tick > previousMessageTick + 20) {
playerIn.sendMessage(new TextComponentString(validationError));
previousMessageTick = tick;
}
return true;
}
}
} else {
playerIn.sendMessage(new TextComponentTranslation("for.multiblock.error.notConnected"));
return true;
}
}
// Don't open the GUI if the multiblock isn't assembled
if (controller == null || !controller.isAssembled()) {
return false;
}
if (!worldIn.isRemote) {
part.openGui(playerIn);
}
return true;
}
use of forestry.api.multiblock.IMultiblockController in project ForestryMC by ForestryMC.
the class MultiblockEventHandlerClient method onGameOverlay.
@SubscribeEvent
public void onGameOverlay(RenderGameOverlayEvent.Post event) {
if (GeneticsUtil.hasNaturalistEye(Minecraft.getMinecraft().player)) {
if (event.getType() == RenderGameOverlayEvent.ElementType.ALL && Minecraft.getMinecraft().currentScreen == null) {
Minecraft minecraft = Minecraft.getMinecraft();
RayTraceResult posHit = minecraft.objectMouseOver;
ScaledResolution resolution = event.getResolution();
if (posHit != null && posHit.getBlockPos() != null) {
TileUtil.actOnTile(minecraft.world, posHit.getBlockPos(), IMultiblockComponent.class, component -> {
IMultiblockController controller = component.getMultiblockLogic().getController();
String lastValidationError = controller.getLastValidationError();
if (lastValidationError != null) {
lastValidationError = TextFormatting.DARK_RED.toString() + TextFormatting.ITALIC.toString() + lastValidationError;
minecraft.fontRenderer.drawSplitString(lastValidationError, resolution.getScaledWidth() / 2 + 35, resolution.getScaledHeight() / 2 - 25, 128, 16777215);
}
});
}
}
}
}
use of forestry.api.multiblock.IMultiblockController in project ForestryMC by ForestryMC.
the class MultiblockEventHandlerClient method onWorldRenderLast.
@SubscribeEvent
public void onWorldRenderLast(RenderWorldLastEvent event) {
if (GeneticsUtil.hasNaturalistEye(Minecraft.getMinecraft().player)) {
try {
World world = Minecraft.getMinecraft().world;
Set<IMultiblockControllerInternal> controllers = MultiblockRegistry.getControllersFromWorld(world);
if (!controllers.isEmpty()) {
float partialTicks = event.getPartialTicks();
EntityPlayer player = Minecraft.getMinecraft().player;
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.enableBlend();
GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
GlStateManager.disableTexture2D();
GlStateManager.glLineWidth(2.0F);
GlStateManager.depthMask(false);
for (IMultiblockController controller : controllers) {
if (controller != null) {
BlockPos lastErrorPosition = controller.getLastValidationErrorPosition();
if (lastErrorPosition != null) {
if (world.isBlockLoaded(lastErrorPosition) && player.getDistanceSq(lastErrorPosition) < 64F) {
AxisAlignedBB box = Block.FULL_BLOCK_AABB.offset(lastErrorPosition.getX() - playerX, lastErrorPosition.getY() - playerY, lastErrorPosition.getZ() - playerZ);
RenderGlobal.drawSelectionBoundingBox(box, 1.0F, 0.0F, 0.0F, 0.25F);
RenderGlobal.renderFilledBox(box, 1.0F, 0.0F, 0.0F, 0.125F);
}
}
}
}
GlStateManager.depthMask(true);
GlStateManager.enableTexture2D();
GlStateManager.disableBlend();
GlStateManager.popMatrix();
}
} catch (Exception e) {
Log.error("Failed to render the position of a multiblock exception.", e);
}
}
}
use of forestry.api.multiblock.IMultiblockController in project ForestryMC by ForestryMC.
the class BlockGreenhouse method onBlockActivated.
@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
if (playerIn.isSneaking()) {
return false;
}
MultiblockTileEntityForestry part = TileUtil.getTile(worldIn, pos, MultiblockTileEntityForestry.class);
if (part == null) {
return false;
}
IMultiblockController controller = part.getMultiblockLogic().getController();
ItemStack mainHand = playerIn.getHeldItemMainhand();
if (mainHand.isEmpty()) {
if (playerIn.getHeldItemOffhand().isEmpty()) {
// multiblock-debugging message if the machine is not assembled.
if (!controller.isAssembled()) {
String validationError = controller.getLastValidationError();
if (validationError != null) {
long tick = worldIn.getTotalWorldTime();
if (tick > previousMessageTick + 20) {
playerIn.sendMessage(new TextComponentString(validationError));
previousMessageTick = tick;
}
return true;
}
}
}
}
// Don't open the GUI if the multiblock isn't assembled
if (!controller.isAssembled()) {
return false;
}
if (!worldIn.isRemote) {
part.openGui(playerIn);
}
return true;
}
use of forestry.api.multiblock.IMultiblockController in project ForestryMC by ForestryMC.
the class BlockGreenhouse method getCamouflageHandler.
@Override
public ICamouflageHandler getCamouflageHandler(IBlockAccess world, BlockPos pos) {
TileEntity tile = TileUtil.getTile(world, pos, TileEntity.class);
if (tile instanceof ICamouflagedTile) {
ICamouflagedTile block = (ICamouflagedTile) tile;
ICamouflageHandler handler = null;
if (tile instanceof ICamouflageHandler) {
handler = (ICamouflageHandler) tile;
}
if ((handler == null || handler.getCamouflageBlock().isEmpty()) && tile instanceof IMultiblockComponent) {
IMultiblockComponent component = (IMultiblockComponent) tile;
IMultiblockController controller = component.getMultiblockLogic().getController();
if (controller instanceof ICamouflageHandler) {
handler = (ICamouflageHandler) controller;
}
}
return handler;
}
return null;
}
Aggregations