Search in sources :

Example 1 with IMultiblockController

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;
}
Also used : IMultiblockController(forestry.api.multiblock.IMultiblockController) TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) MultiblockTileEntityForestry(forestry.core.multiblock.MultiblockTileEntityForestry) TextComponentString(net.minecraft.util.text.TextComponentString) ItemStack(net.minecraft.item.ItemStack) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 2 with IMultiblockController

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);
                    }
                });
            }
        }
    }
}
Also used : ScaledResolution(net.minecraft.client.gui.ScaledResolution) IMultiblockController(forestry.api.multiblock.IMultiblockController) RayTraceResult(net.minecraft.util.math.RayTraceResult) Minecraft(net.minecraft.client.Minecraft) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 3 with IMultiblockController

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);
        }
    }
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) IMultiblockController(forestry.api.multiblock.IMultiblockController) EntityPlayer(net.minecraft.entity.player.EntityPlayer) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 4 with IMultiblockController

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;
}
Also used : IMultiblockController(forestry.api.multiblock.IMultiblockController) MultiblockTileEntityForestry(forestry.core.multiblock.MultiblockTileEntityForestry) TextComponentString(net.minecraft.util.text.TextComponentString) ItemStack(net.minecraft.item.ItemStack) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 5 with IMultiblockController

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;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IMultiblockController(forestry.api.multiblock.IMultiblockController) ICamouflagedTile(forestry.api.core.ICamouflagedTile) ICamouflageHandler(forestry.api.core.ICamouflageHandler) IMultiblockComponent(forestry.api.multiblock.IMultiblockComponent)

Aggregations

IMultiblockController (forestry.api.multiblock.IMultiblockController)8 ICamouflageHandler (forestry.api.core.ICamouflageHandler)4 ICamouflagedTile (forestry.api.core.ICamouflagedTile)4 IMultiblockComponent (forestry.api.multiblock.IMultiblockComponent)4 ItemStack (net.minecraft.item.ItemStack)4 TileEntity (net.minecraft.tileentity.TileEntity)4 MultiblockTileEntityForestry (forestry.core.multiblock.MultiblockTileEntityForestry)2 TextComponentString (net.minecraft.util.text.TextComponentString)2 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)2 Nullable (javax.annotation.Nullable)1 Minecraft (net.minecraft.client.Minecraft)1 ScaledResolution (net.minecraft.client.gui.ScaledResolution)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)1 BlockPos (net.minecraft.util.math.BlockPos)1 RayTraceResult (net.minecraft.util.math.RayTraceResult)1 TextComponentTranslation (net.minecraft.util.text.TextComponentTranslation)1 World (net.minecraft.world.World)1