public override void DoSmelt(IWorldAccessor world, ISlotProvider cookingSlotsProvider, ItemSlot inputSlot, ItemSlot outputSlot)
        {
            ItemStack[] stacks = GetCookingStacks(cookingSlotsProvider);

            CookingRecipe recipe = GetMatchingCookingRecipe(world, stacks);

            Block     block       = world.GetBlock(CodeWithPath(CodeWithoutParts(1) + "-cooked"));
            ItemStack outputStack = new ItemStack(block);

            if (recipe != null)
            {
                int quantityServings = recipe.GetQuantityServings(stacks);
                for (int i = 0; i < stacks.Length; i++)
                {
                    stacks[i].StackSize /= quantityServings;
                }

                ((BlockCookedContainer)block).SetContents(recipe.Code, quantityServings, outputStack, stacks);

                outputStack.Collectible.SetTemperature(world, outputStack, GetIngredientsTemperature(world, stacks));
                outputSlot.Itemstack = outputStack;
                inputSlot.Itemstack  = null;

                for (int i = 0; i < cookingSlotsProvider.Slots.Length; i++)
                {
                    cookingSlotsProvider.Slots[i].Itemstack = null;
                }
                return;
            }
        }
Exemple #2
0
    private void PlaceFakeBlocks(IWorldAccessor world, BlockPos pos)
    {
        Block    toPlaceBlock = world.GetBlock(new AssetLocation("temporalengineering:multiblockwood"));
        BlockPos tmpPos       = new BlockPos();

        for (int d1 = -1; d1 <= 1; d1++)
        {
            for (int d2 = -1; d2 <= 1; d2++)
            {
                if (d1 == 0 && d2 == 0)
                {
                    continue;
                }
                if (powerOutFacing == BlockFacing.EAST || powerOutFacing == BlockFacing.WEST)
                {
                    tmpPos.Set(pos.X, pos.Y + d1, pos.Z + d2);
                }
                else
                {
                    tmpPos.Set(pos.X + d2, pos.Y + d1, pos.Z);
                }
                world.BlockAccessor.SetBlock(toPlaceBlock.BlockId, tmpPos);
                BEMPMultiblockBase be = world.BlockAccessor.GetBlockEntity(tmpPos) as BEMPMultiblockBase;
                if (be != null)
                {
                    be.Principal = pos;
                }
            }
        }
    }
        public int baseWork       = 5; // the base amount of work needed.

        public override bool DoPlaceBlock(IWorldAccessor world, IPlayer byPlayer, BlockSelection blockSel, ItemStack byItemStack)
        {
            string orientation;
            string oDirections;

            if (blockSel.Face.Index == 5)
            {
                orientation = "up";
                oDirections = SuggestedHVOrientation(byPlayer, blockSel)[0].ToString();
            }
            else if (blockSel.Face.Index == 4)
            {
                orientation = "down";
                oDirections = SuggestedHVOrientation(byPlayer, blockSel)[0].ToString();
            }
            else
            {
                orientation = "horizontal";
                oDirections = blockSel.Face.Opposite.ToString();
            }

            AssetLocation blockSwapLocation = new AssetLocation(Code.Domain, CodeWithoutParts(2) + "-" + orientation + "-" + oDirections);
            Block         blockSwap         = world.GetBlock(blockSwapLocation);

            world.BlockAccessor.SetBlock(blockSwap.Id, blockSel.Position);

            PlugnFeatherBE BE = world.BlockAccessor.GetBlockEntity(blockSel.Position) as PlugnFeatherBE;

            BE.orientation = orientation;
            BE.facing      = oDirections;

            return(true);
        }
Exemple #4
0
        public override ItemStack OnPickBlock(IWorldAccessor world, BlockPos pos)
        {
            AssetLocation loc   = CodeWithVariants(new string[] { "habitat", "cover" }, new string[] { "land", "free" });
            Block         block = world.GetBlock(loc);

            return(new ItemStack(block));
        }
        public override ItemStack OnPickBlock(IWorldAccessor world, BlockPos pos)
        {
            AssetLocation loc   = CodeWithParts("free", "normal");
            Block         block = world.GetBlock(loc);

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

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

            if (becrock != null)
            {
                ItemStack[] contents = becrock.GetContentStacks();
                for (int i = 0; i < contents.Length; i++)
                {
                    // if any of the crock's contents still has a stack, return a crock with all the contents
                    if (contents[i] != null)
                    {
                        SetContents(stack, contents);

                        if (becrock.RecipeCode != null)
                        {
                            stack.Attributes.SetString("recipeCode", becrock.RecipeCode);
                            stack.Attributes.SetFloat("quantityServings", becrock.QuantityServings);
                            stack.Attributes.SetBool("sealed", becrock.Sealed);
                        }
                    }
                }
            }

            return(stack);
        }
