Пример #1
0
        public bool TryConstruct(IWorldAccessor world, BlockPos pos, CollectibleObject obj, IPlayer player)
        {
            int stage = Stage;

            if (obj.Attributes?["firepitConstructable"]?.AsBool(false) != true)
            {
                return(false);
            }

            CombustibleProperties combprops = obj.CombustibleProps;

            if (stage == 5)
            {
                return(false);
            }

            if (stage == 4 && world.BlockAccessor.GetBlock(pos.DownCopy()).Code.Path.Equals("firewoodpile"))
            {
                Block charcoalPitBlock = world.GetBlock(new AssetLocation("charcoalpit"));
                if (charcoalPitBlock != null)
                {
                    world.BlockAccessor.SetBlock(charcoalPitBlock.BlockId, pos);

                    BlockEntityCharcoalPit be = world.BlockAccessor.GetBlockEntity(pos) as BlockEntityCharcoalPit;
                    be?.Init(player);

                    return(true);
                }
            }

            Block block = world.GetBlock(CodeWithParts(NextStageCodePart));

            world.BlockAccessor.ExchangeBlock(block.BlockId, pos);
            world.BlockAccessor.MarkBlockDirty(pos);
            if (block.Sounds != null)
            {
                world.PlaySoundAt(block.Sounds.Place, pos.X, pos.Y, pos.Z, player);
            }

            if (stage == 4)
            {
                BlockEntity be = world.BlockAccessor.GetBlockEntity(pos);
                if (be is BlockEntityFirepit)
                {
                    ((BlockEntityFirepit)be).igniteWithFuel(combprops, 4);
                }
            }

            return(true);
        }
Пример #2
0
        private bool canSmelt()
        {
            CombustibleProperties fuelCopts = fuelCombustibleOpts;

            if (fuelCopts == null)
            {
                return(false);
            }
            bool smeltableInput = canHeatInput();

            return
                ((BurnsAllFuell || smeltableInput)
                 // Require fuel
                 && fuelCopts.BurnTemperature * HeatModifier > 0);
            //&& fuelCopts.BurnTemperature.Equals(0f); // not sure but it stop it override my BurnTemperature for now.
        }
Пример #3
0
        private bool canSmelt()
        {
            CombustibleProperties fuelCopts = fuelCombustibleOpts;

            if (fuelCopts == null)
            {
                return(false);
            }

            bool smeltableInput = canHeatInput();

            return
                ((BurnsAllFuell || smeltableInput)
                 // Require fuel
                 && fuelCopts.BurnTemperature * HeatModifier > 0
                );
        }
Пример #4
0
        public string GetOutputText(IWorldAccessor world, ISlotProvider cookingSlotsProvider, ItemSlot inputSlot)
        {
            if (inputSlot.Itemstack == null)
            {
                return(null);
            }

            if (inputSlot.Itemstack.Collectible is BlockSmeltingContainer)
            {
                BlockSmeltingContainer bsc = (BlockSmeltingContainer)inputSlot.Itemstack.Collectible;

                ItemStack[] stacks = bsc.GetIngredients(world, cookingSlotsProvider);

                for (int i = 0; i < stacks.Length; i++)
                {
                    CombustibleProperties props = stacks[i]?.Collectible.CombustibleProps;
                    if (props != null && !props.RequiresContainer)
                    {
                        return(null);
                    }
                }

                AlloyRecipe alloy = bsc.GetMatchingAlloy(world, stacks);

                if (alloy != null)
                {
                    double quantity = alloy.GetTotalOutputQuantity(stacks);
                    return(string.Format("Will create {0} units of {1}", (int)Math.Round(quantity * 100, 4), CheapMetalNameHax(alloy.Output.ResolvedItemstack)));
                }

                MatchedSmeltableStack match = GetSingleSmeltableStack(stacks);
                if (match != null)
                {
                    return(string.Format("Will create {0} units of {1}", (int)Math.Round(match.stackSize * 100, 4), CheapMetalNameHax(match.output)));
                }

                return(null);
            }

            return(null);
        }
