Skip to content

Commit

Permalink
Incomplete lunar water config
Browse files Browse the repository at this point in the history
  • Loading branch information
democat3457 committed Apr 14, 2021
1 parent b006402 commit a5dade3
Show file tree
Hide file tree
Showing 11 changed files with 127 additions and 32 deletions.
68 changes: 64 additions & 4 deletions src/main/java/de/ellpeck/nyx/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,20 @@
import com.google.common.collect.Sets;
import de.ellpeck.nyx.capabilities.NyxWorld;
import de.ellpeck.nyx.lunarevents.StarShower;
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;

import java.io.File;
import java.util.AbstractMap.SimpleEntry;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

public final class Config {

Expand Down Expand Up @@ -58,24 +66,60 @@ public final class Config {
public static int crystalDurability;
public static int hammerDamage;
public static double bowDamageMultiplier;
public static Set<LunarWaterSource> lunarWaterRemoveNegative;
public static Set<LunarWaterSource> lunarWaterRemoveAll;

public static void init(File file) {
private static Map<LunarWaterSource, Set<String>> _lunarWaterEffects = new HashMap<>();
public static Map<LunarWaterSource, Set<PotionEffect>> lunarWaterEffects;

public static void preInit(File file) {
instance = new Configuration(file);
instance.load();
load();
}

public static void init() {
lunarWaterEffects = _lunarWaterEffects.entrySet().stream()
.map(e -> new SimpleEntry<LunarWaterSource, Set<PotionEffect>>(e.getKey(), e.getValue().stream()
.map(s -> {
String[] split = s.split(";");
if (split.length != 3)
return new PotionEffect((Potion) null);
return new PotionEffect(Potion.getPotionFromResourceLocation(split[0]), MathHelper.getInt(split[1], 20), MathHelper.getInt(split[2], 0));
})
.filter(p -> p.getPotion() != null)
.collect(Collectors.toSet()))
)
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
}

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());
lunarWater = instance.get("general", "lunarWater", true, "If lunar water should be enabled").getBoolean();
lunarWaterItemParts = instance.get("general", "lunarWaterItem", "minecraft:dye:11", "The item that needs to be dropped into a cauldron to turn it into lunar water. Examples include 'minecraft:stick', 'minecraft:wool:3', and 'ore:stone'").getString().split(":");
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();
moonEventTint = instance.get("general", "moonEventTint", true, "If moon events should tint the sky").getBoolean();
lunarWaterTicks = instance.get("general", "lunarWaterTicks", new int[]{1200, -1, 4800, 4800, 3600, 3600, 2400, 2400, 600, -1}, "The amount of ticks that a cauldron of water must be exposed to the night sky to be ready to turn into lunar water, per moon phase. From first to last, the entries are: Full moon, new moon, waning crescent, waxing crescent, third quarter, first quarter, waning gibbous, waxing gibbous, harvest moon and blood moon. Set any entry to -1 to disable lunar water production for that phase.").getIntList();
eventNotifications = instance.get("general", "eventNotifications", true, "If moon events should be announced in chat when they start").getBoolean();


lunarWater = instance.get("lunarWater", "lunarWater", true, "If lunar water should be enabled").getBoolean();
lunarWaterItemParts = instance.get("lunarWater", "lunarWaterItem", "minecraft:dye:11", "The item that needs to be dropped into a cauldron to turn it into lunar water.\nExamples include 'minecraft:stick', 'minecraft:wool:3', and 'ore:stone'").getString().split(":");
lunarWaterTicks = instance.get("lunarWater", "lunarWaterTicks", new int[]{1200, -1, 4800, 4800, 3600, 3600, 2400, 2400, 600, -1},
"The amount of ticks that a cauldron of water must be exposed to the night sky to be ready to turn into lunar water, per moon phase.\n" +
"From first to last, the entries are: Full moon, new moon, waning crescent, waxing crescent, third quarter, first quarter, waning gibbous, waxing gibbous, harvest moon and blood moon.\n" +
"Set any entry to -1 to disable lunar water production for that phase.").getIntList();
lunarWaterRemoveNegative = getLunarWaterConfig("lunarWater", "lunarWaterRemoveNegative", LunarWaterSource.ALL, "Which lunar water methods should clear negative effects\nPossible values are " + String.join(", ", LunarWaterSource.getNames()));
lunarWaterRemoveAll = getLunarWaterConfig("lunarWater", "lunarWaterRemoveAll", LunarWaterSource.NONE, "Which lunar water methods should clear all effects\nPossible values are " + String.join(", ", LunarWaterSource.getNames()));
for (LunarWaterSource c : LunarWaterSource.values()) {
_lunarWaterEffects.put(c,
Sets.newHashSet(
instance.get("lunarWater",
"lunarWaterEffects" + c.name(),
new String[]{"minecraft:regeneration;100;1"},
"The effects that lunar water in the method '" + c.name() + "' should give")
.getStringList()));
}

fullMoon = instance.get("fullMoon", "fullMoon", true, "If the vanilla full moon should be considered a proper lunar event").getBoolean();
addPotionEffects = instance.get("fullMoon", "addPotionEffects", true, "If mobs spawned during a full moon should have random potion effects applied to them (similarly to spiders in the base game)").getBoolean();
additionalMobsChance = instance.get("fullMoon", "additionalMobsChance", 5, "The chance for an additional mob to be spawned when a mob spawns during a full moon. The higher the number, the less likely. Set to 0 to disable.", 0, 1000).getInt();
Expand Down Expand Up @@ -140,6 +184,22 @@ public static double getMeteorChance(World world, NyxWorld data) {
return visitedGate ? meteorChanceAfterGate : meteorChance;
}

public static LunarWaterSource getLunarWaterConfig(String category, String key, LunarWaterSource defaultValue, String comment) {
return LunarWaterSource.valueOf(instance.get(category, key, defaultValue.name(), comment, LunarWaterSource.getNames()).getString());
}

public static Set<LunarWaterSource> getLunarWaterConfig(String category, String key, Set<LunarWaterSource> defaultValue, String comment) {
return Arrays.stream(instance.get(category, key,
defaultValue.stream()
.map(LunarWaterSource::name)
.collect(Collectors.toList())
.toArray(new String[0]), comment)
.getStringList())
.filter(LunarWaterSource::containsName)
.map(LunarWaterSource::valueOf)
.collect(Collectors.toSet());
}

public static class LunarEventConfig {

public boolean enabled;
Expand Down
24 changes: 24 additions & 0 deletions src/main/java/de/ellpeck/nyx/LunarWaterSource.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package de.ellpeck.nyx;

import java.util.Arrays;
import java.util.Set;
import java.util.stream.Collectors;

import com.google.common.collect.Sets;

public enum LunarWaterSource {
BOTTLE,
STANDING,
CAULDRON;

public static final Set<LunarWaterSource> NONE = Sets.newHashSet();
public static final Set<LunarWaterSource> ALL = Sets.newHashSet(BOTTLE, STANDING, CAULDRON);

public static String[] getNames() {
return Arrays.stream(values()).map(LunarWaterSource::name).collect(Collectors.toList()).toArray(new String[0]);
}

public static boolean containsName(String s) {
return Arrays.stream(values()).map(LunarWaterSource::name).anyMatch(s::equals);
}
}
3 changes: 2 additions & 1 deletion src/main/java/de/ellpeck/nyx/Nyx.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,15 @@ public class Nyx {

@EventHandler
public void preInit(FMLPreInitializationEvent event) {
Config.init(event.getSuggestedConfigurationFile());
Config.preInit(event.getSuggestedConfigurationFile());
Registry.preInit();
PacketHandler.init();
}

@EventHandler
public void init(FMLInitializationEvent event) {
Registry.init();
Config.init();
}

@EventHandler
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/de/ellpeck/nyx/Registry.java
Original file line number Diff line number Diff line change
Expand Up @@ -161,17 +161,17 @@ public static void onItemRegistry(RegistryEvent.Register<Item> event) {
unrefinedCrystal = initItem(new Item(), "unrefined_crystal");
scythe = initItem(new Scythe(), "scythe");
meteorIngot = initItem(new Item(), "meteor_ingot");
meteorBow = initItem(new Bow(), "meteor_bow");
meteorPickaxe = initItem(new Pickaxe(meteorToolMaterial), "meteor_pickaxe");
meteorAxe = initItem(new Axe(meteorToolMaterial, 12, -3.2F), "meteor_axe");
meteorBow = initItem(new MeteorBow(), "meteor_bow");
meteorPickaxe = initItem(new MeteorPickaxe(meteorToolMaterial), "meteor_pickaxe");
meteorAxe = initItem(new MeteorAxe(meteorToolMaterial, 12, -3.2F), "meteor_axe");
meteorShovel = initItem(new ItemSpade(meteorToolMaterial), "meteor_shovel");
meteorHoe = initItem(new ItemHoe(meteorToolMaterial), "meteor_hoe");
meteorSword = initItem(new ItemSword(meteorToolMaterial), "meteor_sword");
meteorHelm = initItem(new ItemArmor(meteorArmorMaterial, 0, EntityEquipmentSlot.HEAD), "meteor_helm");
meteorChest = initItem(new ItemArmor(meteorArmorMaterial, 1, EntityEquipmentSlot.CHEST), "meteor_chest");
meteorPants = initItem(new ItemArmor(meteorArmorMaterial, 2, EntityEquipmentSlot.LEGS), "meteor_pants");
meteorBoots = initItem(new ItemArmor(meteorArmorMaterial, 3, EntityEquipmentSlot.FEET), "meteor_boots");
meteorHammer = initItem(new Hammer(meteorToolMaterial), "meteor_hammer");
meteorHammer = initItem(new MeteorHammer(meteorToolMaterial), "meteor_hammer");
}
if (Config.fallingStars)
fallenStar = initItem(new FallenStar(), "fallen_star");
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/de/ellpeck/nyx/blocks/LunarWater.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package de.ellpeck.nyx.blocks;

import de.ellpeck.nyx.LunarWaterSource;
import de.ellpeck.nyx.Nyx;
import de.ellpeck.nyx.items.LunarWaterBottle;
import net.minecraft.block.material.Material;
Expand All @@ -26,7 +27,7 @@ public LunarWater(Fluid fluid) {
@Override
public void onEntityCollision(World worldIn, BlockPos pos, IBlockState state, Entity entityIn) {
if (entityIn instanceof EntityLivingBase)
LunarWaterBottle.applyLunarWater((EntityLivingBase) entityIn);
LunarWaterBottle.applyLunarWater((EntityLivingBase) entityIn, LunarWaterSource.STANDING);
}

@Override
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/de/ellpeck/nyx/blocks/LunarWaterCauldron.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package de.ellpeck.nyx.blocks;

import de.ellpeck.nyx.LunarWaterSource;
import de.ellpeck.nyx.Registry;
import de.ellpeck.nyx.items.LunarWaterBottle;
import net.minecraft.block.BlockCauldron;
Expand Down Expand Up @@ -96,7 +97,7 @@ public void onEntityCollision(World worldIn, BlockPos pos, IBlockState state, En
did = true;
}
if (entityIn instanceof EntityLivingBase) {
if (LunarWaterBottle.applyLunarWater((EntityLivingBase) entityIn))
if (LunarWaterBottle.applyLunarWater((EntityLivingBase) entityIn, LunarWaterSource.CAULDRON))
did = true;
}
if (did)
Expand Down
34 changes: 21 additions & 13 deletions src/main/java/de/ellpeck/nyx/items/LunarWaterBottle.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package de.ellpeck.nyx.items;

import de.ellpeck.nyx.Config;
import de.ellpeck.nyx.LunarWaterSource;
import de.ellpeck.nyx.Registry;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items;
import net.minecraft.init.MobEffects;
import net.minecraft.item.EnumAction;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
Expand Down Expand Up @@ -33,30 +34,37 @@ public LunarWaterBottle() {
this.setMaxStackSize(1);
}

public static boolean applyLunarWater(EntityLivingBase entity) {
public static boolean applyLunarWater(EntityLivingBase entity, LunarWaterSource type) {
boolean did = false;

Set<Potion> effectsToRemove = new HashSet<>();
for (PotionEffect effect : entity.getActivePotionEffects()) {
Potion potion = effect.getPotion();
if (potion.isBadEffect()) {
effectsToRemove.add(potion);
did = true;
if (Config.lunarWaterRemoveNegative.contains(type) || Config.lunarWaterRemoveAll.contains(type)) {
Set<Potion> effectsToRemove = new HashSet<>();
for (PotionEffect effect : entity.getActivePotionEffects()) {
Potion potion = effect.getPotion();
// Check if bad potion or if we should remove all anyway
if ((potion.isBadEffect() || Config.lunarWaterRemoveAll.contains(type))
// Prevent feedback loops by making sure it's not reapplied after
&& Config.lunarWaterEffects.get(type).stream().map(PotionEffect::getPotion).noneMatch(p -> p.getRegistryName().equals(potion.getRegistryName()))){
effectsToRemove.add(potion);
did = true;
}
}
effectsToRemove.forEach(entity::removePotionEffect);
}
effectsToRemove.forEach(entity::removePotionEffect);

if (entity.getActivePotionEffect(MobEffects.REGENERATION) == null) {
entity.addPotionEffect(new PotionEffect(MobEffects.REGENERATION, 5 * 20, 1));
did = true;
for (PotionEffect effect : Config.lunarWaterEffects.get(type)) {
if (entity.getActivePotionEffect(effect.getPotion()) == null) {
entity.addPotionEffect(effect);
did = true;
}
}
return did;
}

@Override
public ItemStack onItemUseFinish(ItemStack stack, World worldIn, EntityLivingBase entityLiving) {
if (!worldIn.isRemote)
applyLunarWater(entityLiving);
applyLunarWater(entityLiving, LunarWaterSource.BOTTLE);
EntityPlayer player = entityLiving instanceof EntityPlayer ? (EntityPlayer) entityLiving : null;
if (player == null || !player.capabilities.isCreativeMode) {
stack.shrink(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import net.minecraft.item.ItemAxe;

public class Axe extends ItemAxe {
public Axe(ToolMaterial material, float damage, float speed) {
public class MeteorAxe extends ItemAxe {
public MeteorAxe(ToolMaterial material, float damage, float speed) {
super(material, damage, speed);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@

import javax.annotation.Nullable;

public class Bow extends ItemBow {
public class MeteorBow extends ItemBow {

public Bow() {
public MeteorBow() {
this.setMaxDamage(2250);
// modified copy of super, since we increase the use time from 20 to 30
this.addPropertyOverride(new ResourceLocation("pull"), new IItemPropertyGetter() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
import net.minecraft.world.WorldServer;
import net.minecraftforge.common.ForgeHooks;

public class Hammer extends Pickaxe {
public Hammer(ToolMaterial material) {
public class MeteorHammer extends MeteorPickaxe {
public MeteorHammer(ToolMaterial material) {
super(material);
this.setMaxDamage(5500);
this.attackDamage = 15;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import net.minecraft.item.ItemPickaxe;
import net.minecraft.item.ItemStack;

public class Pickaxe extends ItemPickaxe {
public Pickaxe(ToolMaterial material) {
public class MeteorPickaxe extends ItemPickaxe {
public MeteorPickaxe(ToolMaterial material) {
super(material);
}

Expand Down

0 comments on commit a5dade3

Please sign in to comment.