Jump to content

How do i use meta data for logs in this case?? [UNSOLVED] [1.7.10]


WiseNoobCrusher

Recommended Posts

I am trying to make it so that my raw latex drops from oak logs but i can't get it to work cause of the meta data...

 

Here is my code:

 

ItemRawLatex class:

 

package com.hardwareplus.mod;

import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraftforge.event.world.BlockEvent;

public class ItemRawLatex extends Item{
 @SubscribeEvent
 public void onDrops(BlockEvent.HarvestDropsEvent event) {

 if (event.block == Blocks.log);
 event.drops.add(new ItemStack(HardwarePlus.itemRawLatex));
 }
}

 

and yes i have MinecraftForge.EVENT_BUS.register(new YourEventHandler()); in my main class in my event handler

 

i have it like this:

 

MinecraftForge.EVENT_BUS.register(new HardwarePlus());

Link to comment
Share on other sites

i mean when anyone has picked up the log once with the raw latex, they cannot just place it back down and get more raw latex!

 

My event handler:

 

package com.hardwareplus.mod;

import net.minecraft.block.Block;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.minecraftforge.event.world.BlockEvent.BreakEvent;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;

public class YourEventHandler {
 @SubscribeEvent
 public void blockBreak(BreakEvent event) {
	 Block block = event.block;
	 World world = event.world;
	 int x = event.x;
	 int y = event.y;
	 int z = event.z;
	 if (block == Blocks.log) {
	 if(event.blockMetadata == 0)
	 {
	 world.spawnEntityInWorld(new EntityItem(world, x, y, z, new ItemStack(HardwarePlus.itemRawLatex)));
	 }
	}
 }
}

Link to comment
Share on other sites

yes i dont want it to drop the log that was used to drop the latex and changed the code which still works

New code:

package com.hardwareplus.mod;

import net.minecraft.block.Block;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.minecraftforge.event.world.BlockEvent.BreakEvent;
import net.minecraftforge.event.world.BlockEvent.HarvestDropsEvent;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;

public class YourEventHandler {
 @SubscribeEvent
 public void onBlockHarvest(HarvestDropsEvent event) {
	 Block block = event.block;
	 World world = event.world;
	 int x = event.x;
	 int y = event.y;
	 int z = event.z;
	 if (block == Blocks.log) {
	 if(event.blockMetadata == 0)
	 {
	 world.spawnEntityInWorld(new EntityItem(world, x, y, z, new ItemStack(HardwarePlus.itemRawLatex)));
	 }
	}
 }
}

 

Link to comment
Share on other sites

Alternatively, if you are not comfortable with iterators / you just want one thing to drop, an easier solution is to clear the drops list completely and then add your stack to it.

event.drops.clear();
event.drops.add(new ItemStack(yourItem));

Done.

 

However, if you don't know how to use iterators, you could use this as an excuse to learn about them, because they are very useful.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.