# [1.8/1.7.10] Custom Portal - Item [Solved]

## Recommended Posts

Hello everyone,

Would anyone maybe know how can I convert this code from 1.7.10 to 1.8 ?

~ I know that .getBlock was replaced by .getBlockState and BlockPos. But I just don't know how it works in this code that I had for 1.7.10.

```public boolean onItemUse(ItemStack stack, EntityPlayer player, World par3World, int x, int y, int z, int side, float hitX, float hitY, float hitZ)
{
if(!par3World.isRemote && par3World.getBlock(x, y, z).equals(Blocks.cobblestone))
{
if(par3World.getBlock(x, y, z).equals(Blocks.cobblestone) && par3World.getBlock(x - 1, y, z).equals(Blocks.cobblestone) && par3World.getBlock(x - 2, y + 1, z).equals(Blocks.cobblestone) && par3World.getBlock(x - 2, y + 2, z).equals(Blocks.cobblestone) && par3World.getBlock(x - 2, y + 3, z).equals(Blocks.cobblestone) && par3World.getBlock(x + 1, y + 1, z).equals(Blocks.cobblestone) && par3World.getBlock(x + 1, y + 2, z).equals(Blocks.cobblestone) && par3World.getBlock(x + 1, y + 3, z).equals(Blocks.cobblestone) && par3World.getBlock(x - 1, y + 4, z).equals(Blocks.cobblestone) && par3World.getBlock(x, y + 4, z).equals(Blocks.cobblestone))
{
for(int i = 0; i < 3; i++)
{
par3World.setBlock(x, y + 1 + i, z, CustomBlocks.portal);
par3World.setBlock(x - 1, y + 1 + i, z, CustomBlocks.portal);
}
if(!player.capabilities.isCreativeMode)
{
stack.stackSize--;
}
return true;
}
}
}```

##### Share on other sites

Put an @Override over the onItemUse function and change the x, y, and z integers to one BlockPos. The side must also be changed to EnumFacing instead, like this:

```@Override
public boolean onItemUse(ItemStack stack, EntityPlayer player, World par3World, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ)
```

The world's get and set blocks are replaced with setBlockState and getBlockState. So you get and set like this:

`par3World.getBlockState(BlockPos pos).getBlock();`

`par3World.setBlockState(Block block, block.getDefaultState());`

The editing of the x, y, and z variables when you check if the portal is created is done as follows:

You simply call the BlockPos variable, which will be named pos in this example, and call .north(), .east().... respectively.

You can add a number as an argument to specify how many blocks you want to go in that direction, but you don't need that.

```pos.south(); //returns a new BlockPos with coordinates that have increased by one block along the z-axis;
pos.north(); //returns a new BlockPos woth coodinates that have decreased by one block along the z-axis;
pos.east();   //returns a new BlockPos woth coodinates that have increased by one block along the x-axis;
pos.west();  //returns a new BlockPos woth coodinates that have decreased by one block along the x-axis;
pos.up();     //returns a new BlockPos woth coodinates that have increased by one block along the y-axis;
pos.down();     //returns a new BlockPos woth coodinates that have decreased by one block along the y-axis;

pos.south(2).east(); //to blocks south and one block east
```

I thing you get the idea

I might be terribly wrong.. Like really, really wrong. But I'm just trying to help.

##### Share on other sites

• 2 weeks later...

Uhm, so I tried to do it but I think I messed up stuff and I don't get what to do when ( x,y,z ) is just there but not called. See for yourself:

