public override void FromTreeAttributes(ITreeAttribute tree, IWorldAccessor worldForResolving) { base.FromTreeAttributes(tree, worldForResolving); ovenInv.FromTreeAttributes(tree); burning = tree.GetInt("burn") > 0; rotation = tree.GetInt("rota"); ovenTemperature = tree.GetFloat("temp"); fuelBurnTime = tree.GetFloat("tfuel"); for (int i = 0; i < itemCapacity; i++) { bakingData[i] = OvenItemData.ReadFromTree(tree, i); } if (Api?.Side == EnumAppSide.Client) { updateMeshes(); if (clientSidePrevBurning != IsBurning) { ToggleAmbientSounds(IsBurning); clientSidePrevBurning = IsBurning; MarkDirty(true); } } }
public BlockEntityOven() { bakingData = new OvenItemData[itemCapacity]; for (int i = 0; i < itemCapacity; i++) { bakingData[i] = new OvenItemData(); } woodrand = new int[fuelitemCapacity]; ovenInv = new InventoryOven("oven-0", itemCapacity, fuelitemCapacity); meshes = new MeshData[itemCapacity + fuelitemCapacity]; }
protected virtual void IncrementallyBake(float dt, int slotIndex) { ItemSlot slot = Inventory[slotIndex]; OvenItemData bakeData = bakingData[slotIndex]; float targetTemp = bakeData.BrowningPoint; if (targetTemp == 0) { targetTemp = 160f; //prevents any possible divide by zero } float diff = bakeData.temp / targetTemp; float timeFactor = bakeData.TimeToBake; if (timeFactor == 0) { timeFactor = 1; //prevents any possible divide by zero } float delta = GameMath.Clamp((int)diff, 1, 30) * dt / timeFactor; float currentLevel = bakeData.BakedLevel; if (bakeData.temp > targetTemp) { currentLevel = bakeData.BakedLevel + delta; bakeData.BakedLevel = currentLevel; } var bakeProps = BakingProperties.ReadFrom(slot.Itemstack); float levelFrom = bakeProps?.LevelFrom ?? 0f; float levelTo = bakeProps?.LevelTo ?? 1f; float startHeightMul = bakeProps?.StartScaleY ?? 1f; float endHeightMul = bakeProps?.EndScaleY ?? 1f; float progress = GameMath.Clamp((currentLevel - levelFrom) / (levelTo - levelFrom), 0, 1); float heightMul = GameMath.Mix(startHeightMul, endHeightMul, progress); float nowHeightMulStaged = (int)(heightMul * BakingStageThreshold) / (float)BakingStageThreshold; bool reDraw = nowHeightMulStaged != bakeData.CurHeightMul; bakeData.CurHeightMul = nowHeightMulStaged; // see if increasing the partBaked by delta, has moved this stack up to the next "bakedStage", i.e. a different item if (currentLevel > levelTo) { float nowTemp = bakeData.temp; string resultCode = bakeProps?.ResultCode; if (resultCode != null) { ItemStack resultStack = null; if (slot.Itemstack.Class == EnumItemClass.Block) { Block block = Api.World.GetBlock(new AssetLocation(resultCode)); if (block != null) { resultStack = new ItemStack(block); } } else { Item item = Api.World.GetItem(new AssetLocation(resultCode)); if (item != null) { resultStack = new ItemStack(item); } } if (resultStack != null) { var collObjCb = ovenInv[slotIndex].Itemstack.Collectible as IBakeableCallback; if (collObjCb != null) { collObjCb.OnBaked(ovenInv[slotIndex].Itemstack, resultStack); } ovenInv[slotIndex].Itemstack = resultStack; bakingData[slotIndex] = new OvenItemData(resultStack); bakingData[slotIndex].temp = nowTemp; reDraw = true; } } else { // Allow the oven also to 'smelt' low-temperature bakeable items which do not have specific baking properties ItemSlot result = new DummySlot(null); if (slot.Itemstack.Collectible.CanSmelt(Api.World, ovenInv, slot.Itemstack, null)) { slot.Itemstack.Collectible.DoSmelt(Api.World, ovenInv, ovenInv[slotIndex], result); if (!result.Empty) { ovenInv[slotIndex].Itemstack = result.Itemstack; bakingData[slotIndex] = new OvenItemData(result.Itemstack); bakingData[slotIndex].temp = nowTemp; reDraw = true; } } } } if (reDraw) { updateMesh(slotIndex); MarkDirty(true); } }
protected virtual bool TryPut(ItemSlot slot) { if (IsBurning || !FuelSlot.Empty) { return(false); } BakingProperties bakingProps = BakingProperties.ReadFrom(slot.Itemstack); if (bakingProps == null) { return(false); } if (slot.Itemstack.Attributes.GetBool("bakeable", true) == false) { return(false); } // For large items (pies) check all 4 oven slots are empty before adding the item if (bakingProps.LargeItem) { for (int index = 0; index < itemCapacity; index++) { if (!ovenInv[index].Empty) { return(false); } } } for (int index = 0; index < itemCapacity; index++) { if (ovenInv[index].Empty) { int moved = slot.TryPutInto(Api.World, ovenInv[index]); if (moved > 0) { // We store the baked level data into the BlockEntity itself, for continuity and to avoid adding unwanted attributes to the ItemStacks (which e.g. could cause them not to stack) bakingData[index] = new OvenItemData(ovenInv[index].Itemstack); updateMesh(index); MarkDirty(true); lastRemoved = null; } return(moved > 0); } else if (index == 0) { // Disallow other items from being inserted if slot 0 holds a large item (a pie) BakingProperties slot0Props = BakingProperties.ReadFrom(ovenInv[index].Itemstack); if (slot0Props != null && slot0Props.LargeItem) { return(false); } } } return(false); }