Help to join 2 code pieces

Started by gustavowizard123 on

Topic category: Help with modding (Java Edition)

Last seen on 19:53, 2. Jun 2021
Joined Sep 2016
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Help to join 2 code pieces

guys im trying to make my water mob here to die in land (air) and to swim faster (using dolphin grace), i got 2 update ticks here, but when i use both on the code i got errors (cant use both of the same type) and when i try to merge only one of them work; these are the 2 parts i want to join:

 

PART 1 (Fish die on land):

protected void updateAir(int p_209207_1_) {
      	if (this.isAlive() && !this.isInWaterOrBubbleColumn()) {
         this.setAir(p_209207_1_ - 1);
         if (this.getAir() == -20) {
            this.setAir(0);
            this.attackEntityFrom(DamageSource.DROWN, 2.0F);
         	}
     		 } else {
         this.setAir(300);
      		}

   		}

   		public void baseTick() {
      	int i = this.getAir();
      	super.baseTick();
      	this.updateAir(i);
   	   }

 

 

PART 2 (fish swim faster): - its a procedure this one

@Override
		public void baseTick() {
			super.baseTick();
			int x = (int) this.getPosX();
			int y = (int) this.getPosY();
			int z = (int) this.getPosZ();
			Entity entity = this;
			{
				java.util.HashMap<String, Object> $_dependencies = new java.util.HashMap<>();
				$_dependencies.put("entity", entity);
				PenguinGentooOnEntityTickUpdateProcedure.executeProcedure($_dependencies);
			}
		}

 

Last seen on 03:10, 19. Feb 2022
Joined Jun 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
why do you need to code this…
Sat, 07/04/2020 - 01:13

why do you need to code this... you can literally check for air and/or give potion effects with procedures...

Last seen on 19:53, 2. Jun 2021
Joined Sep 2016
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
i can make the 1st code on…
Sat, 07/04/2020 - 01:59

i can make the 1st code on procedure? cool but i dont know how, sounds complicated :O

Last seen on 03:10, 19. Feb 2022
Joined Jun 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
yeah, just do on mob tick…
Sat, 07/04/2020 - 02:42

yeah, just do on mob tick update trigger, check for block at x y z and x y+1 z (for 2 block tall mobs), and if the blocks are air, deal damage to entity

Last seen on 19:53, 2. Jun 2021
Joined Sep 2016
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
i did just like that and my…
Sat, 07/04/2020 - 03:44

i did just like that and my world crashed even before loading :/

 

Last seen on 19:53, 2. Jun 2021
Joined Sep 2016
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
top part works ok
Sat, 07/04/2020 - 03:50

top part works ok

Last seen on 03:10, 19. Feb 2022
Joined Jun 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
drowning damage doesn't work…
Sat, 07/04/2020 - 04:30

drowning damage doesn't work on ocean mobs lmao

switch the damage type to generic or something

Last seen on 19:53, 2. Jun 2021
Joined Sep 2016
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
yeah i did it aint work…
Sat, 07/04/2020 - 06:41

yeah i did it aint work anyway (it crashes the game before i create the world), i must be missing something here...

and strangly, drown damage do damage water mobs, look this code here on shark:

 

//DIE ON LAND CODE - REPLACE DROWN CODE WITH THIS
        protected void updateAir(int p_209207_1_) {
          if (this.isAlive() && !this.isInWaterOrBubbleColumn()) {
         this.setAir(p_209207_1_ - 1);
         if (this.getAir() == -20) {
            this.setAir(0);
            this.attackEntityFrom(DamageSource.DROWN, 2.0F);   <---------------------------------------
             }
              } else {
         this.setAir(300);
              }

           }

           public void baseTick() {
          int i = this.getAir();
          super.baseTick();
          this.updateAir(i);
          }
        // DIE ON LAND END

 

Last seen on 19:53, 2. Jun 2021
Joined Sep 2016
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
i tried now as a separete…
Sat, 07/04/2020 - 07:07

i tried now as a separete procedure but nothing happens, i think its not that simple as i tought

Last seen on 19:53, 2. Jun 2021
Joined Sep 2016
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
i replace 'while do' for 'if…
Sat, 07/04/2020 - 07:26

i replace 'while do' for 'if do', and it works, (while was crashing the game on super fast loops i guess), but now all i can do is kill the mob in 1 blow..hum..

Last seen on 19:53, 2. Jun 2021
Joined Sep 2016
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
it worked like that, almost…
Sat, 07/04/2020 - 07:52

it worked like that, almost perfect:

h

Last seen on 19:53, 2. Jun 2021
Joined Sep 2016
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
the only variable that i…
Sat, 07/04/2020 - 07:53

the only variable that i cant reach here is the Time betheewen the repeat loops there, its very fast, when i open the code i see this suspicious '-1' there, anybody can explain me what it is?

 

if (((world.isAirBlock(new BlockPos((int) x, (int) y, (int) z))) == (true))) {
			if ((((entity instanceof LivingEntity) ? ((LivingEntity) entity).getHealth() : -1) > 0)) {
				for (int index0 = 0; index0 < (int) (35); index0++) {
					entity.attackEntityFrom(DamageSource.GENERIC, (float) 3);
				}
			}
		}

 

Last seen on 14:43, 2. Aug 2022
Joined Nov 2018
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I assume it takes away 1…
Mon, 07/27/2020 - 15:04

I assume it takes away 1 from the health.