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

Hey, i am trying to place a block when interacting with a mob. But when i just spawn it using this code:

world.setBlockWithNotify((int)this.posX, (int)this.posY + 5, (int)this.posZ, MyBlock.block.blockID);

it places it, and when i reload the world, it's gone.

when i try this:

if(!world.isRemote) world.setBlockWithNotify((int)this.posX, (int)this.posY + 5, (int)this.posZ, MethyrBlocks.methyrFarmSide.blockID);

nothing happens (it wont even place the block) and when i try when the world IS remote, the same happens as doing nothing.

when i type:

System.out.println(world.isRemote);

i get two true messages.

Can somebody please help me with this, it's really annoying :/

Take the check for world.isRemote off. A block change must happen both client (world.isRemote) and server (!world.isRemote) side in order for it to stay there.

 

  • Author

But as i said, thats not working, then i will see the block, but when i reload the world it will be disappeared... Thats (i think) caused by the fact that it only places the block server side, because world.isRemote gives me "true" twice :/

Make sure that you're doing it in code that will be run by the server, not the client

Protip: try and find answers yourself before asking on the forum.

It's pretty likely that there is an answer.

 

Was I helpful? Give me a thank you!

 

 

width=635 height=903http://bit.ly/HZ03zy[/img]

 

 

Tired of waiting for mods to port to bukkit?

use BukkitForge! (now with a working version of WorldEdit!)

Make sure that you're doing it in code that will be run by the server, not the client

 

Where exactly would you put that code?

In one of my blocks I have

 

@Override
public void onBlockPlacedBy(World par1World, int par2, int par3, int par4, EntityLiving par5EntityLiving) {
par1World.setBlock(par2, par3 + 1, par4, 3004);
par1World.setBlock(par2, par3 + 2, par4, 3005);
}

 

to place two other blocks directly above this block.

  • 3 months later...

and how can i do that?

 

Did you ever find out?  I cant see to find any answer yet it must be possible, people must know how to get it

Well you are only saying the lines of code and with the !world.isRemote it seems fine..

So where are you calling these lines from as mentioned above you need to call them inn a method the server reads at all.

 

It would probably help you get help faster and better if you provided more of your code for the action you are trying to do :)

If you guys dont get it.. then well ya.. try harder...

 

I know, I imagine once one knows how to get them into a method the server reads it will be really simple and it will all make sense.  But how, as laifsjo asked back in december, do we do that?

 

World world = Minecraft.getMinecraft().theWorld; returns a world object, but the method scheduleBlockUpdate() of this world object does nothing, so calling world.setBlock() of this would to place for example a block of sand does not schedule an update, so  the sand never starts to fall.

 

So, how do we get the server world. how do we call methods from our mod on the server, either a real server on another machine, or the local one started by the  minecraft client?

 

How do we write code that is called by the server? 

 

 

 

 

 

I know, I imagine once one knows how to get them into a method the server reads it will be really simple and it will all make sense.

 

And it is, but it seems to be not said anywhere  ;D

 

Please correct me if I am wrong, but the code runs on both the server and the client, but not at  the same time,  see here (http://www.minecraftforge.net/forum/index.php/topic,7929.msg40041.html#msg40041) for my original post and imagine a lot of head banging on a desk and me saying "why why why"

 

Hi

 

What does @SideOnly(Side.CLIENT) actually do?

 

I had thought it meant the code only ran or applied to the client or server side of the mod. 

 

But in my block I have this:

 

	
    @Override
    @SideOnly(Side.CLIENT)
public void registerIcons(IconRegister iconRegister)
{
	String tex;
	LogHelper.detail("Loading " + this.getUnlocalizedName2() + " rotting textures...");
	iconBuffer = new Icon[16];
	tex = Reference.MOD_ID + ":" + this.getUnlocalizedName2() + "_00";
	iconBuffer[0] =  iconRegister.registerIcon(tex); 
	LogHelper.verbose("Loaded " + tex);
	tex = Reference.MOD_ID + ":" + this.getUnlocalizedName2() + "_01";
	iconBuffer[1] =  iconRegister.registerIcon(tex);

 

Yet the log messages are being logged twice, so what is happening?  I am trying to understand what it does?

 

Thanks,

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.