Esempio n. 1
0
    public override void Initialize(ICoreAPI api)
    {
        base.Initialize(api);
        Api = api;

        pvBh = GetBehavior <BEBehaviorTFRotaryGenerator>();

        if (api.World.Side == EnumAppSide.Server)
        {
            RegisterGameTickListener(tick, 100);
        }

        if (energyStorage == null)
        {
            energyStorage = new FluxStorage(MyMiniLib.GetAttributeInt(Block, "storage", 10000), 0, MyMiniLib.GetAttributeInt(Block, "output", 500));
        }

        maxgenerate = MyMiniLib.GetAttributeInt(Block, "maxgenerate", 200);
        maxspeed    = MyMiniLib.GetAttributeInt(Block, "maxspeed", 5);

        Facing = BlockFacing.FromCode(Block.Variant["side"]);
        if (Facing == null)
        {
            Facing = BlockFacing.NORTH;
        }
    }
Esempio n. 2
0
    public override void Initialize(ICoreAPI api)
    {
        base.Initialize(api);
        if (contents != null)
        {
            contents.ResolveBlockOrItem(api.World);
        }

        if (energyStorage == null)
        {
            energyStorage = new FluxStorage(MyMiniLib.GetAttributeInt(Block, "storage", 10000), MyMiniLib.GetAttributeInt(Block, "input", 1000), 0);
        }

        if (api is ICoreClientAPI)
        {
            ICoreClientAPI capi = (ICoreClientAPI)api;
            capi.Event.RegisterRenderer(renderer = new TFForgeContentsRenderer(Pos, capi), EnumRenderStage.Opaque, "tfforge");
            renderer.SetContents(contents, burning, true);

            RegisterGameTickListener(OnClientTick, 500);
        }

        consume = MyMiniLib.GetAttributeInt(Block, "consume", 500);

        wsys = api.ModLoader.GetModSystem <WeatherSystemBase>();

        if (api.Side.IsServer())
        {
            RegisterGameTickListener(OnCommonTick, 250);
        }
    }
Esempio n. 3
0
    public override void OnLoaded(ICoreAPI api)
    {
        face     = BlockFacing.FromCode(Variant["side"]);
        transfer = MyMiniLib.GetAttributeInt(this, "transfer", transfer);

        base.OnLoaded(api);
    }
Esempio n. 4
0
    public override void FromTreeAttributes(ITreeAttribute tree, IWorldAccessor worldForResolving)
    {
        base.FromTreeAttributes(tree, worldForResolving);

        contents           = tree.GetItemstack("contents");
        burning            = tree.GetInt("burning") > 0;
        lastTickTotalHours = tree.GetDouble("lastTickTotalHours");

        if (Api != null)
        {
            if (contents != null)
            {
                contents.ResolveBlockOrItem(Api.World);
            }
        }
        if (renderer != null)
        {
            renderer.SetContents(contents, burning, true);
        }

        if (energyStorage == null)
        {
            energyStorage = new FluxStorage(MyMiniLib.GetAttributeInt(Block, "storage", 10000), MyMiniLib.GetAttributeInt(Block, "input", 1000), 0);
        }
        energyStorage.setEnergy(tree.GetFloat("energy"));
    }
Esempio n. 5
0
    public override void OnLoaded(ICoreAPI api)
    {
        powerOutFacing = BlockFacing.FromCode(Variant["side"]).Opposite;
        consume        = MyMiniLib.GetAttributeInt(this, "consume", consume);

        base.OnLoaded(api);
    }
Esempio n. 6
0
    protected void transferEnergy(BlockFacing side, float dt)
    {
        BlockPos    outPos     = Pos.Copy().Offset(side);
        BlockEntity tileEntity = Api.World.BlockAccessor.GetBlockEntity(outPos);

        if (tileEntity == null)
        {
            return;
        }
        if (!(tileEntity is IFluxStorage))
        {
            return;
        }
        if (tileEntity is IEnergyPoint && ((IEnergyPoint)tileEntity).GetCore() == GetCore())
        {
            return;
        }
        float eout = Math.Min(MyMiniLib.GetAttributeInt(Block, "transfer", 500) * dt, core.storage.getEnergyStored() * dt);

        eout = ((IFluxStorage)tileEntity).receiveEnergy(side.Opposite, eout, false, dt);
        if (tileEntity is IEnergyPoint && eout > 0)
        {
            ((IEnergyPoint)tileEntity).AddSkipSide(side.Opposite);
        }
        core.storage.modifyEnergyStored(-eout);
    }
