Ejemplo n.º 1
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);
        }
Ejemplo 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();
        }
Ejemplo n.º 3
0
    public void CheckScopes()
    {
        int i = 0;

        for (int count = buckets.Count; i < count; i++)
        {
            BlockBucket blockBucket = buckets[i];
            switch (blockBucket.scopeState)
            {
            case BlockBucket.State.Active:
            case BlockBucket.State.Pausing:
                blockBucket.scopeState = (blockBucket.IsNeeded ? BlockBucket.State.Active : BlockBucket.State.Pausing);
                break;

            case BlockBucket.State.Paused:
                if (blockBucket.IsNeeded)
                {
                    blockBucket.scopeState           = BlockBucket.State.Active;
                    blockBucket.scope.SuspendCollect = false;
                }
                break;
            }
        }
    }
Ejemplo n.º 4
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);
                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);
        }
Ejemplo n.º 5
0
    private void ParseContent()
    {
        if (parsed)
        {
            return;
        }
        parsed = true;
        ctext.InitData();
        TextAsset           activeContent = ActiveContent;
        List <CreditsBlock> list          = new List <CreditsBlock>();

        string[] array = activeContent.text.Split('\n');
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = array[i].Trim();
        }
        int   j   = 0;
        float num = 0f;

        while (j < array.Length)
        {
            for (; j < array.Length && string.IsNullOrEmpty(array[j]); j++)
            {
            }
            if (j < array.Length)
            {
                string text = array[j++];
                while (j < array.Length && !string.IsNullOrEmpty(array[j]))
                {
                    text = text + "\r\n" + array[j++];
                }
                CreditsBlock component = UnityEngine.Object.Instantiate(ctext.blockPrefab.gameObject).GetComponent <CreditsBlock>();
                component.transform.SetParent(base.transform, worldPositionStays: false);
                component.transform.position = num * Vector3.up;
                component.Initialize(num, text, ctext);
                blocks.Add(component);
                list.Add(component);
                num -= blockSpacing;
                NetIdentity netIdentity = component.gameObject.AddComponent <NetIdentity>();
                netIdentity.sceneId       = (uint)blocks.Count;
                component.blockId         = netIdentity;
                component.gameObject.name = "CrBlock" + netIdentity.sceneId.ToString();
            }
        }
        startupDoorY = num - showAhead;
        topY         = 0f;
        uint num2 = (uint)NetHost.CalcMaxPossibleSizeForContainerContentsTier0();

        buckets.Clear();
        uint num3 = 288u;
        int  k    = 0;

        for (int count = list.Count; k < count; k++)
        {
            CreditsBlock creditsBlock = list[k];
            int          bitsRequired = creditsBlock.bitsRequired;
            int          count2       = buckets.Count;
            int          num4         = count2 - 1;
            if (num4 < 0 || buckets[num4].bitsLeft < bitsRequired)
            {
                num4++;
            }
            BlockBucket blockBucket;
            if (num4 < count2)
            {
                blockBucket = buckets[num4];
            }
            else
            {
                blockBucket = new BlockBucket();
                buckets.Add(blockBucket);
                if (num3 > 1054)
                {
                    throw new ApplicationException("Run out of auxilliary net ids");
                }
                blockBucket.go                        = new GameObject("LettersScope" + num3.ToString());
                blockBucket.scope                     = blockBucket.go.AddComponent <NetScope>();
                blockBucket.scope.enabled             = false;
                blockBucket.scope.netId               = num3++;
                blockBucket.scope.AllowSuspendCollect = true;
                blockBucket.go.transform.SetParent(base.gameObject.transform, worldPositionStays: false);
                blockBucket.scope.enabled = true;
                blockBucket.bitsLeft      = (int)(num2 * 8) - NetScope.CalculateDeltaPrefixSize(blockBucket.scope.netId);
            }
            blockBucket.blocks.Add(creditsBlock);
            blockBucket.bitsLeft -= bitsRequired;
            creditsBlock.transform.SetParent(blockBucket.go.transform, worldPositionStays: true);
            creditsBlock.bucket = blockBucket;
        }
        int l = 0;

        for (int count3 = buckets.Count; l < count3; l++)
        {
            BlockBucket blockBucket2 = buckets[l];
            blockBucket2.scope.StartNetwork();
        }
        CheckScopes();
    }