From 56075f163d504f89444a3c3310930382e5d956b0 Mon Sep 17 00:00:00 2001 From: Colin Wong Date: Mon, 7 Jun 2021 21:40:04 -0500 Subject: [PATCH] Version 1.5.0 - Changes dimension configs from names to IDs - Adds meteor dimension config --- build.gradle | 2 +- src/main/java/de/ellpeck/nyx/Config.java | 28 ++++++++++++------- .../de/ellpeck/nyx/capabilities/NyxWorld.java | 14 +++++----- .../java/de/ellpeck/nyx/events/Events.java | 4 +-- 4 files changed, 28 insertions(+), 20 deletions(-) diff --git a/build.gradle b/build.gradle index db9418a..ba9db32 100644 --- a/build.gradle +++ b/build.gradle @@ -11,7 +11,7 @@ buildscript { apply plugin: 'net.minecraftforge.gradle.forge' apply plugin: 'maven' -version = "1.4.6" +version = "1.5.0" group = "de.ellpeck.nyx" archivesBaseName = "Nyx" diff --git a/src/main/java/de/ellpeck/nyx/Config.java b/src/main/java/de/ellpeck/nyx/Config.java index 29a84da..89ba424 100644 --- a/src/main/java/de/ellpeck/nyx/Config.java +++ b/src/main/java/de/ellpeck/nyx/Config.java @@ -7,7 +7,6 @@ import net.minecraft.potion.Potion; import net.minecraft.potion.PotionEffect; import net.minecraft.util.math.MathHelper; -import net.minecraft.world.DimensionType; import net.minecraft.world.World; import net.minecraftforge.common.config.Configuration; @@ -22,7 +21,7 @@ public final class Config { public static Configuration instance; - public static Set allowedDimensions; + public static Set allowedDimensions; public static boolean enchantments; public static boolean lunarWater; public static String[] lunarWaterItemParts; @@ -57,7 +56,7 @@ public final class Config { public static int[] lunarWaterTicks; public static double meteorChance; public static double meteorChanceNight; - public static String meteorGateDimension; + public static int meteorGateDimension; public static double meteorChanceAfterGate; public static double meteorChanceAfterGateNight; public static double meteorChanceStarShower; @@ -66,9 +65,10 @@ public final class Config { public static boolean meteors; public static int meteorDisallowRadius; public static int meteorDisallowTime; + public static Set meteorSpawnDimensions; public static boolean meteorKillUnloaded; public static boolean meteorCacheUnloaded; - public static Set enchantingWhitelistDimensions; + public static Set enchantingWhitelistDimensions; public static boolean eventNotifications; public static int crystalDurability; public static int hammerDamage; @@ -114,7 +114,7 @@ public static void init() { } public static void load() { - allowedDimensions = Sets.newHashSet(instance.get("general", "allowedDimensions", new String[]{"overworld"}, "Names of the dimensions that lunar events should occur in").getStringList()); + allowedDimensions = getDimensionConfig("general", "allowedDimensions", new String[]{"0"}, "IDs of the dimensions that lunar events should occur in"); meteorShardGuardianChance = instance.get("general", "meteorShardGuardianChance", 0.05, "The chance in percent (1 = 100%) for a meteor shard to be dropped from an elder guardian", 0, 1).getDouble(); mobDuplicationBlacklist = Sets.newHashSet(instance.get("general", "mobDuplicationBlacklist", new String[0], "The registry names of entities that should not be spawned during the full and blood moons. If isMobDuplicationWhitelist is true, this acts as a whitelist instead.").getStringList()); isMobDuplicationWhitelist = instance.get("general", "isMobDuplicationWhitelist", false, "If the mobDuplicationBlacklist should act as a whitelist instead").getBoolean(); @@ -155,7 +155,7 @@ public static void load() { maxLevelLunarEdgeDamage = instance.get("enchantments", "maxLevelLunarEdgeDamage", 3.25, "The amount of additional damage that should be applied to an item with max level lunar edge on a full moon.").getDouble(); baseLunarEdgeDamage = instance.get("enchantments", "baseLunarEdgeDamage", 0, "The amount of additional damage that will always be applied regardless of moon phase.").getDouble(); disallowDayEnchanting = instance.get("enchantments", "disallowDayEnchanting", true, "If enchanting should be disallowed during the day").getBoolean(); - enchantingWhitelistDimensions = Sets.newHashSet(instance.get("enchantments", "enchantingWhitelistDimensions", new String[]{"the_nether", "the_end"}, "A list of names of dimensions where enchanting is always allowed, and not just at night").getStringList()); + enchantingWhitelistDimensions = getDimensionConfig("enchantments", "enchantingWhitelistDimensions", new String[]{"-1", "1"}, "A list of dimension IDs where enchanting is always allowed, and not just at night"); harvestMoon = new LunarEventConfig("harvestMoon", "harvestMoon", "Harvest Moon", 0.05); colorHarvestMoon = Integer.parseInt(instance.get("harvestMoon", "harvestMoonColor", "3f3fc0", "The hex code of the harvest moon color").getString(), 16); @@ -180,9 +180,10 @@ public static void load() { bloodMoonOnFull = instance.get("bloodMoon", "bloodMoonOnFull", true, "If the blood moon should only occur on full moon nights").getBoolean(); meteors = instance.get("meteors", "meteors", true, "If meteor content should be enabled").getBoolean(); + meteorSpawnDimensions = getDimensionConfig("meteors", "meteorDimensions", new String[]{"0"}, "The IDs of dimensions to spawn meteors in (meteorChanceEnd ignores this!)"); meteorChance = instance.get("meteors", "meteorChance", 0.00014, "The chance of a meteor spawning every second, during the day").getDouble(); meteorChanceNight = instance.get("meteors", "meteorChanceNight", 0.0024, "The chance of a meteor spawning every second, during nighttime").getDouble(); - meteorGateDimension = instance.get("meteors", "meteorGateDimension", "the_nether", "The dimension that needs to be entered to increase the spawning of meteors").getString(); + meteorGateDimension = instance.get("meteors", "meteorGateDimension", -1, "The dimension that needs to be entered to increase the spawning of meteors").getInt(); meteorChanceAfterGate = instance.get("meteors", "meteorChanceAfterGate", 0.0002, "The chance of a meteor spawning every second, during the day, after the gate dimension has been entered once").getDouble(); meteorChanceAfterGateNight = instance.get("meteors", "meteorChanceAfterGateNight", 0.003, "The chance of a meteor spawning every second, during the night, after the gate dimension has been entered once").getDouble(); meteorChanceStarShower = instance.get("meteors", "meteorChanceStarShower", 0.0075, "The chance of a meteor spawning every second, during a star shower").getDouble(); @@ -210,11 +211,11 @@ public static void load() { } public static double getMeteorChance(World world, NyxWorld data) { - DimensionType dim = world.provider.getDimensionType(); - if (dim == DimensionType.THE_END) + int dim = world.provider.getDimension(); + if (dim == 1) return meteorChanceEnd; - if (!Config.allowedDimensions.contains(dim.getName())) + if (!Config.meteorSpawnDimensions.contains(dim)) return 0; boolean visitedGate = data.visitedDimensions.contains(meteorGateDimension); if (!NyxWorld.isDaytime(world)) { @@ -243,6 +244,13 @@ public static Set getLunarWaterConfig(String category, String .collect(Collectors.toSet()); } + public static Set getDimensionConfig(String category, String key, String[] defaultValue, String comment) { + return Arrays.stream(instance.get(category, key, defaultValue, comment).getStringList()) + .map(s -> MathHelper.getInt(s, Integer.MIN_VALUE)) + .filter(i -> i != Integer.MIN_VALUE) + .collect(Collectors.toSet()); + } + public static class LunarEventConfig { public boolean enabled; diff --git a/src/main/java/de/ellpeck/nyx/capabilities/NyxWorld.java b/src/main/java/de/ellpeck/nyx/capabilities/NyxWorld.java index f71ca57..c3a3848 100644 --- a/src/main/java/de/ellpeck/nyx/capabilities/NyxWorld.java +++ b/src/main/java/de/ellpeck/nyx/capabilities/NyxWorld.java @@ -7,9 +7,9 @@ import de.ellpeck.nyx.network.PacketNyxWorld; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagInt; import net.minecraft.nbt.NBTTagList; import net.minecraft.nbt.NBTTagLong; -import net.minecraft.nbt.NBTTagString; import net.minecraft.util.EnumFacing; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.ChunkPos; @@ -35,7 +35,7 @@ public class NyxWorld implements ICapabilityProvider, INBTSerializable cachedMeteorPositions = new HashSet<>(); public final Map playersPresentTicks = new HashMap<>(); public final Set meteorLandingSites = new HashSet<>(); - public final Set visitedDimensions = new HashSet<>(); + public final Set visitedDimensions = new HashSet<>(); public float eventSkyModifier; public int currentSkyColor; public LunarEvent currentEvent; @@ -57,7 +57,7 @@ public void update() { // add to visited dimensions list if (this.world.getTotalWorldTime() % 200 == 0) { for (EntityPlayer player : this.world.getMinecraftServer().getPlayerList().getPlayers()) - this.visitedDimensions.add(player.world.provider.getDimensionType().getName()); + this.visitedDimensions.add(player.world.provider.getDimension()); } // calculate which chunks have players close to them for meteor spawning @@ -87,7 +87,7 @@ public void update() { } // moon event stuff - String dimension = this.world.provider.getDimensionType().getName(); + int dimension = this.world.provider.getDimension(); if (Config.allowedDimensions.contains(dimension)) { moonPhase = this.world.getCurrentMoonPhaseFactor(); @@ -176,8 +176,8 @@ public NBTTagCompound serializeNBT(boolean client) { } compound.setTag("players_present_ticks", ticks); NBTTagList dimensions = new NBTTagList(); - for (String dim : this.visitedDimensions) - dimensions.appendTag(new NBTTagString(dim)); + for (int dim : this.visitedDimensions) + dimensions.appendTag(new NBTTagInt(dim)); compound.setTag("visited_dims", dimensions); } return compound; @@ -214,7 +214,7 @@ public void deserializeNBT(NBTTagCompound compound, boolean client) { this.visitedDimensions.clear(); NBTTagList dimensions = compound.getTagList("visited_dims", Constants.NBT.TAG_STRING); for (int i = 0; i < dimensions.tagCount(); i++) - this.visitedDimensions.add(((NBTTagString) dimensions.get(i)).getString()); + this.visitedDimensions.add(((NBTTagInt) dimensions.get(i)).getInt()); } } diff --git a/src/main/java/de/ellpeck/nyx/events/Events.java b/src/main/java/de/ellpeck/nyx/events/Events.java index 61074b8..44f6211 100644 --- a/src/main/java/de/ellpeck/nyx/events/Events.java +++ b/src/main/java/de/ellpeck/nyx/events/Events.java @@ -191,7 +191,7 @@ public static void onWorldTick(TickEvent.WorldTickEvent event) { // Falling stars if (!event.world.isRemote && Config.fallingStars && !NyxWorld.isDaytime(event.world) && event.world.getTotalWorldTime() % 20 == 0) { - String dimension = event.world.provider.getDimensionType().getName(); + int dimension = event.world.provider.getDimension(); if (Config.allowedDimensions.contains(dimension)) { for (EntityPlayer player : event.world.playerEntities) { if (event.world.rand.nextFloat() > (data.currentEvent instanceof StarShower ? Config.fallingStarRarityShower : Config.fallingStarRarity)) @@ -411,7 +411,7 @@ public static void onInteract(PlayerInteractEvent.RightClickBlock event) { break ench; if (!(block instanceof BlockEnchantmentTable)) break ench; - if (Config.enchantingWhitelistDimensions.contains(world.provider.getDimensionType().getName())) + if (Config.enchantingWhitelistDimensions.contains(world.provider.getDimension())) break ench; event.setUseBlock(Event.Result.DENY); player.sendStatusMessage(new TextComponentTranslation("info." + Nyx.ID + ".day_enchanting"), true);