Jump to content

[Solved]Struggling with world.setBlock changes not preserved


lido666

Recommended Posts

Hopefully somebody can help!

 

Struggling with world.setBlock using forge 1.7.2 and gradle, I have the following code:

 

World world = Minecraft.getMinecraft().theWorld;

world.setBlock(xPos+x, yPos+1, zPos+z, Blocks.air,0,0);

world.setBlock(xPos+x, yPos, zPos+z, Blocks.coal_block,20,20);

 

I can set blocks within my mod, but the blocks reverts back to what they were before the .setBlock command (ie. if you try and use an item on them).  when I exist a world, and return, my changes are gone. 

 

Rather than using custom blocks, I want to use standard inventory for the time being (unless I must create a custom block)  ?  If this something linked to client side changes to server side changes?

 

 

It appears that I am making changes to a client side (cache) which is then being overidden by the server side cache? 

 

Any suggestions please ?

 

Many thanks Lido666

 

Link to comment
Share on other sites

I am calling this from my class which is triggered from the event_bus, eg

 

@SubscribeEvent

public void onPlayerUpdate(LivingUpdateEvent event)

 

Where should I setup my event bus from to receive play events ?

 

Many thanks in advance

Lide

o6666

Link to comment
Share on other sites

Thanks for the quick response.  Play events are exactly how you described them above.

 

I create the hook on to the event bus using:

 

@EventHandler

    public void init(FMLInitializationEvent event){

       

    // We add the command below (and a new ItemPickupHandler class), all events now go in that class

    MinecraftForge.EVENT_BUS.register(new ItemPickupHandler());

 

It is from this class that I am calling the .setBlock

 

 

Link to comment
Share on other sites

world.isRemote returns true.

 

I have setup client and server side classes using:

    @SidedProxy(clientSide = "com.example.examplemod.proxy.ClientProxyClass", serverSide = "com.example.examplemod.proxy.ServerProxy")

    public static proxyCommon proxy;

 

Do I need to register my event_bus handler from the class ServerProxy ?

 

Many thanks in advance

Lido666

Link to comment
Share on other sites

Thank you.  Even when using 'onLivingUpdateEvent',  I only ever get events which are remote.  Used the code below, and only received remote events, even when mining, jumping,  crafting.    Any suggestions please?

 

 

@SubscribeEvent

public void onLivingUpdateEvent(LivingUpdateEvent event)

{

world = Minecraft.getMinecraft().theWorld;

if (world!=null) System.out.println("I am on server" + world.isRemote);

}

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.

×
×
  • Create New...

Important Information

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