From 556bda18e6e6499599af21daf8a0359dd8782e01 Mon Sep 17 00:00:00 2001 From: The_Fireplace Date: Tue, 29 Nov 2022 09:51:28 -0600 Subject: [PATCH] [1.19] Fixed skeleton spawn crash RandomSource can crash if used from multiple threads, switch to a normal Random --- changelog.txt | 3 ++- .../dev/the_fireplace/overlord/util/SkeletonSpawnUtils.java | 5 ++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/changelog.txt b/changelog.txt index bf846975..a7ac21c9 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1 +1,2 @@ -Fixed skeleton hitboxes \ No newline at end of file +Fixed skeleton hitboxes +[1.19] Fixed skeleton spawn crash \ No newline at end of file diff --git a/common/src/main/java/dev/the_fireplace/overlord/util/SkeletonSpawnUtils.java b/common/src/main/java/dev/the_fireplace/overlord/util/SkeletonSpawnUtils.java index d982a51f..92458d50 100644 --- a/common/src/main/java/dev/the_fireplace/overlord/util/SkeletonSpawnUtils.java +++ b/common/src/main/java/dev/the_fireplace/overlord/util/SkeletonSpawnUtils.java @@ -10,20 +10,23 @@ import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.time.temporal.ChronoUnit; +import java.util.Random; public final class SkeletonSpawnUtils { private final OverlordItems overlordItems; + private final Random random; @Inject public SkeletonSpawnUtils(OverlordItems overlordItems) { this.overlordItems = overlordItems; + this.random = new Random(); } public void addMask(LivingEntity entity) { int daysSinceUndertaleReleased = (int) ChronoUnit.DAYS.between(LocalDate.parse("2015-09-15", DateTimeFormatter.ofPattern("y-M-d")), LocalDateTime.now()); int daysSince1710Released = (int) ChronoUnit.DAYS.between(LocalDate.parse("2014-06-26", DateTimeFormatter.ofPattern("y-M-d")), LocalDateTime.now()); - if (entity.getCommandSenderWorld().getRandom().nextInt(daysSinceUndertaleReleased + daysSince1710Released) == 0 + if (random.nextInt(daysSinceUndertaleReleased + daysSince1710Released) == 0 && entity.getItemBySlot(EquipmentSlot.HEAD).isEmpty() ) { entity.setItemSlot(EquipmentSlot.HEAD, new ItemStack(overlordItems.getSansMask()));