Exemple #1
0
        public override string GetPlacedBlockInfo(IWorldAccessor world, BlockPos pos, IPlayer forPlayer)
        {
            string text = "";

            float litres = GetCurrentLitres(pos);

            if (litres <= 0)
            {
                text = "";
            }

            BlockEntityCauld becauld = world.BlockAccessor.GetBlockEntity(pos) as BlockEntityCauld;

            if (becauld != null)
            {
                ItemSlot outslot = becauld.Inventory[5];
                ItemSlot inslot  = becauld.Inventory[6];
                if (text.Length > 0)
                {
                    text += "\n";
                }
                else
                {
                    text += Lang.Get("Contents:");
                }
                if (inslot.Empty && outslot.Empty)
                {
                    text += "\nEmpty";
                }
                else
                {
                    if (!outslot.Empty)
                    {
                        WaterTightContainableProps outprops = BlockLiquidContainerBase.GetContainableProps(outslot.Itemstack);
                        text += "\n" + Lang.Get("Potion out: {0} Litres of {1}", outslot.Itemstack.StackSize / outprops.ItemsPerLitre, outslot.Itemstack.GetName());
                    }

                    if (!inslot.Empty)
                    {
                        WaterTightContainableProps inprops = BlockLiquidContainerBase.GetContainableProps(inslot.Itemstack);
                        text += "\n" + Lang.Get("Potion in: {0} Litres of {1}", becauld.Inventory[6].Itemstack.StackSize / inprops.ItemsPerLitre, becauld.Inventory[6].Itemstack.GetName());
                    }
                    if (becauld.isFull)
                    {
                        text += "\nEmpty output to mix new potions";
                    }
                }
            }


            return(text);
        }
Exemple #2
0
        public override void OnLoaded(ICoreAPI api)
        {
            base.OnLoaded(api);

            if (Attributes?["capacityLitres"].Exists == true)
            {
                capacityLitresFromAttributes = Attributes["capacityLitres"].AsInt(50);
            }


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

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

                foreach (CollectibleObject obj in api.World.Collectibles)
                {
                    if (obj is ILiquidSource || obj is ILiquidSink || obj is BlockWateringCan)
                    {
                        List <ItemStack> stacks = obj.GetHandBookStacks(capi);
                        if (stacks != null)
                        {
                            liquidContainerStacks.AddRange(stacks);
                        }
                    }
                }

                ItemStack[] lstacks = liquidContainerStacks.ToArray();

                return(new WorldInteraction[] {
                    new WorldInteraction()
                    {
                        ActionLangCode = "blockhelp-bucket-rightclick",
                        MouseButton = EnumMouseButton.Right,
                        Itemstacks = lstacks,
                        GetMatchingStacks = (wi, bs, ws) =>
                        {
                            BlockEntityCauld becauld = api.World.BlockAccessor.GetBlockEntity(bs.Position) as BlockEntityCauld;
                            return lstacks;
                        }
                    }
                });
            });
        }
Exemple #3
0
        public override int GetContainerSlotId(BlockPos pos)
        {
            BlockEntityCauld becontainer = api.World.BlockAccessor.GetBlockEntity(pos) as BlockEntityCauld;

            if (becontainer == null)
            {
                return(6);
            }

            if (!becontainer.Inventory[5].Empty)
            {
                becontainer.isFull = true;
                return(5);
            }
            becontainer.isFull = false;
            return(6);
        }
Exemple #4
0
        private bool onMixClick()
        {
            BlockEntityCauld becauld = capi.World.BlockAccessor.GetBlockEntity(BlockEntityPosition) as BlockEntityCauld;

            if (becauld == null)
            {
                return(true);
            }

            becauld.MixCauld();
            capi.Network.SendBlockEntityPacket(BlockEntityPosition.X, BlockEntityPosition.Y, BlockEntityPosition.Z, 1337);
            Vec3d pos = BlockEntityPosition.ToVec3d().Add(0.5, 0.5, 0.5);

            capi.World.PlaySoundAt(new AssetLocation("sounds/player/seal"), pos.X, pos.Y, pos.Z, null);

            return(true);
        }
Exemple #5
0
        private void fullnessMeterDraw(Context ctx, ImageSurface surface, ElementBounds currentBounds)
        {
            ItemSlot liquidSlot = Inventory[6] as ItemSlot;

            if (liquidSlot.Empty)
            {
                return;
            }

            BlockEntityCauld becauld       = capi.World.BlockAccessor.GetBlockEntity(BlockEntityPosition) as BlockEntityCauld;
            float            itemsPerLitre = 1f;
            int capacity = becauld.capacityLitres;

            WaterTightContainableProps props = BlockLiquidContainerBase.GetContainableProps(liquidSlot.Itemstack);

            if (props != null)
            {
                itemsPerLitre = props.ItemsPerLitre;
                capacity      = Math.Max(capacity, props.MaxStackSize);
            }

            float fullnessRelative = liquidSlot.StackSize / itemsPerLitre / capacity;

            double offY = (1 - fullnessRelative) * currentBounds.InnerHeight;

            ctx.Rectangle(0, offY, currentBounds.InnerWidth, currentBounds.InnerHeight - offY);

            CompositeTexture tex = props?.Texture ?? liquidSlot.Itemstack.Collectible.Attributes?["inContainerTexture"].AsObject <CompositeTexture>(null, liquidSlot.Itemstack.Collectible.Code.Domain);

            if (tex != null)
            {
                ctx.Save();
                Matrix m = ctx.Matrix;
                m.Scale(GuiElement.scaled(3), GuiElement.scaled(3));
                ctx.Matrix = m;

                AssetLocation loc = tex.Base.Clone().WithPathAppendixOnce(".png");
                GuiElement.fillWithPattern(capi, ctx, loc, true, false, tex.Alpha);

                ctx.Restore();
            }
        }
