public bool OnContainedInteractStart(BlockEntityContainer be, ItemSlot slot, IPlayer byPlayer, BlockSelection blockSel)
        {
            var targetSlot = byPlayer.InventoryManager.ActiveHotbarSlot;

            if (targetSlot.Empty)
            {
                return(false);
            }

            if ((targetSlot.Itemstack.Collectible.Attributes?.IsTrue("mealContainer") == true || targetSlot.Itemstack.Block is IBlockMealContainer) && GetServings(api.World, slot.Itemstack) > 0)
            {
                if (targetSlot.StackSize > 1)
                {
                    targetSlot = new DummySlot(targetSlot.TakeOut(1));
                    byPlayer.InventoryManager.ActiveHotbarSlot.MarkDirty();
                    ServeIntoStack(targetSlot, slot, api.World);
                    if (!byPlayer.InventoryManager.TryGiveItemstack(targetSlot.Itemstack, true))
                    {
                        api.World.SpawnItemEntity(targetSlot.Itemstack, byPlayer.Entity.ServerPos.XYZ);
                    }
                }
                else
                {
                    ServeIntoStack(targetSlot, slot, api.World);
                }

                slot.MarkDirty();
                be.MarkDirty(true);
                return(true);
            }



            return(false);
        }
        /// <summary>
        /// Tries to take out as much items/liquid as possible from a placed bucket and returns it
        /// </summary>
        /// <param name="world"></param>
        /// <param name="pos"></param>
        /// <param name="quantityItem"></param>
        public ItemStack TryTakeContent(IWorldAccessor world, BlockPos pos, int quantityItem)
        {
            BlockEntityContainer becontainer = world.BlockAccessor.GetBlockEntity(pos) as BlockEntityContainer;

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

            ItemStack stack = becontainer.Inventory[GetContainerSlotId(world, pos)].Itemstack;

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

            ItemStack takenStack = stack.Clone();

            takenStack.StackSize = quantityItem;

            stack.StackSize -= quantityItem;
            if (stack.StackSize <= 0)
            {
                becontainer.Inventory[GetContainerSlotId(world, pos)].Itemstack = null;
            }
            else
            {
                becontainer.Inventory[GetContainerSlotId(world, pos)].Itemstack = stack;
            }

            becontainer.Inventory[GetContainerSlotId(world, pos)].MarkDirty();
            becontainer.MarkDirty(true);

            return(takenStack);
        }
        public override string GetPlacedBlockInfo(IWorldAccessor world, BlockPos pos, IPlayer forPlayer)
        {
            float litres = GetCurrentLitres(world, pos);

            BlockEntityContainer becontainer = world.BlockAccessor.GetBlockEntity(pos) as BlockEntityContainer;

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

            ItemSlot  slot         = becontainer.Inventory[GetContainerSlotId(world, pos)];
            ItemStack contentStack = slot.Itemstack;


            if (litres <= 0)
            {
                return(Lang.Get("Empty"));
            }

            string incontainername = Lang.Get("incontainer-" + contentStack.Class.ToString().ToLowerInvariant() + "-" + contentStack.Collectible.Code.Path);
            string text            = Lang.Get("Contents:\n{0} litres of {1}", litres, incontainername);

            text += BlockBucket.PerishableInfoCompact(api, slot, 0, false);

            return(text);
        }
Example #4
0
 public void OnContainedInteractStop(float secondsUsed, BlockEntityContainer be, ItemSlot slot, IPlayer byPlayer, BlockSelection blockSel)
 {
     if (tryFinishEatMeal(secondsUsed, slot, byPlayer.Entity, true))
     {
         be.MarkDirty(true);
     }
 }
        /// <summary>
        /// Retrives the containable properties of the currently contained itemstack of a placed water container
        /// </summary>
        /// <param name="world"></param>
        /// <param name="pos"></param>
        /// <returns></returns>
        public WaterTightContainableProps GetContentProps(IWorldAccessor world, BlockPos pos)
        {
            BlockEntityContainer becontainer = world.BlockAccessor.GetBlockEntity(pos) as BlockEntityContainer;

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

            int slotid = GetContainerSlotId(world, pos);

            if (slotid >= becontainer.Inventory.Count)
            {
                return(null);
            }

            ItemStack stack = becontainer.Inventory[slotid]?.Itemstack;

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

            return(GetInContainerProps(stack));
        }
