Skip to content

Commit

Permalink
Ability to configure lunar water item
Browse files Browse the repository at this point in the history
  • Loading branch information
democat3457 committed Mar 17, 2021
1 parent c16083e commit 901af72
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/main/java/de/ellpeck/nyx/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public final class Config {
public static Set<String> allowedDimensions;
public static boolean enchantments;
public static boolean lunarWater;
public static String lunarWaterItem;
public static String[] lunarWaterItemParts;
public static boolean addPotionEffects;
public static int additionalMobsChance;
public static boolean lunarEdgeXp;
Expand Down Expand Up @@ -66,7 +66,7 @@ public static void init(File file) {
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();
lunarWaterItem = 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();
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();
Expand Down
45 changes: 43 additions & 2 deletions src/main/java/de/ellpeck/nyx/entities/CauldronTracker.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,20 @@
import net.minecraft.init.Items;
import net.minecraft.item.EnumDyeColor;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.Ingredient;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTUtil;
import net.minecraft.network.datasync.DataParameter;
import net.minecraft.network.datasync.DataSerializers;
import net.minecraft.network.datasync.EntityDataManager;
import net.minecraft.util.EnumParticleTypes;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.fml.common.registry.ForgeRegistries;
import net.minecraftforge.oredict.OreDictionary;

import java.util.List;

Expand Down Expand Up @@ -95,12 +99,49 @@ public void onEntityUpdate() {
}
} else {
List<EntityItem> items = this.world.getEntitiesWithinAABB(EntityItem.class, new AxisAlignedBB(this.trackingPos));

Ingredient toMatch = null;
switch (Config.lunarWaterItemParts.length) {
case 1:
ResourceLocation r1 = new ResourceLocation(Config.lunarWaterItemParts[0]);
if (ForgeRegistries.ITEMS.containsKey(r1))
toMatch = Ingredient.fromItem(ForgeRegistries.ITEMS.getValue(r1));
break;
case 2:
if ("ore".equals(Config.lunarWaterItemParts[0]))
toMatch = Ingredient.fromStacks(OreDictionary.getOres(Config.lunarWaterItemParts[1]).toArray(new ItemStack[0]));
else {
ResourceLocation r2 = new ResourceLocation(Config.lunarWaterItemParts[0], Config.lunarWaterItemParts[1]);
if (ForgeRegistries.ITEMS.containsKey(r2))
toMatch = Ingredient.fromItem(ForgeRegistries.ITEMS.getValue(r2));
}
break;
case 3:
ResourceLocation r3 = new ResourceLocation(Config.lunarWaterItemParts[0], Config.lunarWaterItemParts[1]);
if (ForgeRegistries.ITEMS.containsKey(r3)) {
int meta = 0;
try {
meta = Integer.parseInt(Config.lunarWaterItemParts[2]);
} catch (Exception e) {
if ("*".equals(Config.lunarWaterItemParts[2]))
meta = 32767;
}
toMatch = Ingredient.fromStacks(new ItemStack(ForgeRegistries.ITEMS.getValue(r3), 1, meta));
}
break;
default:
break;
}
if (toMatch == null)
toMatch = Ingredient.fromStacks(new ItemStack(Items.DYE, 1, EnumDyeColor.BLUE.getDyeDamage()));

for (EntityItem item : items) {
if (item.isDead)
continue;
ItemStack stack = item.getItem();
if (stack.getItem() != Items.DYE || stack.getMetadata() != EnumDyeColor.BLUE.getDyeDamage())

if (!toMatch.apply(item.getItem()))
continue;

item.setDead();

IBlockState newState = Registry.lunarWaterCauldron.getDefaultState().withProperty(BlockCauldron.LEVEL, level);
Expand Down

0 comments on commit 901af72

Please sign in to comment.