Jump to content

Recommended Posts

Posted

Ok, here is my question, is it possible to have the texture of a custom modeled block change based on an event, like if it's right clicked with an item... I have an idea on how I could do it, but I don't know where to place the code.

Member of Aerotech Networks, a Multi-Gaming server.

Also Currently porting the "Rise of the Automatons" minecraft mod

Posted

Well I was planning on making my custom block to change it's texture when it is rightclicked with a certain item, like a stick makes it's texture be texture 2, while on default it would be texture 1. I would assume I could use either a switch to set texture based on metadata of the block, but I don't know how to impliment it.

Member of Aerotech Networks, a Multi-Gaming server.

Also Currently porting the "Rise of the Automatons" minecraft mod

Posted

Well, all you really have to do is think logical. Let us analyse what you want:

- change texture

- right click

- change metadata

- stick

 

The block class has a convenient right click method which we can simply override

 

    @Override
    public boolean onBlockActivated(World parWorld, int parXCoordinate, ...)
    {	
return false;
    }

 

The metadata as well can easily be set in this method by calling:

 

parWorld.setBlockMetadataWithNotify(parXCoordinate, parYCoordinate, ...);

 

If it is just two texture you can toggle inbetween them by putting an if statement as a parameter: ParWorld.getBlockMetaData(x, y, z) == 0 ? 1 : 0

 

Selecting what to hold can also be achieved here, simply use the player parameter

 

player.getHeldItem().getItem().equals(Items.stick)

 

And rendering, well, you allready know a switch and then it is a simple matter of finding the correct method, as there are several that do just about the same things so I won't post any and leave it up to you, have a look in the Block.class and simply get the metadata and return the correct texture.

 

Not that hard is it? All you have to do is think logical, have a look in the base classes what is allready there, what you can use and you're good to go.

Posted

Ok, so in my attempt to see if I could get it to start to work, I now get a null point exception when I right click it, here is the crash:

 

  Reveal hidden contents

 

Member of Aerotech Networks, a Multi-Gaming server.

Also Currently porting the "Rise of the Automatons" minecraft mod

Posted

To be specific it seems to happen only with an empty hand, so how do I fix that, or make it detect if right clicked with an empty hand?

Member of Aerotech Networks, a Multi-Gaming server.

Also Currently porting the "Rise of the Automatons" minecraft mod

Posted

You have at least a null pointer exception on right click.

Did you actually check if the player is holding something before you're trying to check that illusive item?

Minecraft doesn't check before it returns a method like a sensibly written program would do,

instead it just throws the nulls everywhere and hopes you catch them.

 

And then you have something about nbt which I do not wish to adress since I simply do not know what that is about?

Nbt not being able to find its mapping, how?

It would be nice if someone else could clarify that or otherwise I would definitely need to see the code about that.

Posted

Well, I have fixed that issue, now I have discovered something with my testing, you see I was making my block print a certain phrase when it's right clicked with a stick, and noticed it printed it two times, how would I resolve this, for future reference?

 

Member of Aerotech Networks, a Multi-Gaming server.

Also Currently porting the "Rise of the Automatons" minecraft mod

Posted

Ok and now I can't seem to understand how to get the texture to change correctly, I seem to be confusing myself :(

Member of Aerotech Networks, a Multi-Gaming server.

Also Currently porting the "Rise of the Automatons" minecraft mod

Posted

To see if I can get help... here are the render file and the block file.

 

  Reveal hidden contents

 

Member of Aerotech Networks, a Multi-Gaming server.

Also Currently porting the "Rise of the Automatons" minecraft mod

Posted

I don't want to be annoying but try to find something out yourself, I too had to just look at the error logs and look up how things are done in minecraft. E.g. I've only been modding, like what? 2 weeks? Which also applies to java since I come from c++/vb.net and only got into that to mod minecraft.

If you want to get further than this try to be a bit more proactive in finding your problems.

 

  Quote

Well, I have fixed that issue, now I have discovered something with my testing, you see I was making my block print a certain phrase when it's right clicked with a stick, and noticed it printed it two times, how would I resolve this, for future reference?

 

I have noticed that the right click function, no matter where it is applied to in minecraft, triggers twice. I haven't bothered looking for a solution since if does that it could be an intended feature, and well, it's so easy to fix in the function itself that it really isn't bothersome at all. It might just be however that the basecode doesn't distinguish between a key-down and a key-up so two keysignals are sent.

In any case, don't worry about it.

 

  Quote

Ok and now I can't seem to understand how to get the texture to change correctly, I seem to be confusing myself

 

You are changing a value in your tileentity class that isn't passed through to your tileentityrender class and secondly, you're trying to load textures in the middle of the runtime of your block, not really ideal if I may say so.

A simple solution: Make a resourcelocation for every texture in your RenderAIBeacon class.

In your Tileentity class(which doesn't seem to be included)create a new byte variable.

If you want to load texture 1, set that var to 1, if you want to load texture 2 set it to 2 etc.

In your render class again, cast your tileentity to your tileentityclass and simple go and get that value with a switch, and if it is 2 bind texture two, if it is 1 bind texture one etc.

Thirdly, the block class is static, e.g. it persists for all blocks that are made of that type, if you would somehow succeed in changing its texture there it would change it for every single other block of that class in your world.

Posted

Hmm, this does make sense.. Kinda ironic, I get high 90's in college level java programming classes, yet minecraft modding makes little sense to me

Member of Aerotech Networks, a Multi-Gaming server.

Also Currently porting the "Rise of the Automatons" minecraft mod

Posted

It triggers once only. Once for client and once for server so it may seem like it triggers twice. When printing debugging lines to console you should always check the side as well (for example if you have World reference, check is World.isRemote returns true or false).

 

To archive desired effect you should decide do you want to use metadata or nbt to store data for texture. If it is just the texture metadata is easiest way to do so. So you store that data in right-click method and in renderer you retrive that data by getting it from block (metadata for example, TileEntity.getWorldObj().getBlockMetadata(.... ) and then check what it is and set correct texture.

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.