Exemple #7
0
        public override void OnBlockPlaced(IWorldAccessor world, BlockPos pos, ref EnumHandling handling)
        {
            handling = EnumHandling.PassThrough;

            IterateOverEach(pos, (mpos) =>
            {
                if (mpos == pos)
                {
                    return(true);
                }

                int dx = mpos.X - pos.X;
                int dy = mpos.Y - pos.Y;
                int dz = mpos.Z - pos.Z;

                string sdx = (dx < 0 ? "n" : (dx > 0 ? "p" : "")) + Math.Abs(dx);
                string sdy = (dy < 0 ? "n" : (dy > 0 ? "p" : "")) + Math.Abs(dy);
                string sdz = (dz < 0 ? "n" : (dz > 0 ? "p" : "")) + Math.Abs(dz);

                AssetLocation loc = new AssetLocation("multiblock-" + type + "-" + sdx + "-" + sdy + "-" + sdz);
                Block block       = world.GetBlock(loc);

                if (block == null)
                {
                    throw new IndexOutOfRangeException("Multiblocks are currently limited to 3x3x with the controller being in the middle of it, yours likely exceeds the limit because I could not find block with code " + loc.Path);
                }

                world.BlockAccessor.SetBlock(block.Id, mpos);
                return(true);
            });
        }
        public override void DoSmelt(IWorldAccessor world, ISlotProvider cookingSlotsProvider, IItemSlot inputSlot, IItemSlot outputSlot)
        {
            ItemStack[] stacks = GetCookingStacks(cookingSlotsProvider);

            CookingRecipe recipe = GetMatchingCookingRecipe(world, stacks);

            Block     block       = world.GetBlock(CodeWithPath(FirstCodePart() + "-cooked"));
            ItemStack outputStack = new ItemStack(block);

            if (recipe != null)
            {
                int quantityServings = recipe.GetQuantityServings(stacks);
                for (int i = 0; i < stacks.Length; i++)
                {
                    stacks[i].StackSize /= quantityServings;
                }
                // Not active. Let's sacrifice mergability for letting players select how meals should look and named like
                //stacks = stacks.OrderBy(stack => stack.Collectible.Code.ToShortString()).ToArray(); // Required so that different arrangments of ingredients still create mergable meal bowls

                ((BlockCookedContainer)block).SetContents(recipe.Code, quantityServings, outputStack, stacks);

                outputStack.Collectible.SetTemperature(world, outputStack, GetIngredientsTemperature(world, stacks));
                outputSlot.Itemstack = outputStack;
                inputSlot.Itemstack  = null;

                for (int i = 0; i < cookingSlotsProvider.Slots.Length; i++)
                {
                    cookingSlotsProvider.Slots[i].Itemstack = null;
                }
                return;
            }
        }
        public override bool TryPlaceBlock(IWorldAccessor world, IPlayer byPlayer, ItemStack itemstack, BlockSelection blockSel, ref string failureCode)
        {
            if (!CanPlaceBlock(world, byPlayer, blockSel, ref failureCode))
            {
                return(false);
            }

            foreach (BlockFacing face in BlockFacing.HORIZONTALS)
            {
                BlockPos pos = blockSel.Position.AddCopy(face);

                IMechanicalPowerBlock block = world.BlockAccessor.GetBlock(pos) as IMechanicalPowerBlock;
                if (block != null)
                {
                    if (block.HasMechPowerConnectorAt(world, pos, face.Opposite))
                    {
                        AssetLocation loc          = new AssetLocation(FirstCodePart() + "-" + face.GetCCW().Code);
                        Block         toPlaceBlock = world.GetBlock(loc);
                        if (toPlaceBlock.DoPlaceBlock(world, byPlayer, blockSel, itemstack))
                        {
                            block.DidConnectAt(world, pos, face.Opposite);
                            WasPlaced(world, blockSel.Position, face);
                            return(true);
                        }
                    }
                }
            }

            if (base.TryPlaceBlock(world, byPlayer, itemstack, blockSel, ref failureCode))
            {
                WasPlaced(world, blockSel.Position, null);
                return(true);
            }
            return(false);
        }
        public bool RemoveResource(IWorldAccessor world, IPlayer byplayer, BlockSelection blockSel, string stype, int quant)
        {
            if (storedType == "" || storedtypes[stype] <= 0)
            {
                return(false);
            }
            if (quant > storedtypes[stype])
            {
                quant = storedtypes[stype];
            }

            ItemStack givestack;

            if (stype == "sand" || stype == "gravel")
            {
                Block filler = world.GetBlock(new AssetLocation("game", stype + "-" + storedType));
                givestack = new ItemStack(filler, Math.Min(filler.MaxStackSize, quant));
            }
            else
            {
                Item filler = world.GetItem(new AssetLocation("game", stype + "-" + storedType));
                givestack = new ItemStack(filler, Math.Min(filler.MaxStackSize, quant));
            }

            if (!byplayer.InventoryManager.TryGiveItemstack(givestack.Clone()))
            {
                world.SpawnItemEntity(givestack.Clone(), blockSel.HitPosition + (blockSel.HitPosition.Normalize() * .5) + blockSel.Position.ToVec3d(), blockSel.HitPosition.Normalize() * .05);
            }
            storedtypes[stype] -= givestack.StackSize;
            return(true);
        }
        public ItemStack GetItemStack(IWorldAccessor world, int variant)
        {
            ItemStack stack = null;

            AssetLocation code = codes[variant % codes.Length];

            int quantity = (int)minQuantity + (int)(world.Rand.NextDouble() * (maxQuantity - (int)minQuantity));

            if (type == EnumItemClass.Block)
            {
                Block block = world.GetBlock(code);
                if (block != null)
                {
                    stack = new ItemStack(block, quantity);
                }
                else
                {
                    world.Logger.Warning("LootItem: Failed resolving block code {0}", code);
                }
            }
            else
            {
                Item item = world.GetItem(code);
                if (item != null)
                {
                    stack = new ItemStack(item, quantity);
                }
                else
                {
                    world.Logger.Warning("LootItem: Failed resolving item code {0}", code);
                }
            }

            return(stack);
        }
        public override bool OnBlockInteractStart(IWorldAccessor world, IPlayer byPlayer, BlockSelection blockSel, ref EnumHandling handling)
        {
            if (!world.Claims.TryAccess(byPlayer, blockSel.Position, EnumBlockAccessFlags.Use))
            {
                return(false);
            }
            if (!block.Code.Path.Contains("empty"))
            {
                handling = EnumHandling.PreventDefault;

                //handles the collection of items, and the transformation of the block.
                world.Logger.VerboseDebug("Collecting item(s) from target block at {0}.", blockSel.Position);

                if (block.Drops != null && block.Drops.Length > 1)
                {
                    BlockDropItemStack drop  = block.Drops[0];
                    ItemStack          stack = drop.GetNextItemStack();

                    if (!byPlayer.InventoryManager.TryGiveItemstack(stack))
                    {
                        world.SpawnItemEntity(drop.GetNextItemStack(), blockSel.Position.ToVec3d().Add(0.5, 0.5, 0.5));
                    }

                    AssetLocation loc = block.Code.CopyWithPath(block.Code.Path.Replace(block.Code.Path.Split('-').Last(), "empty"));

                    world.BlockAccessor.SetBlock(world.GetBlock(loc).BlockId, blockSel.Position);

                    world.PlaySoundAt(new AssetLocation("sounds/player/collect"), blockSel.Position.X, blockSel.Position.Y, blockSel.Position.Z, byPlayer);
                }

                return(true);
            }

            return(false);
        }
