Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package net.mcreator.fishoohfishsworldofmana.entity;
- import net.minecraftforge.registries.ObjectHolder;
- import net.minecraftforge.registries.ForgeRegistries;
- import net.minecraftforge.fml.network.NetworkHooks;
- import net.minecraftforge.fml.network.FMLPlayMessages;
- import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
- import net.minecraftforge.fml.client.registry.RenderingRegistry;
- import net.minecraftforge.eventbus.api.SubscribeEvent;
- import net.minecraftforge.client.event.ModelRegistryEvent;
- import net.minecraftforge.api.distmarker.OnlyIn;
- import net.minecraftforge.api.distmarker.Dist;
- import net.minecraft.world.World;
- import net.minecraft.util.math.vector.Vector3d;
- import net.minecraft.util.math.MathHelper;
- import net.minecraft.util.math.BlockPos;
- import net.minecraft.util.ResourceLocation;
- import net.minecraft.util.Hand;
- import net.minecraft.util.DamageSource;
- import net.minecraft.pathfinding.FlyingPathNavigator;
- import net.minecraft.particles.ParticleTypes;
- import net.minecraft.network.IPacket;
- import net.minecraft.item.SpawnEggItem;
- import net.minecraft.item.Items;
- import net.minecraft.item.ItemStack;
- import net.minecraft.item.ItemGroup;
- import net.minecraft.item.Item;
- import net.minecraft.entity.projectile.AbstractArrowEntity;
- import net.minecraft.entity.player.PlayerEntity;
- import net.minecraft.entity.passive.TameableEntity;
- import net.minecraft.entity.ai.goal.WaterAvoidingRandomWalkingGoal;
- import net.minecraft.entity.ai.goal.RangedAttackGoal;
- import net.minecraft.entity.ai.goal.RandomWalkingGoal;
- import net.minecraft.entity.ai.goal.OwnerHurtTargetGoal;
- import net.minecraft.entity.ai.goal.OwnerHurtByTargetGoal;
- import net.minecraft.entity.ai.goal.NearestAttackableTargetGoal;
- import net.minecraft.entity.ai.goal.MeleeAttackGoal;
- import net.minecraft.entity.ai.goal.LookRandomlyGoal;
- import net.minecraft.entity.ai.goal.HurtByTargetGoal;
- import net.minecraft.entity.ai.goal.Goal;
- import net.minecraft.entity.ai.goal.FollowOwnerGoal;
- import net.minecraft.entity.ai.controller.FlyingMovementController;
- import net.minecraft.entity.MobEntity;
- import net.minecraft.entity.LivingEntity;
- import net.minecraft.entity.IRendersAsItem;
- import net.minecraft.entity.IRangedAttackMob;
- import net.minecraft.entity.EntityType;
- import net.minecraft.entity.EntityClassification;
- import net.minecraft.entity.Entity;
- import net.minecraft.entity.CreatureAttribute;
- import net.minecraft.entity.AgeableEntity;
- import net.minecraft.client.renderer.model.ModelRenderer;
- import net.minecraft.client.renderer.entity.model.EntityModel;
- import net.minecraft.client.renderer.entity.SpriteRenderer;
- import net.minecraft.client.renderer.entity.MobRenderer;
- import net.minecraft.client.Minecraft;
- import net.minecraft.block.BlockState;
- import net.mcreator.fishoohfishsworldofmana.procedures.PRCSummonedBlazeLifetimeProcedure;
- import net.mcreator.fishoohfishsworldofmana.WomModElements;
- import java.util.Random;
- import java.util.Map;
- import java.util.HashMap;
- import java.util.EnumSet;
- import com.mojang.blaze3d.vertex.IVertexBuilder;
- import com.mojang.blaze3d.matrix.MatrixStack;
- @WomModElements.ModElement.Tag
- public class SummonedBlazeEntity extends WomModElements.ModElement {
- public static EntityType entity = null;
- @ObjectHolder("wom:entitybulletsummoned_blaze")
- public static final EntityType arrow = null;
- public SummonedBlazeEntity(WomModElements instance) {
- super(instance, 235);
- FMLJavaModLoadingContext.get().getModEventBus().register(this);
- }
- @Override
- public void initElements() {
- entity = (EntityType.Builder.<CustomEntity>create(CustomEntity::new, EntityClassification.MONSTER).setShouldReceiveVelocityUpdates(true)
- .setTrackingRange(64).setUpdateInterval(3).setCustomClientFactory(CustomEntity::new).immuneToFire().size(0.6f, 1.8f))
- .build("summoned_blaze").setRegistryName("summoned_blaze");
- elements.entities.add(() -> entity);
- elements.items.add(() -> new SpawnEggItem(entity, -39373, -52480, new Item.Properties().group(ItemGroup.MISC))
- .setRegistryName("summoned_blaze_spawn_egg"));
- elements.entities.add(() -> (EntityType.Builder.<ArrowCustomEntity>create(ArrowCustomEntity::new, EntityClassification.MISC)
- .setShouldReceiveVelocityUpdates(true).setTrackingRange(64).setUpdateInterval(1).setCustomClientFactory(ArrowCustomEntity::new)
- .size(0.5f, 0.5f)).build("entitybulletsummoned_blaze").setRegistryName("entitybulletsummoned_blaze"));
- }
- @SubscribeEvent
- @OnlyIn(Dist.CLIENT)
- public void registerModels(ModelRegistryEvent event) {
- RenderingRegistry.registerEntityRenderingHandler(entity, renderManager -> {
- return new MobRenderer(renderManager, new ModelSummonedBlaze(), 0.5f) {
- @Override
- public ResourceLocation getEntityTexture(Entity entity) {
- return new ResourceLocation("wom:textures/blaze.png");
- }
- };
- });
- RenderingRegistry.registerEntityRenderingHandler(arrow,
- renderManager -> new SpriteRenderer(renderManager, Minecraft.getInstance().getItemRenderer()));
- }
- public static class CustomEntity extends TameableEntity implements IRangedAttackMob {
- public CustomEntity(FMLPlayMessages.SpawnEntity packet, World world) {
- this(entity, world);
- }
- public CustomEntity(EntityType<CustomEntity> type, World world) {
- super(type, world);
- experienceValue = 0;
- setNoAI(false);
- enablePersistence();
- this.moveController = new FlyingMovementController(this, 10, true);
- this.navigator = new FlyingPathNavigator(this, this.world);
- }
- @Override
- public IPacket<?> createSpawnPacket() {
- return NetworkHooks.getEntitySpawningPacket(this);
- }
- @Override
- protected void registerGoals() {
- super.registerGoals();
- this.goalSelector.addGoal(1, new OwnerHurtTargetGoal(this));
- this.goalSelector.addGoal(2, new OwnerHurtByTargetGoal(this));
- this.goalSelector.addGoal(3, new FollowOwnerGoal(this, 1, (float) 10, (float) 2, false));
- this.targetSelector.addGoal(4, new NearestAttackableTargetGoal(this, MobEntity.class, true, true));
- this.goalSelector.addGoal(5, new Goal() {
- {
- this.setMutexFlags(EnumSet.of(Goal.Flag.MOVE));
- }
- public boolean shouldExecute() {
- if (CustomEntity.this.getAttackTarget() != null && !CustomEntity.this.getMoveHelper().isUpdating()) {
- return true;
- } else {
- return false;
- }
- }
- @Override
- public boolean shouldContinueExecuting() {
- return CustomEntity.this.getMoveHelper().isUpdating() && CustomEntity.this.getAttackTarget() != null
- && CustomEntity.this.getAttackTarget().isAlive();
- }
- @Override
- public void startExecuting() {
- LivingEntity livingentity = CustomEntity.this.getAttackTarget();
- Vector3d vec3d = livingentity.getEyePosition(1);
- CustomEntity.this.moveController.setMoveTo(vec3d.x, vec3d.y, vec3d.z, 1);
- }
- @Override
- public void tick() {
- LivingEntity livingentity = CustomEntity.this.getAttackTarget();
- if (CustomEntity.this.getBoundingBox().intersects(livingentity.getBoundingBox())) {
- CustomEntity.this.attackEntityAsMob(livingentity);
- } else {
- double d0 = CustomEntity.this.getDistanceSq(livingentity);
- if (d0 < 16) {
- Vector3d vec3d = livingentity.getEyePosition(1);
- CustomEntity.this.moveController.setMoveTo(vec3d.x, vec3d.y, vec3d.z, 1);
- }
- }
- }
- });
- this.goalSelector.addGoal(6, new MeleeAttackGoal(this, 1.2, true));
- this.goalSelector.addGoal(7, new RandomWalkingGoal(this, 0.8, 20) {
- @Override
- protected Vector3d getPosition() {
- Random random = CustomEntity.this.getRNG();
- double dir_x = CustomEntity.this.getPosX() + ((random.nextFloat() * 2 - 1) * 16);
- double dir_y = CustomEntity.this.getPosY() + ((random.nextFloat() * 2 - 1) * 16);
- double dir_z = CustomEntity.this.getPosZ() + ((random.nextFloat() * 2 - 1) * 16);
- return new Vector3d(dir_x, dir_y, dir_z);
- }
- });
- this.goalSelector.addGoal(8, new WaterAvoidingRandomWalkingGoal(this, 1));
- this.targetSelector.addGoal(9, new HurtByTargetGoal(this).setCallsForHelp(this.getClass()));
- this.goalSelector.addGoal(10, new LookRandomlyGoal(this));
- this.goalSelector.addGoal(1, new RangedAttackGoal(this, 1.25, 20, 10) {
- @Override
- public boolean shouldContinueExecuting() {
- return this.shouldExecute();
- }
- });
- }
- @Override
- public CreatureAttribute getCreatureAttribute() {
- return CreatureAttribute.UNDEFINED;
- }
- @Override
- public boolean canDespawn(double distanceToClosestPlayer) {
- return false;
- }
- @Override
- public net.minecraft.util.SoundEvent getAmbientSound() {
- return (net.minecraft.util.SoundEvent) ForgeRegistries.SOUND_EVENTS.getValue(new ResourceLocation("entity.blaze.ambient"));
- }
- @Override
- public void playStepSound(BlockPos pos, BlockState blockIn) {
- this.playSound((net.minecraft.util.SoundEvent) ForgeRegistries.SOUND_EVENTS.getValue(new ResourceLocation("entity.blaze.burn")), 0.15f,
- 1);
- }
- @Override
- public net.minecraft.util.SoundEvent getHurtSound(DamageSource ds) {
- return (net.minecraft.util.SoundEvent) ForgeRegistries.SOUND_EVENTS.getValue(new ResourceLocation("entity.blaze.hurt"));
- }
- @Override
- public net.minecraft.util.SoundEvent getDeathSound() {
- return (net.minecraft.util.SoundEvent) ForgeRegistries.SOUND_EVENTS.getValue(new ResourceLocation("entity.blaze.death"));
- }
- @Override
- public boolean onLivingFall(float l, float d) {
- return false;
- }
- @Override
- public boolean processInteract(PlayerEntity sourceentity, Hand hand) {
- ItemStack itemstack = sourceentity.getHeldItem(hand);
- boolean retval = true;
- Item item = itemstack.getItem();
- if (itemstack.getItem() instanceof SpawnEggItem) {
- retval = super.processInteract(sourceentity, hand);
- } else if (this.world.isRemote) {
- retval = this.isTamed() && this.isOwner(sourceentity) || this.isBreedingItem(itemstack);
- } else {
- if (this.isTamed()) {
- if (this.isOwner(sourceentity)) {
- if (item.isFood() && this.isBreedingItem(itemstack) && this.getHealth() < this.getMaxHealth()) {
- this.consumeItemFromStack(sourceentity, itemstack);
- this.heal((float) item.getFood().getHealing());
- retval = true;
- } else if (this.isBreedingItem(itemstack) && this.getHealth() < this.getMaxHealth()) {
- this.consumeItemFromStack(sourceentity, itemstack);
- this.heal(4);
- retval = true;
- } else {
- retval = super.processInteract(sourceentity, hand);
- }
- }
- } else if (this.isBreedingItem(itemstack)) {
- this.consumeItemFromStack(sourceentity, itemstack);
- if (this.rand.nextInt(3) == 0 && !net.minecraftforge.event.ForgeEventFactory.onAnimalTame(this, sourceentity)) {
- this.setTamedBy(sourceentity);
- this.world.setEntityState(this, (byte) 7);
- } else {
- this.world.setEntityState(this, (byte) 6);
- }
- this.enablePersistence();
- retval = true;
- } else {
- retval = super.processInteract(sourceentity, hand);
- if (retval)
- this.enablePersistence();
- }
- }
- double x = this.getPosX();
- double y = this.getPosY();
- double z = this.getPosZ();
- Entity entity = this;
- return retval;
- }
- @Override
- public void baseTick() {
- super.baseTick();
- double x = this.getPosX();
- double y = this.getPosY();
- double z = this.getPosZ();
- Entity entity = this;
- {
- Map<String, Object> $_dependencies = new HashMap<>();
- $_dependencies.put("entity", entity);
- PRCSummonedBlazeLifetimeProcedure.executeProcedure($_dependencies);
- }
- }
- @Override
- protected void registerAttributes() {
- super.registerAttributes();
- if (this.getAttribute(SharedMonsterAttributes.MOVEMENT_SPEED) != null)
- this.getAttribute(SharedMonsterAttributes.MOVEMENT_SPEED).setBaseValue(0.3);
- if (this.getAttribute(SharedMonsterAttributes.MAX_HEALTH) != null)
- this.getAttribute(SharedMonsterAttributes.MAX_HEALTH).setBaseValue(10);
- if (this.getAttribute(SharedMonsterAttributes.ARMOR) != null)
- this.getAttribute(SharedMonsterAttributes.ARMOR).setBaseValue(0);
- if (this.getAttribute(SharedMonsterAttributes.ATTACK_DAMAGE) == null)
- this.getAttributes().registerAttribute(SharedMonsterAttributes.ATTACK_DAMAGE);
- this.getAttribute(SharedMonsterAttributes.ATTACK_DAMAGE).setBaseValue(3);
- if (this.getAttribute(SharedMonsterAttributes.FLYING_SPEED) == null)
- this.getAttributes().registerAttribute(SharedMonsterAttributes.FLYING_SPEED);
- this.getAttribute(SharedMonsterAttributes.FLYING_SPEED).setBaseValue(0.3);
- }
- public void attackEntityWithRangedAttack(LivingEntity target, float flval) {
- ArrowCustomEntity entityarrow = new ArrowCustomEntity(arrow, this, this.world);
- double d0 = target.getPosY() + (double) target.getEyeHeight() - 1.1;
- double d1 = target.getPosX() - this.getPosX();
- double d3 = target.getPosZ() - this.getPosZ();
- entityarrow.shoot(d1, d0 - entityarrow.getPosY() + (double) MathHelper.sqrt(d1 * d1 + d3 * d3) * 0.2F, d3, 1.6F, 12.0F);
- world.addEntity(entityarrow);
- }
- @Override
- public AgeableEntity createChild(AgeableEntity ageable) {
- return (CustomEntity) entity.create(this.world);
- }
- @Override
- public boolean isBreedingItem(ItemStack stack) {
- if (stack == null)
- return false;
- return false;
- }
- @Override
- protected void updateFallState(double y, boolean onGroundIn, BlockState state, BlockPos pos) {
- }
- @Override
- public void setNoGravity(boolean ignored) {
- super.setNoGravity(true);
- }
- public void livingTick() {
- super.livingTick();
- this.setNoGravity(true);
- double x = this.getPosX();
- double y = this.getPosY();
- double z = this.getPosZ();
- Random random = this.rand;
- Entity entity = this;
- if (true)
- for (int l = 0; l < 4; ++l) {
- double d0 = (x + random.nextFloat());
- double d1 = (y + random.nextFloat());
- double d2 = (z + random.nextFloat());
- int i1 = random.nextInt(2) * 2 - 1;
- double d3 = (random.nextFloat() - 0.5D) * 0.5D;
- double d4 = (random.nextFloat() - 0.5D) * 0.5D;
- double d5 = (random.nextFloat() - 0.5D) * 0.5D;
- world.addParticle(ParticleTypes.SMOKE, d0, d1, d2, d3, d4, d5);
- }
- }
- }
- @OnlyIn(value = Dist.CLIENT, _interface = IRendersAsItem.class)
- private static class ArrowCustomEntity extends AbstractArrowEntity implements IRendersAsItem {
- public ArrowCustomEntity(FMLPlayMessages.SpawnEntity packet, World world) {
- super(arrow, world);
- }
- public ArrowCustomEntity(EntityType<? extends ArrowCustomEntity> type, World world) {
- super(type, world);
- }
- public ArrowCustomEntity(EntityType<? extends ArrowCustomEntity> type, double x, double y, double z, World world) {
- super(type, x, y, z, world);
- }
- public ArrowCustomEntity(EntityType<? extends ArrowCustomEntity> type, LivingEntity entity, World world) {
- super(type, entity, world);
- }
- @Override
- public IPacket<?> createSpawnPacket() {
- return NetworkHooks.getEntitySpawningPacket(this);
- }
- @Override
- @OnlyIn(Dist.CLIENT)
- public ItemStack getItem() {
- return new ItemStack(Items.FIRE_CHARGE, (int) (1));
- }
- @Override
- protected ItemStack getArrowStack() {
- return new ItemStack(Items.FIRE_CHARGE, (int) (1));
- }
- }
- // Made with Blockbench 3.8.4
- // Exported for Minecraft version 1.15 - 1.16
- // Paste this class into your mod and generate all required imports
- public static class ModelSummonedBlaze extends EntityModel<Entity> {
- private final ModelRenderer Head;
- public ModelSummonedBlaze() {
- textureWidth = 16;
- textureHeight = 16;
- Head = new ModelRenderer(this);
- Head.setRotationPoint(0.0F, 24.0F, 0.0F);
- Head.setTextureOffset(0, 3).addBox(-1.0F, -3.0F, -1.0F, 2.0F, 2.0F, 2.0F, 0.0F, false);
- }
- @Override
- public void render(MatrixStack matrixStack, IVertexBuilder buffer, int packedLight, int packedOverlay, float red, float green, float blue,
- float alpha) {
- Head.render(matrixStack, buffer, packedLight, packedOverlay);
- }
- public void setRotationAngle(ModelRenderer modelRenderer, float x, float y, float z) {
- modelRenderer.rotateAngleX = x;
- modelRenderer.rotateAngleY = y;
- modelRenderer.rotateAngleZ = z;
- }
- public void setRotationAngles(Entity e, float f, float f1, float f2, float f3, float f4) {
- this.Head.rotateAngleY = f3 / (180F / (float) Math.PI);
- this.Head.rotateAngleX = f4 / (180F / (float) Math.PI);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement