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

Hello everyone,

I am triing of making a mod that'll is working with Logs and Trees.

To implement full functionality I wanted to change the time a player needs to break a log if the log is part of a tree.

I tried like so

 

@SubscribeEvent
public void breakSpeed(BreakSpeed speed)
{
	if (speed.state.getBlock() instanceof BlockLog && isATree(speed.state.getBlock))
	{
		speed.newSpeed=100F;

	}


}

But it seems like my code isnt affecting the breakSpeed of the block.. Any Ideas why?

 

1. Did you register it?

2. Is it being called (did you used right event bus?)

 

3. does isATree actually return ture sometimes? (if getting passed)?

1.7.10 is no longer supported by forge, you are on your own.

  • Author

Actually I need to change my problem. How can I make that the event is called only ONCE, when the player starts to interact with the tree. Because otherway I would kill minecraft with calculating if the mined thing is a tree every call..

What exacly do you want to do? Single-calc are best to be lauched right before block is broken (BreakEvent, HarvestCheck)

 

You might wanna use PlayerInteractEvent, tho idk how is it called when you hold left-click (Idk if once per click or continiusly).

1.7.10 is no longer supported by forge, you are on your own.

  • Author

I got some code that breaks a whole tree when u mine one log from it.

Now I wanna realize that it takes longer to break the bigger the tree is.

 

Right now I am triing to safe a value when a player starts to harvest a tree.

Everytime BreakSpeed is called I get that value from the hasmap and use it.

Problem right now:

After breaking a log the BreakSpeed wont stop getting called.

 


private static HashMap<String, Float> map = new HashMap<String, Float>();

@SubscribeEvent
public void breakSpeed(BreakSpeed speed)
{
	System.out.println("call");
	if (!speed.entityPlayer.worldObj.isRemote &&speed.state.getBlock() instanceof BlockLog)
	{
		speed.newSpeed = map.get(speed.entityPlayer.getName());
		System.out.println(speed.newSpeed);
	}
}

@SubscribeEvent
public void interact(PlayerInteractEvent event)
{
	if (!event.world.isRemote)
	{
		if (event.world.getBlockState(event.pos).getBlock() instanceof BlockLog)
		{
			map.put(event.entityPlayer.getName(), 0.1F);
		}
	}
}

 

I doubt it is conventionally possible.

I have some idea for workaround with caching data, but idk if it will be 100% comp with all mods:

If you are interested:

Since player mines one block at the time, you can save WeakHashMap<EntityPlayer, BlockPos> and WeakHashMap<BlockPos, Float> (all server-side).

You will want to put EntityPlayer to 1st map on start of BreakSpeed with the pos of block mined. Then count Float for given pos and put it into 2nd map. And do this all only if pos != saved pos. Then use those keys.

Bad thing here: If 2 players will start mining same block it will override. So ou have to figure something for it. (extend BlockPos as TreeBlockPos and add reference to EntityPlayer (owner of block being mined) and just check if he's not the same, ofc HashMap will be then WeakHashMap<TreeBlockPos, Float>).

 

EDIT:

Tho I am proposing Weak references I don't think they will always be predictable, better check how your map expands and if it really is "weak" (removes not used obj). Ofc. we are talking about 2nd map, 1st one has only one entry per player so I wound't worry.

 

"After breaking a log the BreakSpeed wont stop getting called."

You mean it is being called even if you are not mining anything?

1.7.10 is no longer supported by forge, you are on your own.

  • Author

I need to think about your idea and try a little bit.

 

And yes it is called after breaking the block. Even if Im doing nothing. And the mined block is getting replaced for some seconds. I have NO idea why. I think if that issue is fixxed I can finish my work

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.