Esempio n. 7
0
 public float receiveEnergy(BlockFacing from, float maxReceive, bool simulate, float dt)
 {
     if (from == null || sideConfig[from] == IOEnergySideConfig.INPUT)
     {
         return(energyStorage.receiveEnergy(Math.Min(MyMiniLib.GetAttributeInt(Block, "transfer", 10000) * dt, maxReceive), simulate, dt));
     }
     return(0);
 }
Esempio n. 8
0
    public override void OnLoaded(ICoreAPI api)
    {
        base.OnLoaded(api);

        maxCapacity = MyMiniLib.GetAttributeInt(this, "storage", maxCapacity);
        transfer    = MyMiniLib.GetAttributeInt(this, "output", transfer);
        Durability  = 100;
    }
Esempio n. 9
0
    public override void OnLoaded(ICoreAPI api)
    {
        base.OnLoaded(api);

        consume    = MyMiniLib.GetAttributeInt(this, "consume", consume);
        storage    = MyMiniLib.GetAttributeInt(this, "storage", storage);
        Durability = storage / consume;
    }
Esempio n. 10
0
    public override void FromTreeAttributes(ITreeAttribute tree, IWorldAccessor worldForResolving)
    {
        base.FromTreeAttributes(tree, worldForResolving);

        if (energyStorage == null)
        {
            energyStorage = new FluxStorage(MyMiniLib.GetAttributeInt(Block, "storage", 10000), MyMiniLib.GetAttributeInt(Block, "input", 10000), 0);
        }
        energyStorage.setEnergy(tree.GetFloat("energy", 0));
    }
Esempio n. 11
0
 public float receiveEnergy(BlockFacing from, float maxReceive, bool simulate, float dt)
 {
     if (from == powerOutFacing)
     {
         return(core.storage.receiveEnergy(Math.Min(maxReceive, MyMiniLib.GetAttributeInt(Block, "transfer", 500) * dt), simulate, dt));
     }
     else
     {
         return(0);
     }
 }
Esempio n. 12
0
    //public override void GetBlockInfo(IPlayer forPlayer, StringBuilder dsc)
    //{
    //    base.GetBlockInfo(forPlayer, dsc);
    //    if (energyStorage != null)
    //    {
    //        dsc.AppendLine(energyStorage.GetFluxStorageInfo());
    //    }
    //}

    public override void FromTreeAttributes(ITreeAttribute tree, IWorldAccessor worldForResolving)
    {
        base.FromTreeAttributes(tree, worldForResolving);

        if (energyStorage == null)
        {
            energyStorage = new FluxStorage(MyMiniLib.GetAttributeInt(Block, "transfer", 10000), MyMiniLib.GetAttributeInt(Block, "transfer", 10000), MyMiniLib.GetAttributeInt(Block, "transfer", 10000));
        }
        energyStorage.setEnergy(tree.GetFloat("energy"));
        state = tree.GetBool("state", false);
    }
Esempio n. 13
0
    public override void FromTreeAttributes(ITreeAttribute tree, IWorldAccessor worldForResolving)
    {
        base.FromTreeAttributes(tree, worldForResolving);

        if (energyStorage == null)
        {
            energyStorage = new FluxStorage(MyMiniLib.GetAttributeInt(Block, "storage", 10000), 0, MyMiniLib.GetAttributeInt(Block, "output", 500));
        }
        energyStorage.setEnergy(tree.GetFloat("energy"));
        if (Api != null && Api.World.Side == EnumAppSide.Client)
        {
            generation = tree.GetFloat("gen");
        }
    }
