ActuallyAdditions/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemAllToolAA.java

137 lines
5.8 KiB
Java
Raw Normal View History

2015-08-29 14:33:25 +02:00
/*
2016-05-16 22:52:27 +02:00
* This file ("ItemAllToolAA.java") is part of the Actually Additions mod for Minecraft.
2015-08-29 14:33:25 +02:00
* It is created and owned by Ellpeck and distributed
* under the Actually Additions License to be found at
2016-05-16 22:52:27 +02:00
* http://ellpeck.de/actaddlicense
2015-08-29 14:33:25 +02:00
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
*
2017-01-01 16:23:26 +01:00
* © 2015-2017 Ellpeck
2015-08-29 14:33:25 +02:00
*/
2016-03-19 11:36:17 +01:00
package de.ellpeck.actuallyadditions.mod.items;
2019-05-02 09:08:15 +02:00
import com.google.common.collect.Sets;
2016-01-08 20:51:03 +01:00
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
import de.ellpeck.actuallyadditions.mod.config.values.ConfigStringListValues;
2016-03-19 11:36:17 +01:00
import de.ellpeck.actuallyadditions.mod.items.base.ItemToolAA;
2016-03-19 15:10:20 +01:00
import de.ellpeck.actuallyadditions.mod.util.IColorProvidingItem;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
2021-02-26 22:15:48 +01:00
import net.minecraft.block.state.BlockState;
2016-03-19 11:36:17 +01:00
import net.minecraft.client.renderer.color.IItemColor;
2018-01-04 20:27:16 +01:00
import net.minecraft.enchantment.Enchantment;
2021-02-26 22:15:48 +01:00
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.init.Blocks;
2016-03-18 18:38:39 +01:00
import net.minecraft.init.Items;
2015-07-07 14:32:10 +02:00
import net.minecraft.item.ItemStack;
2016-03-18 23:47:22 +01:00
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumFacing;
2021-02-26 22:15:48 +01:00
import net.minecraft.util.Hand;
2016-01-08 20:51:03 +01:00
import net.minecraft.util.ResourceLocation;
2016-03-18 23:47:22 +01:00
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
2019-05-02 09:08:15 +02:00
import net.minecraftforge.common.IRarity;
2016-03-19 15:10:20 +01:00
import net.minecraftforge.fml.relauncher.Side;
2021-02-26 22:15:48 +01:00
import net.minecraftforge.fml.relauncher.OnlyIn;
import java.util.HashSet;
import java.util.Set;
2019-05-02 09:08:15 +02:00
public class ItemAllToolAA extends ItemToolAA implements IColorProvidingItem {
2016-03-19 15:10:20 +01:00
public final int color;
2015-10-25 23:19:01 +01:00
2019-05-02 09:08:15 +02:00
public ItemAllToolAA(ToolMaterial toolMat, String repairItem, String unlocalizedName, IRarity rarity, int color) {
2018-01-04 20:27:16 +01:00
super(4.0F, -2F, toolMat, repairItem, unlocalizedName, rarity, new HashSet<>());
2016-03-19 11:36:17 +01:00
this.color = color;
2019-05-02 09:08:15 +02:00
this.setMaxDamage(toolMat.getMaxUses() * 4);
2017-04-05 05:13:50 +02:00
this.setHarvestLevels(toolMat.getHarvestLevel());
2016-02-01 17:49:55 +01:00
}
2019-05-02 09:08:15 +02:00
public ItemAllToolAA(ToolMaterial toolMat, ItemStack repairItem, String unlocalizedName, IRarity rarity, int color) {
2018-01-04 20:27:16 +01:00
super(4.0F, -2F, toolMat, repairItem, unlocalizedName, rarity, new HashSet<>());
2015-10-25 23:19:01 +01:00
this.color = color;
2019-05-02 09:08:15 +02:00
this.setMaxDamage(toolMat.getMaxUses() * 4);
2017-04-05 05:13:50 +02:00
this.setHarvestLevels(toolMat.getHarvestLevel());
}
2019-05-02 09:08:15 +02:00
private void setHarvestLevels(int amount) {
for (String s : this.getToolClasses(null)) {
2017-04-05 05:13:50 +02:00
this.setHarvestLevel(s, amount);
}
2015-12-19 10:30:39 +01:00
}
2016-05-02 17:09:23 +02:00
@Override
2019-05-02 09:08:15 +02:00
protected void registerRendering() {
2018-05-10 11:38:58 +02:00
ActuallyAdditions.PROXY.addRenderRegister(new ItemStack(this), new ResourceLocation(ActuallyAdditions.MODID, "item_paxel"), "inventory");
2016-02-01 17:49:55 +01:00
}
@Override
2021-02-26 22:15:48 +01:00
public EnumActionResult onItemUse(PlayerEntity playerIn, World worldIn, BlockPos pos, Hand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
if (!playerIn.isSneaking()) {
return Items.IRON_HOE.onItemUse(playerIn, worldIn, pos, hand, side, hitX, hitY, hitZ);
}
2018-01-04 20:27:16 +01:00
return Items.IRON_SHOVEL.onItemUse(playerIn, worldIn, pos, hand, side, hitX, hitY, hitZ);
}
@Override
2021-02-26 22:15:48 +01:00
public boolean canHarvestBlock(BlockState state, ItemStack stack) {
return this.hasExtraWhitelist(state.getBlock()) || state.getMaterial().isToolNotRequired() || state.getBlock() == Blocks.SNOW_LAYER || state.getBlock() == Blocks.SNOW || (state.getBlock() == Blocks.OBSIDIAN
? this.toolMaterial.getHarvestLevel() >= 3
: state.getBlock() != Blocks.DIAMOND_BLOCK && state.getBlock() != Blocks.DIAMOND_ORE
? state.getBlock() != Blocks.EMERALD_ORE && state.getBlock() != Blocks.EMERALD_BLOCK
? state.getBlock() != Blocks.GOLD_BLOCK && state.getBlock() != Blocks.GOLD_ORE
? state.getBlock() != Blocks.IRON_BLOCK && state.getBlock() != Blocks.IRON_ORE
? state.getBlock() != Blocks.LAPIS_BLOCK && state.getBlock() != Blocks.LAPIS_ORE
? state.getBlock() != Blocks.REDSTONE_ORE && state.getBlock() != Blocks.LIT_REDSTONE_ORE
? state.getMaterial() == Material.ROCK || state.getMaterial() == Material.IRON || state.getMaterial() == Material.ANVIL
: this.toolMaterial.getHarvestLevel() >= 2
: this.toolMaterial.getHarvestLevel() >= 1
: this.toolMaterial.getHarvestLevel() >= 1
: this.toolMaterial.getHarvestLevel() >= 2
: this.toolMaterial.getHarvestLevel() >= 2
: this.toolMaterial.getHarvestLevel() >= 2);
}
2019-05-02 09:08:15 +02:00
private boolean hasExtraWhitelist(Block block) {
2016-04-20 21:39:03 +02:00
String name = block.getRegistryName().toString();
2019-05-02 09:08:15 +02:00
for (String list : ConfigStringListValues.PAXEL_EXTRA_MINING_WHITELIST.getValue()) {
2021-02-26 22:15:48 +01:00
if (list.equals(name)) {
return true;
}
2019-02-27 19:53:05 +01:00
}
2015-10-03 22:13:57 +02:00
return false;
}
2015-06-21 02:28:49 +02:00
@Override
2019-05-02 09:08:15 +02:00
public Set<String> getToolClasses(ItemStack stack) {
2018-01-04 20:27:16 +01:00
return Sets.newHashSet("pickaxe", "axe", "shovel");
2015-06-21 02:28:49 +02:00
}
2015-10-03 10:19:40 +02:00
@Override
2021-02-26 22:15:48 +01:00
public float getDestroySpeed(ItemStack stack, BlockState state) {
2019-05-02 09:08:15 +02:00
if (state.getBlock() == Blocks.WEB) {
return 15.0F;
2019-05-02 09:08:15 +02:00
} else {
2021-02-26 22:15:48 +01:00
return this.hasExtraWhitelist(state.getBlock()) || state.getBlock().getHarvestTool(state) == null || state.getBlock().getHarvestTool(state).isEmpty() || this.getToolClasses(stack).contains(state.getBlock().getHarvestTool(state))
? this.efficiency
: 1.0F;
}
2015-10-03 10:19:40 +02:00
}
2016-03-19 11:36:17 +01:00
2021-02-26 22:15:48 +01:00
@OnlyIn(Dist.CLIENT)
2016-03-19 11:36:17 +01:00
@Override
2019-05-02 09:08:15 +02:00
public IItemColor getItemColor() {
2021-02-26 22:15:48 +01:00
return (stack, pass) -> pass > 0
? ItemAllToolAA.this.color
: 0xFFFFFF;
2019-02-27 19:53:05 +01:00
}
@Override
public boolean canApplyAtEnchantingTable(ItemStack stack, Enchantment enchantment) {
return super.canApplyAtEnchantingTable(stack, enchantment) || enchantment.type.canEnchantItem(Items.DIAMOND_SWORD);
2016-03-19 11:36:17 +01:00
}
2021-02-26 22:15:48 +01:00
}