Jump to content

Checking for Vanilla tool right click.


Minothor

Recommended Posts

Sorry, me again, is there any way of listening for right mouse button clicks on vanilla tools (specifically axes) that doesn't involve access modifiers or listening to every single right click then checking the tool in hand?

I suppose, what I'm asking really, is this: Is there any way to have a function that only listens for rightclicks when a specific tool type is in hand at that moment?

 

(background fluff: I'm hoping to make it possible to right click oak logs with any axe to strip the bark (cork) off. I don't want to add in another type of axe just for stripping bark)

 

Cheers in advance.

-Nick B (Minothor)

Link to comment
Share on other sites

  • 2 weeks later...

Ok, I've decided that the easiest way to support all axes and those from other mods would probably be to register them with the oreDict under "toolAxe".

That said, I'm really struggling with the event handling, I've look up what documentation I can from the Wiki's reference, searching the forums and AtomicStryker's post here: http://www.minecraftforum.net/topic/1419836- )

 

Currently the only thing that Eclipse is being a bit iffy about is the @ForgeSubscribe annotation before the function.

Can anyone shed any light on how and where I'm mucking up here please?

Thanks in Advance,

-Mino

 

Event Handling class:

package minothor.bab.events.EventHandlers;

import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.*;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import net.minecraftforge.event.entity.player.PlayerInteractEvent.Action;
import net.minecraftforge.oredict.OreDictionary;

public class CentEventHandler {

public CentEventHandler(){
	MinecraftForge.EVENT_BUS.register(this);
}


@ForgeSubscribe
public void playerInteract(PlayerInteractEvent event) {
	Action eventAction = event.action;
	World currentWorld = event.entityPlayer.worldObj;
	Block blockAffected = currentWorld.getBlock(event.x, event.y, event.z);
	ItemStack currentTool = event.entityPlayer.getCurrentEquippedItem();
	if(eventAction.RIGHT_CLICK_BLOCK != null){
		System.out.println("Yes, You're Richtclicking");
		if(currentWorld.getBlock(event.x, event.y, event.z) == Blocks.log){
			System.out.println("a Log");
		}
		if (OreDictionary.getOreName(OreDictionary.getOreID(currentTool)).equals("toolAxe")){
			System.out.println("with an Axe!");
		}
	}
}

}

 

Main Class:

package minothor.bab;

import java.util.logging.Logger;

import net.minecraft.block.Block;
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.common.MinecraftForge;
import net.minecraftforge.common.config.Configuration;
import net.minecraftforge.oredict.OreDictionary;
import net.minecraftforge.oredict.ShapedOreRecipe;
import net.minecraftforge.event.ForgeEventFactory;
import minothor.bab.proxy.*;
import minothor.bab.items.*;
import minothor.bab.blocks.*;
import minothor.bab.events.EventHandlers.*;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.Mod.Instance;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.common.registry.LanguageRegistry;


@Mod(modid="BigAssBarrels", name="Big Ass Barrels", version="1.7.2 - Alpha 0.0.1")

