mirror of
https://github.com/BX-Team/DivineMC.git
synced 2026-01-04 15:31:43 +00:00
remove RCT and orb clump for now
This commit is contained in:
211
patches/removed/1.21.5/server/0013-Clump-experience-orbs.patch
Normal file
211
patches/removed/1.21.5/server/0013-Clump-experience-orbs.patch
Normal file
@@ -0,0 +1,211 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: NONPLAYT <76615486+NONPLAYT@users.noreply.github.com>
|
||||
Date: Sat, 1 Feb 2025 16:47:09 +0300
|
||||
Subject: [PATCH] Clump experience orbs
|
||||
|
||||
|
||||
diff --git a/net/minecraft/world/entity/ExperienceOrb.java b/net/minecraft/world/entity/ExperienceOrb.java
|
||||
index a43e5190c0f9ae14ccecccd5b58dc0e17f18b0a1..06ffba13f211851e8f6d630a72b41474673e8df8 100644
|
||||
--- a/net/minecraft/world/entity/ExperienceOrb.java
|
||||
+++ b/net/minecraft/world/entity/ExperienceOrb.java
|
||||
@@ -49,6 +49,10 @@ public class ExperienceOrb extends Entity {
|
||||
@javax.annotation.Nullable
|
||||
public java.util.UUID triggerEntityId;
|
||||
public org.bukkit.entity.ExperienceOrb.SpawnReason spawnReason = org.bukkit.entity.ExperienceOrb.SpawnReason.UNKNOWN;
|
||||
+ // DivineMC start - Clump experience orbs
|
||||
+ public java.util.Map<Integer, Integer> clumps$clumpedMap;
|
||||
+ public Optional<EnchantedItemInUse> clumps$currentEntry;
|
||||
+ // DivineMC end - Clump experience orbs
|
||||
|
||||
private void loadPaperNBT(CompoundTag tag) {
|
||||
if (!tag.contains("Paper.ExpData", net.minecraft.nbt.Tag.TAG_COMPOUND)) {
|
||||
@@ -239,6 +243,28 @@ public class ExperienceOrb extends Entity {
|
||||
}
|
||||
|
||||
private static boolean tryMergeToExisting(ServerLevel level, Vec3 pos, int amount) {
|
||||
+ // DivineMC start - Clump experience orbs
|
||||
+ if (org.bxteam.divinemc.DivineConfig.clumpOrbs) {
|
||||
+ AABB aABB = AABB.ofSize(pos, 1.0D, 1.0D, 1.0D);
|
||||
+ int id = level.getRandom().nextInt(40);
|
||||
+ List<ExperienceOrb> list = level.getEntities(EntityTypeTest.forClass(ExperienceOrb.class), aABB, (experienceOrbx) -> canMerge(experienceOrbx, id, amount));
|
||||
+ if(!list.isEmpty()) {
|
||||
+ ExperienceOrb experienceOrb = list.getFirst();
|
||||
+ java.util.Map<Integer, Integer> clumpedMap = (experienceOrb).clumps$getClumpedMap();
|
||||
+ (experienceOrb).clumps$setClumpedMap(java.util.stream.Stream.of(clumpedMap, java.util.Collections.singletonMap(amount, 1))
|
||||
+ .flatMap(map -> map.entrySet().stream())
|
||||
+ .collect(java.util.stream.Collectors.toMap(java.util.Map.Entry::getKey, java.util.Map.Entry::getValue, Integer::sum)));
|
||||
+ (experienceOrb).count = (clumpedMap.values()
|
||||
+ .stream()
|
||||
+ .reduce(Integer::sum)
|
||||
+ .orElse(1));
|
||||
+ (experienceOrb).age = (0);
|
||||
+ return true;
|
||||
+ } else {
|
||||
+ return false;
|
||||
+ }
|
||||
+ }
|
||||
+ // DivineMC end - Clump experience orbs
|
||||
// Paper - TODO some other event for this kind of merge
|
||||
AABB aabb = AABB.ofSize(pos, 1.0, 1.0, 1.0);
|
||||
int randomInt = level.getRandom().nextInt(40);
|
||||
@@ -254,11 +280,11 @@ public class ExperienceOrb extends Entity {
|
||||
}
|
||||
|
||||
private boolean canMerge(ExperienceOrb orb) {
|
||||
- return orb != this && canMerge(orb, this.getId(), this.value);
|
||||
+ return org.bxteam.divinemc.DivineConfig.clumpOrbs ? orb.isAlive() && !this.is(orb) : orb != this && canMerge(orb, this.getId(), this.value); // DivineMC - Clump experience orbs
|
||||
}
|
||||
|
||||
private static boolean canMerge(ExperienceOrb orb, int amount, int other) {
|
||||
- return !orb.isRemoved() && (orb.getId() - amount) % 40 == 0 && orb.value == other;
|
||||
+ return org.bxteam.divinemc.DivineConfig.clumpOrbs ? orb.isAlive() : !orb.isRemoved() && (orb.getId() - amount) % 40 == 0 && orb.value == other; // DivineMC - Clump experience orbs
|
||||
}
|
||||
|
||||
private void merge(ExperienceOrb orb) {
|
||||
@@ -267,6 +293,18 @@ public class ExperienceOrb extends Entity {
|
||||
return;
|
||||
}
|
||||
// Paper end - call orb merge event
|
||||
+ // DivineMC start - Clump experience orbs
|
||||
+ if (org.bxteam.divinemc.DivineConfig.clumpOrbs) {
|
||||
+ java.util.Map<Integer, Integer> otherMap = (orb).clumps$getClumpedMap();
|
||||
+ this.count = clumps$getClumpedMap().values().stream().reduce(Integer::sum).orElse(1);
|
||||
+ this.age = Math.min(this.age, (orb).age);
|
||||
+ clumps$setClumpedMap(java.util.stream.Stream.of(clumps$getClumpedMap(), otherMap)
|
||||
+ .flatMap(map -> map.entrySet().stream())
|
||||
+ .collect(java.util.stream.Collectors.toMap(java.util.Map.Entry::getKey, java.util.Map.Entry::getValue, Integer::sum)));
|
||||
+ orb.discard(EntityRemoveEvent.Cause.MERGE); // DivineMC - add Bukkit remove cause
|
||||
+ return;
|
||||
+ }
|
||||
+ // DivineMC end - Clump experience orbs
|
||||
this.count = this.count + orb.count;
|
||||
this.age = Math.min(this.age, orb.age);
|
||||
orb.discard(EntityRemoveEvent.Cause.MERGE); // CraftBukkit - add Bukkit remove cause
|
||||
@@ -308,6 +346,13 @@ public class ExperienceOrb extends Entity {
|
||||
compound.putInt("Value", this.value); // Paper - save as Integer
|
||||
compound.putInt("Count", this.count);
|
||||
this.savePaperNBT(compound); // Paper
|
||||
+ // DivineMC start - Clump experience orbs
|
||||
+ if (clumps$clumpedMap != null) {
|
||||
+ CompoundTag map = new CompoundTag();
|
||||
+ clumps$getClumpedMap().forEach((value, count) -> map.putInt(String.valueOf(value), count));
|
||||
+ compound.put("clumpedMap", map);
|
||||
+ }
|
||||
+ // DivineMC end - Clump experience orbs
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -317,10 +362,51 @@ public class ExperienceOrb extends Entity {
|
||||
this.value = compound.getInt("Value"); // Paper - load as Integer
|
||||
this.count = Math.max(compound.getInt("Count"), 1);
|
||||
this.loadPaperNBT(compound); // Paper
|
||||
+ // DivineMC start - Clump experience orbs
|
||||
+ java.util.Map<Integer, Integer> map = new java.util.HashMap<>();
|
||||
+ if (compound.contains("clumpedMap")) {
|
||||
+ CompoundTag clumpedMap = compound.getCompound("clumpedMap");
|
||||
+ for (String s : clumpedMap.getAllKeys()) {
|
||||
+ map.put(Integer.parseInt(s), clumpedMap.getInt(s));
|
||||
+ }
|
||||
+ } else {
|
||||
+ map.put(value, count);
|
||||
+ }
|
||||
+
|
||||
+ clumps$setClumpedMap(map);
|
||||
+ // DivineMC end - Clump experience orbs
|
||||
}
|
||||
|
||||
@Override
|
||||
public void playerTouch(Player entity) {
|
||||
+ // DivineMC start - Clump experience orbs
|
||||
+ if(entity instanceof ServerPlayer && org.bxteam.divinemc.DivineConfig.clumpOrbs) {
|
||||
+ entity.takeXpDelay = 0;
|
||||
+ entity.take(this, 1);
|
||||
+
|
||||
+ if(this.value != 0 || clumps$resolve()) {
|
||||
+ java.util.concurrent.atomic.AtomicInteger toGive = new java.util.concurrent.atomic.AtomicInteger();
|
||||
+ clumps$getClumpedMap().forEach((value, amount) -> {
|
||||
+ int actualValue = value;
|
||||
+
|
||||
+ for(int i = 0; i < amount; i++) {
|
||||
+ int leftOver = actualValue;
|
||||
+ if(leftOver == actualValue) {
|
||||
+ leftOver = this.repairPlayerItems((ServerPlayer) entity, actualValue);
|
||||
+ }
|
||||
+ if(leftOver > 0) {
|
||||
+ toGive.addAndGet(leftOver);
|
||||
+ }
|
||||
+ }
|
||||
+ });
|
||||
+ if(toGive.get() > 0) {
|
||||
+ entity.giveExperiencePoints(toGive.get());
|
||||
+ }
|
||||
+ }
|
||||
+ this.discard();
|
||||
+ return;
|
||||
+ }
|
||||
+ // DivineMC end - Clump experience orbs
|
||||
if (entity instanceof ServerPlayer serverPlayer) {
|
||||
if (entity.takeXpDelay == 0 && new com.destroystokyo.paper.event.player.PlayerPickupExperienceEvent(serverPlayer.getBukkitEntity(), (org.bukkit.entity.ExperienceOrb) this.getBukkitEntity()).callEvent()) { // Paper - PlayerPickupExperienceEvent
|
||||
entity.takeXpDelay = CraftEventFactory.callPlayerXpCooldownEvent(entity, this.level().purpurConfig.playerExpPickupDelay, PlayerExpCooldownChangeEvent.ChangeReason.PICKUP_ORB).getNewCooldown(); // CraftBukkit - entityhuman.takeXpDelay = 2; // Purpur - Configurable player pickup exp delay
|
||||
@@ -338,10 +424,57 @@ public class ExperienceOrb extends Entity {
|
||||
}
|
||||
}
|
||||
|
||||
- private int repairPlayerItems(ServerPlayer player, int value) {
|
||||
- Optional<EnchantedItemInUse> randomItemWith = level().purpurConfig.useBetterMending ? EnchantmentHelper.getMostDamagedItemWith(EnchantmentEffectComponents.REPAIR_WITH_XP, player) : EnchantmentHelper.getRandomItemWith( // Purpur - Add option to mend the most damaged equipment first
|
||||
- EnchantmentEffectComponents.REPAIR_WITH_XP, player, ItemStack::isDamaged
|
||||
- );
|
||||
+ // DivineMC start - Clump experience orbs
|
||||
+ public Optional<EnchantedItemInUse> clumps$captureCurrentEntry(Optional<EnchantedItemInUse> entry) {
|
||||
+ clumps$currentEntry = entry;
|
||||
+ return entry;
|
||||
+ }
|
||||
+
|
||||
+ public java.util.Map<Integer, Integer> clumps$getClumpedMap() {
|
||||
+ if (clumps$clumpedMap == null) {
|
||||
+ clumps$clumpedMap = new java.util.HashMap<>();
|
||||
+ clumps$clumpedMap.put(this.value, 1);
|
||||
+ }
|
||||
+
|
||||
+ return clumps$clumpedMap;
|
||||
+ }
|
||||
+
|
||||
+ public void clumps$setClumpedMap(java.util.Map<Integer, Integer> map) {
|
||||
+ clumps$clumpedMap = map;
|
||||
+ clumps$resolve();
|
||||
+ }
|
||||
+
|
||||
+ public boolean clumps$resolve() {
|
||||
+ value = clumps$getClumpedMap().entrySet()
|
||||
+ .stream()
|
||||
+ .map(entry -> entry.getKey() * entry.getValue())
|
||||
+ .reduce(Integer::sum)
|
||||
+ .orElse(1);
|
||||
+
|
||||
+ return value > 0;
|
||||
+ }
|
||||
+
|
||||
+ private int repairPlayerItems(ServerPlayer player, int amount) {
|
||||
+ Optional<EnchantedItemInUse> randomItemWith = clumps$captureCurrentEntry(level().purpurConfig.useBetterMending ? EnchantmentHelper.getMostDamagedItemWith(EnchantmentEffectComponents.REPAIR_WITH_XP, player) : EnchantmentHelper.getRandomItemWith(EnchantmentEffectComponents.REPAIR_WITH_XP, player, ItemStack::isDamaged)); // Purpur - Add option to mend the most damaged equipment first
|
||||
+
|
||||
+ if (org.bxteam.divinemc.DivineConfig.clumpOrbs) {
|
||||
+ return clumps$currentEntry
|
||||
+ .map(foundItem -> {
|
||||
+ ItemStack itemstack = foundItem.itemStack();
|
||||
+ int xpToRepair = EnchantmentHelper.modifyDurabilityToRepairFromXp(player.serverLevel(), itemstack, (int) (amount * 1));
|
||||
+ int toRepair = Math.min(xpToRepair, itemstack.getDamageValue());
|
||||
+ itemstack.setDamageValue(itemstack.getDamageValue() - toRepair);
|
||||
+ if(toRepair > 0) {
|
||||
+ int used = amount - toRepair * amount / xpToRepair;
|
||||
+ if(used > 0) {
|
||||
+ return this.repairPlayerItems(player, used);
|
||||
+ }
|
||||
+ }
|
||||
+ return 0;
|
||||
+ })
|
||||
+ .orElse(amount);
|
||||
+ }
|
||||
+ // DivineMC end - Clump experience orbs
|
||||
if (randomItemWith.isPresent()) {
|
||||
ItemStack itemStack = randomItemWith.get().itemStack();
|
||||
int i = EnchantmentHelper.modifyDurabilityToRepairFromXp(player.serverLevel(), itemStack, value);
|
||||
@@ -0,0 +1,114 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: NONPLAYT <76615486+NONPLAYT@users.noreply.github.com>
|
||||
Date: Mon, 24 Feb 2025 19:58:39 +0300
|
||||
Subject: [PATCH] Regionized Chunk Ticking
|
||||
|
||||
|
||||
diff --git a/net/minecraft/server/level/ServerChunkCache.java b/net/minecraft/server/level/ServerChunkCache.java
|
||||
index ae0e36d198ad8243920c8e8a55c0be4945542763..7f982949304535376dabf42aab1848cabc8987cf 100644
|
||||
--- a/net/minecraft/server/level/ServerChunkCache.java
|
||||
+++ b/net/minecraft/server/level/ServerChunkCache.java
|
||||
@@ -54,6 +54,10 @@ public class ServerChunkCache extends ChunkSource implements ca.spottedleaf.moon
|
||||
private static final Logger LOGGER = LogUtils.getLogger();
|
||||
private final DistanceManager distanceManager;
|
||||
private final ServerLevel level;
|
||||
+ // DivineMC - Regionized Chunk Ticking
|
||||
+ public static final Executor REGION_EXECUTOR = java.util.concurrent.Executors.newFixedThreadPool(org.bxteam.divinemc.DivineConfig.regionizedChunkTickingExecutorThreadCount, new org.bxteam.divinemc.util.NamedAgnosticThreadFactory<>("region_ticking", ca.spottedleaf.moonrise.common.util.TickThread::new, org.bxteam.divinemc.DivineConfig.regionizedChunkTickingExecutorThreadPriority));
|
||||
+ public volatile int tickingRegionsCount = 0;
|
||||
+ // DivineMC end - Regionized Chunk Ticking
|
||||
public final Thread mainThread;
|
||||
final ThreadedLevelLightEngine lightEngine;
|
||||
public final ServerChunkCache.MainThreadExecutor mainThreadProcessor;
|
||||
@@ -461,6 +465,46 @@ public class ServerChunkCache extends ChunkSource implements ca.spottedleaf.moon
|
||||
((ca.spottedleaf.moonrise.patches.chunk_system.level.ChunkSystemServerLevel)this.level).moonrise$getChunkTaskScheduler().chunkHolderManager.close(save, true); // Paper - rewrite chunk system
|
||||
}
|
||||
|
||||
+ // DivineMC start - Regionized Chunk Ticking
|
||||
+ private static final int[] DX = {1, -1, 0, 0, 1, -1, -1, 1};
|
||||
+ private static final int[] DZ = {0, 0, 1, -1, 1, 1, -1, -1};
|
||||
+
|
||||
+ private List<LevelChunk>[] splitChunksIntoRegions(List<LevelChunk> chunks) {
|
||||
+ int size = chunks.size();
|
||||
+ java.util.IdentityHashMap<LevelChunk, Boolean> chunkSet = new java.util.IdentityHashMap<>(size);
|
||||
+
|
||||
+ for (LevelChunk chunk : chunks) {
|
||||
+ chunkSet.put(chunk, Boolean.TRUE);
|
||||
+ }
|
||||
+
|
||||
+ List<List<LevelChunk>> groups = new it.unimi.dsi.fastutil.objects.ObjectArrayList<>(size >> 3);
|
||||
+ LevelChunk[] stack = new LevelChunk[size];
|
||||
+ int stackPointer = 0;
|
||||
+
|
||||
+ for (LevelChunk chunk : chunks) {
|
||||
+ if (chunkSet.remove(chunk) == null) continue;
|
||||
+
|
||||
+ List<LevelChunk> group = new it.unimi.dsi.fastutil.objects.ObjectArrayList<>(64);
|
||||
+ stack[stackPointer++] = chunk;
|
||||
+
|
||||
+ while (stackPointer > 0) {
|
||||
+ LevelChunk current = stack[--stackPointer];
|
||||
+ group.add(current);
|
||||
+
|
||||
+ for (int i = 0; i < 8; i++) {
|
||||
+ LevelChunk neighbor = getChunk(current.locX + DX[i], current.locZ + DZ[i], false);
|
||||
+ if (neighbor == null || chunkSet.remove(neighbor) == null) continue;
|
||||
+ stack[stackPointer++] = neighbor;
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ groups.add(group);
|
||||
+ }
|
||||
+
|
||||
+ return groups.toArray(new List[0]);
|
||||
+ }
|
||||
+ // DivineMC end - Regionized Chunk Ticking
|
||||
+
|
||||
@Override
|
||||
public void tick(BooleanSupplier hasTimeLeft, boolean tickChunks) {
|
||||
if (this.level.tickRateManager().runsNormally() || !tickChunks || this.level.spigotConfig.unloadFrozenChunks) { // Spigot
|
||||
@@ -492,7 +536,44 @@ public class ServerChunkCache extends ChunkSource implements ca.spottedleaf.moon
|
||||
this.shuffleRandom.setSeed(this.level.random.nextLong());
|
||||
if (!this.level.paperConfig().entities.spawning.perPlayerMobSpawns) Util.shuffle(list, this.shuffleRandom); // Paper - Optional per player mob spawns; do not need this when per-player is enabled
|
||||
// Paper end - chunk tick iteration optimisation
|
||||
- this.tickChunks(l, list);
|
||||
+ // DivineMC start - Regionized Chunk Ticking
|
||||
+ if (org.bxteam.divinemc.DivineConfig.enableRegionizedChunkTicking) {
|
||||
+ List<LevelChunk>[] regions = splitChunksIntoRegions(list);
|
||||
+ int regionCount = regions.length;
|
||||
+ this.tickingRegionsCount = regionCount;
|
||||
+ java.util.concurrent.CountDownLatch latch = new java.util.concurrent.CountDownLatch(regionCount);
|
||||
+
|
||||
+ try {
|
||||
+ java.util.concurrent.ForkJoinPool.managedBlock(new java.util.concurrent.ForkJoinPool.ManagedBlocker() {
|
||||
+ @Override
|
||||
+ public boolean block() throws InterruptedException {
|
||||
+ for (List<LevelChunk> region : regions) {
|
||||
+ if (region == null) continue;
|
||||
+ REGION_EXECUTOR.execute(() -> {
|
||||
+ try {
|
||||
+ tickChunks(l, region);
|
||||
+ } finally {
|
||||
+ latch.countDown();
|
||||
+ }
|
||||
+ });
|
||||
+ }
|
||||
+
|
||||
+ latch.await();
|
||||
+ return true;
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public boolean isReleasable() {
|
||||
+ return latch.getCount() == 0;
|
||||
+ }
|
||||
+ });
|
||||
+ } catch (InterruptedException ex) {
|
||||
+ throw new RuntimeException("Interrupted managed block during region ticking", ex);
|
||||
+ }
|
||||
+ } else {
|
||||
+ this.tickChunks(l, list);
|
||||
+ }
|
||||
+ // DivineMC end - Regionized Chunk Ticking
|
||||
} finally {
|
||||
list.clear();
|
||||
}
|
||||
Reference in New Issue
Block a user