package net.mcreator.zombiemobs.entity;

import net.mcreator.zombiemobs.procedures.ZomWaterSpawnProcedure;
import net.minecraft.util.RandomSource;
import net.minecraft.core.BlockPos;
import net.minecraft.world.entity.MobSpawnType;
import net.minecraft.world.level.ServerLevelAccessor;
import net.minecraftforge.common.ForgeMod;
import net.minecraft.world.entity.ai.attributes.Attribute;
import net.minecraft.world.entity.ai.attributes.AttributeSupplier;
import net.minecraft.world.level.levelgen.Heightmap;
import net.minecraft.world.entity.SpawnPlacements;
import net.minecraft.world.level.LevelReader;
import net.mcreator.zombiemobs.procedures.ZombieDolphinOnEntityTickUpdateProcedure;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.resources.ResourceLocation;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraft.sounds.SoundEvent;
import net.minecraft.world.entity.MobType;
import net.minecraft.world.entity.ai.goal.RandomSwimmingGoal;
import net.minecraft.world.entity.ai.goal.target.HurtByTargetGoal;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.PathfinderMob;
import net.minecraft.world.entity.ai.goal.MeleeAttackGoal;
import net.minecraft.world.level.LevelAccessor;
import net.mcreator.zombiemobs.procedures.GameRuleAnimalsProcedure;
import net.minecraft.world.entity.animal.Dolphin;
import net.minecraft.world.entity.npc.Villager;
import net.minecraft.world.entity.ai.goal.Goal;
import net.minecraft.world.entity.ai.goal.target.NearestAttackableTargetGoal;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.entity.ai.navigation.WaterBoundPathNavigation;
import net.minecraft.world.entity.ai.navigation.PathNavigation;
import net.minecraft.world.entity.Entity;
import net.minecraftforge.network.NetworkHooks;
import net.minecraft.network.protocol.Packet;
import net.minecraft.world.entity.ai.attributes.Attributes;
import net.minecraft.util.Mth;
import net.minecraft.world.entity.Mob;
import net.minecraft.world.entity.ai.control.MoveControl;
import net.minecraft.world.level.pathfinder.BlockPathTypes;
import net.mcreator.zombiemobs.init.ZombiemobsModEntities;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.level.Level;
import net.minecraftforge.network.PlayMessages;
import net.minecraft.world.entity.monster.Monster;

public class ZombieDolphinEntity extends Monster
{
    public ZombieDolphinEntity(final PlayMessages.SpawnEntity packet, final Level world) {
        this((EntityType<ZombieDolphinEntity>)ZombiemobsModEntities.ZOMBIE_DOLPHIN.get(), world);
    }
    
    public ZombieDolphinEntity(final EntityType<ZombieDolphinEntity> type, final Level world) {
        super((EntityType)type, world);
        this.f_21364_ = 6;
        this.m_21557_(false);
        this.m_21441_(BlockPathTypes.WATER, 0.0f);
        this.f_21342_ = new MoveControl(this) {
            public void m_8126_() {
                if (ZombieDolphinEntity.this.m_20069_()) {
                    ZombieDolphinEntity.this.m_20256_(ZombieDolphinEntity.this.m_20184_().m_82520_(0.0, 0.005, 0.0));
                }
                if (this.f_24981_ == MoveControl.Operation.MOVE_TO && !ZombieDolphinEntity.this.m_21573_().m_26571_()) {
                    final double dx = this.f_24975_ - ZombieDolphinEntity.this.m_20185_();
                    final double dy = this.f_24976_ - ZombieDolphinEntity.this.m_20186_();
                    final double dz = this.f_24977_ - ZombieDolphinEntity.this.m_20189_();
                    final float f = (float)(Mth.m_14136_(dz, dx) * 57.29577951308232) - 90.0f;
                    final float f2 = (float)(this.f_24978_ * ZombieDolphinEntity.this.m_21051_(Attributes.f_22279_).m_22135_());
                    ZombieDolphinEntity.this.m_146922_(this.m_24991_(ZombieDolphinEntity.this.m_146908_(), f, 10.0f));
                    ZombieDolphinEntity.this.f_20883_ = ZombieDolphinEntity.this.m_146908_();
                    ZombieDolphinEntity.this.f_20885_ = ZombieDolphinEntity.this.m_146908_();
                    if (ZombieDolphinEntity.this.m_20069_()) {
                        ZombieDolphinEntity.this.m_7910_((float)ZombieDolphinEntity.this.m_21051_(Attributes.f_22279_).m_22135_());
                        float f3 = -(float)(Mth.m_14136_(dy, (double)(float)Math.sqrt(dx * dx + dz * dz)) * 57.29577951308232);
                        f3 = Mth.m_14036_(Mth.m_14177_(f3), -85.0f, 85.0f);
                        ZombieDolphinEntity.this.m_146926_(this.m_24991_(ZombieDolphinEntity.this.m_146909_(), f3, 5.0f));
                        final float f4 = Mth.m_14089_(ZombieDolphinEntity.this.m_146909_() * 0.017453292f);
                        ZombieDolphinEntity.this.m_21564_(f4 * f2);
                        ZombieDolphinEntity.this.m_21567_((float)(f2 * dy));
                    }
                    else {
                        ZombieDolphinEntity.this.m_7910_(f2 * 0.05f);
                    }
                }
                else {
                    ZombieDolphinEntity.this.m_7910_(0.0f);
                    ZombieDolphinEntity.this.m_21567_(0.0f);
                    ZombieDolphinEntity.this.m_21564_(0.0f);
                }
            }
        };
    }
    
