BloodMagic/src/main/java/WayofTime/bloodmagic/item/ItemBoundShovel.java

114 lines
4.9 KiB
Java
Raw Normal View History

package WayofTime.bloodmagic.item;
2018-03-07 19:43:00 -08:00
import WayofTime.bloodmagic.client.IMeshProvider;
import WayofTime.bloodmagic.client.mesh.CustomMeshDefinitionActivatable;
import WayofTime.bloodmagic.core.data.SoulTicket;
import WayofTime.bloodmagic.util.BlockStack;
import WayofTime.bloodmagic.util.ItemStackWrapper;
import WayofTime.bloodmagic.util.helper.NetworkHelper;
import com.google.common.collect.*;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
2016-03-18 16:31:55 -04:00
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.renderer.ItemMeshDefinition;
import net.minecraft.enchantment.EnchantmentHelper;
2016-03-15 19:38:45 -07:00
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.ai.attributes.AttributeModifier;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
2016-03-18 16:31:55 -04:00
import net.minecraft.init.Enchantments;
import net.minecraft.inventory.EntityEquipmentSlot;
import net.minecraft.item.ItemStack;
2016-03-18 16:31:55 -04:00
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.world.BlockEvent;
import net.minecraftforge.fml.common.eventhandler.Event;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
2017-08-15 21:30:48 -07:00
import java.util.Set;
2018-03-07 19:43:00 -08:00
import java.util.function.Consumer;
2017-08-15 21:30:48 -07:00
public class ItemBoundShovel extends ItemBoundTool implements IMeshProvider {
2016-04-24 10:06:28 -07:00
private static final Set<Block> EFFECTIVE_ON = Sets.newHashSet(Blocks.CLAY, Blocks.DIRT, Blocks.FARMLAND, Blocks.GRASS, Blocks.GRAVEL, Blocks.MYCELIUM, Blocks.SAND, Blocks.SNOW, Blocks.SNOW_LAYER, Blocks.SOUL_SAND);
2017-08-15 21:30:48 -07:00
public ItemBoundShovel() {
2016-03-15 19:38:45 -07:00
super("shovel", 1, EFFECTIVE_ON);
}
@Override
2017-08-15 21:30:48 -07:00
public boolean hitEntity(ItemStack stack, EntityLivingBase target, EntityLivingBase attacker) {
2016-03-15 19:38:45 -07:00
return true;
}
@Override
2017-08-15 21:30:48 -07:00
public boolean onBlockDestroyed(ItemStack stack, World world, IBlockState block, BlockPos pos, EntityLivingBase entityLiving) {
2016-03-15 19:38:45 -07:00
return true;
}
@Override
2017-08-15 21:30:48 -07:00
protected void onBoundRelease(ItemStack stack, World world, EntityPlayer player, int charge) {
if (world.isRemote)
return;
2016-04-24 10:06:28 -07:00
int fortuneLvl = EnchantmentHelper.getEnchantmentLevel(Enchantments.FORTUNE, stack);
boolean silkTouch = EnchantmentHelper.getEnchantmentLevel(Enchantments.SILK_TOUCH, stack) > 0;
int range = charge / 6; //Charge is a max of 30 - want 5 to be the max
HashMultiset<ItemStackWrapper> drops = HashMultiset.create();
BlockPos playerPos = player.getPosition();
2017-08-15 21:30:48 -07:00
for (int i = -range; i <= range; i++) {
for (int j = 0; j <= 2 * range; j++) {
for (int k = -range; k <= range; k++) {
BlockPos blockPos = playerPos.add(i, j, k);
BlockStack blockStack = BlockStack.getStackFromPos(world, blockPos);
2016-03-18 16:31:55 -04:00
if (blockStack.getBlock().isAir(blockStack.getState(), world, blockPos))
continue;
Material material = blockStack.getState().getMaterial();
if (material != Material.GROUND && material != Material.CLAY && material != Material.GRASS && !EFFECTIVE_ON.contains(blockStack.getBlock()))
continue;
BlockEvent.BreakEvent event = new BlockEvent.BreakEvent(world, blockPos, blockStack.getState(), player);
if (MinecraftForge.EVENT_BUS.post(event) || event.getResult() == Event.Result.DENY)
continue;
sharedHarvest(stack, world, player, blockPos, blockStack, drops, silkTouch, fortuneLvl);
}
}
}
NetworkHelper.getSoulNetwork(player).syphonAndDamage(player, SoulTicket.item(stack, world, player, (int) (charge * charge * charge / 2.7)));
world.createExplosion(player, playerPos.getX(), playerPos.getY(), playerPos.getZ(), 0.5F, false);
dropStacks(drops, world, playerPos.add(0, 1, 0));
}
@Override
2017-08-15 21:30:48 -07:00
public Multimap<String, AttributeModifier> getItemAttributeModifiers(EntityEquipmentSlot equipmentSlot) {
2016-03-18 16:31:55 -04:00
Multimap<String, AttributeModifier> multimap = super.getItemAttributeModifiers(equipmentSlot);
2017-08-15 21:30:48 -07:00
if (equipmentSlot == EntityEquipmentSlot.MAINHAND) {
2017-01-01 22:26:42 -08:00
multimap.put(SharedMonsterAttributes.ATTACK_DAMAGE.getName(), new AttributeModifier(ATTACK_DAMAGE_MODIFIER, "Weapon modifier", 5, 0));
multimap.put(SharedMonsterAttributes.ATTACK_SPEED.getName(), new AttributeModifier(ATTACK_SPEED_MODIFIER, "Tool modifier", -2.5, 0));
}
return multimap;
}
@Override
@SideOnly(Side.CLIENT)
2017-08-15 21:30:48 -07:00
public ItemMeshDefinition getMeshDefinition() {
2017-08-16 16:39:57 -07:00
return new CustomMeshDefinitionActivatable("bound_shovel");
}
@Override
2018-03-07 19:43:00 -08:00
public void gatherVariants(Consumer<String> variants) {
variants.accept("active=true");
variants.accept("active=false");
}
}