Esempio n. 1
0
        public override string GetBlockInfo(IPlayer forPlayer)
        {
            string    a        = "\n";
            ItemStack contents = bucket.GetContent(api.World, pos);

            if (contents != null)
            {
                if (contents.Item.FirstCodePart() == "milkportion")
                {
                    a += "Becomes Curds In " + (int)(updateTime - api.World.Calendar.TotalHours) + " Hours";
                }
            }
            return(a + base.GetBlockInfo(forPlayer));
        }
Esempio n. 2
0
        public override void OnHeldInteractStop(float secondsUsed, ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel)
        {
            if (blockSel == null || slot.Itemstack.Collectible.Variant["contents"] == "curds" || slot.Itemstack.Collectible.Variant["contents"] == "cheese")
            {
                return;
            }
            BlockPos pos      = blockSel.Position;
            Block    selBlock = api.World.BlockAccessor.GetBlock(pos);

            if (api.World.Side.IsServer())
            {
                if (selBlock is BlockBucket)
                {
                    BlockBucket bucket = selBlock as BlockBucket;
                    WaterTightContainableProps contentProps = bucket.GetContentProps(byEntity.World, pos);
                    if (bucket.GetContent(byEntity.World, pos) != null)
                    {
                        ItemStack contents = bucket.GetContent(byEntity.World, pos);
                        if (contents.Item.Code.Path == "curdsportion" && slot.Itemstack.Collectible.Variant["contents"] == "none")
                        {
                            ItemStack curdsandwhey = new ItemStack(CodeWithPart("curdsandwhey", 2).GetBlock(api), 1);

                            bucket.TryTakeContent(api.World, pos, 2);

                            TryGiveItem(curdsandwhey, slot, byEntity, contentProps, pos);
                            return;
                        }
                    }
                    if ((bucket.GetContent(byEntity.World, pos) == null || bucket.GetContent(byEntity.World, pos).Item.Code.Path == "wheyportion") && slot.Itemstack.Collectible.Variant["contents"] == "curdsandwhey")
                    {
                        ItemStack curds       = new ItemStack(CodeWithPart("curds", 2).GetBlock(api), 1);
                        ItemStack wheyportion = new ItemStack(new AssetLocation("wheyportion").GetItem(api), 1);
                        bucket.TryPutContent(api.World, pos, wheyportion, 1);

                        TryGiveItem(curds, slot, byEntity, contentProps, pos);
                        return;
                    }
                }
            }
            slot.MarkDirty();
        }
Esempio n. 3
0
        public override void OnInteract(EntityAgent byEntity, ItemSlot itemslot, Vec3d hitPosition, EnumInteractMode mode, ref EnumHandling handled)
        {
            if (itemslot.Itemstack == null)
            {
                return;
            }
            if (itemslot.Itemstack.Block is BlockBucket)
            {
                handled = EnumHandling.PreventDefault;
                ItemStack milkstack = new ItemStack(milk, RemainingLiters);

                BlockBucket bucket   = itemslot.Itemstack.Block as BlockBucket;
                ItemStack   contents = bucket.GetContent(byEntity.World, itemslot.Itemstack);
                if ((contents == null || contents.Item == milk) && RemainingLiters > 0)
                {
                    if (contents?.StackSize != null && contents.StackSize / milkProps.ItemsPerLitre >= bucket.CapacityLitres)
                    {
                        return;
                    }
                    DummySlot slot = new DummySlot(itemslot.TakeOut(1));

                    int taken = bucket.TryPutContent(byEntity.World, slot.Itemstack, milkstack, 1);
                    if (taken > 0)
                    {
                        RemainingLiters -= taken;
                        if (byEntity.World.Side == EnumAppSide.Client)
                        {
                            byEntity.World.SpawnCubeParticles(entity.Pos.XYZ + new Vec3d(0, 0.5, 0), milkstack, 0.3f, 4, 0.5f, (byEntity as EntityPlayer)?.Player);
                        }
                        if (id == 0 && RemainingLiters < defaultvalue)
                        {
                            if (NextTimeMilkable == 0)
                            {
                                NextTimeMilkable = GetNextTimeMilkable();
                            }
                            id = entity.World.RegisterGameTickListener(MilkListener, 1000);
                        }
                        byEntity.TryGiveItemStack(slot.Itemstack);
                        itemslot.MarkDirty();
                    }
                }
            }

            base.OnInteract(byEntity, itemslot, hitPosition, mode, ref handled);
        }
        public override void OnInteract(EntityAgent byEntity, ItemSlot itemslot, Vec3d hitPosition, EnumInteractMode mode, ref EnumHandling handled)
        {
            if (itemslot.Itemstack == null)
            {
                return;
            }
            if (itemslot.Itemstack.Block is BlockBucket)
            {
                handled = EnumHandling.PreventDefault;
                ItemStack   milkstack = new ItemStack(milk);
                BlockBucket bucket    = itemslot.Itemstack.Block as BlockBucket;
                ItemStack   contents  = bucket.GetContent(byEntity.World, itemslot.Itemstack);
                if ((contents == null || contents.Item == milk) && RemainingLiters > 0)
                {
                    if (bucket.TryAddContent(byEntity.World, itemslot.Itemstack, milkstack, 1) > 0)
                    {
                        RemainingLiters -= 1;
                        if (byEntity.World.Side == EnumAppSide.Client)
                        {
                            byEntity.World.SpawnCubeParticles(entity.Pos.XYZ + new Vec3d(0, 0.5, 0), milkstack, 0.3f, 4, 0.5f, (byEntity as EntityPlayer)?.Player);
                        }
                        if (id == 0 && RemainingLiters < defaultvalue)
                        {
                            if (NextTimeMilkable == 0)
                            {
                                NextTimeMilkable = GetNextTimeMilkable();
                            }
                            id = entity.World.RegisterGameTickListener(MilkListener, 1000);
                        }
                        itemslot.MarkDirty();
                    }
                }
            }

            base.OnInteract(byEntity, itemslot, hitPosition, mode, ref handled);
        }