Skip to content

Commit

Permalink
Removed Unsafe Random
Browse files Browse the repository at this point in the history
 - Changed from Java's `Random` to `Random.createThreadSafe()`
  • Loading branch information
chronosacaria committed Apr 21, 2024
1 parent be97482 commit eb2408b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
7 changes: 3 additions & 4 deletions src/main/java/chronosacaria/mcda/api/CleanlinessHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
import net.minecraft.sound.SoundCategory;
import net.minecraft.sound.SoundEvent;
import net.minecraft.util.math.Vec3d;

import java.util.Random;
import net.minecraft.util.math.random.Random;

public class CleanlinessHelper {
static Random random = new Random();
@SuppressWarnings("deprecation")
public static Random random = Random.createThreadSafe();

@SuppressWarnings("ConstantConditions")
public static boolean checkFullArmor(LivingEntity livingEntity, ArmorSets armorSets) {
Expand Down Expand Up @@ -71,7 +71,6 @@ public static int mcdaFindHighestDurabilityEquipment(LivingEntity livingEntity)
}

public static void mcdaRandomArmorDamage(LivingEntity livingEntity, float damagePercentage, int totalNumOfPieces, boolean missingBoots){
Random random = new Random();
int index = random.nextInt(totalNumOfPieces);
if (missingBoots)
index++;
Expand Down
7 changes: 3 additions & 4 deletions src/main/java/chronosacaria/mcda/mixin/ItemEntryMixin.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package chronosacaria.mcda.mixin;

import chronosacaria.mcda.api.CleanlinessHelper;
import chronosacaria.mcda.effects.ArmorEffectID;
import chronosacaria.mcda.effects.ArmorEffects;
import chronosacaria.mcda.items.ArmorSetItem;
Expand All @@ -13,7 +14,6 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

@Mixin(ItemEntry.class)
public class ItemEntryMixin {
Expand All @@ -28,11 +28,10 @@ public class ItemEntryMixin {
ArrayList<List<ArmorEffectID>> effects = new ArrayList<>(List.of(ArmorEffects.ARMOR_EFFECT_ID_LIST,
ArmorEffects.RED_ARMOR_EFFECT_ID_LIST, ArmorEffects.GREEN_ARMOR_EFFECT_ID_LIST,
ArmorEffects.BLUE_ARMOR_EFFECT_ID_LIST, ArmorEffects.PURPLE_ARMOR_EFFECT_ID_LIST));

if (sets.contains(armorItem.getSet())) {
stack.getOrCreateNbt().putInt("dominance", new Random().nextInt(99));
stack.getOrCreateNbt().putInt("dominance", CleanlinessHelper.random.nextInt(99));
stack.getOrCreateNbt().putInt("mystery_effect",
new Random().nextInt(effects.get(sets.indexOf(armorItem.getSet())).size() - 1) + 1);
CleanlinessHelper.random.nextInt(effects.get(sets.indexOf(armorItem.getSet())).size() - 1) + 1);
args.set(0, stack);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/mcda.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
"ItemEntryMixin",
"ItemStackMixin",
"LivingEntityMixin",
"PlayerEntityMixin",
"PersistentProjectileEntityMixin",
"PiglinBrainMixin",
"PlayerEntityMixin",
"PlayerTeleportationStateAccessor",
"PowderSnowBlockMixin",
"ServerPlayerEntityMixin",
Expand Down

0 comments on commit eb2408b

Please sign in to comment.