Jump to content

[1.8] BreakSpeed


Mistram

Recommended Posts

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?

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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);
		}
	}
}

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

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.