Jump to content

Recommended Posts

Posted

Hello everyone,

I am new here on the forums and new to Minecraft modding in general, but I do have intermediate Java experience and some modding experience with other games. I am working on my first basic mod and I thought it would be relatively simple... My hope is to create a block that, when placed, prevents hostile mobs from spawning within a (somewhat large) radius of its location. Creation of the block was pretty easy, and the code to prevent mob spawning seemed straight forward as well. Where I have now hit a wall is how to "attach" the code to prevent mob spawning to a block, and to have it only affect mobs within a certain radius / block range. Initially I tired subscribing to the EntityJoinWorldEvent within my blocks class, but I learned that this code executes regardless of the blocks existence in the world. My next idea was to keep track of my blocks in the world as they are placed, then iterate over them during the EntityJoinWorldEvent to see if the mob is within range, however creating / storing a list of my blocks as they are placed into the world seems to be a lot harder than I would have initially thought. The reality is that I don't know enough about Minecraft's systems to know if this is even the right way to get this done; Is there perhaps another event or function that is directly tied to an in-world block that I can use to execute my own code when events are fired? Is there any way to lookup or find the location(s) of blocks within loaded chunks using their name or ID? I know that there are mods that have already done similar things to what I am trying, so I'm pretty sure its possible and I'm just not looking at it right... Any help is much appreciated!

 

I was also curious if there is any 'official' or unofficial but widely recognized source for mod tutorials, API documentation etc. I have read through the Forge Documentation here, and have found links to the Forge 1.11.2 java-docs, but beyond that there seems to be a lack of modern (1.10+) forge documentation & tutorials. Are there any java-docs for 1.12.2 or 1.13 yet?

Posted

You can also accomplish this without TEs (TileEntities), but only if you do all your own data handling, which I most certainly do not suggest for what you're trying.  TEs are the way to go as was suggested; once you figure them out, they're much simpler to deal with in most cases than manual data handling.

 

Since this is your first time dealing with TEs (TileEntities), here's a tip:

Don't extend BlockContainer to get your TE on your block, instead just extend Block, and override the methods hasTileEntity(IBlockState) and createTileEntity().  You probably get the idea from the method names, but the first should simply return true in your case, and the 2nd should return an instance of your TileEntity.

 

This is one of the pointers given in the Common issues and recommendations, which is good to read through every once in a while; it will probably end up saving you time by preventing some potentially very time-consuming mistakes (yes, speaking from experience :P)

Posted

Awesome, thank you both very much for the quick and helpful replies. I will read up more on TileEntities, fully read the Common Issues post(I confess I've only skimmed through it >_<) and then give it a shot here shortly. Thanks again!

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.