mirror of
https://github.com/PaperMC/Paper.git
synced 2025-08-15 20:23:53 -07:00
Fixup luck and random implementation in CB loot-tables (#11926)
This commit is contained in:
@@ -24,13 +24,14 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void fill(Container container, LootParams params, long seed) {
|
public void fill(Container container, LootParams params, long seed) {
|
||||||
|
- LootContext lootContext = new LootContext.Builder(params).withOptionalRandomSeed(seed).create(this.randomSequence);
|
||||||
+ // CraftBukkit start
|
+ // CraftBukkit start
|
||||||
+ this.fillInventory(container, params, seed, false);
|
+ this.fill(container, params, seed == 0L ? null : RandomSource.create(seed), false);
|
||||||
+ }
|
+ }
|
||||||
+
|
+
|
||||||
+ public void fillInventory(Container container, LootParams params, long seed, boolean plugin) {
|
+ public void fill(Container container, LootParams params, RandomSource randomSource, boolean plugin) {
|
||||||
+ // CraftBukkit end
|
+ // CraftBukkit end
|
||||||
LootContext lootContext = new LootContext.Builder(params).withOptionalRandomSeed(seed).create(this.randomSequence);
|
+ LootContext lootContext = new LootContext.Builder(params).withOptionalRandomSource(randomSource).create(this.randomSequence);
|
||||||
ObjectArrayList<ItemStack> randomItems = this.getRandomItems(lootContext);
|
ObjectArrayList<ItemStack> randomItems = this.getRandomItems(lootContext);
|
||||||
RandomSource random = lootContext.getRandom();
|
RandomSource random = lootContext.getRandom();
|
||||||
+ // CraftBukkit start
|
+ // CraftBukkit start
|
||||||
|
@@ -27,6 +27,7 @@ import org.bukkit.craftbukkit.inventory.CraftInventory;
|
|||||||
import org.bukkit.craftbukkit.inventory.CraftItemStack;
|
import org.bukkit.craftbukkit.inventory.CraftItemStack;
|
||||||
import org.bukkit.craftbukkit.util.CraftLocation;
|
import org.bukkit.craftbukkit.util.CraftLocation;
|
||||||
import org.bukkit.craftbukkit.util.CraftNamespacedKey;
|
import org.bukkit.craftbukkit.util.CraftNamespacedKey;
|
||||||
|
import org.bukkit.craftbukkit.util.RandomSourceWrapper;
|
||||||
import org.bukkit.inventory.Inventory;
|
import org.bukkit.inventory.Inventory;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.loot.LootContext;
|
import org.bukkit.loot.LootContext;
|
||||||
@@ -68,8 +69,8 @@ public class CraftLootTable implements org.bukkit.loot.LootTable {
|
|||||||
@Override
|
@Override
|
||||||
public Collection<ItemStack> populateLoot(Random random, LootContext context) {
|
public Collection<ItemStack> populateLoot(Random random, LootContext context) {
|
||||||
Preconditions.checkArgument(context != null, "LootContext cannot be null");
|
Preconditions.checkArgument(context != null, "LootContext cannot be null");
|
||||||
LootParams nmsContext = this.convertContext(context, random);
|
LootParams nmsContext = this.convertContext(context);
|
||||||
List<net.minecraft.world.item.ItemStack> nmsItems = this.handle.getRandomItems(nmsContext);
|
List<net.minecraft.world.item.ItemStack> nmsItems = this.handle.getRandomItems(nmsContext, random == null ? null : new RandomSourceWrapper(random));
|
||||||
Collection<ItemStack> bukkit = new ArrayList<>(nmsItems.size());
|
Collection<ItemStack> bukkit = new ArrayList<>(nmsItems.size());
|
||||||
|
|
||||||
for (net.minecraft.world.item.ItemStack item : nmsItems) {
|
for (net.minecraft.world.item.ItemStack item : nmsItems) {
|
||||||
@@ -86,12 +87,12 @@ public class CraftLootTable implements org.bukkit.loot.LootTable {
|
|||||||
public void fillInventory(Inventory inventory, Random random, LootContext context) {
|
public void fillInventory(Inventory inventory, Random random, LootContext context) {
|
||||||
Preconditions.checkArgument(inventory != null, "Inventory cannot be null");
|
Preconditions.checkArgument(inventory != null, "Inventory cannot be null");
|
||||||
Preconditions.checkArgument(context != null, "LootContext cannot be null");
|
Preconditions.checkArgument(context != null, "LootContext cannot be null");
|
||||||
LootParams nmsContext = this.convertContext(context, random);
|
LootParams nmsContext = this.convertContext(context);
|
||||||
CraftInventory craftInventory = (CraftInventory) inventory;
|
CraftInventory craftInventory = (CraftInventory) inventory;
|
||||||
Container handle = craftInventory.getInventory();
|
Container handle = craftInventory.getInventory();
|
||||||
|
|
||||||
// TODO: When events are added, call event here w/ custom reason?
|
// TODO: When events are added, call event here w/ custom reason?
|
||||||
this.getHandle().fillInventory(handle, nmsContext, random.nextLong(), true);
|
this.getHandle().fill(handle, nmsContext, random == null ? null : new RandomSourceWrapper(random), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -99,19 +100,16 @@ public class CraftLootTable implements org.bukkit.loot.LootTable {
|
|||||||
return this.key;
|
return this.key;
|
||||||
}
|
}
|
||||||
|
|
||||||
private LootParams convertContext(LootContext context, Random random) {
|
private LootParams convertContext(LootContext context) {
|
||||||
Preconditions.checkArgument(context != null, "LootContext cannot be null");
|
Preconditions.checkArgument(context != null, "LootContext cannot be null");
|
||||||
Location loc = context.getLocation();
|
Location loc = context.getLocation();
|
||||||
Preconditions.checkArgument(loc.getWorld() != null, "LootContext.getLocation#getWorld cannot be null");
|
Preconditions.checkArgument(loc.getWorld() != null, "LootContext.getLocation#getWorld cannot be null");
|
||||||
ServerLevel handle = ((CraftWorld) loc.getWorld()).getHandle();
|
ServerLevel handle = ((CraftWorld) loc.getWorld()).getHandle();
|
||||||
|
|
||||||
LootParams.Builder builder = new LootParams.Builder(handle);
|
LootParams.Builder builder = new LootParams.Builder(handle);
|
||||||
if (random != null) {
|
|
||||||
// builder = builder.withRandom(new RandomSourceWrapper(random));
|
|
||||||
}
|
|
||||||
this.setMaybe(builder, LootContextParams.ORIGIN, CraftLocation.toVec3D(loc));
|
this.setMaybe(builder, LootContextParams.ORIGIN, CraftLocation.toVec3D(loc));
|
||||||
if (this.getHandle() != LootTable.EMPTY) {
|
if (this.getHandle() != LootTable.EMPTY) {
|
||||||
// builder.luck(context.getLuck());
|
builder.withLuck(context.getLuck());
|
||||||
|
|
||||||
if (context.getLootedEntity() != null) {
|
if (context.getLootedEntity() != null) {
|
||||||
Entity nmsLootedEntity = ((CraftEntity) context.getLootedEntity()).getHandle();
|
Entity nmsLootedEntity = ((CraftEntity) context.getLootedEntity()).getHandle();
|
||||||
|
Reference in New Issue
Block a user