Jump to content

call a method from a specific block using the blocks co-ordinates


Recommended Posts

Posted

hi, i need to call a method "isBeingProvided" which belongs to a certain block using the co-ordinates of the block

 

so i need to know if that's even possible,  the method will be called by a few other blocks and they are able to find this specific block which acts like a signal booster for energy, the blocks need to check that every "booster" block within 10 blocks of them are being provided with energy.

 

i have added the "isBeingProvided" method into those booster blocks but don't have a clue how i would be able to call the method... can anybody help me out?

Posted

If the block has a TileEntity and the method is a part of that TE then sure.

Just do world.getTileEntityAt(x,y,z) to grab the TE for that block, and call the method on it :)

 

The question is when do you need to call this method, or rather from where do you need to call it?

  Quote

If you guys dont get it.. then well ya.. try harder...

Posted

i'm calling the method from another block when the block updates (although i need to reconsider this as the block spreads and ends up 20*20*20 blocks which is very CPU intensive :/)

 

and at the moment the method is actually in the block itself, i will look for a tile entity tutorial now..... a "getBlock(world,x,y,z)" would have been much easier for those occasions where  you only need to call a single method haha..... i wonder if i can implement that by creating an API...... hmmmm

Posted

Are you using vectors to define length between blocks? Also, if your wondering if you can get the location when a player hits the block then you could do a EntityPlayer.raytrace(), but seeing as how your dealing with energy it seems you may not be looking for the location only when someone uses the block.

Posted

vectors to define the length between blocks? could you explain that a bit more please?

 

i'm using a method i was taught in college for searching arrays haha.... treating the map as a very big array

 

for int i /// x

for int j /// y

for int k /// z

 

 

at the moment it doesn't check for energy, it just spreads the block when it finds a provider or booster block.

there's an if statement

 

if the block at  par1 + i, par2 + j, par3 + k is a generator or booster then spread the block

 

 

Posted

int id = world.getBlockId(x, y, z);

BlockYourBlock b = (BlockYourBlock)Block.blocksList[id];

b.functionCall();

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

OFFTOPIC (kinda)

Well, what if I want to find coordinates of block player is clicking on when it's not TE?

I mean - best way?

  Quote

1.7.10 is no longer supported by forge, you are on your own.

Posted

world.raycast(...)

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

You can use ray trace, or you can make the method on the client side and call the minecraft objectMouseOver coords. It can grab the x, y, z coords of a block. But ray trace is probably your best bet because it can be done server side.

Posted

Hi

 

I'd suggest that it's probably more efficient to make your "booster" blocks into TileEntities.  Unlike normal blocks, TileEntity is stored in a list with [x,y,z] coordinate which makes it relatively easy to find if there aren't too many - just ask WorldServer.getAllTileEntityInBox for a list of all tile entities in a certain [x,y,z] range, then step through them to find all the booster blocks.  NB this needs to be done on the server side.

 

-TGG

 

WorldServer.getAllTileEntityInBox

  /**

    * pars: min x,y,z , max x,y,z

    */

    public List getAllTileEntityInBox(int par1, int par2, int par3, int par4, int par5, int par6)

 

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

    • That is incorrect. Use the run.bat or run.sh to run the server.
    • Hello, I have been trying for days to create my server with forge-1.20.1-47.4.1-installer, which installs the server, but the forge-1.20.1-47.4.1.jar file, which is necessary to create the server, does not appear. I no longer know what to do. Help. hola buenas, llevo dias intentando poder hacer mi servidor con forge-1.20.1-47.4.1-installer el cual instalo el server, pero no aparece el archivo forge-1.20.1-47.4.1.jar , el cual es necesario para poder crear el server, ya no se que hacer ayuda.
    • Does this happen if you use the regular vanilla minecraft launcher? Also, unsure if TLauncher ever has a legit usage, as I have always seen it associated with software piracy, but if it has a legit mode, make sure it is using online mode so that it can authenticate your MS account to login. Aside from that, more information is likely needed. Post logs, as well as the paths you are placing files in (screenshots of your file explorer can be helpful as well).
    • I am using a third-party launcher that has pre-installed forge versions of Minecraft.  When I insert mods from CurseForge, I extract the files and as expected put them in the .mods folder. I am guessing that there is an error with the file transfer but I don't know for sure and sometimes I use Forge to test mods that I created before releasing previously on a different pc, so I don't know if it is the if it an extraction error but if are any tips or knowledge reply and I will read it. This is also will be kept on the forum for others that have the issues.
    • I make wires and i need connection 2 wires block. I have BooleanPropertys registered, but in mod loading it show Unknown the property in assets/wuntare/blockState. public static final BooleanProperty CONNECTED_NORTH = BooleanProperty.create("connected_north"); public static final BooleanProperty CONNECTED_SOUTH = BooleanProperty.create("connected_south"); public static final BooleanProperty CONNECTED_WEST = BooleanProperty.create("connected_west"); public static final BooleanProperty CONNECTED_EAST = BooleanProperty.create("connected_east"); public static final BooleanProperty CONNECTED_UP = BooleanProperty.create("connected_up"); public static final BooleanProperty CONNECTED_DOWN = BooleanProperty.create("connected_down"); public CopperWireWithoutInsulation0(Properties properties) { super(properties); this.registerDefaultState(this.stateDefinition.any() .setValue(CONNECTED_NORTH, false) .setValue(CONNECTED_SOUTH, false) .setValue(CONNECTED_WEST, false) .setValue(CONNECTED_EAST, false) .setValue(CONNECTED_UP, false) .setValue(CONNECTED_DOWN, false)); } @Override protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) { builder.add(CONNECTED_NORTH, CONNECTED_SOUTH, CONNECTED_WEST, CONNECTED_EAST, CONNECTED_UP, CONNECTED_DOWN); } In this part blockState have problem "multipart": [ { "apply": { "model": "wuntare:block/copper_wire_without_insulation0" } }, { "when": { "connected_north": true }, "apply": { "model": "wuntare:block/copper_wire_without_insulation0_north" } },  
  • Topics

×
×
  • Create New...

Important Information

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