2019-11-04 19:08:49 +01:00
|
|
|
package de.ellpeck.naturesaura.items.tools;
|
|
|
|
|
|
|
|
import de.ellpeck.naturesaura.Helper;
|
|
|
|
import de.ellpeck.naturesaura.NaturesAura;
|
|
|
|
import de.ellpeck.naturesaura.api.NaturesAuraAPI;
|
2021-12-04 15:40:09 +01:00
|
|
|
import de.ellpeck.naturesaura.api.misc.ILevelData;
|
2020-01-29 00:40:28 +01:00
|
|
|
import de.ellpeck.naturesaura.data.ItemModelGenerator;
|
2019-11-04 19:08:49 +01:00
|
|
|
import de.ellpeck.naturesaura.items.ModItems;
|
2021-12-04 15:40:09 +01:00
|
|
|
import de.ellpeck.naturesaura.misc.LevelData;
|
2020-01-29 00:40:28 +01:00
|
|
|
import de.ellpeck.naturesaura.reg.ICustomItemModel;
|
2019-11-04 19:08:49 +01:00
|
|
|
import de.ellpeck.naturesaura.reg.IModItem;
|
2020-01-22 01:32:26 +01:00
|
|
|
import de.ellpeck.naturesaura.reg.ModRegistry;
|
2019-11-04 19:08:49 +01:00
|
|
|
import net.minecraft.block.BlockState;
|
2020-05-13 17:57:31 +02:00
|
|
|
import net.minecraft.entity.Entity;
|
|
|
|
import net.minecraft.entity.item.ItemEntity;
|
2021-12-04 15:40:09 +01:00
|
|
|
import net.minecraft.entity.player.Player;
|
2019-11-04 19:08:49 +01:00
|
|
|
import net.minecraft.item.IItemTier;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.item.ItemUseContext;
|
|
|
|
import net.minecraft.item.PickaxeItem;
|
2021-12-04 15:40:09 +01:00
|
|
|
import net.minecraft.nbt.CompoundTag;
|
|
|
|
import net.minecraft.util.InteractionResult;
|
2020-01-26 00:43:12 +01:00
|
|
|
import net.minecraft.util.SoundCategory;
|
|
|
|
import net.minecraft.util.SoundEvents;
|
2020-05-13 17:57:31 +02:00
|
|
|
import net.minecraft.util.math.AxisAlignedBB;
|
2019-11-04 19:08:49 +01:00
|
|
|
import net.minecraft.util.math.BlockPos;
|
2021-12-04 15:40:09 +01:00
|
|
|
import net.minecraft.level.Level;
|
2019-11-04 19:08:49 +01:00
|
|
|
import net.minecraftforge.common.capabilities.ICapabilityProvider;
|
|
|
|
|
|
|
|
import javax.annotation.Nullable;
|
|
|
|
|
2020-01-29 00:40:28 +01:00
|
|
|
public class ItemPickaxe extends PickaxeItem implements IModItem, ICustomItemModel {
|
2019-11-04 19:08:49 +01:00
|
|
|
|
|
|
|
private final String baseName;
|
|
|
|
|
2020-01-26 01:41:49 +01:00
|
|
|
public ItemPickaxe(String baseName, IItemTier material, int damage, float speed) {
|
2019-11-04 19:08:49 +01:00
|
|
|
super(material, damage, speed, new Properties().group(NaturesAura.CREATIVE_TAB));
|
|
|
|
this.baseName = baseName;
|
2020-01-22 01:32:26 +01:00
|
|
|
ModRegistry.add(this);
|
2019-11-04 19:08:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getBaseName() {
|
|
|
|
return this.baseName;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2021-12-04 15:40:09 +01:00
|
|
|
public InteractionResult onItemUse(ItemUseContext context) {
|
2020-01-23 19:20:47 +01:00
|
|
|
if (this == ModItems.INFUSED_IRON_PICKAXE) {
|
2021-12-04 15:40:09 +01:00
|
|
|
Player player = context.getPlayer();
|
|
|
|
Level level = context.getLevel();
|
2019-11-04 19:08:49 +01:00
|
|
|
BlockPos pos = context.getPos();
|
|
|
|
ItemStack stack = player.getHeldItem(context.getHand());
|
2021-12-04 15:40:09 +01:00
|
|
|
BlockState state = level.getBlockState(pos);
|
2019-11-04 19:08:49 +01:00
|
|
|
BlockState result = NaturesAuraAPI.BOTANIST_PICKAXE_CONVERSIONS.get(state);
|
|
|
|
if (result != null) {
|
2021-12-04 15:40:09 +01:00
|
|
|
if (!level.isClientSide) {
|
|
|
|
level.setBlockState(pos, result);
|
2020-01-26 00:43:12 +01:00
|
|
|
|
2021-12-04 15:40:09 +01:00
|
|
|
LevelData data = (LevelData) ILevelData.getLevelData(level);
|
2020-03-14 03:10:56 +01:00
|
|
|
data.addMossStone(pos);
|
2020-01-26 00:43:12 +01:00
|
|
|
}
|
2021-12-04 15:40:09 +01:00
|
|
|
level.playSound(player, pos, SoundEvents.BLOCK_STONE_PLACE, SoundCategory.BLOCKS, 1.0F, 1.0F);
|
|
|
|
stack.damageItem(15, player, Player -> Player.sendBreakAnimation(context.getHand()));
|
|
|
|
return InteractionResult.SUCCESS;
|
2019-11-04 19:08:49 +01:00
|
|
|
}
|
|
|
|
}
|
2021-12-04 15:40:09 +01:00
|
|
|
return InteractionResult.PASS;
|
2019-11-04 19:08:49 +01:00
|
|
|
}
|
|
|
|
|
2020-05-13 17:57:31 +02:00
|
|
|
@Override
|
2021-12-04 15:40:09 +01:00
|
|
|
public void inventoryTick(ItemStack stack, Level levelIn, Entity entityIn, int itemSlot, boolean isSelected) {
|
2020-05-13 17:57:31 +02:00
|
|
|
if (this == ModItems.SKY_PICKAXE) {
|
2021-12-04 15:40:09 +01:00
|
|
|
if (!(entityIn instanceof Player))
|
2020-05-13 17:57:31 +02:00
|
|
|
return;
|
2021-12-04 15:40:09 +01:00
|
|
|
if (!isSelected || levelIn.isClientSide)
|
2020-05-13 17:57:31 +02:00
|
|
|
return;
|
|
|
|
AxisAlignedBB bounds = new AxisAlignedBB(entityIn.getPosition()).grow(3.5F);
|
2021-12-04 15:40:09 +01:00
|
|
|
for (ItemEntity item : levelIn.getEntitiesWithinAABB(ItemEntity.class, bounds)) {
|
2020-05-13 17:57:31 +02:00
|
|
|
// only pick up freshly dropped items
|
2020-07-12 18:56:46 +02:00
|
|
|
if (item.ticksExisted >= 5 || !item.isAlive())
|
2020-05-13 17:57:31 +02:00
|
|
|
continue;
|
|
|
|
item.setPickupDelay(0);
|
2021-12-04 15:40:09 +01:00
|
|
|
item.onCollideWithPlayer((Player) entityIn);
|
2020-05-13 17:57:31 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-04 19:08:49 +01:00
|
|
|
@Nullable
|
|
|
|
@Override
|
2021-12-04 15:40:09 +01:00
|
|
|
public ICapabilityProvider initCapabilities(ItemStack stack, @Nullable CompoundTag nbt) {
|
2020-05-13 15:52:46 +02:00
|
|
|
return Helper.makeRechargeProvider(stack, true);
|
2019-11-04 19:08:49 +01:00
|
|
|
}
|
2020-01-29 00:40:28 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void generateCustomItemModel(ItemModelGenerator generator) {
|
|
|
|
generator.withExistingParent(this.getBaseName(), "item/handheld").texture("layer0", "item/" + this.getBaseName());
|
|
|
|
}
|
|
|
|
|
2019-11-04 19:08:49 +01:00
|
|
|
}
|