public override void OnBlockPlaced(ItemStack byItemStack = null) { BlockCookedContainer blockpot = byItemStack?.Block as BlockCookedContainer; if (blockpot != null) { TreeAttribute tempTree = byItemStack.Attributes?["temperature"] as TreeAttribute; ItemStack[] stacks = blockpot.GetNonEmptyContents(Api.World, byItemStack); for (int i = 0; i < stacks.Length; i++) { ItemStack stack = stacks[i].Clone(); Inventory[i].Itemstack = stack; // Clone temp attribute if (tempTree != null) { stack.Attributes["temperature"] = tempTree.Clone(); } } RecipeCode = blockpot.GetRecipeCode(Api.World, byItemStack); QuantityServings = blockpot.GetServings(Api.World, byItemStack); } if (Api.Side == EnumAppSide.Client) { currentMesh = GenMesh(); MarkDirty(true); } }
/// <summary> Creates a <see cref="CarriedBlock"/> from the specified world /// and position, but doesn't remove it. Returns null if unsuccessful. </summary> /// <example cref="ArgumentNullException"> Thrown if world or pos is null. </exception> public static CarriedBlock Get(IWorldAccessor world, BlockPos pos, CarrySlot slot) { if (world == null) { throw new ArgumentNullException(nameof(world)); } if (pos == null) { throw new ArgumentNullException(nameof(pos)); } var block = world.BlockAccessor.GetBlock(pos); if (block.Id == 0) { return(null); // Can't pick up air. } var stack = block.OnPickBlock(world, pos) ?? new ItemStack(block); ITreeAttribute blockEntityData = null; if (world.Side == EnumAppSide.Server) { var blockEntity = world.BlockAccessor.GetBlockEntity(pos); if (blockEntity != null) { blockEntityData = new TreeAttribute(); blockEntity.ToTreeAttributes(blockEntityData); blockEntityData = blockEntityData.Clone(); // We don't need to keep the position. blockEntityData.RemoveAttribute("posx"); blockEntityData.RemoveAttribute("posy"); blockEntityData.RemoveAttribute("posz"); // And angle needs to be removed, or else it will // override the angle set from block placement. blockEntityData.RemoveAttribute("meshAngle"); } } return(new CarriedBlock(slot, stack, blockEntityData)); }