Esempio n. 14
0
    public override void Initialize(ICoreAPI api)
    {
        base.Initialize(api);
        Api  = api;
        face = BlockFacing.FromCode(Block.Variant["side"]);

        if (api.World.Side == EnumAppSide.Server)
        {
            RegisterGameTickListener(tick, 250);
        }

        if (energyStorage == null)
        {
            energyStorage = new FluxStorage(MyMiniLib.GetAttributeInt(Block, "transfer", 10000), MyMiniLib.GetAttributeInt(Block, "transfer", 10000), MyMiniLib.GetAttributeInt(Block, "transfer", 10000));
        }
        if (sideConfig.Count == 0)
        {
            string[] splitedPath = Block.Code.ToString().Split('-');
            if (splitedPath.Length >= 6)
            {
                foreach (BlockFacing f in BlockFacing.ALLFACES)
                {
                    if (splitedPath[splitedPath.Length - 6 + f.Index] == IOEnergySideConfig.INPUT.toString())
                    {
                        sideConfig.Add(f, IOEnergySideConfig.INPUT);
                    }
                    else if (splitedPath[splitedPath.Length - 6 + f.Index] == IOEnergySideConfig.OUTPUT.toString())
                    {
                        sideConfig.Add(f, IOEnergySideConfig.OUTPUT);
                    }
                    else
                    {
                        sideConfig.Add(f, IOEnergySideConfig.NONE);
                    }
                }
            }
            else
            {
                foreach (BlockFacing f in BlockFacing.ALLFACES)
                {
                    sideConfig.Add(f, IOEnergySideConfig.NONE);
                }
            }
        }
        if (face != null)
        {
            sideConfig[face] = IOEnergySideConfig.NONE;
        }
    }
Esempio n. 15
0
    public override void Initialize(ICoreAPI api)
    {
        base.Initialize(api);

        if (energyStorage == null)
        {
            energyStorage = new FluxStorage(MyMiniLib.GetAttributeInt(Block, "storage", 10000), MyMiniLib.GetAttributeInt(Block, "input", 1000), 0);
        }

        inventory.pos = Pos;
        inventory.LateInitialize("smelting-" + Pos.X + "/" + Pos.Y + "/" + Pos.Z, api);

        RegisterGameTickListener(OnBurnTick, 250);
        RegisterGameTickListener(On500msTick, 500);
    }
Esempio n. 16
0
    public override void Initialize(ICoreAPI api)
    {
        base.Initialize(api);

        if (energyStorage == null)
        {
            energyStorage = new FluxStorage(MyMiniLib.GetAttributeInt(Block, "storage", 10000), MyMiniLib.GetAttributeInt(Block, "input", 10000), 0);
        }

        consume = MyMiniLib.GetAttributeInt(Block, "consume", 1000);

        if (Api.Side.IsServer())
        {
            RegisterGameTickListener(OnServerTick, 250);
        }
    }
Esempio n. 17
0
    public override void OnLoaded(ICoreAPI api)
    {
        if (api.Side != EnumAppSide.Client)
        {
            return;
        }
        ICoreClientAPI capi = api as ICoreClientAPI;

        output = MyMiniLib.GetAttributeInt(this, "output", output);

        interactions = ObjectCacheUtil.GetOrCreate(api, "chargerBlockInteractions", () =>
        {
            List <ItemStack> rackableStacklist = new List <ItemStack>();

            foreach (CollectibleObject obj in api.World.Collectibles)
            {
                if (obj.Attributes?["rechargeable"].AsBool() != true)
                {
                    continue;
                }

                List <ItemStack> stacks = obj.GetHandBookStacks(capi);
                if (stacks != null)
                {
                    rackableStacklist.AddRange(stacks);
                }
            }

            return(new WorldInteraction[] {
                new WorldInteraction()
                {
                    ActionLangCode = "blockhelp-toolrack-place",
                    HotKeyCode = null,
                    MouseButton = EnumMouseButton.Right,
                    Itemstacks = rackableStacklist.ToArray()
                },
                new WorldInteraction()
                {
                    ActionLangCode = "blockhelp-toolrack-take",
                    HotKeyCode = null,
                    MouseButton = EnumMouseButton.Right,
                }
            });
        });
    }
Esempio n. 18
0
    public override void OnLoaded(ICoreAPI api)
    {
        base.OnLoaded(api);

        transfer = MyMiniLib.GetAttributeInt(this, "transfer", transfer);

        interactions = ObjectCacheUtil.GetOrCreate(api, "wireconnectInteractions", () =>
        {
            return(new WorldInteraction[]
            {
                new WorldInteraction()
                {
                    ActionLangCode = "blockhelp-temporalengineering-wireconnect",
                    MouseButton = EnumMouseButton.Right,
                    Itemstacks = new ItemStack[] { new ItemStack(api.World.GetItem(new AssetLocation("temporalengineering:wire-copper"))) }
                },
            });
        });
    }
