Example #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);
        }
    }
Example #2
0
    /**
     * Returns true if a heat source is under the block
     */

    public bool IsHeated()
    {
        if (!this.CanTick())
        {
            return(this.hasHeat);
        }

        if (!this.requiresHeat)
        {
            return(this.hasHeat = true);
        }

        World world = GameManager.Instance.World;

        // If TE is on very bottom of world this will prevent out of boundary shenanigans.
        if (this.ToWorldPos() == this.heatedBlockCoords[0])
        {
            return(this.hasHeat = false);
        }

        Dictionary <Vector3i, TileEntity> tileEntitiesUnderneath = CoordinateHelper.GetTileEntitiesInCoordinatesWithType(world, this.heatedBlockCoords, TileEntityType.Workstation);

        if (tileEntitiesUnderneath.Count == 0)
        {
            return(this.hasHeat = false);
        }

        foreach (KeyValuePair <Vector3i, TileEntity> entry in tileEntitiesUnderneath)
        {
            TileEntityWorkstation otherTileEntity = entry.Value as TileEntityWorkstation;
            Vector3i otherTileEntityPos           = entry.Key;

            foreach (string heatSource in this.heatSources)
            {
                if (!CoordinateHelper.BlockAtCoordinateIs(world, otherTileEntityPos, heatSource))
                {
                    continue;
                }

                // Checks that there is fuel being used for the workstation as well as if it's burning.
                foreach (ItemStack itemStack in otherTileEntity.Fuel)
                {
                    if (itemStack != null & !itemStack.Equals(ItemStack.Empty.Clone()))
                    {
                        if (otherTileEntity.IsActive(world))
                        {
                            return(this.hasHeat = true);
                        }
                    }
                }
            }
        }
        return(this.hasHeat = false);
    }
Example #3
0
 public static bool Prefix(TileEntityWorkstation __instance, ref float ___currentBurnTimeLeft)
 {
     AdvLogging.DisplayLog(AdvFeatureClass, "UpdateTick()");
     if (!Configuration.CheckFeatureStatus(AdvFeatureClass, Feature))
         return true;
     if (___currentBurnTimeLeft < 0.5f)
     {
         if (SphereII_PowerWorkstationHelper.CheckWorkstationForPower(__instance))
             ___currentBurnTimeLeft = 5f;
     }
     AdvLogging.DisplayLog(AdvFeatureClass, "Current Burn Time: " + ___currentBurnTimeLeft);
     return true;
 }
 public BCMTileEntityWorkstation(Vector3i pos, TileEntityWorkstation te) : base(pos, te)
 {
     //todo
     //te.BurnTimeLeft;
     //te.BurnTotalTimeLeft;
     //te.Fuel;
     //te.Input;
     //te.IsBurning;
     //te.MaterialNames;
     //te.Output;
     //te.Queue;
     //te.Tools;
 }
 public TileEntityPoweredWorkstationSDX(Chunk _chunk) : base(_chunk)
 {
     workstation = new TileEntityWorkstation(_chunk);
 }
Example #6
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);
    }
        private void SetHistory(TileEntityWorkstation te)
        {
//			burnTimeLeft = te.BurnTimeLeft;
//			totalBurnTimeLeft = te.BurnTotalTimeLeft;
//			isBurning = te.IsBurning;
            //Log.Out ("TOOLS");
            tools = new KeyValuePair <int, int> [te.Tools.Length];
            for (var i = 0; i < te.Tools.Length; i++)
            {
                KeyValuePair <int, int> kvp;
                if (te.Tools [i] != null)
                {
                    kvp = new KeyValuePair <int, int> (te.Tools [i].itemValue.type, te.Tools [i].count);
                }
                else
                {
                    kvp = new KeyValuePair <int, int> (0, 0);
                }

                tools[i] = kvp;
            }

            //Log.Out ("FUEL");
            fuel = new KeyValuePair <int, int> [te.Fuel.Length];
            for (var i = 0; i < te.Fuel.Length; i++)
            {
                KeyValuePair <int, int> kvp;
                if (te.Fuel[i] != null)
                {
                    kvp = new KeyValuePair <int, int> (te.Fuel [i].itemValue.type, te.Fuel [i].count);
                }
                else
                {
                    kvp = new KeyValuePair <int, int> (0, 0);
                }
                fuel[i] = kvp;
            }

            //Log.Out ("INPUT");
            input = new KeyValuePair <int, int> [te.Input.Length];
            for (var i = 0; i < te.Input.Length - te.MaterialNames.Length; i++)
            {
                KeyValuePair <int, int> kvp;
                if (te.Input [i] != null)
                {
                    kvp = new KeyValuePair <int, int> (te.Input [i].itemValue.type, te.Input [i].count);
                }
                else
                {
                    kvp = new KeyValuePair <int, int> (0, 0);
                }
                input[i] = kvp;
            }

            //Log.Out ("OUTPUT");
            output = new KeyValuePair <int, int> [te.Output.Length];
            for (var i = 0; i < te.Output.Length; i++)
            {
                KeyValuePair <int, int> kvp;
                if (te.Output[i] != null)
                {
                    kvp = new KeyValuePair <int, int> (te.Output [i].itemValue.type, te.Output [i].count);
                }
                else
                {
                    kvp = new KeyValuePair <int, int> (0, 0);
                }
                output[i] = kvp;
            }

            //Log.Out ("QUEUE");
            recipes = new KeyValuePair <int, int> [te.Queue.Length];
            for (var i = 0; i < te.Queue.Length; i++)
            {
                KeyValuePair <int, int> kvp;
                if (te.Queue [i] != null && te.Queue[i].Recipe != null)
                {
                    kvp = new KeyValuePair <int, int> (te.Queue [i].Recipe.itemValueType, te.Queue [i].Multiplier);
                }
                else
                {
                    kvp = new KeyValuePair <int, int> (0, 0);
                }

                recipes[i] = kvp;
            }
        }
        public TEWorkstationChangedHandler(TileEntityWorkstation te)
        {
            //inputMaterials = new KeyValuePair<int, int>[te.MaterialNames.Length];

            SetHistory(te);
        }