Пример #5
0
        public bool Construct(IWorldAccessor world, BlockPos pos, CombustibleProperties props)
        {
            int stage = this.Stage;

            switch (stage)
            {
            case 4:
                if (((AssetLocation)((CollectibleObject)world.BlockAccessor.GetBlock(pos.DownCopy(1))).Code).Path.Equals("firewoodpile"))
                {
                    Block block = world.GetBlock(new AssetLocation("charcoalpit"));
                    if (block != null)
                    {
                        world.BlockAccessor.SetBlock((ushort)block.BlockId, pos);
                        return(true);
                    }
                    break;
                }
                break;

            case 5:
                return(false);
            }
            Block block1 = world.GetBlock(((CollectibleObject)this).CodeWithParts(new string[1]
            {
                this.NextStageCodePart
            }));

            world.BlockAccessor.ExchangeBlock((ushort)block1.BlockId, pos);
            world.BlockAccessor.MarkBlockDirty(pos);
            if (block1.Sounds != null)
            {
                world.PlaySoundAt((AssetLocation)((BlockSounds)block1.Sounds).Place, (double)pos.X, (double)pos.Y, (double)pos.Z, (IPlayer)null, true, 32f, 1f);
            }
            if (stage == 4)
            {
                BlockEntity blockEntity = world.BlockAccessor.GetBlockEntity(pos);
                // if (blockEntity is BlockEntityFirepit)
                //  ((BlockEntityFirepit) blockEntity).igniteWithFuel(props, 4f);
            }
            return(true);
        }
Пример #6
0
        public override void GetHeldItemInfo(ItemSlot inSlot, StringBuilder dsc, IWorldAccessor world, bool withDebugInfo)
        {
            if (CombustibleProps?.SmeltedStack == null)
            {
                base.GetHeldItemInfo(inSlot, dsc, world, withDebugInfo);
                return;
            }

            CombustibleProperties props = CombustibleProps;

            base.GetHeldItemInfo(inSlot, dsc, world, withDebugInfo);

            string smelttype    = CombustibleProps.SmeltingType.ToString().ToLowerInvariant();
            int    instacksize  = CombustibleProps.SmeltedRatio;
            int    outstacksize = CombustibleProps.SmeltedStack.ResolvedItemstack.StackSize;
            float  units        = outstacksize * 100f / instacksize;

            string metalname = CombustibleProps.SmeltedStack.ResolvedItemstack.GetName().Replace(" ingot", "");

            string str = Lang.Get("game:smeltdesc-" + smelttype + "ore-plural", units.ToString("0.#"), metalname);

            dsc.AppendLine(str);
        }
Пример #7
0
        public ItemStack getSmeltedOre(IItemSlot oreSlot)
        {
            if (oreSlot.Itemstack == null)
            {
                return(null);
            }

            CombustibleProperties compustibleOpts = oreSlot.Itemstack.Collectible.CombustibleProps;

            if (compustibleOpts == null)
            {
                return(null);
            }

            ItemStack smelted = compustibleOpts.SmeltedStack.ResolvedItemstack.Clone();

            if (compustibleOpts.MeltingPoint <= MaxTemperature)
            {
                return(smelted);
            }

            return(null);
        }
Пример #8
0
        public override bool CanSmelt(IWorldAccessor world, ISlotProvider cookingSlotsProvider, ItemStack inputStack, ItemStack outputStack)
        {
            ItemStack[] stacks = GetIngredients(world, cookingSlotsProvider);

            // Got alloy?
            if (GetMatchingAlloy(world, stacks) != null)
            {
                return(true);
            }

            for (int i = 0; i < stacks.Length; i++)
            {
                CombustibleProperties props = stacks[i]?.Collectible.CombustibleProps;
                if (props != null && !props.RequiresContainer)
                {
                    return(false);
                }
            }

            MatchedSmeltableStack match = GetSingleSmeltableStack(stacks);

            return(match != null);
        }