Example #6
0
        public override ItemStack OnPickBlock(IWorldAccessor world, BlockPos pos)
        {
            ItemStack stack = new ItemStack(world.GetBlock(CodeWithVariant("side", "east")));

            BlockEntityContainer bec = world.BlockAccessor.GetBlockEntity(pos) as BlockEntityContainer;

            if (bec != null)
            {
                SetContents(stack, bec.GetContentStacks());
            }


            BlockEntityCrock becrock = world.BlockAccessor.GetBlockEntity(pos) as BlockEntityCrock;

            if (becrock == null)
            {
                return(stack);
            }

            ItemStack[] stacks = becrock.inventory.Where(slot => !slot.Empty).Select(slot => slot.Itemstack).ToArray();
            if (becrock.RecipeCode != null)
            {
                stack.Attributes.SetString("recipeCode", becrock.RecipeCode);
                stack.Attributes.SetFloat("quantityServings", becrock.QuantityServings);
                stack.Attributes.SetBool("sealed", becrock.Sealed);
            }

            return(stack);
        }
Example #7
0
        public bool OnContainedInteractStep(float secondsUsed, BlockEntityContainer be, ItemSlot slot, IPlayer byPlayer, BlockSelection blockSel)
        {
            if (!byPlayer.Entity.Controls.Sneak)
            {
                return(false);
            }

            return(tryPlacedContinueEatMeal(secondsUsed, slot, byPlayer, blockSel));
        }
Example #8
0
        public bool OnContainedInteractStart(BlockEntityContainer be, ItemSlot slot, IPlayer byPlayer, BlockSelection blockSel)
        {
            if (!byPlayer.Entity.Controls.Sneak)
            {
                return(false);
            }

            return(tryPlacedBeginEatMeal(slot, byPlayer));
        }
Example #9
0
        private void UpdateTube(float dt)
        {
            //setup the north mask
            BlockEntityContainer check = Api.World.BlockAccessor.GetBlockEntity(Pos.NorthCopy()) as BlockEntityContainer;

            if (check != null)
            {
                AttachmentMask[0] = check.Inventory is InventoryGeneric;
            }

            //setup the attachment mask
            check = Api.World.BlockAccessor.GetBlockEntity(Pos.SouthCopy()) as BlockEntityContainer;
            if (check != null)
            {
                AttachmentMask[1] = check.Inventory is InventoryGeneric;
            }

            //setup the attachment mask
            check = Api.World.BlockAccessor.GetBlockEntity(Pos.EastCopy()) as BlockEntityContainer;
            if (check != null)
            {
                AttachmentMask[2] = check.Inventory is InventoryGeneric;
            }

            //setup the attachment mask
            check = Api.World.BlockAccessor.GetBlockEntity(Pos.WestCopy()) as BlockEntityContainer;
            if (check != null)
            {
                AttachmentMask[3] = check.Inventory is InventoryGeneric;
            }

            //setup the attachment mask
            check = Api.World.BlockAccessor.GetBlockEntity(Pos.UpCopy()) as BlockEntityContainer;
            if (check != null)
            {
                AttachmentMask[4] = check.Inventory is InventoryGeneric;
            }

            //setup the attachment mask
            check = Api.World.BlockAccessor.GetBlockEntity(Pos.DownCopy()) as BlockEntityContainer;
            if (check != null)
            {
                AttachmentMask[5] = check.Inventory is InventoryGeneric;
            }

            //Elbow default is West and Up
            //3way default is West, South and Up
            //4way default is west, east, south and Up
            //5 way default is NOT down.
            //6 way is yes.
            //cross default is up east down west
            //straight default is east-west
            //T default is East, west, up

            //orient from west as the origin (-x)
        }
        /// <summary>
        /// Retrieve the contents of a placed container
        /// </summary>
        /// <param name="world"></param>
        /// <param name="pos"></param>
        /// <returns></returns>
        public ItemStack GetContent(IWorldAccessor world, BlockPos pos)
        {
            BlockEntityContainer becontainer = world.BlockAccessor.GetBlockEntity(pos) as BlockEntityContainer;

            if (becontainer == null)
            {
                return(null);
            }
            return(becontainer.Inventory[GetContainerSlotId(world, pos)].Itemstack);
        }