Exemple #6
0
        public override bool OnBlockInteractStart(IWorldAccessor world, IPlayer byPlayer, BlockSelection blockSel)
        {
            BlockEntityCauld becauld = null;

            if (blockSel.Position != null)
            {
                becauld = world.BlockAccessor.GetBlockEntity(blockSel.Position) as BlockEntityCauld;
            }

            bool handled = base.OnBlockInteractStart(world, byPlayer, blockSel);

            if (!handled && !byPlayer.WorldData.EntityControls.Sneak && blockSel.Position != null)
            {
                if (becauld != null)
                {
                    becauld.OnBlockInteract(byPlayer);
                }

                return(true);
            }

            return(handled);
        }
Exemple #7
0
        string getContentsText()
        {
            string contents = "Contents:";

            if (Inventory[0].Empty && Inventory[1].Empty && Inventory[2].Empty && Inventory[3].Empty && Inventory[4].Empty && Inventory[5].Empty && Inventory[6].Empty)
            {
                contents += "\nNone.";
            }
            else
            {
                BlockEntityCauld becauld = capi.World.BlockAccessor.GetBlockEntity(BlockEntityPosition) as BlockEntityCauld;
                if (!Inventory[6].Empty)
                {
                    ItemStack stack = Inventory[6].Itemstack;
                    WaterTightContainableProps props = BlockLiquidContainerBase.GetContainableProps(stack);

                    if (props != null)
                    {
                        string incontainername = Lang.Get("incontainer-" + stack.Class.ToString().ToLowerInvariant() + "-" + stack.Collectible.Code.Path);
                        contents += "\n" + Lang.Get(props.MaxStackSize > 0 ? "Potion in: {0}x of {1}" : "{0} litres of {1}", (float)stack.StackSize / props.ItemsPerLitre, incontainername);
                    }
                    else
                    {
                        contents += "\n" + Lang.Get("{0}x of {1}", stack.StackSize, stack.GetName());
                    }
                }
                if (!Inventory[5].Empty)
                {
                    ItemStack stack = Inventory[5].Itemstack;
                    WaterTightContainableProps props = BlockLiquidContainerBase.GetContainableProps(stack);

                    if (props != null)
                    {
                        string incontainername = Lang.Get("incontainer-" + stack.Class.ToString().ToLowerInvariant() + "-" + stack.Collectible.Code.Path);
                        contents += "\n" + Lang.Get(props.MaxStackSize > 0 ? "Potion out: {0}x of {1}" : "{0} litres of {1}", (float)stack.StackSize / props.ItemsPerLitre, incontainername);
                    }
                    else
                    {
                        contents += "\n" + Lang.Get("{0}x of {1}", stack.StackSize, stack.GetName());
                    }
                }

                Dictionary <string, float> essencesDic   = new Dictionary <string, float>();
                Dictionary <string, float> maxEssenceDic = new Dictionary <string, float>();
                try
                {
                    IAsset maxEssences = capi.Assets.TryGet("alchemy:config/essences.json");
                    if (maxEssences != null)
                    {
                        maxEssenceDic = maxEssences.ToObject <Dictionary <string, float> >();
                    }
                }
                catch (Exception e)
                {
                    capi.World.Logger.Error("Failed loading potion effects for potion {0}. Will ignore. Exception: {1}", e);
                }
                for (int i = 0; i < 5; i++)
                {
                    if (!Inventory[i].Empty)
                    {
                        JsonObject essences = Inventory[i].Itemstack.ItemAttributes?["potionessences"];
                        foreach (var essence in maxEssenceDic.Keys.ToList())
                        {
                            if (essences[essence].Exists)
                            {
                                if (!essencesDic.ContainsKey(essence))
                                {
                                    essencesDic.Add(essence, 0);
                                }
                                essencesDic[essence] = (essencesDic[essence] + essences[essence].AsFloat() < maxEssenceDic[essence]) ? essencesDic[essence] += essences[essence].AsFloat() : maxEssenceDic[essence];
                                if (essencesDic[essence] == 0.0f)
                                {
                                    essencesDic.Remove(essence);
                                }
                            }
                        }
                    }
                }
                foreach (var essence in essencesDic.Keys.ToList())
                {
                    if (essence == "duration")
                    {
                        contents += "\n" + Lang.Get("increased duration by {0}", essencesDic[essence]);
                    }
                    else
                    {
                        contents += "\n" + Lang.Get("{0} units of {1} essence", essencesDic[essence], essence);
                    }
                }
                if (!Inventory[5].Empty)
                {
                    contents += "\n\nEmpty output to mix different new potions";
                }
            }

            return(contents);
        }