Пример #9
0
        protected virtual void OnBurnTick(float dt)
        {
            dt *= 1.25f;   //slight speedup because everything just felt too slow...

            // Only tick on the server and merely sync to client
            if (Api is ICoreClientAPI)
            {
                // TODO: maybe update rendered transitions gradually?  similar to renderer?.contentStackRenderer?.OnUpdate(InputStackTemp);
                return;
            }

            // Use up fuel
            if (fuelBurnTime > 0)
            {
                fuelBurnTime -= dt;

                if (fuelBurnTime <= 0)
                {
                    fuelBurnTime = 0;
                    burning      = false;
                    CombustibleProperties props = FuelSlot.Itemstack.Collectible.CombustibleProps;
                    if (props?.SmeltedStack == null)
                    {
                        FuelSlot.Itemstack = null;
                        for (int i = 0; i < itemCapacity; i++)
                        {
                            bakingData[i].CurHeightMul = 1;
                        }
                    }
                    else
                    {
                        // Allows for wood ash inserted by mods (for example, LazyWarlock's Tweaks)
                        int count = FuelSlot.StackSize;
                        FuelSlot.Itemstack           = props.SmeltedStack.ResolvedItemstack.Clone();
                        FuelSlot.Itemstack.StackSize = count * props.SmeltedRatio;
                    }
                    MarkDirty(true);
                }
            }

            // Heat furnace slowly if fire is burning, or else cool down very slowly
            if (IsBurning)
            {
                ovenTemperature = ChangeTemperature(ovenTemperature, maxTemperature, dt * FuelSlot.StackSize / fuelitemCapacity);
            }
            else
            {
                int environmentTemperature = EnvironmentTemperature();
                if (ovenTemperature > environmentTemperature)
                {
                    HeatInput(dt);
                    ovenTemperature = ChangeTemperature(ovenTemperature, environmentTemperature, dt / 24f);
                }
            }


            // Sync to client every 500ms
            if (++syncCount % 5 == 0 && (IsBurning || prevOvenTemperature != ovenTemperature || !Inventory.Empty))
            {
                MarkDirty();
                prevOvenTemperature = ovenTemperature;
            }
        }
Пример #10
0
        internal bool OnPlayerInteract(IWorldAccessor world, IPlayer byPlayer, BlockSelection blockSel)
        {
            ItemSlot slot = byPlayer.InventoryManager.ActiveHotbarSlot;

            if (!byPlayer.Entity.Controls.Sneak)
            {
                if (contents == null)
                {
                    return(false);
                }
                ItemStack split = contents.Clone();
                split.StackSize = 1;
                contents.StackSize--;

                if (contents.StackSize == 0)
                {
                    contents = null;
                }

                if (!byPlayer.InventoryManager.TryGiveItemstack(split))
                {
                    world.SpawnItemEntity(split, Pos.ToVec3d().Add(0.5, 0.5, 0.5));
                }

                renderer?.SetContents(contents, stackRenderHeight, burning, true);
                MarkDirty(true);
                Api.World.PlaySoundAt(new AssetLocation("sounds/block/ingot"), Pos.X, Pos.Y, Pos.Z, byPlayer, false);

                return(true);
            }
            else
            {
                if (slot.Itemstack == null)
                {
                    return(false);
                }

                // Add fuel
                CombustibleProperties combprops = slot.Itemstack.Collectible.CombustibleProps;
                if (combprops != null && combprops.BurnTemperature > 1000)
                {
                    (Api as ICoreClientAPI)?.World.Player.TriggerFpAnimation(EnumHandInteract.HeldItemInteract);

                    renderer?.SetContents(contents, stackRenderHeight, burning, false);
                    MarkDirty(true);

                    if (byPlayer.WorldData.CurrentGameMode != EnumGameMode.Creative)
                    {
                        slot.TakeOut(1);
                        slot.MarkDirty();
                    }


                    return(true);
                }


                string firstCodePart   = slot.Itemstack.Collectible.FirstCodePart();
                bool   forgableGeneric = slot.Itemstack.Collectible.Attributes?.IsTrue("forgable") == true;

                // Add heatable item
                if (contents == null && (firstCodePart == "ingot" || firstCodePart == "metalplate" || firstCodePart == "workitem" || forgableGeneric))
                {
                    contents           = slot.Itemstack.Clone();
                    contents.StackSize = 1;

                    slot.TakeOut(1);
                    slot.MarkDirty();

                    renderer?.SetContents(contents, stackRenderHeight, burning, true);
                    MarkDirty();
                    Api.World.PlaySoundAt(new AssetLocation("sounds/block/ingot"), Pos.X, Pos.Y, Pos.Z, byPlayer, false);

                    return(true);
                }

                // Merge heatable item
                if (!forgableGeneric && contents != null && contents.Equals(Api.World, slot.Itemstack, GlobalConstants.IgnoredStackAttributes) && contents.StackSize < maxItems && contents.StackSize < contents.Collectible.MaxStackSize)
                {
                    float myTemp  = contents.Collectible.GetTemperature(Api.World, contents);
                    float histemp = slot.Itemstack.Collectible.GetTemperature(Api.World, slot.Itemstack);

                    contents.Collectible.SetTemperature(world, contents, (myTemp * contents.StackSize + histemp * 1) / (contents.StackSize + 1));
                    contents.StackSize++;

                    slot.TakeOut(1);
                    slot.MarkDirty();

                    renderer?.SetContents(contents, stackRenderHeight, burning, true);
                    Api.World.PlaySoundAt(new AssetLocation("sounds/block/ingot"), Pos.X, Pos.Y, Pos.Z, byPlayer, false);

                    MarkDirty();
                    return(true);
                }

                return(false);
            }
        }
