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;
|
2023-02-17 14:21:39 +01:00
|
|
|
import net.minecraft.core.BlockPos;
|
2021-12-04 15:40:09 +01:00
|
|
|
import net.minecraft.nbt.CompoundTag;
|
2021-12-04 19:17:21 +01:00
|
|
|
import net.minecraft.sounds.SoundEvents;
|
|
|
|
import net.minecraft.sounds.SoundSource;
|
2023-02-21 11:43:10 +01:00
|
|
|
import net.minecraft.world.InteractionHand;
|
2021-12-04 19:17:21 +01:00
|
|
|
import net.minecraft.world.InteractionResult;
|
2023-02-21 11:43:10 +01:00
|
|
|
import net.minecraft.world.InteractionResultHolder;
|
2021-12-04 19:17:21 +01:00
|
|
|
import net.minecraft.world.entity.Entity;
|
|
|
|
import net.minecraft.world.entity.item.ItemEntity;
|
|
|
|
import net.minecraft.world.entity.player.Player;
|
|
|
|
import net.minecraft.world.item.ItemStack;
|
|
|
|
import net.minecraft.world.item.PickaxeItem;
|
|
|
|
import net.minecraft.world.item.Tier;
|
|
|
|
import net.minecraft.world.item.context.UseOnContext;
|
|
|
|
import net.minecraft.world.level.Level;
|
|
|
|
import net.minecraft.world.phys.AABB;
|
2023-02-17 14:21:39 +01:00
|
|
|
import net.minecraftforge.common.Tags;
|
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;
|
|
|
|
|
2021-12-04 19:17:21 +01:00
|
|
|
public ItemPickaxe(String baseName, Tier material, int damage, float speed) {
|
2023-07-08 12:32:27 +02:00
|
|
|
super(material, damage, speed, new Properties());
|
2019-11-04 19:08:49 +01:00
|
|
|
this.baseName = baseName;
|
2022-06-27 15:24:04 +02:00
|
|
|
ModRegistry.ALL_ITEMS.add(this);
|
2019-11-04 19:08:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getBaseName() {
|
|
|
|
return this.baseName;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2021-12-04 19:17:21 +01:00
|
|
|
public InteractionResult useOn(UseOnContext context) {
|
2020-01-23 19:20:47 +01:00
|
|
|
if (this == ModItems.INFUSED_IRON_PICKAXE) {
|
2021-12-15 16:30:22 +01:00
|
|
|
var player = context.getPlayer();
|
|
|
|
var level = context.getLevel();
|
|
|
|
var pos = context.getClickedPos();
|
|
|
|
var stack = player.getItemInHand(context.getHand());
|
|
|
|
var state = level.getBlockState(pos);
|
|
|
|
var result = NaturesAuraAPI.BOTANIST_PICKAXE_CONVERSIONS.get(state);
|
2019-11-04 19:08:49 +01:00
|
|
|
if (result != null) {
|
2021-12-04 15:40:09 +01:00
|
|
|
if (!level.isClientSide) {
|
2021-12-04 19:17:21 +01:00
|
|
|
level.setBlockAndUpdate(pos, result);
|
2020-01-26 00:43:12 +01:00
|
|
|
|
2021-12-15 16:30:22 +01:00
|
|
|
var 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 19:17:21 +01:00
|
|
|
level.playSound(player, pos, SoundEvents.STONE_PLACE, SoundSource.BLOCKS, 1.0F, 1.0F);
|
|
|
|
stack.hurtAndBreak(15, player, p -> p.broadcastBreakEvent(context.getHand()));
|
2021-12-04 15:40:09 +01:00
|
|
|
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;
|
2023-02-17 11:12:50 +01:00
|
|
|
var bounds = new AABB(entityIn.blockPosition()).inflate(4);
|
2021-12-15 16:30:22 +01:00
|
|
|
for (var item : levelIn.getEntitiesOfClass(ItemEntity.class, bounds)) {
|
2020-05-13 17:57:31 +02:00
|
|
|
// only pick up freshly dropped items
|
2021-12-04 19:17:21 +01:00
|
|
|
if (item.tickCount >= 5 || !item.isAlive())
|
2020-05-13 17:57:31 +02:00
|
|
|
continue;
|
2021-12-04 19:17:21 +01:00
|
|
|
item.setPickUpDelay(0);
|
|
|
|
item.playerTouch((Player) entityIn);
|
2020-05-13 17:57:31 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-17 14:21:39 +01:00
|
|
|
@Override
|
|
|
|
public boolean onBlockStartBreak(ItemStack itemstack, BlockPos pos, Player player) {
|
2023-07-08 12:32:27 +02:00
|
|
|
if (itemstack.getItem() == ModItems.DEPTH_PICKAXE && Helper.isToolEnabled(itemstack) && player.level().getBlockState(pos).is(Tags.Blocks.ORES)) {
|
|
|
|
Helper.mineRecursively(player.level(), pos, pos, true, 5, 5, s -> s.is(Tags.Blocks.ORES));
|
2023-02-17 14:21:39 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-02-21 11:43:10 +01:00
|
|
|
@Override
|
|
|
|
public InteractionResultHolder<ItemStack> use(Level level, Player player, InteractionHand hand) {
|
|
|
|
var stack = player.getItemInHand(hand);
|
|
|
|
if (stack.getItem() == ModItems.DEPTH_PICKAXE && Helper.toggleToolEnabled(player, stack))
|
|
|
|
return InteractionResultHolder.success(stack);
|
|
|
|
return super.use(level, player, hand);
|
|
|
|
}
|
|
|
|
|
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) {
|
2023-02-21 11:43:10 +01:00
|
|
|
if (this == ModItems.DEPTH_PICKAXE)
|
|
|
|
return;
|
2020-01-29 00:40:28 +01:00
|
|
|
generator.withExistingParent(this.getBaseName(), "item/handheld").texture("layer0", "item/" + this.getBaseName());
|
|
|
|
}
|
|
|
|
|
2019-11-04 19:08:49 +01:00
|
|
|
}
|