how can I solve this code?

Started by Darkblue0511 on

Topic category: Help with Minecraft modding (Java Edition)

Joined Jul 2018
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
how can I solve this code?
Thu, 07/12/2018 - 09:16 (edited)

https://blog.naver.com/dohan0511/221317781519

visit my blog to see the screenshot.

NO VIRUSES.Please visit and see the screenshot.

(Can you tell me how to upload a picture? I don't know..)

This code makes error.. how can I fix it?

I want to make this procedure:

heal 

wait 1 second

heal 

wait 1 second

heal 

wait 1 second

heal 

wait 1 second

heal 

Edited by Darkblue0511 on Thu, 07/12/2018 - 09:16
Joined Aug 2013
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
First of all... if you…
Thu, 07/12/2018 - 09:09

First of all... if you everytime when you have some error, PASTE THE LOG. That is why the log exist.

Also never use just Thread.sleep(), unless you want to freeze the whole game!e for the time specified, as you are running it from the same thread that controls most of the game. If you want to use that, look into multithreading or make some sort of simple timer or use for example TickHandler.

Also even if I don't know the error you got and I don't use the procedures at all as that can't offer me anything beneficial,  the code snippet has wrong formatting - there is a missing semicolon, most likely.

Joined Jul 2018
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Thank you so much for reply…
Thu, 07/12/2018 - 09:15

Thank you so much for reply my question.

I recieved your advice.

But.. how can I wait 1 seconds???

Joined Jul 2018
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
:clean:deobfCompileDummyTask…
Thu, 07/12/2018 - 09:16

:clean
:deobfCompileDummyTask
:deobfProvidedDummyTask
:sourceApiJava
:compileApiJava UP-TO-DATE
:processApiResources UP-TO-DATE
:apiClasses UP-TO-DATE
:sourceMainJava
C:\Pylo\MCreator179\forge\build\sources\main\java\mod\mcreator\mcreator_bandageelement.java:34: error: ';' expected
   ((EntityLivingBase)entity).addPotionEffect(new PotionEffect(MobEffects.INSTANT_HEALTH,(int) 1,(int) 1));Thread.sleep(100)if(entity instanceof EntityLivingBase)
                                                                                                                            ^
C:\Pylo\MCreator179\forge\build\sources\main\java\mod\mcreator\mcreator_bandageelement.java:35: error: ';' expected
   ((EntityLivingBase)entity).addPotionEffect(new PotionEffect(MobEffects.INSTANT_HEALTH,(int) 1,(int) 1));Thread.sleep(100)if(entity instanceof EntityLivingBase)
                                                                                                                            ^
C:\Pylo\MCreator179\forge\build\sources\main\java\mod\mcreator\mcreator_bandageelement.java:36: error: ';' expected
   ((EntityLivingBase)entity).addPotionEffect(new PotionEffect(MobEffects.INSTANT_HEALTH,(int) 1,(int) 1));Thread.sleep(100)if(entity instanceof EntityLivingBase)
                                                                                                                            ^
C:\Pylo\MCreator179\forge\build\sources\main\java\mod\mcreator\mcreator_bandageelement.java:37: error: ';' expected
   ((EntityLivingBase)entity).addPotionEffect(new PotionEffect(MobEffects.INSTANT_HEALTH,(int) 1,(int) 1));Thread.sleep(100)if(entity instanceof EntityLivingBase)
                                                                                                                            ^
4 errors
:compileJava FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':compileJava'.
> Compilation failed; see the compiler error output for details.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 11.458 secs
C:\Pylo\MCreator179\forge>
Task completed with return code 0 in 11919 milliseconds

Joined Aug 2017
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
You have to use this code:…
Thu, 07/12/2018 - 16:06

You have to use this code:

try{Thread.sleep(100);} catch (InterruptedException e) {e.printStackTrace();}

Joined Aug 2013
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Basically you can: Just…
Thu, 07/12/2018 - 16:11

Basically you can:

  • Just create a variable of type int and set it to seconds*20 and each game tick decrease by one. This is the simplest but also the worst. Use it only for client only or global things, unless there is nont any other way. Also is not performance friendly.
  • Create a TickHandler and save to a avroable of type long current game time + your desired delay and each tick check if the current game time is greater or equal to the variable. Still recommended mostly for client or global or when using NBT/Capability
  • Create your own thread and use Thread.sleep(). Do not use for getting and setting blocks in the World. Check TimerTask class. Also I believe that there is some Forge method for handling threads but I have not my Forge source available right now.
Joined Aug 2017
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
it does not work without the…
Thu, 07/12/2018 - 16:17

it does not work without the try and catch and you forgot the semicolon.

Joined Aug 2013
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
The thing is that if you use…
Thu, 07/12/2018 - 16:25

The thing is that if you use it this way, you will prevent the main thread from doing anything, except things like rendering. It can be good when you do some stuffslike reading files on start up but it is definitely not something you want to use in game.

Joined Aug 2017
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I now.
Thu, 07/12/2018 - 16:49

I now.

Joined Aug 2017
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
*know
Thu, 07/12/2018 - 16:50

*know