Пример #11
0
            public void OnTick(float par)
            {
                //Check for container
                BlockPos contPos = new BlockPos(Pos.X, Pos.Y + 1, Pos.Z);

                checkblock = Api.World.BlockAccessor.GetBlockEntity(contPos);
                //if (checkblock == null) { return; } //no container no point running

                var inputContainer = checkblock as BlockEntityContainer;

                if (inputContainer == null)
                {
                    return;
                }

                BlockPos[] checksides =
                {
                    new BlockPos(Pos.X - 1, Pos.Y, Pos.Z),
                    new BlockPos(Pos.X + 1, Pos.Y, Pos.Z),
                    new BlockPos(Pos.X,     Pos.Y, Pos.Z + 1),
                    new BlockPos(Pos.X,     Pos.Y, Pos.Z - 1)
                };

                foreach (BlockPos checkPos in checksides)
                {
                    //try to find a firepit
                    checkblock = Api.World.BlockAccessor.GetBlockEntity(checkPos);
                    //Nothing at firepit location, nothing we can do, there is no point, good day sir!

                    var firepit = checkblock as BlockEntityFirepit;
                    //NO Firepit then you musta quit
                    if (firepit == null)
                    {
                        continue;
                    }
                    if (firepit.fuelSlot == null)
                    {
                        continue;
                    }
                    if (firepit.fuelSlot.StackSize > 0)
                    {
                        if (!firepit.canIgniteFuel && !firepit.IsBurning)
                        {
                            CollectibleObject cob = firepit.fuelSlot.Itemstack.Collectible;
                            if (cob == null)
                            {
                                continue;
                            }
                            CombustibleProperties cpr = cob.CombustibleProps;
                            if (cpr == null)
                            {
                                continue;
                            }
                            firepit.igniteFuel();
                        }
                        continue;
                    }

                    //check if firepit needs fuel - is it cooking something, or has a heat using generator above it
                    bool     dofuel            = false;
                    BlockPos checkforgenerator = checkPos.UpCopy();
                    checkblock = Api.World.BlockAccessor.GetBlockEntity(checkforgenerator);
                    var generator = checkblock as BEEGenerator;
                    if (generator != null)
                    {
                        if (generator.IsOn && generator.RequiresHeat)
                        {
                            dofuel = true;
                        }
                    }
                    if (firepit.inputSlot != null && firepit.inputSlot.StackSize > 0)
                    {
                        dofuel = true;
                    }
                    if (!dofuel)
                    {
                        continue;
                    }

                    //IF fuel is in the fuelSlot don't bother

                    //TODO figure out how to keep firepit lit, also figure out how to verify fuel
                    //OK looks like we need fuel, attempt to add a piece
                    ItemSlot sourceSlot = inputContainer.Inventory.GetAutoPullFromSlot(BlockFacing.DOWN);
                    if (sourceSlot == null)
                    {
                        continue;
                    }

                    //check if slot contains fuel
                    CollectibleObject co = sourceSlot.Itemstack.Collectible;
                    if (co == null)
                    {
                        continue;
                    }
                    CombustibleProperties cp = co.CombustibleProps;
                    if (cp == null)
                    {
                        continue;
                    }

                    int quantity = 1;
                    ItemStackMoveOperation op = new ItemStackMoveOperation(Api.World, EnumMouseButton.Left, 0, EnumMergePriority.DirectMerge, quantity);

                    int qmoved = sourceSlot.TryPutInto(firepit.fuelSlot, ref op);
                    firepit.fuelSlot.MarkDirty();
                    sourceSlot.MarkDirty();
                }
            }