Example #11
0
        public override ItemStack OnPickBlock(IWorldAccessor world, BlockPos pos)
        {
            ItemStack stack = base.OnPickBlock(world, pos);

            BlockEntityContainer bec = world.BlockAccessor.GetBlockEntity(pos) as BlockEntityContainer;

            if (bec != null)
            {
                SetContents(stack, bec.GetContentStacks());
            }

            return(stack);
        }
        /// <summary>
        /// Sets the contents to placed container block
        /// </summary>
        /// <param name="world"></param>
        /// <param name="pos"></param>
        /// <param name="content"></param>
        public void SetContent(IWorldAccessor world, BlockPos pos, ItemStack content)
        {
            BlockEntityContainer beContainer = world.BlockAccessor.GetBlockEntity(pos) as BlockEntityContainer;

            if (beContainer == null)
            {
                return;
            }

            new DummySlot(content).TryPutInto(world, beContainer.Inventory[GetContainerSlotId(world, pos)], content.StackSize);

            beContainer.Inventory[GetContainerSlotId(world, pos)].MarkDirty();
            beContainer.MarkDirty(true);
        }
Example #13
0
        public override int GetRandomColor(ICoreClientAPI capi, BlockPos pos, BlockFacing facing, int rndIndex = -1)
        {
            BlockEntityContainer bem = capi.World.BlockAccessor.GetBlockEntity(pos) as BlockEntityContainer;

            if (bem == null)
            {
                return(base.GetRandomColor(capi, pos, facing, rndIndex));
            }

            ItemStack[] stacks = bem.GetNonEmptyContentStacks(false);

            if (stacks != null && stacks.Length > 0)
            {
                return(GetRandomContentColor(capi, stacks));
            }
            else
            {
                return(base.GetRandomColor(capi, pos, facing, rndIndex));
            }
        }
 public bool OnContainedInteractStep(float secondsUsed, BlockEntityContainer be, ItemSlot slot, IPlayer byPlayer, BlockSelection blockSel)
 {
     return(false);
 }
Example #15
0
        /// <summary>
        /// Attempts to move the item from slot to slot.
        /// </summary>
        /// <param name="dt"></param>
        public void MoveItem(float dt)
        {
            //check above.  Then check below.
            BlockPos InputPosition  = pos.AddCopy(InputFace);
            BlockPos OutputPosition = pos.AddCopy(OutputFace);

            //if inventory below, attempt to move item in me to below
            if (api.World.BlockAccessor.GetBlockEntity(OutputPosition) is BlockEntityContainer && !inventory.IsEmpty)
            {
                BlockEntityContainer outputBox    = (BlockEntityContainer)api.World.BlockAccessor.GetBlockEntity(OutputPosition);
                ItemSlot             transferSlot = null;
                foreach (ItemSlot slot in inventory)
                {
                    if (!slot.Empty)
                    {
                        transferSlot = slot;
                        break;
                    }
                }

                if (transferSlot != null)
                {
                    WeightedSlot ws = outputBox.Inventory.GetBestSuitedSlot(transferSlot);
                    if (ws.slot != null)
                    {
                        ItemStackMoveOperation op = new ItemStackMoveOperation(api.World, EnumMouseButton.Left, 0, EnumMergePriority.DirectMerge, FlowAmount);
                        if (transferSlot.TryPutInto(ws.slot, ref op) > 0)
                        {
                            if (api.World.Rand.NextDouble() < 0.2)
                            {
                                api.World.PlaySoundAt(new AssetLocation("sounds/block/hoppertumble"), pos.X + 0.5, pos.Y + 0.5, pos.Z + 0.5, null, true, 8, 0.5f);
                            }
                        }
                    }
                } //transfer slot
            }     //Output move.

            //if inventory above, attempt to move item from above into me.  (LATER ON: CHECK FILTER)
            if (api.World.BlockAccessor.GetBlockEntity(InputPosition) is BlockEntityContainer)
            {
                BlockEntityContainer inputBox = (BlockEntityContainer)api.World.BlockAccessor.GetBlockEntity(InputPosition);
                if (inputBox.Inventory is InventoryGeneric)
                {
                    InventoryGeneric inputInventory = (InventoryGeneric)inputBox.Inventory;
                    if (!inputInventory.IsEmpty)
                    {
                        ItemSlot transferSlot = null;
                        foreach (ItemSlot slot in inputInventory)
                        {
                            if (!slot.Empty)
                            {
                                transferSlot = slot;
                            }
                        }

                        if (transferSlot != null)
                        {
                            WeightedSlot ws = inventory.GetBestSuitedSlot(transferSlot);
                            if (ws.slot != null)
                            {
                                ItemStackMoveOperation op = new ItemStackMoveOperation(api.World, EnumMouseButton.Left, 0, EnumMergePriority.DirectMerge, FlowAmount);

                                if (transferSlot.TryPutInto(ws.slot, ref op) > 0)
                                {
                                    if (api.World.Rand.NextDouble() < 0.2)
                                    {
                                        api.World.PlaySoundAt(new AssetLocation("sounds/block/hoppertumble"), pos.X + 0.5, pos.Y + 0.5, pos.Z + 0.5, null, true, 8, 0.5f);
                                    }
                                }
                            }
                        } //transfer slot
                    }     //Inventory empty check
                }         //Inventory Generic check.
            }             //Check for Block entity container.
        }