public class bab {
public static final String modid = "BigAssBarrels";
public static final String name = "Bigass Barrels";
public static final String version = "1.7.2 - Alpha 0.0.1";

@Instance(value = "BigAssBarrels")
public static bab instance;
@SidedProxy(clientSide="minothor.bab.proxy.clientProxy", serverSide="minothor.bab.proxy.commonProxy")
public static commonProxy proxy;


//Declare Tab
//Set Creative Tab Icon
public static CreativeTabs tabBAB;
//public static CreativeTabs tabBAB;

//Declare Items
public static Item itemBark;
public static Item itemCork;

//Declare Blocks
public static Block blockCork;
public static Block blockStrippedOak;

//Declare Tools
public static Item itemMallet;

//Declare Event Handler used
public static CentEventHandler CentralHandler;

//public static logger;
@EventHandler
public void preInit(FMLPreInitializationEvent event) {

	Configuration config = new Configuration(event.getSuggestedConfigurationFile());
	config.load();
	//config stuff here
	config.save();

	tabBAB = new CreativeTabs("tabBAB"){
		public Item getTabIconItem() {
			return itemCork;
		}
	};

	itemBark = new Item().setUnlocalizedName("StrippedBark").setCreativeTab(tabBAB).setTextureName(modid + ":" + "StrippedBark");
	GameRegistry.registerItem(itemBark, "StrippedBark");

	itemCork= new Item().setUnlocalizedName("BottleCork").setCreativeTab(tabBAB).setTextureName(modid + ":" + "BottleCork");
	GameRegistry.registerItem(itemCork, "BottleCork");

	itemMallet = new itemMallet().setCreativeTab(tabBAB).setTextureName(modid + ":" + "WoodenMallet");
	GameRegistry.registerItem(itemMallet, "WoodenMallet");

	blockCork = new blockCork().setCreativeTab(tabBAB).setBlockTextureName(modid + ":" + "BlockCork");
	GameRegistry.registerBlock(blockCork, "BlockCork");

	blockStrippedOak = new blockStrippedOak().setCreativeTab(tabBAB);
	GameRegistry.registerBlock(blockStrippedOak, "BlockStrippedOak");

	GameRegistry.addRecipe(new ItemStack(Item.getItemFromBlock(blockCork)), "XXX", "XYX", "XXX", 'X', new ItemStack(itemBark), 'Y', new ItemStack(itemCork));

	GameRegistry.addRecipe(new ShapedOreRecipe( new ItemStack(itemMallet), "-X", "Y-",  'X', "logWood", 'Y', new ItemStack(Items.stick)));

	OreDictionary.registerOre("logWood", blockStrippedOak);

	GameRegistry.addRecipe(new ItemStack(Blocks.planks,4),  "X", 'X', new ItemStack(Item.getItemFromBlock(blockStrippedOak)));

	GameRegistry.addRecipe(new ItemStack(itemCork), "X", "X", 'X', new ItemStack(itemBark));

	//Creating toolAxe Oredictionary Section
	OreDictionary.registerOre("toolAxe", Items.wooden_axe);
	OreDictionary.registerOre("toolAxe", Items.stone_axe);
	OreDictionary.registerOre("toolAxe", Items.iron_axe);
	OreDictionary.registerOre("toolAxe", Items.golden_axe);
	OreDictionary.registerOre("toolAxe", Items.diamond_axe);
	//System.out.println(OreDictionary.getOres("toolAxe"));

	//Registering Events Handlers
	CentralHandler = new CentEventHandler();

}
@EventHandler
public void load(FMLInitializationEvent event) {

	proxy.registerRenderers();

}
@EventHandler
public void postInit(FMLPostInitializationEvent event) {
	// Stub Method
}


}

Link to comment
Share on other sites

Ok, I've decided that the easiest way to support all axes and those from other mods would probably be to register them with the oreDict under "toolAxe".

 

Not at all. Why would any other mod register one of their axes in an "ore" dictionary? Answer: they won't. Use the instanceof ItemAxe or at least instanceof ItemTool (Here you would check the name for having 'axe' or 'hatchet' in it but not pickaxe) Any coder with any brains is likely not going to make an axe in some other class.

 

The OreDictionary should be reserved for crafting.

 

