示例#1
0
文件: BEEForge.cs 项目: wqpvs/qptech
        public override void Initialize(ICoreAPI api)
        {
            base.Initialize(api);

            if (contents != null)
            {
                contents.ResolveBlockOrItem(api.World);
            }
            if (Block.Attributes != null)
            {
                maxHeat           = Block.Attributes["maxHeat"].AsFloat(maxHeat);
                degreesPerHour    = Block.Attributes["degreesPerHour"].AsFloat(degreesPerHour);
                maxItems          = Block.Attributes["maxItems"].AsInt(maxItems);
                stackRenderHeight = Block.Attributes["stackRenderHeight"].AsFloat(stackRenderHeight);
                elementShapeName  = Block.Attributes["elementShapeName"].AsString(elementShapeName);
            }
            if (api is ICoreClientAPI)
            {
                ICoreClientAPI capi = (ICoreClientAPI)api;
                capi.Event.RegisterRenderer(renderer = new EForgeContentsRenderer(Pos, capi, elementShapeName), EnumRenderStage.Opaque, "forge");
                renderer.SetContents(contents, stackRenderHeight, (deviceState == enDeviceState.RUNNING), true);

                RegisterGameTickListener(OnClientTick, 50);
            }
            RegisterGameTickListener(OnCommonTick, 200);
        }
示例#2
0
文件: BEEForge.cs 项目: wqpvs/qptech
        public override void FromTreeAttributes(ITreeAttribute tree, IWorldAccessor worldForResolving)
        {
            base.FromTreeAttributes(tree, worldForResolving);

            contents = tree.GetItemstack("contents");

            lastTickTotalHours = tree.GetDouble("lastTickTotalHours");

            if (Api != null)
            {
                contents?.ResolveBlockOrItem(Api.World);
            }
            if (renderer != null)
            {
                renderer.SetContents(contents, stackRenderHeight, burning, true);
            }
        }
示例#3
0
文件: BEEForge.cs 项目: wqpvs/qptech
        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);
            }
        }