    public Packet<?> m_5654_() {
        return (Packet<?>)NetworkHooks.getEntitySpawningPacket((Entity)this);
    }
    
    protected PathNavigation m_6037_(final Level world) {
        return (PathNavigation)new WaterBoundPathNavigation((Mob)this, world);
    }
    
    protected void m_8099_() {
        super.m_8099_();
        this.f_21346_.m_25352_(1, (Goal)new NearestAttackableTargetGoal((Mob)this, (Class)Player.class, false, false));
        this.f_21346_.m_25352_(2, (Goal)new NearestAttackableTargetGoal((Mob)this, (Class)Villager.class, false, false));
        this.f_21346_.m_25352_(3, (Goal)new NearestAttackableTargetGoal(this, Dolphin.class, false, false) {
            public boolean m_8036_() {
                final double x = ZombieDolphinEntity.this.m_20185_();
                final double y = ZombieDolphinEntity.this.m_20186_();
                final double z = ZombieDolphinEntity.this.m_20189_();
                final Entity entity = (Entity)ZombieDolphinEntity.this;
                final Level world = ZombieDolphinEntity.this.f_19853_;
                return super.m_8036_() && GameRuleAnimalsProcedure.execute((LevelAccessor)world);
            }
            
            public boolean m_8045_() {
                final double x = ZombieDolphinEntity.this.m_20185_();
                final double y = ZombieDolphinEntity.this.m_20186_();
                final double z = ZombieDolphinEntity.this.m_20189_();
                final Entity entity = (Entity)ZombieDolphinEntity.this;
                final Level world = ZombieDolphinEntity.this.f_19853_;
                return super.m_8045_() && GameRuleAnimalsProcedure.execute((LevelAccessor)world);
            }
        });
        this.f_21345_.m_25352_(4, (Goal)new MeleeAttackGoal(this, 3.0, false) {
            protected double m_6639_(final LivingEntity entity) {
                return 4.0 + entity.m_20205_() * entity.m_20205_();
            }
        });
        this.f_21346_.m_25352_(5, (Goal)new HurtByTargetGoal((PathfinderMob)this, new Class[0]));
        this.f_21345_.m_25352_(6, (Goal)new RandomSwimmingGoal((PathfinderMob)this, 1.0, 40));
    }
    
    public MobType m_6336_() {
        return MobType.f_21644_;
    }
    
    public SoundEvent m_7515_() {
        return (SoundEvent)ForgeRegistries.SOUND_EVENTS.getValue(new ResourceLocation("entity.squid.ambient"));
    }
    
    public SoundEvent m_7975_(final DamageSource ds) {
        return (SoundEvent)ForgeRegistries.SOUND_EVENTS.getValue(new ResourceLocation(""));
    }
    
    public SoundEvent m_5592_() {
        return (SoundEvent)ForgeRegistries.SOUND_EVENTS.getValue(new ResourceLocation(""));
    }
    
    public boolean m_6469_(final DamageSource source, final float amount) {
        return source != DamageSource.f_19312_ && super.m_6469_(source, amount);
    }
    
    public void m_6075_() {
        super.m_6075_();
        ZombieDolphinOnEntityTickUpdateProcedure.execute((Entity)this);
    }
    
