Beispiel #1
0
    public static void ChangePlantIfNeeded(TileEntityWorkstation tew)
    {
        string newPlantAboveName = "";

        Vector3i blockAbovePos = tew.ToWorldPos();

        blockAbovePos.y += 1;
        BlockValue blockAbove = GameManager.Instance.World.GetBlock(blockAbovePos);
        Block      block      = Block.list[blockAbove.type];

        int curRecipeidx = tew.Queue.Length - 1;

        if (tew.Queue[curRecipeidx] != null && tew.Queue[curRecipeidx].Recipe != null)
        {
            string curRecipe = tew.Queue[curRecipeidx].Recipe.GetName();
            if (hydroCropsDict.ContainsKey(curRecipe) && block.GetBlockName() != hydroCropsDict[curRecipe])
            {
                newPlantAboveName = hydroCropsDict[curRecipe];
            }
        }
        else
        {
            if (block.GetBlockName() != "air")
            {
                newPlantAboveName = "air";
            }
        }

        // if needed, change the plant above the workstation or fallback to air if nothing is cooking
        if (newPlantAboveName != "")
        {
            BlockValue newPlantBlock = Block.GetBlockValue(newPlantAboveName);
            GameManager.Instance.World.SetBlockRPC(blockAbovePos, newPlantBlock);
        }
    }
Beispiel #2
0
    public static bool IsHydroponicFarmPowered(TileEntityWorkstation tew)
    {
        Vector3i powerBlockPos = tew.ToWorldPos();

        powerBlockPos.y -= 1;
        BlockValue powerBlockValue = GameManager.Instance.World.GetBlock(powerBlockPos);
        Block      powerBlock      = Block.list[powerBlockValue.type];

        bool isPowered = false;

        if (powerBlock.GetBlockName() == "hydroponicFarmPower")
        {
            // Is Power block powered
            Chunk chunk = (Chunk)GameManager.Instance.World.GetChunkFromWorldPos(powerBlockPos);
            isPowered = BlockHydroponicFarmPower.IsBlockPoweredUp(powerBlockPos, chunk.ClrIdx);

            // Halt crafting UI
            EntityPlayerLocal player   = GameManager.Instance.World.GetPrimaryPlayer();
            LocalPlayerUI     playerUI = player.PlayerUI;
            BlockValue        block    = GameManager.Instance.World.GetBlock(tew.ToWorldPos());
            string            text     = string.Format("workstation_{0}", Block.list[block.type].GetBlockName());
            if (playerUI.windowManager.Contains(text))
            {
                XUiC_WorkstationWindowGroup workstationWindowGroup = ((XUiC_WorkstationWindowGroup)((XUiWindowGroup)playerUI.windowManager.GetWindow(text)).Controller);
                if (workstationWindowGroup.WorkstationData != null && workstationWindowGroup.WorkstationData.TileEntity == tew)
                {
                    // The name of the XUiC_CraftingQueue field of XUiC_WorkstationWindowGroup is obfuscated so we find it by type to call it.
                    XUiC_CraftingQueue craftingQueue = null;
                    var listOfFieldNames             = typeof(XUiC_WorkstationWindowGroup).GetFields();
                    foreach (FieldInfo fieldInfo in listOfFieldNames)
                    {
                        FieldInfo field = null;
                        if (fieldInfo.FieldType == typeof(XUiC_CraftingQueue))
                        {
                            field = fieldInfo;
                        }
                        if (field != null)
                        {
                            craftingQueue = (XUiC_CraftingQueue)field.GetValue(workstationWindowGroup);
                        }
                    }

                    if (craftingQueue != null)
                    {
                        if (!isPowered)
                        {
                            //workstationWindowGroup.FNW.HaltCrafting();
                            craftingQueue.HaltCrafting();
                        }
                        else
                        {
                            //workstationWindowGroup.FNW.ResumeCrafting();
                            craftingQueue.ResumeCrafting();
                        }
                    }
                }
            }

            TileEntityWorkstationPatchFunctions.ChangePlantIfNeeded(tew);
            return(isPowered);
        }

        return(true);
    }