9
0
mirror of https://github.com/LeavesMC/Leaves.git synced 2026-01-04 15:41:31 +00:00
Files
LeavesMC/patches/server/0120-Loot-world-random.patch
2023-09-12 18:48:51 +08:00

67 lines
4.1 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: violetc <58360096+s-yh-china@users.noreply.github.com>
Date: Mon, 4 Sep 2023 22:09:10 +0800
Subject: [PATCH] Loot world random
diff --git a/src/main/java/net/minecraft/world/entity/projectile/FishingHook.java b/src/main/java/net/minecraft/world/entity/projectile/FishingHook.java
index d57e6c88524482b4d37930d0fd2e9f7911c6d3a0..9a82ef9c4545f7d82806fc68b14c1b34aebc21e6 100644
--- a/src/main/java/net/minecraft/world/entity/projectile/FishingHook.java
+++ b/src/main/java/net/minecraft/world/entity/projectile/FishingHook.java
@@ -496,7 +496,7 @@ public class FishingHook extends Projectile {
} else if (this.nibble > 0) {
LootParams lootparams = (new LootParams.Builder((ServerLevel) this.level())).withParameter(LootContextParams.ORIGIN, this.position()).withParameter(LootContextParams.TOOL, usedItem).withParameter(LootContextParams.THIS_ENTITY, this).withLuck((float) this.luck + entityhuman.getLuck()).create(LootContextParamSets.FISHING);
LootTable loottable = this.level().getServer().getLootData().getLootTable(BuiltInLootTables.FISHING);
- List<ItemStack> list = loottable.getRandomItems(lootparams);
+ List<ItemStack> list = top.leavesmc.leaves.LeavesConfig.lootWorldRandom ? loottable.getRandomItems(lootparams, this.random) : loottable.getRandomItems(lootparams); // Leaves - world random
CriteriaTriggers.FISHING_ROD_HOOKED.trigger((ServerPlayer) entityhuman, usedItem, this, list);
Iterator iterator = list.iterator();
diff --git a/src/main/java/net/minecraft/world/level/storage/loot/LootContext.java b/src/main/java/net/minecraft/world/level/storage/loot/LootContext.java
index 17df8b341c65ca24fd2a18424f221918d0a7a111..9b55abb89cdf817633d7d2b7d202765f272cebe7 100644
--- a/src/main/java/net/minecraft/world/level/storage/loot/LootContext.java
+++ b/src/main/java/net/minecraft/world/level/storage/loot/LootContext.java
@@ -97,6 +97,13 @@ public class LootContext {
this.params = parameters;
}
+ // Leaves start - world random
+ public LootContext.Builder withRandom(RandomSource random) {
+ this.random = random;
+ return this;
+ }
+ // Leaves end - world random
+
public LootContext.Builder withOptionalRandomSeed(long seed) {
if (seed != 0L) {
this.random = RandomSource.create(seed);
@@ -113,6 +120,11 @@ public class LootContext {
ServerLevel serverLevel = this.getLevel();
MinecraftServer minecraftServer = serverLevel.getServer();
RandomSource randomSource;
+ // Leaves start - world random
+ if (top.leavesmc.leaves.LeavesConfig.lootWorldRandom) {
+ return new LootContext(this.params, serverLevel.getRandom(), minecraftServer.getLootData());
+ }
+ // Leaves end - world random
if (this.random != null) {
randomSource = this.random;
} else if (randomSequenceId != null) {
diff --git a/src/main/java/net/minecraft/world/level/storage/loot/LootTable.java b/src/main/java/net/minecraft/world/level/storage/loot/LootTable.java
index e46a0afa45ee771a0114703acc314d7cf8e8ffed..e7242ba6460b31bb0bb66869f39ea3be0691a80c 100644
--- a/src/main/java/net/minecraft/world/level/storage/loot/LootTable.java
+++ b/src/main/java/net/minecraft/world/level/storage/loot/LootTable.java
@@ -127,6 +127,12 @@ public class LootTable {
return this.getRandomItems((new LootContext.Builder(parameters)).create(this.randomSequence));
}
+ // Leaves start - world random
+ public ObjectArrayList<ItemStack> getRandomItems(LootParams parameters, RandomSource randomSource) {
+ return this.getRandomItems((new LootContext.Builder(parameters)).withRandom(randomSource).create(this.randomSequence));
+ }
+ // Leaves end - world random
+
private ObjectArrayList<ItemStack> getRandomItems(LootContext context) {
ObjectArrayList<ItemStack> objectarraylist = new ObjectArrayList();