Random Changes

This commit is contained in:
Zoë
2022-08-19 20:36:32 -05:00
parent 5f5c4f85c7
commit 6cd91bcc1d
32 changed files with 161 additions and 97 deletions

View File

@@ -13,7 +13,7 @@ import org.json.simple.JSONObject;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.random.RandomGenerator;
import com.dfsek.terra.addons.structure.structures.loot.functions.AmountFunction;
import com.dfsek.terra.addons.structure.structures.loot.functions.DamageFunction;
@@ -86,11 +86,11 @@ public class Entry {
/**
* Fetches a single ItemStack from the Entry, applying all functions to it.
*
* @param r The Random instance to apply functions with
* @param r The RandomGenerator instance to apply functions with
*
* @return ItemStack - The ItemStack with all functions applied.
*/
public ItemStack getItem(Random r) {
public ItemStack getItem(RandomGenerator r) {
ItemStack item = this.item.newItemStack(1);
for(LootFunction f : functions) {
item = f.apply(item, r);

View File

@@ -14,7 +14,7 @@ import org.json.simple.parser.ParseException;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.random.RandomGenerator;
import com.dfsek.terra.api.Platform;
import com.dfsek.terra.api.inventory.Inventory;
@@ -44,7 +44,7 @@ public class LootTableImpl implements com.dfsek.terra.api.structure.LootTable {
}
@Override
public void fillInventory(Inventory i, Random r) {
public void fillInventory(Inventory i, RandomGenerator r) {
List<ItemStack> loot = getLoot(r);
for(ItemStack stack : loot) {
int attempts = 0;
@@ -70,7 +70,7 @@ public class LootTableImpl implements com.dfsek.terra.api.structure.LootTable {
}
@Override
public List<ItemStack> getLoot(Random r) {
public List<ItemStack> getLoot(RandomGenerator r) {
List<ItemStack> itemList = new ArrayList<>();
for(Pool pool : pools) {
itemList.addAll(pool.getItems(r));

View File

@@ -13,7 +13,7 @@ import org.json.simple.JSONObject;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.random.RandomGenerator;
import com.dfsek.terra.api.Platform;
import com.dfsek.terra.api.inventory.ItemStack;
@@ -51,13 +51,13 @@ public class Pool {
}
/**
* Fetches a list of items from the pool using the provided Random instance.
* Fetches a list of items from the pool using the provided RandomGenerator instance.
*
* @param r The Random instance to use.
* @param r The RandomGenerator instance to use.
*
* @return List&lt;ItemStack&gt; - The list of items fetched.
*/
public List<ItemStack> getItems(Random r) {
public List<ItemStack> getItems(RandomGenerator r) {
int rolls = r.nextInt(max - min + 1) + min;
List<ItemStack> items = new ArrayList<>();

View File

@@ -8,7 +8,7 @@
package com.dfsek.terra.addons.structure.structures.loot.functions;
import java.util.Random;
import java.util.random.RandomGenerator;
import com.dfsek.terra.api.inventory.ItemStack;
@@ -35,12 +35,12 @@ public class AmountFunction implements LootFunction {
* Applies the function to an ItemStack.
*
* @param original The ItemStack on which to apply the function.
* @param r The Random instance to use.
* @param r The RandomGenerator instance to use.
*
* @return - ItemStack - The mutated ItemStack.
*/
@Override
public ItemStack apply(ItemStack original, Random r) {
public ItemStack apply(ItemStack original, RandomGenerator r) {
original.setAmount(r.nextInt(max - min + 1) + min);
return original;
}

View File

@@ -7,7 +7,7 @@
package com.dfsek.terra.addons.structure.structures.loot.functions;
import java.util.Random;
import java.util.random.RandomGenerator;
import com.dfsek.terra.api.inventory.ItemStack;
import com.dfsek.terra.api.inventory.item.Damageable;
@@ -36,12 +36,12 @@ public class DamageFunction implements LootFunction {
* Applies the function to an ItemStack.
*
* @param original The ItemStack on which to apply the function.
* @param r The Random instance to use.
* @param r The RandomGenerator instance to use.
*
* @return - ItemStack - The mutated ItemStack.
*/
@Override
public ItemStack apply(ItemStack original, Random r) {
public ItemStack apply(ItemStack original, RandomGenerator r) {
if(original == null) return null;
if(!original.isDamageable()) return original;
ItemMeta meta = original.getItemMeta();

View File

@@ -15,7 +15,7 @@ import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Random;
import java.util.random.RandomGenerator;
import com.dfsek.terra.api.Platform;
import com.dfsek.terra.api.inventory.ItemStack;
@@ -42,12 +42,12 @@ public class EnchantFunction implements LootFunction {
* Applies the function to an ItemStack.
*
* @param original The ItemStack on which to apply the function.
* @param r The Random instance to use.
* @param r The RandomGenerator instance to use.
*
* @return - ItemStack - The mutated ItemStack.
*/
@Override
public ItemStack apply(ItemStack original, Random r) {
public ItemStack apply(ItemStack original, RandomGenerator r) {
if(original.getItemMeta() == null) return original;
double enchant = (r.nextDouble() * (max - min)) + min;

View File

@@ -8,7 +8,7 @@
package com.dfsek.terra.addons.structure.structures.loot.functions;
import java.util.Random;
import java.util.random.RandomGenerator;
import com.dfsek.terra.api.inventory.ItemStack;
@@ -21,9 +21,9 @@ public interface LootFunction {
* Applies the function to an ItemStack.
*
* @param original The ItemStack on which to apply the function.
* @param r The Random instance to use.
* @param r The RandomGenerator instance to use.
*
* @return - ItemStack - The mutated ItemStack.
*/
ItemStack apply(ItemStack original, Random r);
ItemStack apply(ItemStack original, RandomGenerator r);
}