Пример #12
0
        internal bool OnPlayerInteract(IWorldAccessor world, IPlayer byPlayer, BlockSelection blockSel)
        {
            IItemSlot slot = byPlayer.InventoryManager.ActiveHotbarSlot;

            if (!byPlayer.Entity.Controls.Sneak)
            {
                if (contents == null)
                {
                    return(false);
                }
                ItemStack split = contents.Clone();
                split.StackSize = 1;
                contents.StackSize--;

                if (contents.StackSize == 0)
                {
                    contents = null;
                }

                //api.World.Logger.Notification("Forge item retrieve temp: {0}, side {1}", split.Collectible.GetTemperature(api.World, split), api.Side);

                if (!byPlayer.InventoryManager.TryGiveItemstack(split))
                {
                    world.SpawnItemEntity(contents, pos.ToVec3d().Add(0.5, 0.5, 0.5));
                }

                renderer?.SetContents(contents, fuelLevel, burning, true);
                MarkDirty();
                api.World.PlaySoundAt(new AssetLocation("sounds/block/ingot"), pos.X, pos.Y, pos.Z, byPlayer, false);

                return(true);
            }
            else
            {
                if (slot.Itemstack == null)
                {
                    return(false);
                }

                // Add fuel
                CombustibleProperties combprops = slot.Itemstack.Collectible.CombustibleProps;
                if (combprops != null && combprops.BurnTemperature > 1000)
                {
                    if (fuelLevel >= 10 / 16f)
                    {
                        return(false);
                    }
                    fuelLevel += 1 / 16f;

                    renderer?.SetContents(contents, fuelLevel, burning, false);
                    MarkDirty();

                    slot.TakeOut(1);
                    slot.MarkDirty();


                    return(true);
                }


                string firstCodePart = slot.Itemstack.Collectible.FirstCodePart();

                // Add heatable item
                if (contents == null && (firstCodePart == "ingot" || firstCodePart == "metalplate" || firstCodePart == "workitem"))
                {
                    contents           = slot.Itemstack.Clone();
                    contents.StackSize = 1;

                    slot.TakeOut(1);
                    slot.MarkDirty();

                    renderer?.SetContents(contents, fuelLevel, burning, true);
                    MarkDirty();
                    api.World.PlaySoundAt(new AssetLocation("sounds/block/ingot"), pos.X, pos.Y, pos.Z, byPlayer, false);

                    return(true);
                }

                // Merge heatable item
                if (contents != null && contents.Equals(api.World, slot.Itemstack, GlobalConstants.IgnoredStackAttributes) && contents.StackSize < 4 && contents.StackSize < contents.Collectible.MaxStackSize)
                {
                    float myTemp  = contents.Collectible.GetTemperature(api.World, contents);
                    float histemp = slot.Itemstack.Collectible.GetTemperature(api.World, slot.Itemstack);

                    contents.Collectible.SetTemperature(world, contents, (myTemp * contents.StackSize + histemp * 1) / (contents.StackSize + 1));
                    contents.StackSize++;

                    slot.TakeOut(1);
                    slot.MarkDirty();

                    renderer?.SetContents(contents, fuelLevel, burning, true);
                    api.World.PlaySoundAt(new AssetLocation("sounds/block/ingot"), pos.X, pos.Y, pos.Z, byPlayer, false);

                    MarkDirty();
                    return(true);
                }

                return(false);
            }
        }