Jump to content

About pressure plate/door mechanics?


icecubert

Recommended Posts

I have looked at a couple of online documentations with the forge hierarchies but I couldn't find an answer.

 

A BlockDoor is a block, so in both states (open and closed) it acts as a block. Does this mean that it technically takes up the whole "cube" and some of it is without collisions, or is it a special sized block. Is there any way to get the block adjacent to the door? I tried to look for location, adjacent, nearby, etc... methods but they don't seem to exist for a door.

 

My next best bet was to implement a pressure plate mechanism, however when I checked the methods none of them seemed to explain the effect that pressure plates have. Any ideas about what those might be?

 

tl;dr I want to be able to detect players on top of/nearby/in blocks. I tried to look online for the appropriate methods, but I couldn't find them. If they exist I apologize for the question. Thanks!

Link to comment
Share on other sites

Hi

 

You can get adjacent blocks if you know the [x,y,z] coordinate of your door block. 

The method you're overriding will give you World, call world.getBlock() with the coordinates of the adjacent block.

See also here

http://greyminecraftcoder.blogspot.com.au/2013/07/blocks.html

 

My usual strategy for figuring out how something works is to google it first, check a couple of links, then if nothing promising, just look at the vanilla.

 

For example:

Pressure plate?  search on pressure -> BlockBasePressurePlate looks promising

browse through methods ->

 

    /**
     * Ticks the block if it's been scheduled
     */
   public void updateTick(World par1World, int par2, int par3, int par4, Random par5Random)

    /**
     * Triggered whenever an entity collides with this block (enters into the block). Args: world, x, y, z, entity
     */
    public void onEntityCollidedWithBlock(World par1World, int par2, int par3, int par4, Entity par5Entity)

    /**
     * Checks if there are mobs on the plate. If a mob is on the plate and it is off, it turns it on, and vice versa.
     */
    protected void setStateIfMobInteractsWithPlate(World par1World, int par2, int par3, int par4, int par5)

I reckon we've hit paydirt there.

 

It's nearly always possible to get there pretty easily this way.  Just think of the vanilla block / item / text command that does something, search for it in vanilla, spend a bit of time figuring out how the code works, then model your new code on it.

 

-TGG

 

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.