Example #16
0
        public override void OnHeldInteractStart(ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, bool firstEvent, ref EnumHandHandling handHandling)
        {
            if (blockSel == null)
            {
                base.OnHeldInteractStart(slot, byEntity, blockSel, entitySel, firstEvent, ref handHandling);
                return;
            }

            BlockLiquidContainerBase blockLiqContainer = byEntity.World.BlockAccessor.GetBlock(blockSel.Position) as BlockLiquidContainerBase;
            IPlayer player = (byEntity as EntityPlayer)?.Player;

            string contents = BowlContentItemCode();

            if (blockLiqContainer != null)
            {
                if (contents == null)
                {
                    ItemStack stack = blockLiqContainer.GetContent(byEntity.World, blockSel.Position);
                    if (stack != null && ContentBlockForContents(stack.Collectible.Code.Path) != null)
                    {
                        InsertIntoBowl(slot, byEntity, stack.Collectible.Code.Path);
                        blockLiqContainer.TryTakeContent(byEntity.World, blockSel.Position, 1);
                    }

                    BlockEntityContainer bebarrel = api.World.BlockAccessor.GetBlockEntity(blockSel.Position) as BlockEntityContainer;
                    if (bebarrel != null && bebarrel.Inventory.Count > 0)
                    {
                        stack = bebarrel.Inventory[0].Itemstack;

                        if (stack != null && stack.Collectible.Attributes["crockable"].AsBool() == true)
                        {
                            Block     mealblock = api.World.GetBlock(AssetLocation.Create(slot.Itemstack.Collectible.Attributes["mealBlockCode"].AsString(), slot.Itemstack.Collectible.Code.Domain));
                            ItemStack mealstack = new ItemStack(mealblock);
                            mealstack.StackSize = 1;

                            (mealblock as IBlockMealContainer).SetContents(null, mealstack, new ItemStack[] { bebarrel.Inventory[0].TakeOut(4) }, 1);

                            if (slot.StackSize == 1)
                            {
                                slot.Itemstack = mealstack;
                            }
                            else
                            {
                                slot.TakeOut(1);
                                if (!player.InventoryManager.TryGiveItemstack(mealstack, true))
                                {
                                    api.World.SpawnItemEntity(mealstack, byEntity.Pos.XYZ.Add(0.5, 0.5, 0.5));
                                }
                            }
                            slot.MarkDirty();

                            bebarrel.MarkDirty(true);
                        }
                    }
                }
                else
                {
                    ItemStack stack = blockLiqContainer.GetContent(byEntity.World, blockSel.Position);
                    if (stack == null || stack.Collectible.Code.Equals(new AssetLocation(BowlContentItemCode())))
                    {
                        Item contentItem = byEntity.World.GetItem(new AssetLocation(BowlContentItemCode()));
                        if (blockLiqContainer.TryPutContent(byEntity.World, blockSel.Position, new ItemStack(contentItem), 1) > 0)
                        {
                            EmptyOutBowl(slot, byEntity);
                        }
                    }
                }

                handHandling = EnumHandHandling.PreventDefaultAction;
                return;
            }


            handHandling = EnumHandHandling.PreventDefault;

            base.OnHeldInteractStart(slot, byEntity, blockSel, entitySel, firstEvent, ref handHandling);
        }
 public void OnContainedInteractStop(float secondsUsed, BlockEntityContainer be, ItemSlot slot, IPlayer byPlayer, BlockSelection blockSel)
 {
 }