some more botanist tools special features

This commit is contained in:
Ellpeck 2018-10-20 22:40:14 +02:00
parent d30734fe38
commit e83777fe14
2 changed files with 63 additions and 15 deletions

View file

@ -1,21 +1,40 @@
package de.ellpeck.naturesaura.items.tools;
import com.google.common.collect.ImmutableMap;
import de.ellpeck.naturesaura.Helper;
import de.ellpeck.naturesaura.items.ModItems;
import de.ellpeck.naturesaura.reg.IModItem;
import de.ellpeck.naturesaura.reg.IModelProvider;
import de.ellpeck.naturesaura.reg.ModRegistry;
import net.minecraft.block.BlockStoneBrick;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.init.SoundEvents;
import net.minecraft.item.ItemPickaxe;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.common.capabilities.ICapabilityProvider;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import javax.annotation.Nullable;
import java.util.Map;
public class ItemPickaxeNA extends ItemPickaxe implements IModItem, IModelProvider {
private static final Map<IBlockState, IBlockState> BOTANIST_CONVERSION = ImmutableMap.<IBlockState, IBlockState>builder()
.put(Blocks.COBBLESTONE.getDefaultState(), Blocks.MOSSY_COBBLESTONE.getDefaultState())
.put(Blocks.STONEBRICK.getDefaultState().withProperty(BlockStoneBrick.VARIANT, BlockStoneBrick.EnumType.DEFAULT),
Blocks.STONEBRICK.getDefaultState().withProperty(BlockStoneBrick.VARIANT, BlockStoneBrick.EnumType.MOSSY)).build();
private final String baseName;
public ItemPickaxeNA(String baseName, ToolMaterial material) {
@ -48,6 +67,23 @@ public class ItemPickaxeNA extends ItemPickaxe implements IModItem, IModelProvid
public void onPostInit(FMLPostInitializationEvent event) {
}
@Override
public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
if (this == ModItems.INFUSED_PICKAXE) {
ItemStack stack = player.getHeldItem(hand);
IBlockState state = worldIn.getBlockState(pos);
IBlockState result = BOTANIST_CONVERSION.get(state);
if (result != null) {
if (!worldIn.isRemote)
worldIn.setBlockState(pos, result);
worldIn.playSound(player, pos, SoundEvents.BLOCK_STONE_PLACE, SoundCategory.BLOCKS, 1.0F, 1.0F);
stack.damageItem(3, player);
return EnumActionResult.SUCCESS;
}
}
return EnumActionResult.PASS;
}
@Nullable
@Override
public ICapabilityProvider initCapabilities(ItemStack stack, @Nullable NBTTagCompound nbt) {

View file

@ -5,7 +5,9 @@ import de.ellpeck.naturesaura.items.ModItems;
import de.ellpeck.naturesaura.reg.IModItem;
import de.ellpeck.naturesaura.reg.IModelProvider;
import de.ellpeck.naturesaura.reg.ModRegistry;
import net.minecraft.block.BlockDirt;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.init.SoundEvents;
@ -36,32 +38,42 @@ public class ItemShovelNA extends ItemSpade implements IModItem, IModelProvider
@Override
public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
EnumActionResult result = EnumActionResult.PASS;
if (this == ModItems.INFUSED_SHOVEL) {
ItemStack stack = player.getHeldItem(hand);
int range = player.isSneaking() ? 0 : 1;
for (int x = -range; x <= range; x++) {
for (int y = -range; y <= range; y++) {
BlockPos actualPos = pos.add(x, 0, y);
if (player.canPlayerEdit(actualPos.offset(facing), facing, stack)) {
if (facing != EnumFacing.DOWN
&& worldIn.getBlockState(actualPos.up()).getMaterial() == Material.AIR
&& worldIn.getBlockState(actualPos).getBlock() == Blocks.GRASS) {
if (!worldIn.isRemote) {
worldIn.setBlockState(actualPos, Blocks.GRASS_PATH.getDefaultState(), 11);
IBlockState state = worldIn.getBlockState(pos);
int damage = 0;
if (state.getBlock() instanceof BlockDirt) {
if (worldIn.getBlockState(pos.up()).getMaterial() == Material.AIR) {
worldIn.setBlockState(pos, Blocks.GRASS.getDefaultState());
damage = 5;
}
} else {
int range = player.isSneaking() ? 0 : 1;
for (int x = -range; x <= range; x++) {
for (int y = -range; y <= range; y++) {
BlockPos actualPos = pos.add(x, 0, y);
if (player.canPlayerEdit(actualPos.offset(facing), facing, stack)) {
if (facing != EnumFacing.DOWN
&& worldIn.getBlockState(actualPos.up()).getMaterial() == Material.AIR
&& worldIn.getBlockState(actualPos).getBlock() == Blocks.GRASS) {
if (!worldIn.isRemote) {
worldIn.setBlockState(actualPos, Blocks.GRASS_PATH.getDefaultState(), 11);
}
damage = 1;
}
result = EnumActionResult.SUCCESS;
}
}
}
}
if (result == EnumActionResult.SUCCESS) {
if (damage > 0) {
worldIn.playSound(player, pos, SoundEvents.ITEM_SHOVEL_FLATTEN, SoundCategory.BLOCKS, 1.0F, 1.0F);
stack.damageItem(1, player);
stack.damageItem(damage, player);
return EnumActionResult.SUCCESS;
}
}
return result;
return EnumActionResult.PASS;
}
@Override