Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,14 @@
}

public void fill(Container container, LootParams params, long seed) {
- LootContext lootContext = new LootContext.Builder(params).withOptionalRandomSeed(seed).create(this.randomSequence);
+ // 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
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);
RandomSource random = lootContext.getRandom();
+ // CraftBukkit start
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.bukkit.craftbukkit.inventory.CraftItemStack;
import org.bukkit.craftbukkit.util.CraftLocation;
import org.bukkit.craftbukkit.util.CraftNamespacedKey;
import org.bukkit.craftbukkit.util.RandomSourceWrapper;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.loot.LootContext;
Expand Down Expand Up @@ -68,8 +69,8 @@ public LootTable getHandle() {
@Override
public Collection<ItemStack> populateLoot(Random random, LootContext context) {
Preconditions.checkArgument(context != null, "LootContext cannot be null");
LootParams nmsContext = this.convertContext(context, random);
List<net.minecraft.world.item.ItemStack> nmsItems = this.handle.getRandomItems(nmsContext);
LootParams nmsContext = this.convertContext(context);
List<net.minecraft.world.item.ItemStack> nmsItems = this.handle.getRandomItems(nmsContext, random == null ? null : new RandomSourceWrapper(random));
Collection<ItemStack> bukkit = new ArrayList<>(nmsItems.size());

for (net.minecraft.world.item.ItemStack item : nmsItems) {
Expand All @@ -86,32 +87,29 @@ public Collection<ItemStack> populateLoot(Random random, LootContext context) {
public void fillInventory(Inventory inventory, Random random, LootContext context) {
Preconditions.checkArgument(inventory != null, "Inventory 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;
Container handle = craftInventory.getInventory();

// 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
public NamespacedKey getKey() {
return this.key;
}

private LootParams convertContext(LootContext context, Random random) {
private LootParams convertContext(LootContext context) {
Preconditions.checkArgument(context != null, "LootContext cannot be null");
Location loc = context.getLocation();
Preconditions.checkArgument(loc.getWorld() != null, "LootContext.getLocation#getWorld cannot be null");
ServerLevel handle = ((CraftWorld) loc.getWorld()).getHandle();

LootParams.Builder builder = new LootParams.Builder(handle);
if (random != null) {
// builder = builder.withRandom(new RandomSourceWrapper(random));
}
this.setMaybe(builder, LootContextParams.ORIGIN, CraftLocation.toVec3D(loc));
if (this.getHandle() != LootTable.EMPTY) {
// builder.luck(context.getLuck());
builder.withLuck(context.getLuck());

if (context.getLootedEntity() != null) {
Entity nmsLootedEntity = ((CraftEntity) context.getLootedEntity()).getHandle();
Expand Down