Skip to content

Commit

Permalink
fix: don't access world random in variant mixins
Browse files Browse the repository at this point in the history
  • Loading branch information
amyavi committed Jun 28, 2024
1 parent 83c3e85 commit dc8c060
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 23 deletions.
4 changes: 2 additions & 2 deletions src/main/java/com/github/nyuppo/mixin/CatVariantsMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ protected void onReadCustomDataFromNbt(NbtCompound nbt, CallbackInfo ci) {
variant = Variants.getVariant(EntityType.CAT, MoreMobVariants.id(nbt.getString(MoreMobVariants.NBT_KEY)));
}
} else {
variant = Variants.getRandomVariant(EntityType.CAT, ((CatEntity)(Object)this).getWorld().getRandom().nextLong(), ((CatEntity)(Object)this).getWorld().getBiome(((CatEntity)(Object)this).getBlockPos()), null, ((CatEntity)(Object)this).getWorld().getMoonSize());
variant = Variants.getRandomVariant(EntityType.CAT, ((CatEntity)(Object)this).getRandom().nextLong(), ((CatEntity)(Object)this).getWorld().getBiome(((CatEntity)(Object)this).getBlockPos()), null, ((CatEntity)(Object)this).getWorld().getMoonSize());
}

// Update all players in the event that this is from modifying entity data with a command
Expand All @@ -64,7 +64,7 @@ protected void onReadCustomDataFromNbt(NbtCompound nbt, CallbackInfo ci) {

@Override
protected void onInitialize(ServerWorldAccess world, LocalDifficulty difficulty, SpawnReason spawnReason, @Nullable EntityData entityData, @Nullable NbtCompound entityNbt, CallbackInfoReturnable<EntityData> ci) {
variant = Variants.getRandomVariant(EntityType.CAT, world.getRandom().nextLong(), world.getBiome(((CatEntity)(Object)this).getBlockPos()), null, world.getMoonSize());
variant = Variants.getRandomVariant(EntityType.CAT, ((CatEntity)(Object)this).getRandom().nextLong(), world.getBiome(((CatEntity)(Object)this).getBlockPos()), null, world.getMoonSize());

// Check if we should spawn black cats (witch huts)
if (world.toServerWorld().getStructureAccessor().getStructureContaining(((CatEntity) (Object) this).getBlockPos(), StructureTags.CATS_SPAWN_AS_BLACK).hasChildren()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ protected void onReadCustomDataFromNbt(NbtCompound nbt, CallbackInfo ci) {
variant = Variants.getVariant(EntityType.CHICKEN, MoreMobVariants.id(nbt.getString(MoreMobVariants.NBT_KEY)));
}
} else {
variant = Variants.getRandomVariant(EntityType.CHICKEN, ((ChickenEntity)(Object)this).getWorld().getRandom().nextLong(), ((ChickenEntity)(Object)this).getWorld().getBiome(((ChickenEntity)(Object)this).getBlockPos()), null, ((ChickenEntity)(Object)this).getWorld().getMoonSize());
variant = Variants.getRandomVariant(EntityType.CHICKEN, ((ChickenEntity)(Object)this).getRandom().nextLong(), ((ChickenEntity)(Object)this).getWorld().getBiome(((ChickenEntity)(Object)this).getBlockPos()), null, ((ChickenEntity)(Object)this).getWorld().getMoonSize());
}

// Update all players in the event that this is from modifying entity data with a command
Expand All @@ -64,7 +64,7 @@ protected void onReadCustomDataFromNbt(NbtCompound nbt, CallbackInfo ci) {

@Override
protected void onInitialize(ServerWorldAccess world, LocalDifficulty difficulty, SpawnReason spawnReason, @Nullable EntityData entityData, @Nullable NbtCompound entityNbt, CallbackInfoReturnable<EntityData> ci) {
variant = Variants.getRandomVariant(EntityType.CHICKEN, world.getRandom().nextLong(), world.getBiome(((ChickenEntity)(Object)this).getBlockPos()), null, world.getMoonSize());
variant = Variants.getRandomVariant(EntityType.CHICKEN, ((ChickenEntity)(Object)this).getRandom().nextLong(), world.getBiome(((ChickenEntity)(Object)this).getBlockPos()), null, world.getMoonSize());
}

@Inject(
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/github/nyuppo/mixin/CowVariantsMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ protected void onReadCustomDataFromNbt(NbtCompound nbt, CallbackInfo ci) {
variant = Variants.getVariant(EntityType.COW, MoreMobVariants.id(nbt.getString(MoreMobVariants.NBT_KEY)));
}
} else {
variant = Variants.getRandomVariant(EntityType.COW, ((CowEntity)(Object)this).getWorld().getRandom().nextLong(), ((CowEntity)(Object)this).getWorld().getBiome(((CowEntity)(Object)this).getBlockPos()), null, ((CowEntity)(Object)this).getWorld().getMoonSize());
variant = Variants.getRandomVariant(EntityType.COW, ((CowEntity)(Object)this).getRandom().nextLong(), ((CowEntity)(Object)this).getWorld().getBiome(((CowEntity)(Object)this).getBlockPos()), null, ((CowEntity)(Object)this).getWorld().getMoonSize());
}

// Update all players in the event that this is from modifying entity data with a command
Expand All @@ -62,7 +62,7 @@ protected void onReadCustomDataFromNbt(NbtCompound nbt, CallbackInfo ci) {

@Override
protected void onInitialize(ServerWorldAccess world, LocalDifficulty difficulty, SpawnReason spawnReason, @Nullable EntityData entityData, @Nullable NbtCompound entityNbt, CallbackInfoReturnable<EntityData> ci) {
variant = Variants.getRandomVariant(EntityType.COW, world.getRandom().nextLong(), world.getBiome(((CowEntity)(Object)this).getBlockPos()), null, world.getMoonSize());
variant = Variants.getRandomVariant(EntityType.COW, ((CowEntity)(Object)this).getRandom().nextLong(), world.getBiome(((CowEntity)(Object)this).getBlockPos()), null, world.getMoonSize());
}

@Inject(
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/github/nyuppo/mixin/PigVariantsMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ protected void onReadCustomDataFromNbt(NbtCompound nbt, CallbackInfo ci) {
variant = Variants.getVariant(EntityType.PIG, MoreMobVariants.id(nbt.getString(MoreMobVariants.NBT_KEY)));
}
} else {
variant = Variants.getRandomVariant(EntityType.PIG, ((PigEntity)(Object)this).getWorld().getRandom().nextLong(), ((PigEntity)(Object)this).getWorld().getBiome(((PigEntity)(Object)this).getBlockPos()), null, ((PigEntity)(Object)this).getWorld().getMoonSize());
variant = Variants.getRandomVariant(EntityType.PIG, ((PigEntity)(Object)this).getRandom().nextLong(), ((PigEntity)(Object)this).getWorld().getBiome(((PigEntity)(Object)this).getBlockPos()), null, ((PigEntity)(Object)this).getWorld().getMoonSize());
}
isMuddy = nbt.getBoolean(MoreMobVariants.MUDDY_NBT_KEY);
muddyTimeLeft = nbt.getInt(MoreMobVariants.MUDDY_TIMEOUT_NBT_KEY);
Expand All @@ -74,10 +74,10 @@ protected void onReadCustomDataFromNbt(NbtCompound nbt, CallbackInfo ci) {

@Override
protected void onInitialize(ServerWorldAccess world, LocalDifficulty difficulty, SpawnReason spawnReason, @Nullable EntityData entityData, @Nullable NbtCompound entityNbt, CallbackInfoReturnable<EntityData> ci) {
variant = Variants.getRandomVariant(EntityType.PIG, world.getRandom().nextLong(), world.getBiome(((PigEntity)(Object)this).getBlockPos()), null, world.getMoonSize());
variant = Variants.getRandomVariant(EntityType.PIG, ((PigEntity)(Object)this).getRandom().nextLong(), world.getBiome(((PigEntity)(Object)this).getBlockPos()), null, world.getMoonSize());

// 2% chance of pig starting muddy if in swamp
if (world.getBiome(((PigEntity)(Object)this).getBlockPos()).isIn(BiomeTags.RUINED_PORTAL_SWAMP_HAS_STRUCTURE) && world.getRandom().nextDouble() < 0.02) {
if (world.getBiome(((PigEntity)(Object)this).getBlockPos()).isIn(BiomeTags.RUINED_PORTAL_SWAMP_HAS_STRUCTURE) && ((PigEntity)(Object)this).getRandom().nextDouble() < 0.02) {
isMuddy = true;
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/com/github/nyuppo/mixin/SheepVariantsMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ protected void onReadCustomDataFromNbt(NbtCompound nbt, CallbackInfo ci) {
variant = Variants.getVariant(EntityType.SHEEP, MoreMobVariants.id(nbt.getString(MoreMobVariants.NBT_KEY)));
}
} else {
variant = Variants.getRandomVariant(EntityType.SHEEP, ((SheepEntity)(Object)this).getWorld().getRandom().nextLong(), ((SheepEntity)(Object)this).getWorld().getBiome(((SheepEntity)(Object)this).getBlockPos()), null, ((SheepEntity)(Object)this).getWorld().getMoonSize());
variant = Variants.getRandomVariant(EntityType.SHEEP, ((SheepEntity)(Object)this).getRandom().nextLong(), ((SheepEntity)(Object)this).getWorld().getBiome(((SheepEntity)(Object)this).getBlockPos()), null, ((SheepEntity)(Object)this).getWorld().getMoonSize());
}
hornColour = nbt.getString(MoreMobVariants.SHEEP_HORN_COLOUR_NBT_KEY);

Expand All @@ -72,9 +72,9 @@ protected void onReadCustomDataFromNbt(NbtCompound nbt, CallbackInfo ci) {

@Override
protected void onInitialize(ServerWorldAccess world, LocalDifficulty difficulty, SpawnReason spawnReason, @Nullable EntityData entityData, @Nullable NbtCompound entityNbt, CallbackInfoReturnable<EntityData> ci) {
variant = Variants.getRandomVariant(EntityType.SHEEP, world.getRandom().nextLong(), world.getBiome(((SheepEntity)(Object)this).getBlockPos()), null, world.getMoonSize());
variant = Variants.getRandomVariant(EntityType.SHEEP, ((SheepEntity)(Object)this).getRandom().nextLong(), world.getBiome(((SheepEntity)(Object)this).getBlockPos()), null, world.getMoonSize());

SheepHornSettings.SheepHornColour colour = SheepHornSettings.getRandomSheepHornColour(world.getRandom(), world.getBiome(((SheepEntity)(Object)this).getBlockPos()));
SheepHornSettings.SheepHornColour colour = SheepHornSettings.getRandomSheepHornColour(((SheepEntity)(Object)this).getRandom(), world.getBiome(((SheepEntity)(Object)this).getBlockPos()));
if (colour != null) {
hornColour = colour.getId();
}
Expand All @@ -100,10 +100,10 @@ private void onCreateChild(ServerWorld world, PassiveEntity entity, CallbackInfo
&& !nbtParent1.getString(MoreMobVariants.SHEEP_HORN_COLOUR_NBT_KEY).isEmpty()
&& nbtParent2.contains(MoreMobVariants.SHEEP_HORN_COLOUR_NBT_KEY)
&& !nbtParent2.getString(MoreMobVariants.SHEEP_HORN_COLOUR_NBT_KEY).isEmpty()
&& world.getRandom().nextDouble() <= SheepHornSettings.getInheritChance()) {
colour = world.getRandom().nextBoolean() ? nbtParent1.getString(MoreMobVariants.SHEEP_HORN_COLOUR_NBT_KEY) : nbtParent2.getString(MoreMobVariants.SHEEP_HORN_COLOUR_NBT_KEY);
&& ((SheepEntity)(Object)this).getRandom().nextDouble() <= SheepHornSettings.getInheritChance()) {
colour = ((SheepEntity)(Object)this).getRandom().nextBoolean() ? nbtParent1.getString(MoreMobVariants.SHEEP_HORN_COLOUR_NBT_KEY) : nbtParent2.getString(MoreMobVariants.SHEEP_HORN_COLOUR_NBT_KEY);
} else {
SheepHornSettings.SheepHornColour col = SheepHornSettings.getRandomSheepHornColour(world.getRandom(), world.getBiome(((SheepEntity)(Object)this).getBlockPos()));
SheepHornSettings.SheepHornColour col = SheepHornSettings.getRandomSheepHornColour(((SheepEntity)(Object)this).getRandom(), world.getBiome(((SheepEntity)(Object)this).getBlockPos()));
if (col != null) {
colour = col.getId();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ protected void onReadCustomDataFromNbt(NbtCompound nbt, CallbackInfo ci) {
variant = Variants.getVariant(EntityType.SKELETON, MoreMobVariants.id(nbt.getString(MoreMobVariants.NBT_KEY)));
}
} else {
variant = Variants.getRandomVariant(EntityType.SKELETON, ((SkeletonEntity)(Object)this).getWorld().getRandom().nextLong(), ((SkeletonEntity)(Object)this).getWorld().getBiome(((SkeletonEntity)(Object)this).getBlockPos()), null, ((SkeletonEntity)(Object)this).getWorld().getMoonSize());
variant = Variants.getRandomVariant(EntityType.SKELETON, ((SkeletonEntity)(Object)this).getRandom().nextLong(), ((SkeletonEntity)(Object)this).getWorld().getBiome(((SkeletonEntity)(Object)this).getBlockPos()), null, ((SkeletonEntity)(Object)this).getWorld().getMoonSize());
}

// Update all players in the event that this is from modifying entity data with a command
Expand All @@ -60,6 +60,6 @@ protected void onReadCustomDataFromNbt(NbtCompound nbt, CallbackInfo ci) {

@Override
protected void onInitialize(ServerWorldAccess world, LocalDifficulty difficulty, SpawnReason spawnReason, @Nullable EntityData entityData, @Nullable NbtCompound entityNbt, CallbackInfoReturnable<EntityData> ci) {
variant = Variants.getRandomVariant(EntityType.SKELETON, world.getRandom().nextLong(), world.getBiome(((SkeletonEntity)(Object)this).getBlockPos()), null, world.getMoonSize());
variant = Variants.getRandomVariant(EntityType.SKELETON, ((SkeletonEntity)(Object)this).getRandom().nextLong(), world.getBiome(((SkeletonEntity)(Object)this).getBlockPos()), null, world.getMoonSize());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ protected void onReadCustomDataFromNbt(NbtCompound nbt, CallbackInfo ci) {
variant = Variants.getVariant(EntityType.SPIDER, MoreMobVariants.id(nbt.getString(MoreMobVariants.NBT_KEY)));
}
} else {
variant = Variants.getRandomVariant(EntityType.SPIDER, ((SpiderEntity)(Object)this).getWorld().getRandom().nextLong(), ((SpiderEntity)(Object)this).getWorld().getBiome(((SpiderEntity)(Object)this).getBlockPos()), null, ((SpiderEntity)(Object)this).getWorld().getMoonSize());
variant = Variants.getRandomVariant(EntityType.SPIDER, ((SpiderEntity)(Object)this).getRandom().nextLong(), ((SpiderEntity)(Object)this).getWorld().getBiome(((SpiderEntity)(Object)this).getBlockPos()), null, ((SpiderEntity)(Object)this).getWorld().getMoonSize());
}

// Update all players in the event that this is from modifying entity data with a command
Expand All @@ -60,6 +60,6 @@ protected void onReadCustomDataFromNbt(NbtCompound nbt, CallbackInfo ci) {

@Override
protected void onInitialize(ServerWorldAccess world, LocalDifficulty difficulty, SpawnReason spawnReason, @Nullable EntityData entityData, @Nullable NbtCompound entityNbt, CallbackInfoReturnable<EntityData> ci) {
variant = Variants.getRandomVariant(EntityType.SPIDER, world.getRandom().nextLong(), world.getBiome(((SpiderEntity)(Object)this).getBlockPos()), null, world.getMoonSize());
variant = Variants.getRandomVariant(EntityType.SPIDER, ((SpiderEntity)(Object)this).getRandom().nextLong(), world.getBiome(((SpiderEntity)(Object)this).getBlockPos()), null, world.getMoonSize());
}
}
4 changes: 2 additions & 2 deletions src/main/java/com/github/nyuppo/mixin/WolfVariantsMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ protected void onReadCustomDataFromNbt(NbtCompound nbt, CallbackInfo ci) {
variant = Variants.getVariant(EntityType.WOLF, MoreMobVariants.id(nbt.getString(MoreMobVariants.NBT_KEY)));
}
} else {
variant = Variants.getRandomVariant(EntityType.WOLF, ((WolfEntity)(Object)this).getWorld().getRandom().nextLong(), ((WolfEntity)(Object)this).getWorld().getBiome(((WolfEntity)(Object)this).getBlockPos()), null, ((WolfEntity)(Object)this).getWorld().getMoonSize());
variant = Variants.getRandomVariant(EntityType.WOLF, ((WolfEntity)(Object)this).getRandom().nextLong(), ((WolfEntity)(Object)this).getWorld().getBiome(((WolfEntity)(Object)this).getBlockPos()), null, ((WolfEntity)(Object)this).getWorld().getMoonSize());
}

// Update all players in the event that this is from modifying entity data with a command
Expand All @@ -64,7 +64,7 @@ protected void onReadCustomDataFromNbt(NbtCompound nbt, CallbackInfo ci) {

@Override
protected void onInitialize(ServerWorldAccess world, LocalDifficulty difficulty, SpawnReason spawnReason, @Nullable EntityData entityData, @Nullable NbtCompound entityNbt, CallbackInfoReturnable<EntityData> ci) {
variant = Variants.getRandomVariant(EntityType.WOLF, world.getRandom().nextLong(), world.getBiome(((WolfEntity)(Object)this).getBlockPos()), null, world.getMoonSize());
variant = Variants.getRandomVariant(EntityType.WOLF, ((WolfEntity)(Object)this).getRandom().nextLong(), world.getBiome(((WolfEntity)(Object)this).getBlockPos()), null, world.getMoonSize());
}

@Inject(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ protected void onReadCustomDataFromNbt(NbtCompound nbt, CallbackInfo ci) {
variant = Variants.getVariant(EntityType.ZOMBIE, MoreMobVariants.id(nbt.getString(MoreMobVariants.NBT_KEY)));
}
} else {
variant = Variants.getRandomVariant(EntityType.ZOMBIE, ((ZombieEntity)(Object)this).getWorld().getRandom().nextLong(), ((ZombieEntity)(Object)this).getWorld().getBiome(((ZombieEntity)(Object)this).getBlockPos()), null, ((ZombieEntity)(Object)this).getWorld().getMoonSize());
variant = Variants.getRandomVariant(EntityType.ZOMBIE, ((ZombieEntity)(Object)this).getRandom().nextLong(), ((ZombieEntity)(Object)this).getWorld().getBiome(((ZombieEntity)(Object)this).getBlockPos()), null, ((ZombieEntity)(Object)this).getWorld().getMoonSize());
}

// Update all players in the event that this is from modifying entity data with a command
Expand All @@ -60,6 +60,6 @@ protected void onReadCustomDataFromNbt(NbtCompound nbt, CallbackInfo ci) {

@Override
protected void onInitialize(ServerWorldAccess world, LocalDifficulty difficulty, SpawnReason spawnReason, @Nullable EntityData entityData, @Nullable NbtCompound entityNbt, CallbackInfoReturnable<EntityData> ci) {
variant = Variants.getRandomVariant(EntityType.ZOMBIE, world.getRandom().nextLong(), world.getBiome(((ZombieEntity)(Object)this).getBlockPos()), null, world.getMoonSize());
variant = Variants.getRandomVariant(EntityType.ZOMBIE, ((ZombieEntity)(Object)this).getRandom().nextLong(), world.getBiome(((ZombieEntity)(Object)this).getBlockPos()), null, world.getMoonSize());
}
}

0 comments on commit dc8c060

Please sign in to comment.