Exemple #13
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);
        }
Exemple #14
0
        public override void OnGroundIdle(EntityItem entityItem)
        {
            base.OnGroundIdle(entityItem);

            IWorldAccessor world = entityItem.World;

            if (world.Side != EnumAppSide.Server)
            {
                return;
            }

            if (entityItem.Swimming && world.Rand.NextDouble() < 0.01)
            {
                ItemStack[] stacks = GetContents(world, entityItem.Itemstack);

                if (MealMeshCache.ContentsRotten(stacks))
                {
                    for (int i = 0; i < stacks.Length; i++)
                    {
                        if (stacks[i] != null && stacks[i].StackSize > 0 && stacks[i].Collectible.Code.Path == "rot")
                        {
                            world.SpawnItemEntity(stacks[i], entityItem.ServerPos.XYZ);
                        }
                    }

                    Block block = world.GetBlock(new AssetLocation(Attributes["eatenBlock"].AsString()));
                    entityItem.Itemstack = new ItemStack(block);
                    entityItem.WatchedAttributes.MarkPathDirty("itemstack");
                }
            }
        }
Exemple #15
0
        public override TransitionState[] UpdateAndGetTransitionStates(IWorldAccessor world, ItemSlot inslot)
        {
            TransitionState[] states = base.UpdateAndGetTransitionStates(world, inslot);

            ItemStack[] stacks = GetNonEmptyContents(world, inslot.Itemstack);
            if (MealMeshCache.ContentsRotten(stacks))
            {
                inslot.Itemstack.Attributes?.RemoveAttribute("recipeCode");
                inslot.Itemstack.Attributes?.RemoveAttribute("quantityServings");
            }
            if (stacks == null || stacks.Length == 0)
            {
                inslot.Itemstack.Attributes?.RemoveAttribute("recipeCode");
                inslot.Itemstack.Attributes?.RemoveAttribute("quantityServings");
            }

            string eaten = Attributes["eatenBlock"].AsString();

            if ((stacks == null || stacks.Length == 0) && eaten != null)
            {
                Block block = world.GetBlock(new AssetLocation(eaten));

                if (block != null)
                {
                    inslot.Itemstack = new ItemStack(block);
                    inslot.MarkDirty();
                }
            }

            return(states);
        }