Esempio n. 19
0
    protected void transferEnergy(BlockFacing side, float dt)
    {
        if (sideConfig[side] != IOEnergySideConfig.OUTPUT)
        {
            return;
        }
        BlockPos    outPos     = Pos.Copy().Offset(side);
        BlockEntity tileEntity = Api.World.BlockAccessor.GetBlockEntity(outPos);

        if (tileEntity == null)
        {
            return;
        }
        if (!(tileEntity is IFluxStorage))
        {
            return;
        }
        float eout = Math.Min(MyMiniLib.GetAttributeInt(Block, "transfer", 10000) * dt, energyStorage.getEnergyStored() * dt);

        energyStorage.modifyEnergyStored(-((IFluxStorage)tileEntity).receiveEnergy(side.Opposite, eout, false, dt));
    }
Esempio n. 20
0
    public override void Initialize(ICoreAPI api)
    {
        base.Initialize(api);

        if (energyStorage == null)
        {
            energyStorage = new FluxStorage(MyMiniLib.GetAttributeInt(Block, "storage", 10000), MyMiniLib.GetAttributeInt(Block, "input", 1000), MyMiniLib.GetAttributeInt(Block, "output", 1000));
        }

        inventory.LateInitialize("charger-" + Pos.ToString(), api);
        inventory.ResolveBlocksOrItems();

        if (api is ICoreClientAPI)
        {
            loadToolMeshes();
        }
        else
        {
            RegisterGameTickListener(OnTick, 250);
        }
    }
Esempio n. 21
0
 public void InitializeEnergyPoint(ICoreAPI api)
 {
     if (api.World.Side == EnumAppSide.Server)
     {
         foreach (BlockFacing face in BlockFacing.ALLFACES)
         {
             BlockPos pos = Pos.AddCopy(face);
             BlockEntityEnergyDuct block = api.World.BlockAccessor.GetBlockEntity(pos) as BlockEntityEnergyDuct;
             if (block != null)
             {
                 if (core == null)
                 {
                     if (block.core == null)
                     {
                         core = new EnergyDuctCore(MyMiniLib.GetAttributeInt(Block, "transfer", 500));
                         core.ducts.Add(this);
                     }
                     else
                     {
                         core = block.core;
                         core.ducts.Add(this);
                     }
                 }
                 else
                 {
                     if (core != block.core && block.core != null)
                     {
                         core = core.CombineCores(block.core);
                     }
                 }
             }
         }
         if (core == null)
         {
             core = new EnergyDuctCore(MyMiniLib.GetAttributeInt(Block, "transfer", 500));
             core.ducts.Add(this);
         }
     }
 }
Esempio n. 22
0
    public override void FromTreeAttributes(ITreeAttribute tree, IWorldAccessor worldForResolving)
    {
        base.FromTreeAttributes(tree, worldForResolving);
        inventory.FromTreeAttributes(tree.GetTreeAttribute("inventory"));
        if (Api != null)
        {
            inventory.Api = Api;
            inventory.ResolveBlocksOrItems();
        }

        if (Api is ICoreClientAPI)
        {
            loadToolMeshes();
            Api.World.BlockAccessor.MarkBlockDirty(Pos);
        }

        if (energyStorage == null)
        {
            energyStorage = new FluxStorage(MyMiniLib.GetAttributeInt(Block, "storage", 10000), MyMiniLib.GetAttributeInt(Block, "input", 1000), MyMiniLib.GetAttributeInt(Block, "output", 1000));
        }
        energyStorage.setEnergy(tree.GetFloat("energy"));
    }