You should register crafting recipes in Init eventhandler not preinit.

 

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • hola thanks for answering  i set some system outs to see what was happening and is a little weirder than i thought     @Override     protected void saveAdditional( CompoundTag nbt ){                  nbt.put("itemhandler", itemhandler.serializeNBT() );         nbt.putInt("progress", this.progress );         System.out.println("saveAdditional(nbt)");                 System.out.println(NbtUtils.prettyPrint(nbt)); //<-- this is whats getting saved         super.saveAdditional( nbt );     }     @Override     public void load( CompoundTag nbt ){         itemhandler.deserializeNBT( nbt.getCompound("itemhandler") );         this.progress = nbt.getInt("progress" );         System.out.println(NbtUtils.prettyPrint(nbt)); //<-- this is whats minecraft is giving back to the entity          System.out.println("load(nbt)");         super.load( nbt );     }   this dead adventurer body has two parts a block and the blockItem  both has their own itemhandlers and their own menus  *when i change some element inside the menu gui  it triguers the saveAdditional(nbt) system out whit a pretty print of the data beign saved  *when the world map loads it triguers the load(nbt) system out whit a pretty print of the data minecraft is gibing to this BlockEntity       ################ first i set the block entity (dead adventurer body like shaped) and put only a weath seed  in the slot 10 and i get this in the console soo its all right    close minecraft launch it again i see the system out whit the data returned to the entity and its look good theres is only a weed seed  ################ Second, now i gonna change the seed for two arrows  the console says its all right the two arrows are beign saved    now close and fireback again minecraft bam minecraft returns again the original data whit only a wheat seed the arrow data has been loss   try again now i gonna put 3 wheat seeds minecraft's system out says he gets it and save it    close fire again  data loss once more time  and it return just the original wheat seed    ####################################################################################### sorry for the long post and the crappy video  this is the reason why i say its saving the Block Entity data only when it feels like             
    • Yesterday I buy a minecraft server to play with my friends you know... One of my friends send me the list of mods to add and then i start to dowload them, when i add them to the server it start crashing but i don't know about this things because it's my first time buying a minecraft server This is the error: https://paste.ee/p/sJf7B
    • Discovering that a trusted colleague had accessed my Bitcoin account and transferred $30,000 worth of bitcoins was a devastating blow. It shattered the trust I had placed in them and left me feeling vulnerable and betrayed. However, in the face of adversity, I turned to MUYERN TRUST HACKER for assistance in reclaiming control over my finances and holding the perpetrators accountable for their actions. One of the standout features of MUYERN TRUST HACKER was its ability to provide real-time alerts and notifications, keeping me informed every step of the way. With the support of MUYERN TRUST HACKER, I was able to gather irrefutable evidence of the perpetrator's actions and hold them accountable for their crimes. Armed with the information provided by the platform, I pursued legal recourse and ensured that justice was served. The perpetrator faced severe consequences for their actions, including legal penalties and financial restitution. Beyond its role in facilitating the recovery process, MUYERN TRUST HACKER provided me with a sense of empowerment and resilience in the face of adversity. While the experience was undoubtedly challenging, it ultimately served as a testament to the importance of vigilance and the power of technology in safeguarding our digital assets. Thanks to MUYERN TRUST HACKER, I emerged stronger and more resilient, ready to face whatever challenges the future may hold. Mail; muyerntrusted[At] mail-me .c o m
    • Discovering that a trusted colleague had accessed my Bitcoin account and transferred $30,000 worth of bitcoins was a devastating blow. It shattered the trust I had placed in them and left me feeling vulnerable and betrayed. However, in the face of adversity, I turned to MUYERN TRUST HACKER web [ ht tps:// muyerntrusthack.solutions/ ] for assistance in reclaiming control over my finances and holding the perpetrators accountable for their actions. One of the standout features of MUYERN TRUST HACKER was its ability to provide real-time alerts and notifications, keeping me informed every step of the way. With the support of MUYERN TRUST HACKER, I was able to gather irrefutable evidence of the perpetrator's actions and hold them accountable for their crimes. Armed with the information provided by the platform, I pursued legal recourse and ensured that justice was served. The perpetrator faced severe consequences for their actions, including legal penalties and financial restitution. Beyond its role in facilitating the recovery process, MUYERN TRUST HACKER provided me with a sense of empowerment and resilience in the face of adversity. While the experience was undoubtedly challenging, it ultimately served as a testament to the importance of vigilance and the power of technology in safeguarding our digital assets. Thanks to MUYERN TRUST HACKER, I emerged stronger and more resilient, ready to face whatever challenges the future may hold. Mail; muyerntrusted[At] mail-me .c o m  
    • Do you have still this problem? (I have it too so I want to know if you did something with it)  
  • Topics

×
×
  • Create New...

Important Information

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