Exemple #16
0
        public void ServeIntoBowlStack(ItemSlot bowlSlot, ItemSlot potslot, IWorldAccessor world)
        {
            if (world.Side == EnumAppSide.Client)
            {
                return;
            }

            string code      = bowlSlot.Itemstack.Block.Attributes["mealBlockCode"].AsString();
            Block  mealblock = api.World.GetBlock(new AssetLocation(code)) as Block;

            ItemStack[] stacks = GetContents(api.World, potslot.Itemstack);

            float quantityServings   = GetServings(world, potslot.Itemstack);
            float servingsToTransfer = Math.Min(quantityServings, bowlSlot.Itemstack.Block.Attributes["servingCapacity"].AsFloat(1));

            ItemStack stack = new ItemStack(mealblock);

            (mealblock as IBlockMealContainer).SetContents(GetRecipeCode(world, potslot.Itemstack), stack, stacks, servingsToTransfer);

            SetServings(world, potslot.Itemstack, quantityServings - servingsToTransfer);

            if (quantityServings - servingsToTransfer <= 0)
            {
                Block emptyPotBlock = world.GetBlock(new AssetLocation(Attributes["emptiedBlockCode"].AsString()));
                potslot.Itemstack = new ItemStack(emptyPotBlock);
            }

            potslot.MarkDirty();

            bowlSlot.Itemstack = stack;
            bowlSlot.MarkDirty();
        }