Also at the .setBlockState , what do I give to ( Block block, <-- , as in the 1.7.10 it was x,y,z there. Sorry for trouble but I am in the dark here.

Watch for the "***" where the code is for what i ment.

*** ~ I don't know which to call increase or decrease here or just (pos) I can't get though this when I run the code, it doesnt go over this, let alone what I will do on code after that which i probably messed up even more.

```@Override
public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ)
{
System.out.println("pre");
//if(!par3World.isRemote && par3World.getBlock(x, y, z).equals(Blocks.stone))
***
if(!world.isRemote && world.getBlockState(pos.east().up().south().west().down().north()).equals(Blocks.stone))
{
System.out.println("first");
//if(par3World.getBlock(x, y, z).equals(Blocks.stone) && par3World.getBlock(x - 1, y, z).equals(Blocks.stone) && par3World.getBlock(x - 2, y + 1, z).equals(Blocks.stone) && par3World.getBlock(x - 2, y + 2, z).equals(Blocks.stone) && par3World.getBlock(x - 2, y + 3, z).equals(Blocks.stone) && par3World.getBlock(x + 1, y + 1, z).equals(Blocks.stone) && par3World.getBlock(x + 1, y + 2, z).equals(Blocks.stone) && par3World.getBlock(x + 1, y + 3, z).equals(Blocks.stone) && par3World.getBlock(x - 1, y + 4, z).equals(Blocks.stone) && par3World.getBlock(x, y + 4, z).equals(Blocks.stone))
if(world.getBlockState(pos).equals(Blocks.stone) && world.getBlockState(pos.east(-1)).equals(Blocks.stone) && world.getBlockState(pos.west(-2).up(1)).equals(Blocks.stone) && world.getBlockState(pos.west(-2).up(2)).equals(Blocks.stone) && world.getBlockState(pos.west(-2).up(3)).equals(Blocks.stone) && world.getBlockState(pos.east(1).up(1)).equals(Blocks.stone) && world.getBlockState(pos.east(1).up(2)).equals(Blocks.stone) && world.getBlockState(pos.east(1).up(3)).equals(Blocks.stone) && world.getBlockState(pos.west(-1).up(4)).equals(Blocks.stone) && world.getBlockState(pos.up(4)).equals(Blocks.stone))
{
System.out.println("1");
for(int i = 0; i < 3; i++)
System.out.println("2");
{
System.out.println("3");
//par3World.setBlock(x, y + 1 + i, z, CustomBlocks.portal);
world.setBlockState(Block block, CustomBlocks.portal.getDefaultState());
//par3World.setBlock(x - 1, y + 1 + i, z, CustomBlocks.portal);
world.setBlockState(Block block, CustomBlocks.portal.getDefaultState());

}
if(!player.capabilities.isCreativeMode)
System.out.println("4");
{
stack.stackSize--;
System.out.println("5");
}
System.out.println("last");
return true;
//return true;
}
}
return false;
}
```

##### Share on other sites

First of all, sorry for the late answer, but here it is!

Everything is just fine, except this:

`world.getBlockState(pos).equals(Blocks.stone)`

The getBlockState function returns the state the block it is. Kind of the block and the metadata in one class. To get the actual block for comparing you need to add .getBlock() add the end. Like this:

`world.getBlockState(pos).getBlock() == Blocks.stone`

This will compare the block in the IBlockState with the block instance in the Blocks class.

If this was unclear, feel free to say so. I'll just update this post.

I might be terribly wrong.. Like really, really wrong. But I'm just trying to help.

##### Share on other sites

```(pos.east().up().south().west().down().north()).equals(Blocks.stone)
```

Why bother moving the position at all when you counteract the movement?

BlockPos is literally a class that wraps the XYZ coords. Calling pos.up() etc provides a new instance and doesn't modify the original position.

So you've created a shifted copy of a shifted copy of a shifted copy.... Etc that ends up as an exact copy of the coords you had initially.

`world.getBlockState(pos).equals(Blocks.stone)`

BlockState != Block

BlockState.getBlock() like @ovikk said. So that initial if() is always false, so you haven't hit the other issues yet.

`world.setBlockState(BlockPos, BlockState, int flag)`

That's what you're looking for as well. Pos holds all location data, state holds all block info

In all honesty you need to sit down and scratch your head for a while at the vanilla classes that deal with this stuff. You'll have a lot less issues if you actually know what's going on. It sucks but it can't be avoided

I think its my java of the variables.

##### Share on other sites

Okay so I made it finished up the code and it works great and everything expect for the "north", "south" side. While Portal block just doesnt want to show up. ( it works normally for east / west )

Same code as below for south, just that it's on east side, and work normally portal blocks when used the item are there and stays there.

```world.setBlockState(pos.up(i), CustomBlocks.portal.getDefaultState());
world.setBlockState(pos.east().up(i), CustomBlocks.portal.getDefaultState());
```

This code is south - and portal doesn't work , if i replace "portal" block with any other block like "dirt" it works normally. Only for "portal" block it doesnt work

```world.setBlockState(pos.up(i), CustomBlocks.portal.getDefaultState());
world.setBlockState(pos.south().up(i), CustomBlocks.portal.getDefaultState());
```

I was thinking about that south doesn't work because normal block rotation of Portal is for east/west rotation, while for south/north it's in different rotation.

Blocks seem to cancel out if they are neighbour blocks, it happens the same for east/west but it some how works in portal shape, but not for south/north of the side.

##### Share on other sites

Does the portal block have a facing direction, or is it a full block like dirt?

I might be terribly wrong.. Like really, really wrong. But I'm just trying to help.

##### Share on other sites

Does the portal block have a facing direction, or is it a full block like dirt?

It is like normal Portal block ( Copied from nether portal block ). If I am not wrong the direction of "portal block" is east/west.

EDIT: My custom "portal block" is a copy of "nether portal block" from minecraft. Not sure if that tells you anything.

##### Share on other sites

Oh, well that explains why it is not working...

If you copied the BlockPortal class, you'll find that there is a variable called AXIS i your class. If there isn't, add this code to your class:

`public static final PropertyEnum AXIS = PropertyEnum.create("axis", EnumFacing.Axis.class, new EnumFacing.Axis[] {EnumFacing.Axis.X, EnumFacing.Axis.Z});`

Then when you set the block state, you type this:

To place a block with facing you need to add withProperty() when getting the IBlockState:

`getDefaultState().withProperty(YOURBLOCKCLASS.AXIS, THEFACING)`

The first argument in the withProperty function is the property you wish to change. Since we made the property static, we can easily access it. The second argument is the axis the block should be facing. It can either be X or Z. We change this with:

```EnumFacing.Axis.Z //will face in Z axis
EnumFacing.Axis.X //will face in X axis```

So for blocks facing X the function would be:

`world.setBlockState(pos, CustomBlocks.portal.getDefaultState().withProperty(yourblockclass.AXIS, EnumFacing.Axis.X`

For Z it would be the same, except for the fact that the axis should be Z.

Feel free to comment if something was unclear.

I might be terribly wrong.. Like really, really wrong. But I'm just trying to help.

##### Share on other sites

Thank you, ovikk. I finished the code and it works great.

##### Share on other sites

Anytime.

I might be terribly wrong.. Like really, really wrong. But I'm just trying to help.

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

Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.

×   Pasted as rich text.   Restore formatting

Only 75 emoji are allowed.

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

• ### Who's Online (See full list)

×

• #### Activity

×
• Create New...