Skip to content

Commit

Permalink
Scythe drop blacklist
Browse files Browse the repository at this point in the history
  • Loading branch information
democat3457 committed Apr 14, 2021
1 parent c416f50 commit 5766652
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/main/java/de/ellpeck/nyx/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -66,6 +67,8 @@ public final class Config {
public static int crystalDurability;
public static int hammerDamage;
public static double bowDamageMultiplier;
public static Set<ItemStack> scytheDropBlacklist;
private static Set<String> _scytheDropBlacklist;
public static Set<LunarWaterSource> lunarWaterRemoveNegative;
public static Set<LunarWaterSource> lunarWaterRemoveAll;

Expand All @@ -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() {
Expand Down Expand Up @@ -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();
Expand Down
58 changes: 58 additions & 0 deletions src/main/java/de/ellpeck/nyx/ItemMetaHelper.java
Original file line number Diff line number Diff line change
@@ -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<ItemStack> 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<ItemStack> subItems = NonNullList.create();
item.getSubItems(CreativeTabs.SEARCH, subItems);

return new HashSet<>(subItems);
}
}

public static Set<ItemStack> getFromStringArray(String debugString, String[] a) {
return Arrays.stream(a).map(s -> ItemMetaHelper.getFromString(debugString, s)).flatMap(Set::stream)
.collect(Collectors.toSet());
}

public static Set<ItemStack> getFromStringCollection(String debugString, Collection<String> c) {
return getFromStringArray(debugString, c.toArray(new String[0]));
}
}
2 changes: 1 addition & 1 deletion src/main/java/de/ellpeck/nyx/events/Events.java
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand Down
7 changes: 7 additions & 0 deletions src/main/java/de/ellpeck/nyx/items/Scythe.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 5766652

Please sign in to comment.