Exemple #17
0
        public override void OnBlockInteractStop(float secondsUsed, IWorldAccessor world, IPlayer byPlayer, BlockSelection blockSel)
        {
            if (!PlacedBlockEating)
            {
                base.OnBlockInteractStop(secondsUsed, world, byPlayer, blockSel);
            }
            if (!byPlayer.Entity.Controls.Sneak)
            {
                return;
            }

            BlockEntityMeal bemeal    = world.BlockAccessor.GetBlockEntity(blockSel.Position) as BlockEntityMeal;
            ItemStack       stack     = OnPickBlock(world, blockSel.Position);
            DummySlot       dummySlot = new DummySlot(stack, bemeal.inventory);

            dummySlot.MarkedDirty += () => true;


            if (tryFinishEatMeal(secondsUsed, dummySlot, byPlayer.Entity, false))
            {
                float servingsLeft = GetQuantityServings(world, stack);

                if (bemeal.QuantityServings <= 0)
                {
                    Block block = world.GetBlock(new AssetLocation(Attributes["eatenBlock"].AsString()));
                    world.BlockAccessor.SetBlock(block.BlockId, blockSel.Position);
                }
                else
                {
                    bemeal.QuantityServings = servingsLeft;
                    bemeal.MarkDirty(true);
                }
            }
        }
 internal void Resolve(IWorldAccessor world)
 {
     if (Type == EnumItemClass.Block)
     {
         Block block = world.GetBlock(new AssetLocation(Code));
         if (block == null)
         {
             world.Logger.Error("Cannot resolve stack randomizer block with code {0}, wrong code?", Code);
             return;
         }
         ResolvedStack = new ItemStack(block);
         if (Attributes != null)
         {
             ResolvedStack.Attributes = Attributes.ToAttribute() as ITreeAttribute;
         }
     }
     else
     {
         Item item = world.GetItem(new AssetLocation(Code));
         if (item == null)
         {
             world.Logger.Error("Cannot resolve stack randomizer item with code {0}, wrong code?", Code);
             return;
         }
         ResolvedStack = new ItemStack(item);
         if (Attributes != null)
         {
             ResolvedStack.Attributes = Attributes.ToAttribute() as ITreeAttribute;
         }
     }
 }
        public override ItemStack[] GetDrops(
            IWorldAccessor world, BlockPos pos, IPlayer byPlayer,
            ref float dropChanceMultiplier, ref EnumHandling handling)
        {
            if ((byPlayer?.WorldData.CurrentGameMode == EnumGameMode.Creative) ||
                (world.BlockAccessor.GetBlockEntity(pos) is not BlockEntityFarmland farmland))
            {
                return(new ItemStack[0]);
            }

            // Prevent other behaviors from running after this one.
            handling = EnumHandling.PreventSubsequent;

            // Divide each type of nutrient (N, P and K) by its original, "full"
            // fertility to get a value from 0 to 1. Then pick the lowest one.
            var nutrients = farmland.Nutrients.Zip(farmland.OriginalFertility,
                                                   (current, original) => current / original).Min();

            // If this nutrient is below 95%, there is a chance the soil won't drop.
            if ((nutrients < 0.95) && (world.Rand.NextDouble() > nutrients))
            {
                return(new ItemStack[0]);
            }

            var fertility = this.block.FirstCodePart(2);
            var block     = world.GetBlock(new AssetLocation("game", $"soil-{fertility}-none"));

            return(new ItemStack[] { new(block) });
Exemple #20
0
        public override void OnBlockInteractStop(float secondsUsed, IWorldAccessor world, IPlayer byPlayer, BlockSelection blockSel)
        {
            if (!byPlayer.Entity.Controls.Sneak)
            {
                return;
            }

            ItemStack stack = OnPickBlock(world, blockSel.Position);

            if (world.Side == EnumAppSide.Server && secondsUsed >= 1.45f)
            {
                BlockEntityMeal bemeal = world.BlockAccessor.GetBlockEntity(blockSel.Position) as BlockEntityMeal;

                float servingsLeft = Consume(world, byPlayer, GetContents(world, stack), GetQuantityServings(world, stack), GetRecipeCode(world, stack) == null);
                bemeal.QuantityServings = servingsLeft;

                if (bemeal.QuantityServings <= 0)
                {
                    Block block = world.GetBlock(new AssetLocation(Attributes["eatenBlock"].AsString()));
                    world.BlockAccessor.SetBlock(block.BlockId, blockSel.Position);
                }
                else
                {
                    bemeal.QuantityServings--;
                    bemeal.MarkDirty(true);
                }
            }
        }
        public override bool TryPlaceBlock(IWorldAccessor world, IPlayer byPlayer, ItemStack itemstack, BlockSelection blockSel, ref string failureCode)
        {
            foreach (BlockFacing face in BlockFacing.ALLFACES)
            {
                BlockPos pos = blockSel.Position.AddCopy(face);
                IMechanicalPowerBlock block = world.BlockAccessor.GetBlock(pos) as IMechanicalPowerBlock;
                if (block != null)
                {
                    if (block.HasConnectorAt(world, pos, face.GetOpposite()))
                    {
                        Block toPlaceBlock = world.GetBlock(new AssetLocation(FirstCodePart() + "-" + face.Code[0]));
                        world.BlockAccessor.SetBlock(toPlaceBlock.BlockId, blockSel.Position);

                        block.DidConnectAt(world, pos, face.GetOpposite());
                        WasPlaced(world, blockSel.Position, face, block);

                        return(true);
                    }
                }
            }

            failureCode = "requiresaxle";

            return(false);
        }
Exemple #22
0
        /// <summary>
        /// Sets itemstack.block or itemstack.item
        /// </summary>
        /// <param name="resolver"></param>
        /// <param name="sourceForErrorLogging"></param>
        /// <returns></returns>
        public bool Resolve(IWorldAccessor resolver, string sourceForErrorLogging)
        {
            if (Type == EnumItemClass.Block)
            {
                Block block = resolver.GetBlock(Code);
                if (block == null)
                {
                    resolver.Logger.Warning("Failed resolving a blocks block drop or smeltedstack with code {0} in {1}", Code, sourceForErrorLogging);
                    return(false);
                }

                ResolvedItemstack = new ItemStack(block);
            }
            else
            {
                Item item = resolver.GetItem(Code);
                if (item == null)
                {
                    resolver.Logger.Warning("Failed resolving a blocks item drop or smeltedstack with code {0} in {1}", Code, sourceForErrorLogging);
                    return(false);
                }
                ResolvedItemstack = new ItemStack(item);
            }

            if (Attributes != null)
            {
                IAttribute attributes = Attributes.ToAttribute();
                if (attributes is ITreeAttribute)
                {
                    ResolvedItemstack.Attributes = (ITreeAttribute)attributes;
                }
            }

            return(true);
        }
 public override WorldInteraction[] GetPlacedBlockInteractionHelp(IWorldAccessor world, BlockSelection selection, IPlayer forPlayer)
 {
     if (Empty)
     {
         return(new WorldInteraction[]
         {
             new WorldInteraction()
             {
                 ActionLangCode = "blockhelp-torchholder-addtorch",
                 MouseButton = EnumMouseButton.Right,
                 Itemstacks = new ItemStack[] { new ItemStack(world.GetBlock(new AssetLocation("torch-basic-lit-up"))) }
             }
         }.Append(base.GetPlacedBlockInteractionHelp(world, selection, forPlayer)));
     }
     else
     {
         return(new WorldInteraction[]
         {
             new WorldInteraction()
             {
                 ActionLangCode = "blockhelp-torchholder-removetorch",
                 MouseButton = EnumMouseButton.Right,
                 Itemstacks = null
             }
         }.Append(base.GetPlacedBlockInteractionHelp(world, selection, forPlayer)));
     }
 }
        public override void FromTreeAtributes(ITreeAttribute tree, IWorldAccessor worldAccessForResolve)
        {
            base.FromTreeAtributes(tree, worldAccessForResolve);

            block = worldAccessForResolve.GetBlock((ushort)tree.GetInt("blockid"));
            deserializeVoxels(tree.GetBytes("voxels"));
        }
Exemple #25
0
        public override void FromTreeAtributes(ITreeAttribute tree, IWorldAccessor worldForResolving)
        {
            if (inventory == null)
            {
                if (tree.HasAttribute("forBlockId"))
                {
                    InitInventory(worldForResolving.GetBlock((ushort)tree.GetInt("forBlockId")));
                }
                else
                {
                    ITreeAttribute inventroytree = tree.GetTreeAttribute("inventory");
                    int            qslots        = inventroytree.GetInt("qslots");
                    // Must be a basket
                    if (qslots == 8)
                    {
                        quantitySlots       = 8;
                        inventoryClassName  = "basket";
                        dialogTitleLangCode = "basketcontents";
                    }

                    InitInventory(null);
                }
            }


            base.FromTreeAtributes(tree, worldForResolving);
        }
Exemple #26
0
        public override string GetPlacedBlockInfo(IWorldAccessor world, BlockPos pos, IPlayer forPlayer)
        {
            BlockEntityCrock becrock = world.BlockAccessor.GetBlockEntity(pos) as BlockEntityCrock;

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

            BlockMeal mealblock = world.GetBlock(new AssetLocation("bowl-meal")) as BlockMeal;

            CookingRecipe recipe = world.CookingRecipes.FirstOrDefault((rec) => becrock.RecipeCode == rec.Code);

            ItemStack[] stacks = becrock.inventory.Where(slot => !slot.Empty).Select(slot => slot.Itemstack).ToArray();

            if (stacks == null || stacks.Length == 0)
            {
                return("Empty");
            }

            StringBuilder dsc = new StringBuilder();

            if (recipe != null)
            {
                DummySlot firstContentItemSlot = new DummySlot(stacks != null && stacks.Length > 0 ? stacks[0] : null, becrock.inventory);

                if (recipe != null)
                {
                    dsc.AppendLine(recipe.GetOutputName(world, stacks).UcFirst());
                }

                string facts = mealblock.GetContentNutritionFacts(world, new DummySlot(OnPickBlock(world, pos)), null);

                if (facts != null)
                {
                    dsc.Append(facts);
                }

                firstContentItemSlot.Itemstack?.Collectible.AppendPerishableInfoText(firstContentItemSlot, dsc, world);
            }
            else
            {
                dsc.AppendLine("Contents:");
                foreach (var stack in stacks)
                {
                    if (stack == null)
                    {
                        continue;
                    }

                    dsc.AppendLine(stack.StackSize + "x  " + stack.GetName());
                }

                becrock.inventory[0].Itemstack.Collectible.AppendPerishableInfoText(becrock.inventory[0], dsc, api.World);
            }


            return(dsc.ToString());
        }
Exemple #27
0
        public override bool OnBlockInteractStart(IWorldAccessor world, IPlayer byPlayer, BlockSelection blockSel)
        {
            BlockPos pos = blockSel.Position;

            if (Variant["state"] == "closed")
            {
                world.BlockAccessor.SetBlock(world.GetBlock(CodeWithVariant("state", "opened")).Id, pos);
                world.PlaySoundAt(new AssetLocation("sounds/block/cokeovendoor-open"), pos.X + 0.5, pos.Y + 0.5, pos.Z + 0.5, byPlayer, true);
            }
            else
            {
                world.BlockAccessor.SetBlock(world.GetBlock(CodeWithVariant("state", "closed")).Id, pos);
                world.PlaySoundAt(new AssetLocation("sounds/block/cokeovendoor-close"), pos.X + 0.5, pos.Y + 0.5, pos.Z + 0.5, byPlayer, true);
            }

            return(true);
        }
Exemple #28
0
        public bool TryConstruct(IWorldAccessor world, BlockPos pos, CollectibleObject obj)
        {
            int stage = Stage;

            if (obj.Attributes?["firepitConstructable"]?.AsBool(false) != true)
            {
                return(false);
            }

            CombustibleProperties combprops = obj.CombustibleProps;

            if (stage == 5)
            {
                return(false);
            }

            if (stage == 4 && world.BlockAccessor.GetBlock(pos.DownCopy()).Code.Path.Equals("firewoodpile"))
            {
                Block charcoalPitBlock = world.GetBlock(new AssetLocation("charcoalpit"));
                if (charcoalPitBlock != null)
                {
                    world.BlockAccessor.SetBlock(charcoalPitBlock.BlockId, pos);
                    return(true);
                }
            }

            Block block = world.GetBlock(CodeWithParts(NextStageCodePart));

            world.BlockAccessor.ExchangeBlock(block.BlockId, pos);
            world.BlockAccessor.MarkBlockDirty(pos);
            if (block.Sounds != null)
            {
                world.PlaySoundAt(block.Sounds.Place, pos.X, pos.Y, pos.Z);
            }

            if (stage == 4)
            {
                BlockEntity be = world.BlockAccessor.GetBlockEntity(pos);
                if (be is BlockEntityFirepit)
                {
                    ((BlockEntityFirepit)be).igniteWithFuel(combprops, 4);
                }
            }

            return(true);
        }
 public ushort GetLessLiquidBlockId(IWorldAccessor world, Block block)
 {
     if (block.LiquidLevel == 1)
     {
         return(0);
     }
     return(world.GetBlock(block.CodeWithParts("" + (block.LiquidLevel - 1))).BlockId);
 }
        public override void OnBlockBroken(IWorldAccessor world, BlockPos pos, IPlayer byPlayer, float dropQuantityMultiplier = 1)
        {
            base.OnBlockBroken(world, pos, byPlayer, dropQuantityMultiplier);
            Block waterBlock = world.GetBlock(new AssetLocation("water-still-7"));

            world.BlockAccessor.SetBlock(waterBlock.Id, pos);
            world.BlockAccessor.MarkBlockDirty(pos);
        }