public override int GetRandomColor(ICoreClientAPI capi, BlockPos pos, BlockFacing facing) { BlockEntityCookedContainer bem = capi.World.BlockAccessor.GetBlockEntity(pos) as BlockEntityCookedContainer; if (bem == null) { return(base.GetRandomColor(capi, pos, facing)); } ItemStack[] stacks = bem.GetContentStacks(); ItemStack rndStack = stacks[capi.World.Rand.Next(stacks.Length)]; if (capi.World.Rand.NextDouble() < 0.4) { return(capi.BlockTextureAtlas.GetRandomPixel(Textures["ceramic"].Baked.TextureSubId)); } if (rndStack.Class == EnumItemClass.Block) { return(rndStack.Block.GetRandomColor(capi, pos, facing)); } else { return(capi.ItemTextureAtlas.GetRandomPixel(rndStack.Item.FirstTexture.Baked.TextureSubId)); } }
public override bool OnBlockInteractStart(IWorldAccessor world, IPlayer byPlayer, BlockSelection blockSel) { ItemSlot hotbarSlot = byPlayer.InventoryManager.ActiveHotbarSlot; if (!hotbarSlot.Empty && hotbarSlot.Itemstack.Collectible.Code.Path == "bowl-burned") { BlockEntityCookedContainer bec = world.BlockAccessor.GetBlockEntity(blockSel.Position) as BlockEntityCookedContainer; if (bec == null) { return(false); } bec.ServePlayer(byPlayer); return(true); } ItemStack stack = OnPickBlock(world, blockSel.Position); if (byPlayer.InventoryManager.TryGiveItemstack(stack, true)) { world.BlockAccessor.SetBlock(0, blockSel.Position); world.PlaySoundAt(this.Sounds.Place, byPlayer, byPlayer); return(true); } return(base.OnBlockInteractStart(world, byPlayer, blockSel)); }
public override ItemStack OnPickBlock(IWorldAccessor world, BlockPos pos) { ItemStack stack = base.OnPickBlock(world, pos); BlockEntityCookedContainer bec = world.BlockAccessor.GetBlockEntity(pos) as BlockEntityCookedContainer; if (bec != null) { ItemStack[] contentStacks = bec.GetContentStacks(); SetContents(bec.RecipeCode, bec.QuantityServings, stack, contentStacks); float temp = contentStacks.Length > 0 ? contentStacks[0].Collectible.GetTemperature(world, contentStacks[0]) : 0; SetTemperature(world, stack, temp, false); } return(stack); }
internal float PutMeal(BlockPos pos, ItemStack[] itemStack, string recipeCode, float quantityServings) { Block block = api.World.GetBlock(CodeWithVariant("type", "cooked")); api.World.BlockAccessor.SetBlock(block.Id, pos); float servingsToTransfer = Math.Min(quantityServings, this.Attributes["servingCapacity"].AsInt(1)); BlockEntityCookedContainer be = api.World.BlockAccessor.GetBlockEntity(pos) as BlockEntityCookedContainer; be.RecipeCode = recipeCode; be.QuantityServings = quantityServings; for (int i = 0; i < itemStack.Length; i++) { be.inventory[i].Itemstack = itemStack[i]; } be.MarkDirty(true); return(servingsToTransfer); }