Skip to content

Commit

Permalink
Try, but nothing happened (LeavesMC#120)
Browse files Browse the repository at this point in the history
  • Loading branch information
s-yh-china authored and Lumine1909 committed Sep 15, 2024
1 parent c899cea commit b732df8
Showing 1 changed file with 46 additions and 2 deletions.
48 changes: 46 additions & 2 deletions patches/server/0123-Loot-world-random.patch
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,38 @@ 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..d5eea5d36b9fac6001cca262e9a7c397852e4bdb 100644
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
@@ -113,6 +113,11 @@ public class LootContext {
@@ -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;
Expand All @@ -20,3 +47,20 @@ index 17df8b341c65ca24fd2a18424f221918d0a7a111..d5eea5d36b9fac6001cca262e9a7c397
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();

0 comments on commit b732df8

Please sign in to comment.