Posted October 17, 201411 yr hello everyone. i have a little problem with my code that i was tryin to slove for week and couldnt find anything helpful. I'm creating mod were one block after its placed checks types of surroind blocks and replace them if they are water. Actualy loop works from time to time. It depends where it is placed. sometimes loop works fine placed on x,y,z cord but if i move block like x+1 its stops working. I'm replacing existing blocks with customAirBlock. I've checked replacing loop with stone blocks and it works in 100%. But when i put in if() else and i'm tryin to use my custom blocks things go wrong. public class Sponge extends Block { protected Sponge(Material material) { super(material); // TODO Auto-generated constructor stub } private Block BlockCustomAir=new BlockCustomAir(Material.air); public void onBlockAdded(World world, int i, int j, int k) { for (int x=-1; x<2; x++) { for (int y=-1; y<2; y++) { for (int z=-1; z<2; z++) { int flag1=Block.getIdFromBlock(world.getBlock(i+y, j+x, k+z)); int flag2=Block.getIdFromBlock(world.getBlock(i+x, j+y, k+z)); if( flag1==8 || flag2==9 ) { world.setBlock(i+y, j+x, k+z, BlockCustomAir ); //world.setBlock(i+y, j+x, k+z, Block.getBlockById(1)); //world.markBlockForUpdate(i+x, j+y, k+z); } //world.setBlock(i+y, j+x, k+z, Block.getBlockById(0)); } } } } }
October 17, 201411 yr Hi It looks like you're converting code from 1.6.4 or before; don't use IDs any more, compare them to the blocks instead eg Block block = world.getBlock(x + i, y + j, z + k); if (block == Blocks.flowing_water) //etc BTW it looks like you're accidentally swapping x and y sometimes int flag1=Block.getIdFromBlock(world.getBlock(i+y, j+x, k+z)); -TGG
October 18, 201411 yr Author Thank you very much for your help. It worked perfectly but now i have other issue. My Sponge supose to switch water with custom air. But it do it after placing sponge in world. But you can see effect after you relaunch world. When i'm switching custom air to any vanilla block water is replaced instantly after you place the block. But when i am trying to replace water with my custom air block i need to relaunch world to see the effect. I guess i'm making wrong reference to my custom air block and game is able to create it when the world is building. public void onBlockAdded(World world, int i, int j, int k) { for (int x=-1; x<2; x++) { for (int y=-1; y<2; y++) { for (int z=-1; z<2; z++) { Block block=world.getBlock(i+y, j+x, k+z); CustomAirMaterial material=new CustomAirMaterial(); Block BlockCustomAir=new BlockCustomAir(material); if( block==Blocks.water || block==Blocks.flowing_water ) { world.setBlock(i+y, j+x, k+z,BlockCustomAir); } } } } } } [\spoiler] Also i tried to use. The newly created custom air blocks were acting more likely vanilla air blocks not custom air blocks. public static final Block BlockCustomAir = (Block)Block.blockRegistry.getObject("BlockCustomAir");[\spoiler]
October 18, 201411 yr Only modify the world on the server side: !world.isRemote . Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support. 1.12 -> 1.13 primer by williewillus. 1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support. http://www.howoldisminecraft1710.today/
October 18, 201411 yr Author I added @SideOnly before calling method on placedOn. Its wierd because when i'm trying to replace water blocks with stone it works fine but when i change it to mine custom blocks it works but i need to relaunch game. I have no clue what is going wrong here. Is there any other way to refer to mine custom block?
October 18, 201411 yr Don't use @SideOnly!!! Use !world.isRemote ! Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support. 1.12 -> 1.13 primer by williewillus. 1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support. http://www.howoldisminecraft1710.today/
October 18, 201411 yr Author world.markBlockForUpdate() solved my problem. I dont know why but i can replace water with stone without problem but when i want to use my own blocks i need to mark them for udpate. diesieben07 I know its looks ugly. I'lll try to clear code after i finish testing it. And also i dont know how it was in 1.6. I will try to find some tutorials later and check it out. Thanks for advice.
October 19, 201411 yr Author Yea i realized that when i tried to fill up space with water after the sponge is destroyed. Right now i'm calling objects from core mod class CoreTestMod.BlockCustomAir it fixed few glitches for me. thanks for advice !
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.