diff --git a/src/main/java/de/ellpeck/nyx/Config.java b/src/main/java/de/ellpeck/nyx/Config.java index d3d9cb9..06a83a8 100644 --- a/src/main/java/de/ellpeck/nyx/Config.java +++ b/src/main/java/de/ellpeck/nyx/Config.java @@ -3,6 +3,7 @@ import com.google.common.collect.Sets; import de.ellpeck.nyx.capabilities.NyxWorld; import de.ellpeck.nyx.lunarevents.StarShower; +import net.minecraft.item.ItemStack; import net.minecraft.potion.Potion; import net.minecraft.potion.PotionEffect; import net.minecraft.util.math.MathHelper; @@ -66,6 +67,8 @@ public final class Config { public static int crystalDurability; public static int hammerDamage; public static double bowDamageMultiplier; + public static Set scytheDropBlacklist; + private static Set _scytheDropBlacklist; public static Set lunarWaterRemoveNegative; public static Set lunarWaterRemoveAll; @@ -91,6 +94,12 @@ public static void init() { .collect(Collectors.toSet())) ) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); + + scytheDropBlacklist = _scytheDropBlacklist.stream() + .map(s -> ItemMetaHelper.getFromString("scythe drop blacklist", s)) + .flatMap(Set::stream) + .filter(i -> i != null && !i.isEmpty()) + .collect(Collectors.toSet()); } public static void load() { @@ -161,6 +170,7 @@ public static void load() { crystalDurability = instance.get("meteors", "crystalDurability", 1000, "The amount of uses that a gleaning crystal should have for bone-mealing").getInt(); hammerDamage = instance.get("meteors", "hammerDamage", 15, "The amount of damage that the meteor hammer deals if the maximum flight time was used").getInt(); bowDamageMultiplier = instance.get("meteors", "bowDamageMult", 1.75, "The multiplier for the amount of damage inflicted by the meteor bow's arrows").getDouble(); + _scytheDropBlacklist = Sets.newHashSet(instance.get("meteors", "scytheDropBlacklist", new String[0], "Drops that the scythe shouldn't multiply").getStringList()); if (instance.hasChanged()) instance.save(); diff --git a/src/main/java/de/ellpeck/nyx/ItemMetaHelper.java b/src/main/java/de/ellpeck/nyx/ItemMetaHelper.java new file mode 100644 index 0000000..6c21967 --- /dev/null +++ b/src/main/java/de/ellpeck/nyx/ItemMetaHelper.java @@ -0,0 +1,58 @@ +package de.ellpeck.nyx; + +import java.util.Arrays; +import java.util.Collection; +import java.util.HashSet; +import java.util.Set; +import java.util.stream.Collectors; + +import com.google.common.collect.Sets; + +import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.util.NonNullList; +import net.minecraft.util.ResourceLocation; +import net.minecraft.util.math.MathHelper; +import net.minecraftforge.fml.common.registry.ForgeRegistries; + +import static de.ellpeck.nyx.Nyx.LOGGER; + +public class ItemMetaHelper { + public static Set getFromString(String debugString, String s) { + String[] itemData = s.split(":"); + if (itemData.length < 2 || itemData.length > 3) { + LOGGER.warn("Invalid {} '{}'", debugString, s); + return Sets.newHashSet(ItemStack.EMPTY); + } + ResourceLocation r = new ResourceLocation(itemData[0], itemData[1]); + if (!ForgeRegistries.ITEMS.containsKey(r)) + return Sets.newHashSet(ItemStack.EMPTY); + Item item = ForgeRegistries.ITEMS.getValue(r); + + // has meta + if (itemData.length == 3) { + int meta = MathHelper.getInt(itemData[2], -1); + if (meta < 0) { + LOGGER.warn("Invalid meta '{}' for {} '{}'", meta, debugString, s); + return Sets.newHashSet(ItemStack.EMPTY); + } + return Sets.newHashSet(new ItemStack(item, 1, meta)); + } else { + // no meta, wildcard it + NonNullList subItems = NonNullList.create(); + item.getSubItems(CreativeTabs.SEARCH, subItems); + + return new HashSet<>(subItems); + } + } + + public static Set getFromStringArray(String debugString, String[] a) { + return Arrays.stream(a).map(s -> ItemMetaHelper.getFromString(debugString, s)).flatMap(Set::stream) + .collect(Collectors.toSet()); + } + + public static Set getFromStringCollection(String debugString, Collection c) { + return getFromStringArray(debugString, c.toArray(new String[0])); + } +} \ No newline at end of file diff --git a/src/main/java/de/ellpeck/nyx/events/Events.java b/src/main/java/de/ellpeck/nyx/events/Events.java index 713815e..0a95a6b 100644 --- a/src/main/java/de/ellpeck/nyx/events/Events.java +++ b/src/main/java/de/ellpeck/nyx/events/Events.java @@ -441,7 +441,7 @@ public static void onInteract(PlayerInteractEvent.RightClickBlock event) { level = 3; if (!world.isRemote) { - player.setHeldItem(EnumHand.MAIN_HAND, new ItemStack(Items.BUCKET)); + if (!player.isCreative()) player.setHeldItem(EnumHand.MAIN_HAND, new ItemStack(Items.BUCKET)); world.setBlockState(pos, Registry.lunarWaterCauldron.getDefaultState().withProperty(BlockCauldron.LEVEL, level)); } diff --git a/src/main/java/de/ellpeck/nyx/items/Scythe.java b/src/main/java/de/ellpeck/nyx/items/Scythe.java index 3973598..70e50ee 100644 --- a/src/main/java/de/ellpeck/nyx/items/Scythe.java +++ b/src/main/java/de/ellpeck/nyx/items/Scythe.java @@ -1,6 +1,8 @@ package de.ellpeck.nyx.items; import com.google.common.collect.Multimap; + +import de.ellpeck.nyx.Config; import de.ellpeck.nyx.Registry; import net.minecraft.block.Block; import net.minecraft.block.state.IBlockState; @@ -53,6 +55,11 @@ public boolean onBlockStartBreak(ItemStack itemstack, BlockPos pos, EntityPlayer offBlock.getDrops(drops, worldIn, offset, offState, 0); float chance = ForgeEventFactory.fireBlockHarvesting(drops, worldIn, offset, offState, 0, 1, false, player); for (ItemStack drop : drops) { + if (Config.scytheDropBlacklist.stream() + .anyMatch(i -> i.getItem().equals(drop.getItem()) + && i.getMetadata() == drop.getMetadata())) + continue; + if (worldIn.rand.nextFloat() > chance) continue; // increase drop amount by chance