Posted January 6, 20214 yr Please help me to understand what i am doing wrong. I am messing with entities for 3 day and cant fiend any tutorials for 1.16.x that explain how to create just a mob. I try to start with simple thing and recreate a cow but it still doest works package com.klarks.mymod; import net.minecraftforge.eventbus.api.IEventBus; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @Mod(Main.MODID) @Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD) public class Main { public static final String MODID = "mymod"; public Main() { IEventBus bus = FMLJavaModLoadingContext.get().getModEventBus(); MobEnTypes.ENTITY_TYPES.register(bus); } } package com.klarks.mymod; import net.minecraft.block.BlockState; import net.minecraft.entity.*; import net.minecraft.entity.ai.attributes.AttributeModifierMap; import net.minecraft.entity.ai.attributes.Attributes; import net.minecraft.entity.ai.goal.*; import net.minecraft.entity.passive.AnimalEntity; import net.minecraft.entity.passive.CowEntity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.ItemStack; import net.minecraft.item.Items; import net.minecraft.item.crafting.Ingredient; import net.minecraft.util.*; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import net.minecraft.world.server.ServerWorld; public class MobEntity extends AnimalEntity { public MobEntity(EntityType<? extends MobEntity> type, World worldIn) { super(type, worldIn); } protected void registerGoals() { this.goalSelector.addGoal(0, new SwimGoal(this)); this.goalSelector.addGoal(1, new PanicGoal(this, 2.0D)); this.goalSelector.addGoal(2, new BreedGoal(this, 1.0D)); this.goalSelector.addGoal(3, new TemptGoal(this, 1.25D, Ingredient.fromItems(Items.WHEAT), false)); this.goalSelector.addGoal(4, new FollowParentGoal(this, 1.25D)); this.goalSelector.addGoal(6, new WaterAvoidingRandomWalkingGoal(this, 1.0D)); this.goalSelector.addGoal(7, new LookAtGoal(this, PlayerEntity.class, 6.0F)); this.goalSelector.addGoal(8, new LookRandomlyGoal(this)); } public static AttributeModifierMap.MutableAttribute func_234188_eI_() { return net.minecraft.entity.MobEntity.func_233666_p_().createMutableAttribute(Attributes.MAX_HEALTH, 10.0D).createMutableAttribute(Attributes.MOVEMENT_SPEED, (double)0.2F); } protected SoundEvent getAmbientSound() { return SoundEvents.ENTITY_COW_AMBIENT; } protected SoundEvent getHurtSound(DamageSource damageSourceIn) { return SoundEvents.ENTITY_COW_HURT; } protected SoundEvent getDeathSound() { return SoundEvents.ENTITY_COW_DEATH; } protected void playStepSound(BlockPos pos, BlockState blockIn) { this.playSound(SoundEvents.ENTITY_COW_STEP, 0.15F, 1.0F); } protected float getSoundVolume() { return 0.4F; } public ActionResultType func_230254_b_(PlayerEntity p_230254_1_, Hand p_230254_2_) { ItemStack itemstack = p_230254_1_.getHeldItem(p_230254_2_); if (itemstack.getItem() == Items.BUCKET && !this.isChild()) { p_230254_1_.playSound(SoundEvents.ENTITY_COW_MILK, 1.0F, 1.0F); ItemStack itemstack1 = DrinkHelper.fill(itemstack, p_230254_1_, Items.MILK_BUCKET.getDefaultInstance()); p_230254_1_.setHeldItem(p_230254_2_, itemstack1); return ActionResultType.func_233537_a_(this.world.isRemote); } else { return super.func_230254_b_(p_230254_1_, p_230254_2_); } } public CowEntity func_241840_a(ServerWorld p_241840_1_, AgeableEntity p_241840_2_) { return EntityType.COW.create(p_241840_1_); } public MobEntity createChild(AgeableEntity ageableEntity) { return MobEnTypes.GS_COW.get().create(this.world); } protected float getStandingEyeHeight(Pose poseIn, EntitySize sizeIn) { return this.isChild() ? sizeIn.height * 0.95F : 1.3F; } } package com.klarks.mymod; import net.minecraft.entity.EntityClassification; import net.minecraft.entity.EntityType; import net.minecraft.util.ResourceLocation; import net.minecraftforge.fml.RegistryObject; import net.minecraftforge.registries.DeferredRegister; import net.minecraftforge.registries.ForgeRegistries; public class MobEnTypes { public static final DeferredRegister<EntityType<?>> ENTITY_TYPES = DeferredRegister.create(ForgeRegistries.ENTITIES, Main.MODID); public static final RegistryObject<EntityType<MobEntity>> GS_COW = ENTITY_TYPES .register("gs_cow", () -> EntityType.Builder.<MobEntity>create(MobEntity::new, EntityClassification.CREATURE) .size(0.9f, 1.49f) .build(new ResourceLocation(Main.MODID, "gs_cow").toString())); } package com.klarks.mymod; import net.minecraft.client.renderer.entity.CowRenderer; import net.minecraft.client.renderer.entity.EntityRendererManager; import net.minecraft.client.renderer.entity.MobRenderer; import net.minecraft.client.renderer.entity.model.CowModel; import net.minecraft.util.ResourceLocation; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; @OnlyIn(Dist.CLIENT) public class MobIRender extends MobRenderer<MobEntity, CowModel<MobEntity>> { private static final ResourceLocation COW_TEXTURES = new ResourceLocation("textures/entity/cow/cow.png"); public MobIRender(EntityRendererManager renderManagerIn) { super(renderManagerIn, new CowModel<>(), 0.7F); } public ResourceLocation getEntityTexture(MobEntity entity) { return COW_TEXTURES; } } package com.klarks.mymod; import com.sun.jmx.remote.protocol.rmi.ClientProvider; import net.minecraft.entity.EntityClassification; import net.minecraft.world.biome.Biome; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.eventbus.EventBus; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.client.registry.ClientRegistry; import net.minecraftforge.fml.client.registry.RenderingRegistry; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent; import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent; import net.minecraftforge.registries.ForgeRegistries; @Mod.EventBusSubscriber(modid = Main.MODID, bus = Mod.EventBusSubscriber.Bus.MOD, value = Dist.CLIENT) public class ClientEventBusSubscriber { @SubscribeEvent public static void clientSetup(FMLClientSetupEvent event) { RenderingRegistry.registerEntityRenderingHandler(MobEnTypes.GS_COW.get(), MobIRender::new); } @SubscribeEvent public static void onInitBiomesGen(FMLCommonSetupEvent event) { } } Edited January 6, 20214 yr by Klarks
January 6, 20214 yr Please clarify, what exactly is not working? Edited January 6, 20214 yr by Sterling00
January 6, 20214 yr Author When i run client i type in the game "/summon mygame.gs_cow" and then minecraft says Unable to summon entity Edited January 6, 20214 yr by Klarks
January 6, 20214 yr I think this is caused by the fact that you did not create the cows attributes. In your main class cunstructor do: // Register the setup method for modloading bus.addListener(this::setup); and add the method: private void setup (final FMLCommonSetupEvent event) { event.enqueueWork(() -> { GlobalEntityTypeAttributes.put(ModEntityTypes.GS_COW.get(), MobEntity.setCustomAttributes().create() } } Edited January 6, 20214 yr by Sterling00
January 6, 20214 yr Also you should propably rename the "MobEntity" file to something like gsCowEntity to differ from the MobEntity class by Minecraft.
January 6, 20214 yr Author Thank you so much it is working now! Thank you! I thought this thing adds the attributes public static AttributeModifierMap.MutableAttribute func_234188_eI_() { return net.minecraft.entity.MobEntity.func_233666_p_().createMutableAttribute(Attributes.MAX_HEALTH, 10.0D).createMutableAttribute(Attributes.MOVEMENT_SPEED, (double)0.2F); }
January 6, 20214 yr It is only returning the attributes. To set your own attributes change the "MobEntity.setCustomAttributes().create()" to YourEntityClass.func_234188_eI_().create(). I would recommend to rename "func_234188_eI_" to "setCustomAttributes" or something similar though Edited January 6, 20214 yr by Sterling00
January 6, 20214 yr Author Yes i already did so. Thanks private void setup (final FMLCommonSetupEvent event) { event.enqueueWork(() -> { GlobalEntityTypeAttributes.put(MobEnTypes.GS_COW.get(), gsCowEntity.func_234188_eI_().create()); }); }
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.