Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

I have a class that extends ItemSword. It's supposed to be a 'war-hammer' styled weapon, so I want there to be a longer delay (slower swing and more time in between swings). The visual effect can be easily achieved by applying the mining fatigue effect to the player, and it works perfectly (though, if there was a more elegant way of doing it without the potion effect 'swirls' that would be great), however I haven't managed to find a field I can control to increase the delay between actual hits (if I use the potion effect, the hammer moves slowly, but you can rapidly click it like a sword).

 

Is there a field I can simply change, or am I going to have to hardcode this in somehow?

 

 

As a side question, since I don't think it requires an enitre thread for itself - What EventBus is it standard to post custom events to - the one where the event you're extending is posted (e.g. extending ItemPickupEvent, posting on FMLCommonHandler#bus()) or posting on an event bus created by you 'dedicated' to your own mod?

BEFORE ASKING FOR HELP READ THE EAQ!

 

I'll help if I can. Apologies if I do something obviously stupid. :D

 

If you don't know basic Java yet, go and follow these tutorials.

There is no built-in way to achieve attack delay, at least that I have found. What I did is hijack vanilla's EntityLivingBase#attackTime field, since it is not used at all for players, and, using MouseEvent, whenever the player left-clicks with your weapon, you set this timer or, if the timer is already greater than zero, cancel the event, thus preventing any attack from processing. The timer is automatically decremented for you during the player's update tick, so you don't have to worry about managing it.

 

As for getting the hammer to swing slowly without the potion effect... The only way I can think of would be to cancel the normal player rendering from RenderPlayerEvent (only while swinging your hammer, of course) and do the rendering yourself based on current swing time. RenderHandEvent may actually be enough; if so, it is the better option.

 

For custom events, I would post to the same one that the parent event does.

  • Author

Well, that works almost perfectly. This is the code that I'm using:

 

@SubscribeEvent
public void onMouseClicked(MouseEvent event)
{
boolean flag = false;

int bind = Minecraft.getMinecraft().gameSettings.keyBindAttack.getKeyCode();

/*
 * Flag is true if the button is also the same as the keyBinding for attacking.
 */
flag = ((bind == -100) ? (event.button == 0) : ((bind == -99) ? (event.button == 1) : ((bind == -98) ? (event.button == 2) : false)));

if(flag && event.buttonstate)
{
	if(Minecraft.getMinecraft().thePlayer != null)
	{
		EntityPlayer player = Minecraft.getMinecraft().thePlayer;
		if(player.getCurrentEquippedItem() != null && player.getCurrentEquippedItem().getItem() instanceof ItemWarHammer)
		{
			if(player.attackTime != 0)
			{
				event.setCanceled(true);
			}
			else
			{
				player.attackTime = 20;
			}
		}
	}
}
}

 

As you can see, it'll work perfectly, unless the keybinding for attack is a key, rather than a mouse click. Now I thought I could use the KeyInputEvent, however that Event isn't cancelable, and from reading documentation on it, it seems that it occurs AFTER vanilla mechanics. Is there any elegant way to do this? I might be able to do something like that from the ClientTick event and constantly checking if the Minecraft#gameSettings.keyBindAttack is being pressed, but then I'd still have to somehow cancel it, and I think that would be rather difficult.

 

As for the potion effects, making it ambient made it see-through enough for me, until I feel like messing with it. :P

BEFORE ASKING FOR HELP READ THE EAQ!

 

I'll help if I can. Apologies if I do something obviously stupid. :D

 

If you don't know basic Java yet, go and follow these tutorials.

  • Author

First bump.

 

I've actually been really busy and haven't gotten any more time to think over this problem, so I would still greatly appreciate any help. :D

BEFORE ASKING FOR HELP READ THE EAQ!

 

I'll help if I can. Apologies if I do something obviously stupid. :D

 

If you don't know basic Java yet, go and follow these tutorials.

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.