Advertisement
fishfishoohfish

SummonedBlaze

Jun 5th, 2021 (edited)
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 16.41 KB | None | 0 0
  1. package net.mcreator.fishoohfishsworldofmana.entity;
  2.  
  3. import net.minecraftforge.registries.ObjectHolder;
  4. import net.minecraftforge.registries.ForgeRegistries;
  5. import net.minecraftforge.fml.network.NetworkHooks;
  6. import net.minecraftforge.fml.network.FMLPlayMessages;
  7. import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
  8. import net.minecraftforge.fml.client.registry.RenderingRegistry;
  9. import net.minecraftforge.eventbus.api.SubscribeEvent;
  10. import net.minecraftforge.client.event.ModelRegistryEvent;
  11. import net.minecraftforge.api.distmarker.OnlyIn;
  12. import net.minecraftforge.api.distmarker.Dist;
  13.  
  14. import net.minecraft.world.World;
  15. import net.minecraft.util.math.vector.Vector3d;
  16. import net.minecraft.util.math.MathHelper;
  17. import net.minecraft.util.math.BlockPos;
  18. import net.minecraft.util.ResourceLocation;
  19. import net.minecraft.util.Hand;
  20. import net.minecraft.util.DamageSource;
  21. import net.minecraft.pathfinding.FlyingPathNavigator;
  22. import net.minecraft.particles.ParticleTypes;
  23. import net.minecraft.network.IPacket;
  24. import net.minecraft.item.SpawnEggItem;
  25. import net.minecraft.item.Items;
  26. import net.minecraft.item.ItemStack;
  27. import net.minecraft.item.ItemGroup;
  28. import net.minecraft.item.Item;
  29. import net.minecraft.entity.projectile.AbstractArrowEntity;
  30. import net.minecraft.entity.player.PlayerEntity;
  31. import net.minecraft.entity.passive.TameableEntity;
  32. import net.minecraft.entity.ai.goal.WaterAvoidingRandomWalkingGoal;
  33. import net.minecraft.entity.ai.goal.RangedAttackGoal;
  34. import net.minecraft.entity.ai.goal.RandomWalkingGoal;
  35. import net.minecraft.entity.ai.goal.OwnerHurtTargetGoal;
  36. import net.minecraft.entity.ai.goal.OwnerHurtByTargetGoal;
  37. import net.minecraft.entity.ai.goal.NearestAttackableTargetGoal;
  38. import net.minecraft.entity.ai.goal.MeleeAttackGoal;
  39. import net.minecraft.entity.ai.goal.LookRandomlyGoal;
  40. import net.minecraft.entity.ai.goal.HurtByTargetGoal;
  41. import net.minecraft.entity.ai.goal.Goal;
  42. import net.minecraft.entity.ai.goal.FollowOwnerGoal;
  43. import net.minecraft.entity.ai.controller.FlyingMovementController;
  44. import net.minecraft.entity.MobEntity;
  45. import net.minecraft.entity.LivingEntity;
  46. import net.minecraft.entity.IRendersAsItem;
  47. import net.minecraft.entity.IRangedAttackMob;
  48. import net.minecraft.entity.EntityType;
  49. import net.minecraft.entity.EntityClassification;
  50. import net.minecraft.entity.Entity;
  51. import net.minecraft.entity.CreatureAttribute;
  52. import net.minecraft.entity.AgeableEntity;
  53. import net.minecraft.client.renderer.model.ModelRenderer;
  54. import net.minecraft.client.renderer.entity.model.EntityModel;
  55. import net.minecraft.client.renderer.entity.SpriteRenderer;
  56. import net.minecraft.client.renderer.entity.MobRenderer;
  57. import net.minecraft.client.Minecraft;
  58. import net.minecraft.block.BlockState;
  59.  
  60. import net.mcreator.fishoohfishsworldofmana.procedures.PRCSummonedBlazeLifetimeProcedure;
  61. import net.mcreator.fishoohfishsworldofmana.WomModElements;
  62.  
  63. import java.util.Random;
  64. import java.util.Map;
  65. import java.util.HashMap;
  66. import java.util.EnumSet;
  67.  
  68. import com.mojang.blaze3d.vertex.IVertexBuilder;
  69. import com.mojang.blaze3d.matrix.MatrixStack;
  70.  
  71. @WomModElements.ModElement.Tag
  72. public class SummonedBlazeEntity extends WomModElements.ModElement {
  73.     public static EntityType entity = null;
  74.     @ObjectHolder("wom:entitybulletsummoned_blaze")
  75.     public static final EntityType arrow = null;
  76.     public SummonedBlazeEntity(WomModElements instance) {
  77.         super(instance, 235);
  78.         FMLJavaModLoadingContext.get().getModEventBus().register(this);
  79.     }
  80.  
  81.     @Override
  82.     public void initElements() {
  83.         entity = (EntityType.Builder.<CustomEntity>create(CustomEntity::new, EntityClassification.MONSTER).setShouldReceiveVelocityUpdates(true)
  84.                 .setTrackingRange(64).setUpdateInterval(3).setCustomClientFactory(CustomEntity::new).immuneToFire().size(0.6f, 1.8f))
  85.                         .build("summoned_blaze").setRegistryName("summoned_blaze");
  86.         elements.entities.add(() -> entity);
  87.         elements.items.add(() -> new SpawnEggItem(entity, -39373, -52480, new Item.Properties().group(ItemGroup.MISC))
  88.                 .setRegistryName("summoned_blaze_spawn_egg"));
  89.         elements.entities.add(() -> (EntityType.Builder.<ArrowCustomEntity>create(ArrowCustomEntity::new, EntityClassification.MISC)
  90.                 .setShouldReceiveVelocityUpdates(true).setTrackingRange(64).setUpdateInterval(1).setCustomClientFactory(ArrowCustomEntity::new)
  91.                 .size(0.5f, 0.5f)).build("entitybulletsummoned_blaze").setRegistryName("entitybulletsummoned_blaze"));
  92.     }
  93.  
  94.     @SubscribeEvent
  95.     @OnlyIn(Dist.CLIENT)
  96.     public void registerModels(ModelRegistryEvent event) {
  97.         RenderingRegistry.registerEntityRenderingHandler(entity, renderManager -> {
  98.             return new MobRenderer(renderManager, new ModelSummonedBlaze(), 0.5f) {
  99.                 @Override
  100.                 public ResourceLocation getEntityTexture(Entity entity) {
  101.                     return new ResourceLocation("wom:textures/blaze.png");
  102.                 }
  103.             };
  104.         });
  105.         RenderingRegistry.registerEntityRenderingHandler(arrow,
  106.                 renderManager -> new SpriteRenderer(renderManager, Minecraft.getInstance().getItemRenderer()));
  107.     }
  108.     public static class CustomEntity extends TameableEntity implements IRangedAttackMob {
  109.         public CustomEntity(FMLPlayMessages.SpawnEntity packet, World world) {
  110.             this(entity, world);
  111.         }
  112.  
  113.         public CustomEntity(EntityType<CustomEntity> type, World world) {
  114.             super(type, world);
  115.             experienceValue = 0;
  116.             setNoAI(false);
  117.             enablePersistence();
  118.             this.moveController = new FlyingMovementController(this, 10, true);
  119.             this.navigator = new FlyingPathNavigator(this, this.world);
  120.         }
  121.  
  122.         @Override
  123.         public IPacket<?> createSpawnPacket() {
  124.             return NetworkHooks.getEntitySpawningPacket(this);
  125.         }
  126.  
  127.         @Override
  128.         protected void registerGoals() {
  129.             super.registerGoals();
  130.             this.goalSelector.addGoal(1, new OwnerHurtTargetGoal(this));
  131.             this.goalSelector.addGoal(2, new OwnerHurtByTargetGoal(this));
  132.             this.goalSelector.addGoal(3, new FollowOwnerGoal(this, 1, (float) 10, (float) 2, false));
  133.             this.targetSelector.addGoal(4, new NearestAttackableTargetGoal(this, MobEntity.class, true, true));
  134.             this.goalSelector.addGoal(5, new Goal() {
  135.                 {
  136.                     this.setMutexFlags(EnumSet.of(Goal.Flag.MOVE));
  137.                 }
  138.                 public boolean shouldExecute() {
  139.                     if (CustomEntity.this.getAttackTarget() != null && !CustomEntity.this.getMoveHelper().isUpdating()) {
  140.                         return true;
  141.                     } else {
  142.                         return false;
  143.                     }
  144.                 }
  145.  
  146.                 @Override
  147.                 public boolean shouldContinueExecuting() {
  148.                     return CustomEntity.this.getMoveHelper().isUpdating() && CustomEntity.this.getAttackTarget() != null
  149.                             && CustomEntity.this.getAttackTarget().isAlive();
  150.                 }
  151.  
  152.                 @Override
  153.                 public void startExecuting() {
  154.                     LivingEntity livingentity = CustomEntity.this.getAttackTarget();
  155.                     Vector3d vec3d = livingentity.getEyePosition(1);
  156.                     CustomEntity.this.moveController.setMoveTo(vec3d.x, vec3d.y, vec3d.z, 1);
  157.                 }
  158.  
  159.                 @Override
  160.                 public void tick() {
  161.                     LivingEntity livingentity = CustomEntity.this.getAttackTarget();
  162.                     if (CustomEntity.this.getBoundingBox().intersects(livingentity.getBoundingBox())) {
  163.                         CustomEntity.this.attackEntityAsMob(livingentity);
  164.                     } else {
  165.                         double d0 = CustomEntity.this.getDistanceSq(livingentity);
  166.                         if (d0 < 16) {
  167.                             Vector3d vec3d = livingentity.getEyePosition(1);
  168.                             CustomEntity.this.moveController.setMoveTo(vec3d.x, vec3d.y, vec3d.z, 1);
  169.                         }
  170.                     }
  171.                 }
  172.             });
  173.             this.goalSelector.addGoal(6, new MeleeAttackGoal(this, 1.2, true));
  174.             this.goalSelector.addGoal(7, new RandomWalkingGoal(this, 0.8, 20) {
  175.                 @Override
  176.                 protected Vector3d getPosition() {
  177.                     Random random = CustomEntity.this.getRNG();
  178.                     double dir_x = CustomEntity.this.getPosX() + ((random.nextFloat() * 2 - 1) * 16);
  179.                     double dir_y = CustomEntity.this.getPosY() + ((random.nextFloat() * 2 - 1) * 16);
  180.                     double dir_z = CustomEntity.this.getPosZ() + ((random.nextFloat() * 2 - 1) * 16);
  181.                     return new Vector3d(dir_x, dir_y, dir_z);
  182.                 }
  183.             });
  184.             this.goalSelector.addGoal(8, new WaterAvoidingRandomWalkingGoal(this, 1));
  185.             this.targetSelector.addGoal(9, new HurtByTargetGoal(this).setCallsForHelp(this.getClass()));
  186.             this.goalSelector.addGoal(10, new LookRandomlyGoal(this));
  187.             this.goalSelector.addGoal(1, new RangedAttackGoal(this, 1.25, 20, 10) {
  188.                 @Override
  189.                 public boolean shouldContinueExecuting() {
  190.                     return this.shouldExecute();
  191.                 }
  192.             });
  193.         }
  194.  
  195.         @Override
  196.         public CreatureAttribute getCreatureAttribute() {
  197.             return CreatureAttribute.UNDEFINED;
  198.         }
  199.  
  200.         @Override
  201.         public boolean canDespawn(double distanceToClosestPlayer) {
  202.             return false;
  203.         }
  204.  
  205.         @Override
  206.         public net.minecraft.util.SoundEvent getAmbientSound() {
  207.             return (net.minecraft.util.SoundEvent) ForgeRegistries.SOUND_EVENTS.getValue(new ResourceLocation("entity.blaze.ambient"));
  208.         }
  209.  
  210.         @Override
  211.         public void playStepSound(BlockPos pos, BlockState blockIn) {
  212.             this.playSound((net.minecraft.util.SoundEvent) ForgeRegistries.SOUND_EVENTS.getValue(new ResourceLocation("entity.blaze.burn")), 0.15f,
  213.                     1);
  214.         }
  215.  
  216.         @Override
  217.         public net.minecraft.util.SoundEvent getHurtSound(DamageSource ds) {
  218.             return (net.minecraft.util.SoundEvent) ForgeRegistries.SOUND_EVENTS.getValue(new ResourceLocation("entity.blaze.hurt"));
  219.         }
  220.  
  221.         @Override
  222.         public net.minecraft.util.SoundEvent getDeathSound() {
  223.             return (net.minecraft.util.SoundEvent) ForgeRegistries.SOUND_EVENTS.getValue(new ResourceLocation("entity.blaze.death"));
  224.         }
  225.  
  226.         @Override
  227.         public boolean onLivingFall(float l, float d) {
  228.             return false;
  229.         }
  230.  
  231.         @Override
  232.         public boolean processInteract(PlayerEntity sourceentity, Hand hand) {
  233.             ItemStack itemstack = sourceentity.getHeldItem(hand);
  234.             boolean retval = true;
  235.             Item item = itemstack.getItem();
  236.             if (itemstack.getItem() instanceof SpawnEggItem) {
  237.                 retval = super.processInteract(sourceentity, hand);
  238.             } else if (this.world.isRemote) {
  239.                 retval = this.isTamed() && this.isOwner(sourceentity) || this.isBreedingItem(itemstack);
  240.             } else {
  241.                 if (this.isTamed()) {
  242.                     if (this.isOwner(sourceentity)) {
  243.                         if (item.isFood() && this.isBreedingItem(itemstack) && this.getHealth() < this.getMaxHealth()) {
  244.                             this.consumeItemFromStack(sourceentity, itemstack);
  245.                             this.heal((float) item.getFood().getHealing());
  246.                             retval = true;
  247.                         } else if (this.isBreedingItem(itemstack) && this.getHealth() < this.getMaxHealth()) {
  248.                             this.consumeItemFromStack(sourceentity, itemstack);
  249.                             this.heal(4);
  250.                             retval = true;
  251.                         } else {
  252.                             retval = super.processInteract(sourceentity, hand);
  253.                         }
  254.                     }
  255.                 } else if (this.isBreedingItem(itemstack)) {
  256.                     this.consumeItemFromStack(sourceentity, itemstack);
  257.                     if (this.rand.nextInt(3) == 0 && !net.minecraftforge.event.ForgeEventFactory.onAnimalTame(this, sourceentity)) {
  258.                         this.setTamedBy(sourceentity);
  259.                         this.world.setEntityState(this, (byte) 7);
  260.                     } else {
  261.                         this.world.setEntityState(this, (byte) 6);
  262.                     }
  263.                     this.enablePersistence();
  264.                     retval = true;
  265.                 } else {
  266.                     retval = super.processInteract(sourceentity, hand);
  267.                     if (retval)
  268.                         this.enablePersistence();
  269.                 }
  270.             }
  271.             double x = this.getPosX();
  272.             double y = this.getPosY();
  273.             double z = this.getPosZ();
  274.             Entity entity = this;
  275.             return retval;
  276.         }
  277.  
  278.         @Override
  279.         public void baseTick() {
  280.             super.baseTick();
  281.             double x = this.getPosX();
  282.             double y = this.getPosY();
  283.             double z = this.getPosZ();
  284.             Entity entity = this;
  285.             {
  286.                 Map<String, Object> $_dependencies = new HashMap<>();
  287.                 $_dependencies.put("entity", entity);
  288.                 PRCSummonedBlazeLifetimeProcedure.executeProcedure($_dependencies);
  289.             }
  290.         }
  291.  
  292.         @Override
  293.         protected void registerAttributes() {
  294.             super.registerAttributes();
  295.             if (this.getAttribute(SharedMonsterAttributes.MOVEMENT_SPEED) != null)
  296.                 this.getAttribute(SharedMonsterAttributes.MOVEMENT_SPEED).setBaseValue(0.3);
  297.             if (this.getAttribute(SharedMonsterAttributes.MAX_HEALTH) != null)
  298.                 this.getAttribute(SharedMonsterAttributes.MAX_HEALTH).setBaseValue(10);
  299.             if (this.getAttribute(SharedMonsterAttributes.ARMOR) != null)
  300.                 this.getAttribute(SharedMonsterAttributes.ARMOR).setBaseValue(0);
  301.             if (this.getAttribute(SharedMonsterAttributes.ATTACK_DAMAGE) == null)
  302.                 this.getAttributes().registerAttribute(SharedMonsterAttributes.ATTACK_DAMAGE);
  303.             this.getAttribute(SharedMonsterAttributes.ATTACK_DAMAGE).setBaseValue(3);
  304.             if (this.getAttribute(SharedMonsterAttributes.FLYING_SPEED) == null)
  305.                 this.getAttributes().registerAttribute(SharedMonsterAttributes.FLYING_SPEED);
  306.             this.getAttribute(SharedMonsterAttributes.FLYING_SPEED).setBaseValue(0.3);
  307.         }
  308.  
  309.         public void attackEntityWithRangedAttack(LivingEntity target, float flval) {
  310.             ArrowCustomEntity entityarrow = new ArrowCustomEntity(arrow, this, this.world);
  311.             double d0 = target.getPosY() + (double) target.getEyeHeight() - 1.1;
  312.             double d1 = target.getPosX() - this.getPosX();
  313.             double d3 = target.getPosZ() - this.getPosZ();
  314.             entityarrow.shoot(d1, d0 - entityarrow.getPosY() + (double) MathHelper.sqrt(d1 * d1 + d3 * d3) * 0.2F, d3, 1.6F, 12.0F);
  315.             world.addEntity(entityarrow);
  316.         }
  317.  
  318.         @Override
  319.         public AgeableEntity createChild(AgeableEntity ageable) {
  320.             return (CustomEntity) entity.create(this.world);
  321.         }
  322.  
  323.         @Override
  324.         public boolean isBreedingItem(ItemStack stack) {
  325.             if (stack == null)
  326.                 return false;
  327.             return false;
  328.         }
  329.  
  330.         @Override
  331.         protected void updateFallState(double y, boolean onGroundIn, BlockState state, BlockPos pos) {
  332.         }
  333.  
  334.         @Override
  335.         public void setNoGravity(boolean ignored) {
  336.             super.setNoGravity(true);
  337.         }
  338.  
  339.         public void livingTick() {
  340.             super.livingTick();
  341.             this.setNoGravity(true);
  342.             double x = this.getPosX();
  343.             double y = this.getPosY();
  344.             double z = this.getPosZ();
  345.             Random random = this.rand;
  346.             Entity entity = this;
  347.             if (true)
  348.                 for (int l = 0; l < 4; ++l) {
  349.                     double d0 = (x + random.nextFloat());
  350.                     double d1 = (y + random.nextFloat());
  351.                     double d2 = (z + random.nextFloat());
  352.                     int i1 = random.nextInt(2) * 2 - 1;
  353.                     double d3 = (random.nextFloat() - 0.5D) * 0.5D;
  354.                     double d4 = (random.nextFloat() - 0.5D) * 0.5D;
  355.                     double d5 = (random.nextFloat() - 0.5D) * 0.5D;
  356.                     world.addParticle(ParticleTypes.SMOKE, d0, d1, d2, d3, d4, d5);
  357.                 }
  358.         }
  359.     }
  360.  
  361.     @OnlyIn(value = Dist.CLIENT, _interface = IRendersAsItem.class)
  362.     private static class ArrowCustomEntity extends AbstractArrowEntity implements IRendersAsItem {
  363.         public ArrowCustomEntity(FMLPlayMessages.SpawnEntity packet, World world) {
  364.             super(arrow, world);
  365.         }
  366.  
  367.         public ArrowCustomEntity(EntityType<? extends ArrowCustomEntity> type, World world) {
  368.             super(type, world);
  369.         }
  370.  
  371.         public ArrowCustomEntity(EntityType<? extends ArrowCustomEntity> type, double x, double y, double z, World world) {
  372.             super(type, x, y, z, world);
  373.         }
  374.  
  375.         public ArrowCustomEntity(EntityType<? extends ArrowCustomEntity> type, LivingEntity entity, World world) {
  376.             super(type, entity, world);
  377.         }
  378.  
  379.         @Override
  380.         public IPacket<?> createSpawnPacket() {
  381.             return NetworkHooks.getEntitySpawningPacket(this);
  382.         }
  383.  
  384.         @Override
  385.         @OnlyIn(Dist.CLIENT)
  386.         public ItemStack getItem() {
  387.             return new ItemStack(Items.FIRE_CHARGE, (int) (1));
  388.         }
  389.  
  390.         @Override
  391.         protected ItemStack getArrowStack() {
  392.             return new ItemStack(Items.FIRE_CHARGE, (int) (1));
  393.         }
  394.     }
  395.  
  396.     // Made with Blockbench 3.8.4
  397.     // Exported for Minecraft version 1.15 - 1.16
  398.     // Paste this class into your mod and generate all required imports
  399.     public static class ModelSummonedBlaze extends EntityModel<Entity> {
  400.         private final ModelRenderer Head;
  401.         public ModelSummonedBlaze() {
  402.             textureWidth = 16;
  403.             textureHeight = 16;
  404.             Head = new ModelRenderer(this);
  405.             Head.setRotationPoint(0.0F, 24.0F, 0.0F);
  406.             Head.setTextureOffset(0, 3).addBox(-1.0F, -3.0F, -1.0F, 2.0F, 2.0F, 2.0F, 0.0F, false);
  407.         }
  408.  
  409.         @Override
  410.         public void render(MatrixStack matrixStack, IVertexBuilder buffer, int packedLight, int packedOverlay, float red, float green, float blue,
  411.                 float alpha) {
  412.             Head.render(matrixStack, buffer, packedLight, packedOverlay);
  413.         }
  414.  
  415.         public void setRotationAngle(ModelRenderer modelRenderer, float x, float y, float z) {
  416.             modelRenderer.rotateAngleX = x;
  417.             modelRenderer.rotateAngleY = y;
  418.             modelRenderer.rotateAngleZ = z;
  419.         }
  420.  
  421.         public void setRotationAngles(Entity e, float f, float f1, float f2, float f3, float f4) {
  422.             this.Head.rotateAngleY = f3 / (180F / (float) Math.PI);
  423.             this.Head.rotateAngleX = f4 / (180F / (float) Math.PI);
  424.         }
  425.     }
  426. }
  427.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement