This site works best with JavaScript enabled. Please enable JavaScript to get the best experience from this site.
Code doesn't show errors. But my pickaxe won't autosmelt ores.
package com.examplemod.item; import com.idtech.BaseMod; import net.minecraft.block.Block; import net.minecraft.block.BlockOre; import net.minecraft.block.state.IBlockState; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.enchantment.EnchantmentHelper; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.item.EntityXPOrb; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Blocks; import net.minecraft.init.Items; import net.minecraft.item.Item; import net.minecraft.item.ItemHoe; import net.minecraft.item.ItemPickaxe; import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.FurnaceRecipes; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.EnumHand; import net.minecraft.util.EnumParticleTypes; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.RayTraceResult; import net.minecraft.util.math.Vec3d; import net.minecraft.util.text.TextComponentString; import net.minecraft.world.World; import net.minecraftforge.event.entity.player.PlayerInteractEvent; import net.minecraftforge.event.world.BlockEvent; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import java.util.Random; public class ItemFirePickaxe extends ItemPickaxe { public static final String name = "fire_pickaxe"; protected ItemFirePickaxe(){ super(ItemMod.FIRE); //material this.setUnlocalizedName(BaseMod.MODID + "_" + name); this.setCreativeTab(CreativeTabs.TOOLS); } protected PlayerInteractEvent.LeftClickBlock leftClickBlock; protected World world; protected EntityPlayer player; protected void displayMessage(String message) { if (!world.isRemote) { player.sendMessage(new TextComponentString(message)); } } protected BlockPos findBlockAtCursor(float range){ Vec3d posVec = new Vec3d(player.posX, player.posY + player.getEyeHeight(), player.posZ); Vec3d lookVec = player.getLookVec(); // Draw a line from the player to where the player is aiming, save it if // we hit a block. // TODO: 1.12 Change - lookVec uses x, y, z RayTraceResult blockHit = world.rayTraceBlocks(posVec, posVec.addVector(lookVec.x * range, lookVec.y * range, lookVec.z * range)); if (blockHit == null) return null; BlockPos block = blockHit.getBlockPos(); return block; } @SubscribeEvent public void onBlockDestroyed(BlockEvent.HarvestDropsEvent event, PlayerInteractEvent interactEvent, World world) { if(event.getHarvester().getHeldItem(EnumHand.MAIN_HAND)!=null&&event.getHarvester().getHeldItem(EnumHand.MAIN_HAND).getItem() instanceof ItemFirePickaxe){ // final EntityPlayer PLAYER = event.getHarvester(); // if(null == PLAYER || null == PLAYER.getHeldItemMainhand()) return; // { displayMessage("This works yes!!!"); BlockPos pos = leftClickBlock.getPos(); Block block = world.getBlockState(pos).getBlock(); ItemStack stack = FurnaceRecipes.instance().getSmeltingResult(new ItemStack(block));//new ItemStack(event.block,1,event.blockMetadata) if(stack!=null) { ItemStack x=new ItemStack(stack.getItem()); event.getDrops().clear(); event.getDrops().add(x); } } } }
You can't put an event in that class...? You need a seperate class which handles events. You do that by putting the @EventBusSubscriber annotation above the class. Make sure your events are also static.
Code doesn't show errors. But my pickaxe won't autosmelt ores.
You can't put an event in that class...?
You need a seperate class which handles events. You do that by putting the @EventBusSubscriber annotation above the class.
Make sure your events are also static.