Jump to content

[1.7.10] onNeighborBlockChange not working


KakesRevenge

Recommended Posts

Hey,

Im trying to make alfheim portalish multiblock and i have 2 blocks 1.obsidianlampoff 2.obsidianlampon

and when the blocks are in place the obsidianlampoff will become obsidianlampon...

 

Obsidian Lamp On

 

 

package kakesrevenge.nonetherneeded.blockitems;

 

import java.util.Random;

 

import kakesrevenge.nonetherneeded.help.Reference;

import net.minecraft.block.Block;

import net.minecraft.block.material.Material;

import net.minecraft.item.Item;

 

public class ObsidianLampOn extends Block {

 

public ObsidianLampOn(Material rock,String name) {

super(rock);

this.setBlockName(name);

this.setBlockTextureName(Reference.MODID + ":" + "ObsidianLampOn");

this.setLightLevel(1F);

}

 

}

 

 

 

Obsidian Lamp Off

 

 

package kakesrevenge.nonetherneeded.blockitems.blocks;

 

import java.util.Random;

 

import kakesrevenge.nonetherneeded.blockitems.BlockItem;

import kakesrevenge.nonetherneeded.help.Reference;

import net.minecraft.block.Block;

import net.minecraft.block.material.Material;

import net.minecraft.creativetab.CreativeTabs;

import net.minecraft.init.Blocks;

import net.minecraft.world.World;

 

public class ObsidianLampOff extends Block {

 

public ObsidianLampOff(Material rock, String name) {

super(rock);

this.setBlockName(name);

this.setCreativeTab(CreativeTabs.tabBlock);

this.setBlockTextureName(Reference.MODID + ":" + "ObsidianLampOff");

}

 

public void onNeighborBlockChange(World world, int x, int y, int z, Block block) {

if(!world.isRemote) {

if(world.getBlock(x, y,    z - 1) == Blocks.obsidian &&

  world.getBlock(x, y,    z + 1) == Blocks.obsidian &&

  world.getBlock(x, y + 1, z - 2) == Blocks.obsidian &&

  world.getBlock(x, y + 2, z - 2) == Blocks.obsidian &&

  world.getBlock(x, y + 4, z - 1) == Blocks.obsidian &&

  world.getBlock(x, y + 4, z)    == Blocks.obsidian &&

  world.getBlock(x, y + 4, z + 1) == Blocks.obsidian &&

  world.getBlock(x, y + 1, z + 2) == Blocks.obsidian &&

  world.getBlock(x, y + 2, z + 2) == Blocks.obsidian &&

  world.getBlock(x, y + 3, z + 2) == Blocks.obsidian) {

System.out.println("Something REALLY Quite COOL");

world.setBlock(x, y, z, BlockItem.ObsidianLampOn);

}

}

}

}

 

 

 

Im gonna check if there is air block later on and then make the acutal portal class but first i need to get basics to work

System.out.println("Something REALLY Quite COOL"); isNOT printing out and the block isnt changing to lampon.

 

Three images here : http://imgur.com/Arjh767,bf84Kaa,3ily79U#0

 

Any help appreciated thanks in advance.

 

 

I'm beginner in java and in minecraft modding.

Please be specific.

Any code examples are appreciated.

Sorry for my english i'm from Czech republic.

Please hit that thank you button if i helped :)

Link to comment
Share on other sites

Okey so i was testing a little bit and i have added onBlockAdded and onblockUpdate but my problem is when im breaking one of the obsidians on the side it will still be on

 

heres the code :

 

 

package kakesrevenge.nonetherneeded.blockitems.blocks;

 

import java.util.Random;

 

import kakesrevenge.nonetherneeded.blockitems.BlockItem;

import kakesrevenge.nonetherneeded.help.Reference;

import net.minecraft.block.Block;

import net.minecraft.block.material.Material;

import net.minecraft.creativetab.CreativeTabs;

import net.minecraft.init.Blocks;

import net.minecraft.world.World;

 