    public boolean m_6040_() {
        return true;
    }
    
    public boolean m_6914_(final LevelReader world) {
        return world.m_45784_((Entity)this);
    }
    
    public boolean m_6063_() {
        return false;
    }
    
    public static void init() {
        SpawnPlacements.m_21754_((EntityType)ZombiemobsModEntities.ZOMBIE_DOLPHIN.get(), SpawnPlacements.Type.IN_WATER, Heightmap.Types.MOTION_BLOCKING_NO_LEAVES, (entityType, world, reason, pos, random) -> {
            final int x = pos.m_123341_();
            final int y = pos.m_123342_();
            final int z = pos.m_123343_();
            return ZomWaterSpawnProcedure.execute((LevelAccessor)world);
        });
    }
    
    public static AttributeSupplier.Builder createAttributes() {
        AttributeSupplier.Builder builder = Mob.m_21552_();
        builder = builder.m_22268_(Attributes.f_22279_, 0.8);
        builder = builder.m_22268_(Attributes.f_22276_, 12.0);
        builder = builder.m_22268_(Attributes.f_22284_, 0.0);
        builder = builder.m_22268_(Attributes.f_22281_, 3.0);
        builder = builder.m_22268_(Attributes.f_22277_, 12.0);
        builder = builder.m_22268_(Attributes.f_22278_, 0.7);
        builder = builder.m_22268_((Attribute)ForgeMod.SWIM_SPEED.get(), 0.6);
        return builder;
    }
}
 

C Language online compiler

Write, Run & Share C Language code online using OneCompiler's C online compiler for free. It's one of the robust, feature-rich online compilers for C language, running the latest C version which is C18. Getting started with the OneCompiler's C editor is really simple and pretty fast. The editor shows sample boilerplate code when you choose language as 'C' and start coding!

Read inputs from stdin

OneCompiler's C online editor supports stdin and users can give inputs to programs using the STDIN textbox under the I/O tab. Following is a sample C program which takes name as input and print your name with hello.

#include <stdio.h>
int main()
{
    char name[50];
    printf("Enter name:");
    scanf("%s", name);
    printf("Hello %s \n" , name );
    return 0;
    
}

About C

C language is one of the most popular general-purpose programming language developed by Dennis Ritchie at Bell laboratories for UNIX operating system. The initial release of C Language was in the year 1972. Most of the desktop operating systems are written in C Language.

Key features:

  • Structured Programming
  • Popular system programming language
  • UNIX, MySQL and Oracle are completely written in C.
  • Supports variety of platforms
  • Efficient and also handle low-level activities.
  • As fast as assembly language and hence used as system development language.

Syntax help

Loops

1. If-Else:

When ever you want to perform a set of operations based on a condition if-else is used.

if(conditional-expression) {
   // code
} else {
   // code
}

You can also use if-else for nested Ifs and if-else-if ladder when multiple conditions are to be performed on a single variable.

2. Switch:

Switch is an alternative to if-else-if ladder.

switch(conditional-expression) {    
case value1:    
 // code    
 break;  // optional  
case value2:    
 // code    
 break;  // optional  
...    
    
default:     
 // code to be executed when all the above cases are not matched;    
} 

3. For:

For loop is used to iterate a set of statements based on a condition.

for(Initialization; Condition; Increment/decrement){  
  // code  
} 

4. While:

While is also used to iterate a set of statements based on a condition. Usually while is preferred when number of iterations are not known in advance.

while(condition) {  
 // code 
}  

5. Do-While:

Do-while is also used to iterate a set of statements based on a condition. It is mostly used when you need to execute the statements atleast once.

do {
  // code 
} while (condition); 

Arrays

Array is a collection of similar data which is stored in continuous memory addresses. Array values can be fetched using index. Index starts from 0 to size-1.

Syntax

One dimentional Array:

data-type array-name[size];

Two dimensional array:

data-type array-name[size][size];

Functions

Function is a sub-routine which contains set of statements. Usually functions are written when multiple calls are required to same set of statements which increases re-usuability and modularity.

Two types of functions are present in C

  1. Library Functions:

Library functions are the in-built functions which are declared in header files like printf(),scanf(),puts(),gets() etc.,

  1. User defined functions:

User defined functions are the ones which are written by the programmer based on the requirement.

How to declare a Function

return_type function_name(parameters);

How to call a Function

function_name (parameters)

How to define a Function

return_type function_name(parameters) {  
  //code
}