Jump to content

Recommended Posts

Posted

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)

  • 2 weeks later...
Posted

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
}


}

Posted
  On 3/24/2014 at 12:02 PM, Minothor said:

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.

 

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

    • Make a test with another Launcher like the Curseforge Launcher, MultiMC or AT Launcher
    • can anyone help me i am opening forge and add modpacks and then it says unable to update native luancher and i redownlaod java and the luancher it self?
    • The problem occurs also in 1.20.1 Forge, but with an "Error executing task on client" instead. I have "Sinytra Connector" installed. On 1.21.5 Fabric, there is no problem. When this happens, the chat message before the death screen appears gets sent, with an extra dash added.
    • Well, as usual, it was user error. Naming mismatch in sounds.json.  Please delete this post if you find it necessary. 
    • Hello Forge community.  I'm running into an issue with a mod I'm working on.  To preface, I can call /playsound modId:name music @a and I can hear the sound I registered being played in game. Great!  However, I cannot get it to trigger via my mod code.    Registration: public static final RegistryObject<SoundEvent> A_WORLD_OF_MADNESS = SOUND_EVENTS.register("a_world_of_madness", () -> new SoundEvent(new ResourceLocation("tetheredsouls", "a_world_of_madness")));   Playback: Minecraft mc = Minecraft.getInstance(); if (!(mc.player instanceof LocalPlayer) || mc.level == null) return; LocalPlayer player = (LocalPlayer) mc.player; BlockPos pos = player.blockPosition(); SoundEvent track = ModSounds.A_WORLD_OF_MADNESS.get(); System.out.println(track); System.out.println(pos); System.out.println(player); // play exactly like the tutorial: client-only, at the player's position try { mc.level.playLocalSound( player.getX(), player.getY(), player.getZ(), track, SoundSource.MUSIC, // Or MASTER if needed 1f, 1f, false ); System.out.println("[DEBUG] playSound success: " + track.getLocation()); } catch (Exception e) { System.err.println("[ERROR] Failed to play sound: " + track.getLocation()); e.printStackTrace(); } Sounds.json:   { "theme_of_laura": { "category": "music", "sounds": [ { "name": "tetheredsouls:a_world_of_madness", "stream": true } ] } } Things I have tried: - multiple .ogg files. Short .ogg files (5 seconds, <100KB).  - default minecraft sounds imported from import net.minecraft.sounds.SoundEvents; These work given my code. No idea why these are different.  - playSound() method, as well as several others in past iterations that did not work   I would be forever grateful if somebody could point me in the right direction. I've looked at several mod github repositories and found extremely similar code to what I'm doing. I've also found several threads in this forum that did not solve my issue. I just cannot figure out what I'm doing differently, and why I'm able to queue sounds manually with playsound but the code won't play it (despite confirming the code is being run with the debug statements.)
  • Topics

×
×
  • Create New...

Important Information

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