Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

I´ve created a block and I dont know how to make thath if I put two blocks of this type both have independent variables and when clossing the game, both variables get saved to load them again when loading the world.

At the moment I have this code:

public class block2 extends Block {
private int i = 0;
public block2(int id, Material Material) {
	super(id, Material);
}
public boolean onBlockActivated(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9)
{
if (!par1World.isRemote)
{
    this.i = (this.i) + 1;
	par5EntityPlayer.addChatMessage("Numero de banderas obtenidas hasta el momento: " + i);
return true;
}
return false;
}
}

The variable I want to do is i

Hi

 

The important to remember is that there is only one of each Block.  You don't get a block2 for every block [x,y,z] location in the world, there is only one block2.

 

There are two ways to store unique information for every block location:

(1) If you only need to store up to 16 different numbers, you can use block metadata.

(2) If you need more than 16 different numbers, use TileEntity.

 

A quick search on the forge tutorials will show you examples of how to use each one.

http://www.minecraftforge.net/wiki/Tutorials

 

-TGG

I need to use more than 16 but the link doesnt works for me :P

 

Tile Entities are real easy.

 

Change your existing class to extend BlockContainer rather than block, Eclipse will throw an error, just hover over it and take the suggested action ("add unimplemented methods").  We'll come back to this function in a minute.

 

Create a new class, make it extend TileEntity.  This is where the bulk of your block's code will go.  The TE will handle everything, the "block" is just sort of an anchor.  You'll want to take a look at the base TE class to see what methods it has by default, use what you need.

 

Go back to your block class and in that new method that was created, change it from "return null" to make it return a new instance of your TE.  (return new myTileEntity()).

 

Some reference material:

https://github.com/Draco18s/Artifacts/tree/master/draco18s/artifacts/entity

(Some of those are mobs, I use the same package for both just because I never have very many of either)

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.

You can also specify a custom renderer if you need it, either an ISimpleBlockRenderingHandler (which is basically the standard cube renderer) or a TileEntitySpecialRenderer (for model based types).  I wouldn't suggest looking at either in my code, the ISimpleBlockRenderingHandler I have is super complex and completely unnecessary for anything you'd be doing and you'd really want a basic Techne tutorial for models.

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.

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.