private void CreateDrop(EntityAgent byEntity, string rocktype) { IPlayer player = (byEntity as EntityPlayer)?.Player; for (int i = 0; i < drops.Length; i++) { double rnd = api.World.Rand.NextDouble(); PanningDrop drop = drops[i]; float val = drop.Chance.nextFloat(); ItemStack stack = drop.ResolvedStack; if (drops[i].Code.Contains("{rocktype}")) { stack = Resolve(drops[i].Type, drops[i].Code.Replace("{rocktype}", rocktype)); } if (rnd < val && stack != null) { stack = stack.Clone(); if (player == null || !player.InventoryManager.TryGiveItemstack(stack, true)) { api.World.SpawnItemEntity(stack, byEntity.ServerPos.XYZ); } break; } } }
private void CreateDrop(EntityAgent byEntity, string fromBlockCode) { IPlayer player = (byEntity as EntityPlayer)?.Player; PanningDrop[] drops = null; foreach (var val in dropsBySourceMat.Keys) { if (WildcardUtil.Match(val, fromBlockCode)) { drops = dropsBySourceMat[val]; } } if (drops == null) { throw new InvalidOperationException("Coding error, no drops defined for source mat " + fromBlockCode); } string rocktype = api.World.GetBlock(new AssetLocation(fromBlockCode))?.Variant["rock"]; drops.Shuffle(api.World.Rand); for (int i = 0; i < drops.Length; i++) { PanningDrop drop = drops[i]; double rnd = api.World.Rand.NextDouble(); float extraMul = 1f; if (drop.DropModbyStat != null) { // If the stat does not exist, then GetBlended returns 1 \o/ extraMul = byEntity.Stats.GetBlended(drop.DropModbyStat); } float val = drop.Chance.nextFloat() * extraMul; ItemStack stack = drop.ResolvedItemstack; if (drops[i].Code.Path.Contains("{rocktype}")) { stack = Resolve(drops[i].Type, drops[i].Code.Path.Replace("{rocktype}", rocktype)); } if (rnd < val && stack != null) { stack = stack.Clone(); if (player == null || !player.InventoryManager.TryGiveItemstack(stack, true)) { api.World.SpawnItemEntity(stack, byEntity.ServerPos.XYZ); } break; } } }