public class ObsidianLampOff extends Block {

 

public ObsidianLampOff(Material rock, String name) {

super(rock);

this.setBlockName(name);

this.setCreativeTab(CreativeTabs.tabBlock);

this.setBlockTextureName(Reference.MODID + ":" + "ObsidianLampOff");

}

 

public void onNeighborBlockChange(World world, int x, int y, int z, Block block) {

if(!world.isRemote && this.checkNetherGate(world,x,y,z) == true) {

System.out.println("Something REALLY Quite COOL");

world.setBlock(x, y, z, BlockItem.ObsidianLampOn);

} else if (this.checkNetherGate(world,x,y,z) == false) {

world.setBlock(x, y, z, BlockItem.ObsidianLampOff);

}

}

 

public void onBlockAdded (World world, int x, int y, int z) {

if(!world.isRemote && this.checkNetherGate(world, x, y, z) == true) {

System.out.println("Something REALLY Quite COOL");

world.setBlock(x, y, z, BlockItem.ObsidianLampOn);

} else if (this.checkNetherGate(world,x,y,z) == false) {

world.setBlock(x, y, z, BlockItem.ObsidianLampOff);

}

}

 

public void updateTick(World world, int x, int y, int z, Random random) {

if(!world.isRemote && this.checkNetherGate(world, x, y, z) == true) {

System.out.println("Something REALLY Quite COOL");

world.setBlock(x, y, z, BlockItem.ObsidianLampOn);

} else if (this.checkNetherGate(world,x,y,z) == false) {

world.setBlock(x, y, z, BlockItem.ObsidianLampOff);

}

}

 

private boolean checkNetherGate(World world, int x, int y, int z) {

if( world.getBlock(x, y,    z - 1) == Blocks.obsidian &&

    world.getBlock(x, y,    z + 1) == Blocks.obsidian

    /*//Left

world.getBlock(x, y + 1, z - 2) == Blocks.obsidian &&

world.getBlock(x, y + 2, z - 2) == Blocks.obsidian &&

world.getBlock(x, y + 3, z - 2) == Blocks.obsidian &&

            //Right

world.getBlock(x, y + 1, z + 2) == Blocks.obsidian &&

world.getBlock(x, y + 2, z + 2) == Blocks.obsidian &&

world.getBlock(x, y + 3, z + 2) == Blocks.obsidian &&

//upper part

world.getBlock(x, y + 4, z)    == Blocks.obsidian &&

world.getBlock(x, y + 4, z - 1) == Blocks.obsidian &&

world.getBlock(x, y + 4, z + 1) == Blocks.obsidian*/) {

return true;

}

return false;

}

}

 

 

 

I'm beginner in java and in minecraft modding.

Please be specific.

Any code examples are appreciated.

Sorry for my english i'm from Czech republic.

Please hit that thank you button if i helped :)

Link to comment
Share on other sites

As the codes from OnBlockAdded and onNeighborChanged looks fine to me, I wonder if the CheckNetherGate methode returns the right values.

 

Although it looks pretty compact I still have questions about it.

- why don't you use block metaData to determine wich side should be checked?

- Also why are the numbers that high? World.getBlock(x, y+4, y-1) wil check the block thats 4 blocks above and one block to the south!

- and if you still want it to be  compact(but working) why dont you try ForgeDirections?

 

 

Projects:

Discontinued:

- N2ConfigAPI

- Meachanical Crafting Table

 

Latest:

- CollectionUtils

 

Coöperations:

- InGameConfigManager

Link to comment
Share on other sites

1. How ?

2. because the portal is big

3. How to use ForgeDirections ?

I'm beginner in java and in minecraft modding.

Please be specific.

Any code examples are appreciated.

Sorry for my english i'm from Czech republic.

Please hit that thank you button if i helped :)

Link to comment
Share on other sites

I think I didnt realize it was an actual portal, Im sorry.

 

Anyway, there are still a few things you need to do in order to make this work. first you need to consider if the block in qeustion should always be on the bottem in the middle, or if it may be anywhere in the portal.(which require a lot more checking!)

 

Although I sugested using metaData or forgeDirections, I wouldnt mess with it indeed

 

If the block may only be on the middle bottem spot:

Check if blocks are in place for these 2 situations

- portal is facing the X-direction

- portal is facing the Y-direction

 

if the block may be anywhere:

It would require to check for each individueel spot if the portal is correct, for the 2 ways a portal can face! Wich means you need to check for 3x4x2=24 different cases if an portal is correct!

Although it isn't impossible to code it, I wouldn't recommend calling this methode each tick (as you do right now)

Projects:

Discontinued:

- N2ConfigAPI

- Meachanical Crafting Table

 

Latest:

- CollectionUtils

 

Coöperations:

- InGameConfigManager

Link to comment
Share on other sites

Although it isn't impossible to code it, I wouldn't recommend calling this methode each tick (as you do right now)

 

1) He's not calling it every tick.  Blocks get random update ticks, and his isn't set to tick randomly and he's not calling ScheduleUpdateTick anywhere, so his updateTick method isn't being called.

 

2) Even if he was, checking the block volume of a 5x5x5 region doesn't take that long.  It takes ~0.6ms to scan an entire chunk.

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.

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



×
×
  • Create New...

Important Information

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