Esempio n. 23
0
 public void InitializeEnergyPoint(ICoreAPI api)
 {
     if (api.World.Side == EnumAppSide.Server)
     {
         foreach (var kv in wiresList)
         {
             BlockEntityConnector block = api.World.BlockAccessor.GetBlockEntity(kv.Key) as BlockEntityConnector;
             if (block != null)
             {
                 if (core == null)
                 {
                     if (block.core == null)
                     {
                         core = new EnergyDuctCore(MyMiniLib.GetAttributeInt(Block, "transfer", 500));
                         core.ducts.Add(this);
                     }
                     else
                     {
                         core = block.core;
                         core.ducts.Add(this);
                     }
                 }
                 else
                 {
                     if (core != block.core && block.core != null)
                     {
                         core = core.CombineCores(block.core);
                     }
                 }
             }
         }
         if (core == null)
         {
             core = new EnergyDuctCore(MyMiniLib.GetAttributeInt(Block, "transfer", 500));
             core.ducts.Add(this);
         }
     }
 }
Esempio n. 24
0
    public override void FromTreeAttributes(ITreeAttribute tree, IWorldAccessor worldForResolving)
    {
        base.FromTreeAttributes(tree, worldForResolving);
        Inventory.FromTreeAttributes(tree.GetTreeAttribute("inventory"));

        if (Api != null)
        {
            Inventory.AfterBlocksLoaded(Api.World);
        }


        furnaceTemperature    = tree.GetFloat("furnaceTemperature");
        inputStackCookingTime = tree.GetFloat("oreCookingTime");

        if (Api != null)
        {
            if (Api.Side == EnumAppSide.Client)
            {
                if (clientDialog != null)
                {
                    SetDialogValues(clientDialog.Attributes);
                }
            }


            if (Api.Side == EnumAppSide.Client && clientSidePrevBurning != IsBurning)
            {
                clientSidePrevBurning = IsBurning;
                MarkDirty(true);
            }
        }

        if (energyStorage == null)
        {
            energyStorage = new FluxStorage(MyMiniLib.GetAttributeInt(Block, "storage", 10000), MyMiniLib.GetAttributeInt(Block, "input", 1000), 0);
        }
        energyStorage.setEnergy(tree.GetFloat("energy"));
    }
Esempio n. 25
0
    void SetDialogValues(ITreeAttribute dialogTree)
    {
        dialogTree.SetFloat("furnaceTemperature", furnaceTemperature);

        dialogTree.SetInt("maxTemperature", MyMiniLib.GetAttributeInt(Block, "maxheat", 1300));
        dialogTree.SetFloat("oreCookingTime", inputStackCookingTime);

        if (inputSlot.Itemstack != null)
        {
            float meltingDuration = inputSlot.Itemstack.Collectible.GetMeltingDuration(Api.World, inventory, inputSlot);

            dialogTree.SetFloat("oreTemperature", InputStackTemp);
            dialogTree.SetFloat("maxOreCookingTime", meltingDuration);
        }
        else
        {
            dialogTree.RemoveAttribute("oreTemperature");
        }

        dialogTree.SetString("outputText", inventory.GetOutputText());
        dialogTree.SetInt("haveCookingContainer", inventory.HaveCookingContainer ? 1 : 0);
        dialogTree.SetInt("quantityCookingSlots", inventory.CookingSlots.Length);
    }
Esempio n. 26
0
    public override void OnLoaded(ICoreAPI api)
    {
        transfer = MyMiniLib.GetAttributeInt(this, "transfer", transfer);

        base.OnLoaded(api);
    }
Esempio n. 27
0
    private void OnBurnTick(float dt)
    {
        // Only tick on the server and merely sync to client
        if (Api is ICoreClientAPI)
        {
            //renderer.contentStackRenderer.OnUpdate(InputStackTemp);
            return;
        }

        // Furnace is burning: Heat furnace
        if (IsBurning)
        {
            furnaceTemperature = changeTemperature(furnaceTemperature, MyMiniLib.GetAttributeInt(Block, "maxheat", 1300), dt);
        }

        // Ore follows furnace temperature
        if (canHeatInput())
        {
            heatInput(dt);
        }
        else
        {
            inputStackCookingTime = 0;
        }

        if (canHeatOutput())
        {
            heatOutput(dt);
        }


        // Finished smelting? Turn to smelted item
        if (canSmeltInput() && inputStackCookingTime > maxCookingTime())
        {
            smeltItems();
        }

        float consume = MyMiniLib.GetAttributeInt(Block, "consume", 300) * dt;

        if (energyStorage.getEnergyStored() >= consume)
        {
            energyStorage.modifyEnergyStored(-consume);

            if (!IsBurning)
            {
                IsBurning = true;

                Api.World.BlockAccessor.ExchangeBlock(Api.World.GetBlock(Block.CodeWithVariant("state", "lit")).BlockId, Pos);
                MarkDirty(true);
            }
        }
        else
        {
            if (IsBurning)
            {
                IsBurning = false;

                Api.World.BlockAccessor.ExchangeBlock(Api.World.GetBlock(Block.CodeWithVariant("state", "unlit")).BlockId, Pos);
                MarkDirty(true);
            }
        }


        // Furnace is not burning: Cool down furnace and ore also turn of fire
        if (!IsBurning)
        {
            furnaceTemperature = changeTemperature(furnaceTemperature, enviromentTemperature(), dt);
        }
    }
