public void OnTickInChunk(float par) { if (LeakingLogBlockPos != null) { Block leakingLogBlock = Api.World.BlockAccessor.GetBlock(LeakingLogBlockPos); if (CheckLeakingLogBlock(leakingLogBlock)) { if (Api.Side == EnumAppSide.Server) { ItemStack resinVesselstack = Inventory[0].Itemstack; if (Inventory[0].Itemstack == null || resinVesselstack.Item.MaxStackSize > resinVesselstack.StackSize) { BlockBehaviorHarvestable harvestableLog = GetBlockBehaviorHarvestable(leakingLogBlock); HarvestResin(harvestableLog); ReplaceWithHarvested(LeakingLogBlockPos); } LastHarvested = Api.World.Calendar.TotalHours; MarkDirty(); } } } else { SelectLeakingLog(); } }
private void HarvestResin(BlockBehaviorHarvestable behavior) { ItemStack resinVesselstack = Inventory[0].Itemstack; var missedHarvests = (int)Math.Floor((Api.World.Calendar.TotalHours - LastHarvested) / InGameHours); missedHarvests = Math.Max(missedHarvests, 1); // at this point we are sure that there is at least one resin -> minimum 1 harvest! float dropRate = 1; // normally multiplied with player harvestrate ItemStack resinLogStack = behavior.harvestedStack.GetNextItemStack(dropRate); for (var i = 0; i < missedHarvests; i++) { if (resinVesselstack != null) { if (resinVesselstack.Item.Code.Path == behavior.harvestedStack.Code.Path) { resinVesselstack.StackSize += resinLogStack.StackSize; } } else { Inventory[0].Itemstack = resinLogStack; } } UpdateAsset(); }