Skip to content

Commit bf8ca1b

Browse files
committed
clean up patch
1 parent d231cbf commit bf8ca1b

6 files changed

+233
-248
lines changed

atdeprecated-server/minecraft-patches/features/0006-Force-enabled-waypoint.patch

Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,3 +239,166 @@ index 0f8cacbb8fe55a60e2f0c98bf36c005b29f41a4b..7dc3f46c82dcdfa30438bc4016fb9fc0
239239
}
240240

241241
public void breakAllConnections() {
242+
243+
diff --git a/net/minecraft/server/waypoints/ServerWaypointManager.java b/net/minecraft/server/waypoints/ServerWaypointManager.java
244+
index 7dc3f46c82dcdfa30438bc4016fb9fc068680341..75c248892b0ff7b49a623612c0bd546c906989c8 100644
245+
--- a/net/minecraft/server/waypoints/ServerWaypointManager.java
246+
+++ b/net/minecraft/server/waypoints/ServerWaypointManager.java
247+
@@ -6,6 +6,8 @@ import com.google.common.collect.Sets;
248+
import com.google.common.collect.Table;
249+
import com.google.common.collect.Tables;
250+
import com.google.common.collect.Sets.SetView;
251+
+
252+
+import java.util.Collections;
253+
import java.util.HashSet;
254+
import java.util.Map;
255+
import java.util.Set;
256+
@@ -16,32 +18,46 @@ import net.minecraft.world.waypoints.WaypointManager;
257+
import net.minecraft.world.waypoints.WaypointTransmitter;
258+
259+
public class ServerWaypointManager implements WaypointManager<WaypointTransmitter> {
260+
- private final Set<WaypointTransmitter> waypoints = new HashSet<>();
261+
- private final Set<ServerPlayer> players = new HashSet<>();
262+
- private final Table<ServerPlayer, WaypointTransmitter, WaypointTransmitter.Connection> connections = HashBasedTable.create();
263+
+ // atDeprecated start - Thread safe collections
264+
+ private final Set<WaypointTransmitter> waypoints = Collections.synchronizedSet(new HashSet<>());
265+
+ private final Set<ServerPlayer> players = Collections.synchronizedSet(new HashSet<>());
266+
+ private final Table<ServerPlayer, WaypointTransmitter, WaypointTransmitter.Connection> connections = Tables.synchronizedTable(HashBasedTable.create());
267+
+ // atDeprecated end
268+
269+
@Override
270+
public void trackWaypoint(WaypointTransmitter waypoint) {
271+
// atDeprecated start - Force enabled waypoint
272+
- this.waypoints.add(waypoint);
273+
- for (ServerPlayer serverPlayer : this.players) {this.createConnection(serverPlayer, waypoint);}
274+
+ synchronized (this) {
275+
+ this.waypoints.add(waypoint);
276+
+ for (ServerPlayer serverPlayer : this.players) {
277+
+ this.createConnection(serverPlayer, waypoint);
278+
+ }
279+
+ }
280+
// atDeprecated end - Force enabled waypoint
281+
}
282+
283+
@Override
284+
public void updateWaypoint(WaypointTransmitter waypoint) {
285+
- if (this.waypoints.contains(waypoint)) {
286+
- Map<ServerPlayer, WaypointTransmitter.Connection> map = Tables.transpose(this.connections).row(waypoint);
287+
- SetView<ServerPlayer> set = Sets.difference(this.players, map.keySet());
288+
-
289+
- for (Entry<ServerPlayer, WaypointTransmitter.Connection> entry : ImmutableSet.copyOf(map.entrySet())) {
290+
- this.updateConnection(entry.getKey(), waypoint, entry.getValue());
291+
- }
292+
+ // atDeprecated start - Thread safe
293+
+ synchronized (this) {
294+
+ if (this.waypoints.contains(waypoint)) {
295+
+ Map<ServerPlayer, WaypointTransmitter.Connection> map = Tables.transpose(this.connections).row(waypoint);
296+
+ Set<ServerPlayer> currentPlayers = ImmutableSet.copyOf(this.players);
297+
+ SetView<ServerPlayer> set = Sets.difference(currentPlayers, map.keySet());
298+
+
299+
+ // Update existing connections
300+
+ Set<Entry<ServerPlayer, WaypointTransmitter.Connection>> entries = ImmutableSet.copyOf(map.entrySet());
301+
+ for (Entry<ServerPlayer, WaypointTransmitter.Connection> entry : entries) {
302+
+ this.updateConnection(entry.getKey(), waypoint, entry.getValue());
303+
+ }
304+
305+
- for (ServerPlayer serverPlayer : set) {
306+
- this.createConnection(serverPlayer, waypoint);
307+
+ // Create new connections
308+
+ for (ServerPlayer serverPlayer : set) {
309+
+ this.createConnection(serverPlayer, waypoint);
310+
+ }
311+
}
312+
}
313+
+ // atDeprecated end
314+
}
315+
316+
@Override
317+
@@ -53,41 +69,65 @@ public class ServerWaypointManager implements WaypointManager<WaypointTransmitte
318+
319+
public void addPlayer(ServerPlayer player) {
320+
// atDeprecated start - Force enabled waypoint
321+
- this.players.add(player);
322+
- for (WaypointTransmitter waypointTransmitter : this.waypoints) {this.createConnection(player, waypointTransmitter);}
323+
- if (player.isTransmittingWaypoint()) {this.trackWaypoint((WaypointTransmitter)player);}
324+
+ synchronized (this) {
325+
+ this.players.add(player);
326+
+ for (WaypointTransmitter waypointTransmitter : this.waypoints) {
327+
+ this.createConnection(player, waypointTransmitter);
328+
+ }
329+
+ if (player.isTransmittingWaypoint()) {
330+
+ this.trackWaypoint((WaypointTransmitter)player);
331+
+ }
332+
+ }
333+
// atDeprecated end - Force enabled waypoint
334+
}
335+
336+
public void updatePlayer(ServerPlayer player) {
337+
// atDeprecated start - Force enabled waypoint
338+
- Map<WaypointTransmitter, WaypointTransmitter.Connection> map = this.connections.row(player);
339+
- SetView<WaypointTransmitter> set = Sets.difference(this.waypoints, map.keySet());
340+
- for (Entry<WaypointTransmitter, WaypointTransmitter.Connection> entry : ImmutableSet.copyOf(map.entrySet())) {this.updateConnection(player, entry.getKey(), entry.getValue());}
341+
- for (WaypointTransmitter waypointTransmitter : set) {this.createConnection(player, waypointTransmitter);}
342+
+ synchronized (this) {
343+
+ Map<WaypointTransmitter, WaypointTransmitter.Connection> map = this.connections.row(player);
344+
+ SetView<WaypointTransmitter> set = Sets.difference(this.waypoints, map.keySet());
345+
+ for (Entry<WaypointTransmitter, WaypointTransmitter.Connection> entry : ImmutableSet.copyOf(map.entrySet())) {
346+
+ this.updateConnection(player, entry.getKey(), entry.getValue());
347+
+ }
348+
+ for (WaypointTransmitter waypointTransmitter : ImmutableSet.copyOf(set)) {
349+
+ this.createConnection(player, waypointTransmitter);
350+
+ }
351+
+ }
352+
// atDeprecated end - Force enabled waypoint
353+
}
354+
355+
public void removePlayer(ServerPlayer player) {
356+
// atDeprecated start - Force enabled waypoint
357+
- this.connections.row(player).values().removeIf(connection -> {
358+
- connection.disconnect();
359+
- return true;
360+
- });
361+
- this.untrackWaypoint((WaypointTransmitter)player);
362+
- this.players.remove(player);
363+
+ synchronized (this) {
364+
+ this.connections.row(player).values().removeIf(connection -> {
365+
+ connection.disconnect();
366+
+ return true;
367+
+ });
368+
+ this.untrackWaypoint((WaypointTransmitter)player);
369+
+ this.players.remove(player);
370+
+ }
371+
// atDeprecated end - Force enabled waypoint
372+
}
373+
374+
public void breakAllConnections() {
375+
- this.connections.values().forEach(WaypointTransmitter.Connection::disconnect);
376+
- this.connections.clear();
377+
+ // atDeprecated start - Thread safe
378+
+ synchronized (this) {
379+
+ Set<WaypointTransmitter.Connection> currentConnections = ImmutableSet.copyOf(this.connections.values());
380+
+ currentConnections.forEach(WaypointTransmitter.Connection::disconnect);
381+
+ this.connections.clear();
382+
+ }
383+
+ // atDeprecated end
384+
}
385+
386+
public void remakeConnections(WaypointTransmitter waypoint) {
387+
- for (ServerPlayer serverPlayer : this.players) {
388+
- this.createConnection(serverPlayer, waypoint);
389+
+ // atDeprecated start - Thread safe
390+
+ synchronized (this) {
391+
+ Set<ServerPlayer> currentPlayers = ImmutableSet.copyOf(this.players);
392+
+ for (ServerPlayer serverPlayer : currentPlayers) {
393+
+ this.createConnection(serverPlayer, waypoint);
394+
+ }
395+
}
396+
+ // atDeprecated end
397+
}
398+
399+
public Set<WaypointTransmitter> transmitters() {
400+
@@ -132,3 +172,4 @@ public class ServerWaypointManager implements WaypointManager<WaypointTransmitte
401+
}
402+
}
403+
}
404+
+

atdeprecated-server/minecraft-patches/features/0009-Player-Death-Loot-and-XP-Protection-Gamerule.patch renamed to atdeprecated-server/minecraft-patches/features/0008-Player-Death-Loot-and-XP-Protection-Gamerule.patch

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,3 +201,73 @@ index 5de769e7bd56bb3355c3c711d46ce5e103ea4409..b3f09cb52767cca16b711663046c452a
201201
boolean flag = false;
202202
// CraftBukkit start
203203
if (org.bukkit.event.inventory.InventoryPickupItemEvent.getHandlerList().getRegisteredListeners().length > 0) { // Paper - optimize hoppers
204+
205+
diff --git a/net/minecraft/world/level/block/entity/HopperBlockEntity.java b/net/minecraft/world/level/block/entity/HopperBlockEntity.java
206+
index b3f09cb52767cca16b711663046c452a2082c14a..6b90fe800d9d7a9c0942bcfb505b98b4de227958 100644
207+
--- a/net/minecraft/world/level/block/entity/HopperBlockEntity.java
208+
+++ b/net/minecraft/world/level/block/entity/HopperBlockEntity.java
209+
@@ -631,7 +631,7 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen
210+
211+
public static boolean addItem(Container container, ItemEntity item) {
212+
// atDeprecated start - prevent hopper pickup of death loot
213+
- if (item.isDeathLoot && item.level().getGameRules().getBoolean(net.minecraft.world.level.GameRules.RULE_DEATH_ITEMS_HOPPER_CANT_PICKUP)) {
214+
+ if (item.isDeathLoot && item.level() instanceof net.minecraft.server.level.ServerLevel serverLevel && serverLevel.getGameRules().getBoolean(net.minecraft.world.level.GameRules.RULE_DEATH_ITEMS_HOPPER_CANT_PICKUP)) {
215+
return false;
216+
}
217+
// atDeprecated end
218+
219+
diff --git a/net/minecraft/world/entity/player/Player.java b/net/minecraft/world/entity/player/Player.java
220+
index f8e0927db9fd500671b586589cb3ea72dfa226b2..be7bc0caafccdf3c9f6b140240b88e3696094349 100644
221+
--- a/net/minecraft/world/entity/player/Player.java
222+
+++ b/net/minecraft/world/entity/player/Player.java
223+
@@ -1840,12 +1840,13 @@ public abstract class Player extends LivingEntity {
224+
225+
@Override
226+
protected int getBaseExperienceReward(ServerLevel level) {
227+
- // atDeprecated start - Use deathXpDropPercentage gamerule for XP drop
228+
+ // atDeprecated start - Use deathXpDropPercentage gamerule for XP drop (fixed XP calculation)
229+
if (!level.getGameRules().getBoolean(GameRules.RULE_KEEPINVENTORY) && !this.isSpectator()) {
230+
int percent = level.getGameRules().getInt(GameRules.RULE_DEATH_XP_DROP_PERCENTAGE);
231+
if (percent < 0) percent = 0;
232+
if (percent > 100) percent = 100;
233+
- return (int) (this.totalExperience * (percent / 100.0));
234+
+ int xp = getTrueTotalExperience();
235+
+ return (int) (xp * (percent / 100.0));
236+
}
237+
return 0;
238+
// atDeprecated end
239+
@@ -2396,4 +2397,34 @@ public abstract class Player extends LivingEntity {
240+
this.insomniaEnabled = enabled;
241+
}
242+
// atDeprecated end
243+
+
244+
+ // atDeprecated start - Correct XP calculation for death XP drop
245+
+ public int getTrueTotalExperience() {
246+
+ int exp = 0;
247+
+ int level = this.experienceLevel;
248+
+ exp += getExpAtLevel(level);
249+
+ exp += Math.round(getExpToLevelUp(level) * this.experienceProgress);
250+
+ return exp;
251+
+ }
252+
+
253+
+ private int getExpAtLevel(int level) {
254+
+ if (level <= 15) {
255+
+ return level * level + 6 * level;
256+
+ } else if (level <= 30) {
257+
+ return 2 * level * level - 29 * level + 360;
258+
+ } else {
259+
+ return 5 * level * level - 151 * level + 2220;
260+
+ }
261+
+ }
262+
+
263+
+ private float getExpToLevelUp(int level) {
264+
+ if (level <= 15) {
265+
+ return 2 * level + 7;
266+
+ } else if (level <= 30) {
267+
+ return 5 * level - 38;
268+
+ } else {
269+
+ return 9 * level - 158;
270+
+ }
271+
+ }
272+
+ // atDeprecated end
273+
}

0 commit comments

Comments
 (0)