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); } }
public PotInFirepitRenderer(ICoreClientAPI capi, ItemStack stack, BlockPos pos, bool isInOutputSlot) { this.capi = capi; this.stack = stack; this.pos = pos; this.isInOutputSlot = isInOutputSlot; BlockCookedContainer potBlock = capi.World.GetBlock(stack.Collectible.CodeWithVariant("type", "cooked")) as BlockCookedContainer; if (isInOutputSlot) { MealMeshCache meshcache = capi.ModLoader.GetModSystem <MealMeshCache>(); MeshData potMesh = meshcache.CreateMealMesh(potBlock.Shape, potBlock.GetCookingRecipe(capi.World, stack), potBlock.GetContents(capi.World, stack), new Vec3f(0, 2.5f / 16f, 0)); potRef = capi.Render.UploadMesh(potMesh); } else { MeshData potMesh; capi.Tesselator.TesselateShape(potBlock, capi.Assets.TryGet("shapes/block/clay/pot-opened-empty.json").ToObject <Shape>(), out potMesh); potRef = capi.Render.UploadMesh(potMesh); MeshData lidMesh; capi.Tesselator.TesselateShape(potBlock, capi.Assets.TryGet("shapes/block/clay/pot-part-lid.json").ToObject <Shape>(), out lidMesh); lidRef = capi.Render.UploadMesh(lidMesh); } }
public override void Initialize(ICoreAPI api) { base.Initialize(api); ownBlock = Block as BlockCookedContainer; if (Api.Side == EnumAppSide.Client) { RegisterGameTickListener(Every100ms, 200); } }
public override void Initialize(ICoreAPI api) { base.Initialize(api); ownBlock = api.World.BlockAccessor.GetBlock(pos) as BlockCookedContainer; if (api.Side == EnumAppSide.Client) { RegisterGameTickListener(Every100ms, 200); } if (api.Side == EnumAppSide.Client && currentMesh == null) { currentMesh = GenMesh(); MarkDirty(true); } }
public override bool OnBlockInteractStart(IWorldAccessor world, IPlayer byPlayer, BlockSelection blockSel) { int stage = Stage; ItemStack stack = byPlayer.InventoryManager.ActiveHotbarSlot?.Itemstack; if (stage == 5) { BlockEntityFirepit bef = world.BlockAccessor.GetBlockEntity(blockSel.Position) as BlockEntityFirepit; if (bef != null && stack?.Block != null && stack.Block.HasBehavior <BlockBehaviorCanIgnite>()) { return(false); } if (bef != null && stack != null && byPlayer.Entity.Controls.Sneak) { if (stack.Collectible.CombustibleProps != null && stack.Collectible.CombustibleProps.MeltingPoint > 0) { ItemStackMoveOperation op = new ItemStackMoveOperation(world, EnumMouseButton.Button1, 0, EnumMergePriority.DirectMerge, 1); byPlayer.InventoryManager.ActiveHotbarSlot.TryPutInto(bef.inputSlot, ref op); if (op.MovedQuantity > 0) { (byPlayer as IClientPlayer)?.TriggerFpAnimation(EnumHandInteract.HeldItemInteract); return(true); } } if (stack.Collectible.CombustibleProps != null && stack.Collectible.CombustibleProps.BurnTemperature > 0) { ItemStackMoveOperation op = new ItemStackMoveOperation(world, EnumMouseButton.Button1, 0, EnumMergePriority.DirectMerge, 1); byPlayer.InventoryManager.ActiveHotbarSlot.TryPutInto(bef.fuelSlot, ref op); if (op.MovedQuantity > 0) { (byPlayer as IClientPlayer)?.TriggerFpAnimation(EnumHandInteract.HeldItemInteract); return(true); } } } if (stack?.Collectible.Attributes?.IsTrue("mealContainer") == true) { ItemSlot potSlot = null; if (bef?.inputStack?.Collectible is BlockCookedContainer) { potSlot = bef.inputSlot; } if (bef?.outputStack?.Collectible is BlockCookedContainer) { potSlot = bef.outputSlot; } if (potSlot != null) { BlockCookedContainer blockPot = potSlot.Itemstack.Collectible as BlockCookedContainer; ItemSlot targetSlot = byPlayer.InventoryManager.ActiveHotbarSlot; if (byPlayer.InventoryManager.ActiveHotbarSlot.StackSize > 1) { targetSlot = new DummySlot(targetSlot.TakeOut(1)); byPlayer.InventoryManager.ActiveHotbarSlot.MarkDirty(); blockPot.ServeIntoStack(targetSlot, potSlot, world); if (!byPlayer.InventoryManager.TryGiveItemstack(targetSlot.Itemstack, true)) { world.SpawnItemEntity(targetSlot.Itemstack, byPlayer.Entity.ServerPos.XYZ); } } else { blockPot.ServeIntoStack(targetSlot, potSlot, world); } } else { return(false); } return(true); } return(base.OnBlockInteractStart(world, byPlayer, blockSel)); } if (stack != null && TryConstruct(world, blockSel.Position, stack.Collectible, byPlayer)) { if (byPlayer != null && byPlayer.WorldData.CurrentGameMode != EnumGameMode.Creative) { byPlayer.InventoryManager.ActiveHotbarSlot.TakeOut(1); } return(true); } return(false); }