Jump to content

[1.8.9] BreakEvent.block cannot be resolved or is not a field


Dnomyar96

Recommended Posts

Hi all,

 

I just started learning to mod minecraft with the help of a book (Minecraft modding with Forge). In that book there is an example which should make Diamond ore blocks explode. I have the following code:

 

package org.devoxx4kids.forge.mods;

import net.minecraft.init.Blocks;
import net.minecraftforge.event.world.BlockEvent.BreakEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;

public class DiamondOreTrap {
@SubscribeEvent
public void explode(BreakEvent event)
{
	if(event.block != Blocks.diamond_ore)
	{
		return;
	}

	event.world.createExplosion(null, event.x, event.y, event.z, 10, true);
}
}

 

At event.block I get an error stating "block cannot be resolved or is not a field." The same goes for event.x, event.y and event.z. Am I doing something wrong here? Any help is appreciated.

Link to comment
Share on other sites

In 1.8+ this was replaced with an

IBlockState

field named

state

. You must also use the getter (

getState()

) instead of accessing the field directly.

 

Thanks for the answer! Could you maybe explain it a bit more or give me link to where it is explained?

 

Also, a bit off topic, but is there any place where I can see all events? I tried googling but can't seem to find anything. (as in some kind of documentation)

Link to comment
Share on other sites

Thanks for the answer! Could you maybe explain it a bit more or give me link to where it is explained?

Forge's documentation has an introduction to blockstates here.

 

Also, a bit off topic, but is there any place where I can see all events? I tried googling but can't seem to find anything.

Use your IDE to find the subclasses of

net.minecraftforge.fml.common.eventhandler.Event

.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Link to comment
Share on other sites

Thanks for the answer! Could you maybe explain it a bit more or give me link to where it is explained?

Forge's documentation has an introduction to blockstates here.

 

Also, a bit off topic, but is there any place where I can see all events? I tried googling but can't seem to find anything.

Use your IDE to find the subclasses of

net.minecraftforge.fml.common.eventhandler.Event

.

 

Thanks! That should help.

Link to comment
Share on other sites

Thanks for the answer! Could you maybe explain it a bit more or give me link to where it is explained?

Forge's documentation has an introduction to blockstates here.

 

Also, a bit off topic, but is there any place where I can see all events? I tried googling but can't seem to find anything.

Use your IDE to find the subclasses of

net.minecraftforge.fml.common.eventhandler.Event

.

 

First of all, your answer helped a lot. However I'm still having some trouble. I replaced the event.block with event.state.getBlock(). However I can't figure out how to get the coordinates of the block (what currently is event.x etc). Any chance you can help me with that?

 

EDIT: I noticed a getBlockBoundsMaxX() (also for Y, Z and min) method. Does that have anything to do with it?

Link to comment
Share on other sites

Does the event have a BlockPos field? If so, the pos (position) has x, y and z getter methods.

The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting.

Link to comment
Share on other sites

Thanks for the answer! Could you maybe explain it a bit more or give me link to where it is explained?

Forge's documentation has an introduction to blockstates here.

 

Also, a bit off topic, but is there any place where I can see all events? I tried googling but can't seem to find anything.

Use your IDE to find the subclasses of

net.minecraftforge.fml.common.eventhandler.Event

.

 

First of all, your answer helped a lot. However I'm still having some trouble. I replaced the event.block with event.state.getBlock(). However I can't figure out how to get the coordinates of the block (what currently is event.x etc). Any chance you can help me with that?

 

EDIT: I noticed a getBlockBoundsMaxX() (also for Y, Z and min) method. Does that have anything to do with it?

Not event state.getBlock() but event .getState().getBlock()

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

Thanks for the answer! Could you maybe explain it a bit more or give me link to where it is explained?

Forge's documentation has an introduction to blockstates here.

 

Also, a bit off topic, but is there any place where I can see all events? I tried googling but can't seem to find anything.

Use your IDE to find the subclasses of

net.minecraftforge.fml.common.eventhandler.Event

.

 

First of all, your answer helped a lot. However I'm still having some trouble. I replaced the event.block with event.state.getBlock(). However I can't figure out how to get the coordinates of the block (what currently is event.x etc). Any chance you can help me with that?

 

EDIT: I noticed a getBlockBoundsMaxX() (also for Y, Z and min) method. Does that have anything to do with it?

Not event state.getBlock() but event .getState().getBlock()

 

If I do that I get an error saying that it's undefinded for the type BlockEvent.BreakEvent. Eclipse says that the way to fix it is to cast event, but what should I cast it to?

 

Does the event have a BlockPos field? If so, the pos (position) has x, y and z getter methods.

 

It doesn't seem to have a direct BlockPos field. But as for the above, it says I should cast event.

Link to comment
Share on other sites

If I do that I get an error saying that it's undefinded for the type BlockEvent.BreakEvent. Eclipse says that the way to fix it is to cast event, but what should I cast it to?

The getter method didn't exist in 1.8.9, it was only in 1.9 that all event fields were encapsulated with getter methods.

 

It doesn't seem to have a direct BlockPos field. But as for the above, it says I should cast event.

BlockEvent

has a

pos

field of type

BlockPos

.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Link to comment
Share on other sites

Eclipse says that the way to fix it is to cast event, but what should I cast it to?

 

Eclipse's suggestions must always be taken with several grains of salt. They're often like offering to amputate your leg to cure you of athlete's foot.

 

Does the event have a BlockPos field? If so, the pos (position) has x, y and z getter methods.

 

It doesn't seem to have a direct BlockPos field.

 

BlockPos is a class, not a field name. Didn't you even explore the event class to see what's in it? Did you try a text-wise search for "BlockPos"? Please look at the fields and their types and their visibility.

The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting.

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.