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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • How to fix file server-1.20.1-20230612.114412-srg.jar  
    • Just a few months ago I was creating my own plugin for Minecraft 1.20.2 spigot that did the same thing, but the skins were not saved, if you can understand this code that I made a long time ago it may help you.   //This is a class method private static String APIRequest(String value, String url, String toSearch) { try { URL api = new URL(url + value); HttpURLConnection connection = (HttpURLConnection) api.openConnection(); connection.setRequestMethod("GET"); int responseCode = connection.getResponseCode(); if (responseCode == HttpURLConnection.HTTP_OK) { BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream())); StringBuilder response = new StringBuilder(); for (String responseChar; (responseChar = reader.readLine()) != null; ) response.append(responseChar); reader.close(); JSONObject responseObject = new JSONObject(response.toString()); if (!toSearch.equals("id")) return responseObject .getJSONArray("properties") .getJSONObject(0) .getString("value"); else return responseObject.getString("id"); } else { AntiGianka.ConsoleMessage(ChatColor.RED, String.format( "Could not get %s. Response code: %s", ((toSearch.equals("id")) ? "UUID" : "texture"), responseCode )); } } catch (MalformedURLException error) { AntiGianka.ConsoleMessage(ChatColor.RED, "An error occurred while trying to access the URL. Error: " + error); } catch (IOException error) { AntiGianka.ConsoleMessage(ChatColor.RED, "An error occurred while attempting to connect to the URL. Error: " + error); } return ""; } //other class method private void SkinGetter() { String uuid; String textureCoded; if ((uuid = APIRequest(args[0], "https://api.mojang.com/users/profiles/minecraft/", "id")).isEmpty() || (textureCoded = APIRequest(uuid, "https://sessionserver.mojang.com/session/minecraft/profile/", "value")).isEmpty() ) sender.sendMessage(ChatColor.RED + String.format( "An error has occurred while trying to obtain the %s player skin, please check if the name %s is spelled correctly or try again later.", args[0], args[0] ) ); else SkinSetter(textureCoded); } //other more private void SkinSetter(String textureCoded) { JSONObject profile = new JSONObject(new String(Base64.getDecoder().decode(textureCoded))); try { URL textureUrl = new URL(profile.getJSONObject("textures"). getJSONObject("SKIN"). getString("url")); if (sender instanceof Player && args.length == 1) { PlayerTextures playerTextures = ((Player) sender).getPlayerProfile().getTextures(); playerTextures.setSkin(textureUrl); ((Player) sender).getPlayerProfile().setTextures(playerTextures); if (((Player) sender).getPlayerProfile().getTextures().getSkin() != null) sender.sendMessage(((Player) sender).getPlayerProfile().getTextures().getSkin().toString()); else sender.sendMessage("Null"); sender.sendMessage("Skin changed successfully.a"); } else { } AntiGianka.ConsoleMessage(ChatColor.GREEN, "Skin command executed successfully."); } catch (MalformedURLException error) { sender.sendMessage(ChatColor.RED + String.format( "An error has occurred while trying to obtain the %s player skin, please check if the name %s is spelled correctly or try again later.", args[0], args[0] ) ); AntiGianka.ConsoleMessage(ChatColor.RED, "An error occurred while trying to access the URL. Error: " + error); } }  
    • Use /locate structure The chat should show all available structures as suggestion For the Ancient City it is /locate structure ancient_city
    • So does it work without this mod? Did you test it with other builds?
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.