Esempio n. 28
0
    public override void OnLoaded(ICoreAPI api)
    {
        consume = MyMiniLib.GetAttributeInt(this, "consume", consume);

        base.OnLoaded(api);
    }
Esempio n. 29
0
    public override void OnLoaded(ICoreAPI api)
    {
        base.OnLoaded(api);

        consume = MyMiniLib.GetAttributeInt(this, "consume", consume);

        if (api.Side != EnumAppSide.Client)
        {
            return;
        }
        ICoreClientAPI capi = api as ICoreClientAPI;

        interactions = ObjectCacheUtil.GetOrCreate(api, "forgeBlockInteractions", () =>
        {
            List <ItemStack> heatableStacklist = new List <ItemStack>();
            List <ItemStack> fuelStacklist     = new List <ItemStack>();
            List <ItemStack> canIgniteStacks   = new List <ItemStack>();

            foreach (CollectibleObject obj in api.World.Collectibles)
            {
                string firstCodePart = obj.FirstCodePart();

                if (firstCodePart == "ingot" || firstCodePart == "metalplate" || firstCodePart == "workitem")
                {
                    List <ItemStack> stacks = obj.GetHandBookStacks(capi);
                    if (stacks != null)
                    {
                        heatableStacklist.AddRange(stacks);
                    }
                }
                else
                {
                    if (obj.CombustibleProps != null)
                    {
                        if (obj.CombustibleProps.BurnTemperature > 1000)
                        {
                            List <ItemStack> stacks = obj.GetHandBookStacks(capi);
                            if (stacks != null)
                            {
                                fuelStacklist.AddRange(stacks);
                            }
                        }
                    }
                }

                if (obj is Block && (obj as Block).HasBehavior <BlockBehaviorCanIgnite>())
                {
                    List <ItemStack> stacks = obj.GetHandBookStacks(capi);
                    if (stacks != null)
                    {
                        canIgniteStacks.AddRange(stacks);
                    }
                }
            }

            return(new WorldInteraction[] {
                new WorldInteraction()
                {
                    ActionLangCode = "blockhelp-forge-addworkitem",
                    HotKeyCode = "sneak",
                    MouseButton = EnumMouseButton.Right,
                    Itemstacks = heatableStacklist.ToArray(),
                    GetMatchingStacks = (wi, bs, es) =>
                    {
                        BlockEntityForge bef = api.World.BlockAccessor.GetBlockEntity(bs.Position) as BlockEntityForge;
                        if (bef != null && bef.Contents != null)
                        {
                            return wi.Itemstacks.Where(stack => stack.Equals(api.World, bef.Contents, GlobalConstants.IgnoredStackAttributes)).ToArray();
                        }
                        return wi.Itemstacks;
                    }
                },
                new WorldInteraction()
                {
                    ActionLangCode = "blockhelp-forge-takeworkitem",
                    HotKeyCode = null,
                    MouseButton = EnumMouseButton.Right,
                    Itemstacks = heatableStacklist.ToArray(),
                    GetMatchingStacks = (wi, bs, es) =>
                    {
                        BlockEntityForge bef = api.World.BlockAccessor.GetBlockEntity(bs.Position) as BlockEntityForge;
                        if (bef != null && bef.Contents != null)
                        {
                            return new ItemStack[] { bef.Contents };
                        }
                        return null;
                    }
                }
            });
        });
    }