From 295f3e9491336c9c506b8d51cfb023590ceac6c9 Mon Sep 17 00:00:00 2001 From: itsmeow Date: Sat, 24 Apr 2021 20:06:55 -0400 Subject: [PATCH] Convert wisp config hostile_chance to a percentage instead of 1/x --- .../java/dev/itsmeow/whisperwoods/entity/EntityWisp.java | 6 +++++- .../java/dev/itsmeow/whisperwoods/init/ModEntities.java | 2 +- .../whisperwoods/tileentity/TileEntityHandOfFate.java | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/main/java/dev/itsmeow/whisperwoods/entity/EntityWisp.java b/src/main/java/dev/itsmeow/whisperwoods/entity/EntityWisp.java index f6c21a4..6ff79be 100644 --- a/src/main/java/dev/itsmeow/whisperwoods/entity/EntityWisp.java +++ b/src/main/java/dev/itsmeow/whisperwoods/entity/EntityWisp.java @@ -327,10 +327,14 @@ private static Item getItemForVariant(int variant) { return null; } + public boolean getNewHostileChance() { + return getContainer().getCustomConfiguration().getDouble("hostile_chance") / 100D > Math.random(); + } + @Override @Nullable public ILivingEntityData onInitialSpawn(IWorld world, DifficultyInstance difficulty, SpawnReason reason, @Nullable ILivingEntityData livingdata, CompoundNBT compound) { - boolean hostile = this.getRNG().nextInt(getContainer().getCustomConfiguration().getInt("hostile_chance")) == 0; + boolean hostile = this.getNewHostileChance(); int colorVariant = this.getRNG().nextInt(WispColors.values().length) + 1; if (livingdata instanceof WispData) { diff --git a/src/main/java/dev/itsmeow/whisperwoods/init/ModEntities.java b/src/main/java/dev/itsmeow/whisperwoods/init/ModEntities.java index 35e56a5..91f9f6c 100644 --- a/src/main/java/dev/itsmeow/whisperwoods/init/ModEntities.java +++ b/src/main/java/dev/itsmeow/whisperwoods/init/ModEntities.java @@ -64,7 +64,7 @@ public static void subscribe(IEventBus modBus) { .spawn(EntityClassification.CREATURE, 13, 1, 3) .egg(0xc36406, 0xffc008) .size(0.75F, 0.9F) - .config((holder, builder) -> holder.put(builder.comment("Chance of wisp being hostile (soul stealer). Chance is 1/x, where x is the value specified. 0 is no chance, 1 is 100% chance, 2 is 50% chance, etc").worldRestart().defineInRange("hostile_chance", 8, 0, Integer.MAX_VALUE))) + .config((holder, builder) -> holder.put(builder.comment("Chance of wisp being hostile (soul stealer). Chance is a percentage out of 100. 0 is never, 100 is always").worldRestart().defineInRange("hostile_chance", 12.5D, 0D, 100D))) .biomes(Type.FOREST, Type.SWAMP)); public static final EntityTypeContainer HIRSCHGEIST = H.add(EntityHirschgeist.class, EntityHirschgeist::new, "hirschgeist", b -> b diff --git a/src/main/java/dev/itsmeow/whisperwoods/tileentity/TileEntityHandOfFate.java b/src/main/java/dev/itsmeow/whisperwoods/tileentity/TileEntityHandOfFate.java index d588da8..df7e82f 100644 --- a/src/main/java/dev/itsmeow/whisperwoods/tileentity/TileEntityHandOfFate.java +++ b/src/main/java/dev/itsmeow/whisperwoods/tileentity/TileEntityHandOfFate.java @@ -201,7 +201,7 @@ public void onRecipeComplete(HOFRecipe recipe, BlockState state, World worldIn, wisp.setLocationAndAngles((double) pos.getX() + 0.5D, (double) pos.getY() + d0, (double) pos.getZ() + 0.5D, MathHelper.wrapDegrees(world.rand.nextFloat() * 360.0F), 0.0F); wisp.rotationYawHead = wisp.rotationYaw; wisp.renderYawOffset = wisp.rotationYaw; - wisp.isHostile = wisp.getRNG().nextInt(ModEntities.WISP.getCustomConfiguration().getInt("hostile_chance")) == 0; + wisp.isHostile = wisp.getNewHostileChance(); wisp.getDataManager().set(EntityWisp.COLOR_VARIANT, wColor.ordinal() + 1); if (!ForgeEventFactory.doSpecialSpawn(wisp, worldIn, pos.getX(), pos.getY(), pos.getZ(), null, SpawnReason.SPAWN_EGG)) { worldIn.addEntity(wisp);