package fr.ababoude.betterthings.util;import fr.ababoude.betterthings.Main;import fr.ababoude.betterthings.client.renderer.entity.SpongeSheepRenderer;import fr.ababoude.betterthings.entities.ModEntityTypes;import net.minecraftforge.api.distmarker.Dist;import net.minecraftforge.eventbus.api.SubscribeEvent;import net.minecraftforge.fml.client.registry.RenderingRegistry;import net.minecraftforge.fml.common.Mod;import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;@Mod.EventBusSubscriber(modid =Main.MODID, bus =Mod.EventBusSubscriber.Bus.MOD, value =Dist.CLIENT)publicclassClientEventBusSubscriber{@SubscribeEventpublicstaticvoid onClientSetup(FMLClientSetupEvent event){RenderingRegistry.registerEntityRenderingHandler(ModEntityTypes.SPONGE_SHEEP.get(),SpongeSheepRenderer::new);}}
ModEntityTypes :
package fr.ababoude.betterthings.entities;import fr.ababoude.betterthings.Main;import fr.ababoude.betterthings.entities.passive.SpongeSheepEntity;import net.minecraft.entity.EntityClassification;import net.minecraft.util.ResourceLocation;import net.minecraftforge.fml.RegistryObject;import net.minecraftforge.registries.DeferredRegister;import net.minecraftforge.registries.ForgeRegistries;import net.minecraft.entity.EntityType;publicclassModEntityTypes{publicstatic final DeferredRegister<EntityType<?>> ENTITY_TYPES =DeferredRegister.create(ForgeRegistries.ENTITIES,Main.MODID);/**
* .size = Taille de la Hitbox
*/publicstatic final RegistryObject<EntityType<SpongeSheepEntity>> SPONGE_SHEEP = ENTITY_TYPES.register("sponge_sheep",()->EntityType.Builder.create(SpongeSheepEntity::new,EntityClassification.CREATURE).size(0.9F,1.3F).build(newResourceLocation(Main.MODID,"sponge_sheep").toString()));}
SpongeSheepEntity :
package fr.ababoude.betterthings.entities.passive;import fr.ababoude.betterthings.entities.ModEntityTypes;import net.minecraft.block.BlockState;import net.minecraft.entity.AgeableEntity;import net.minecraft.entity.EntityType;import net.minecraft.entity.MobEntity;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.player.PlayerEntity;import net.minecraft.item.Items;import net.minecraft.item.crafting.Ingredient;import net.minecraft.util.DamageSource;import net.minecraft.util.SoundEvent;import net.minecraft.util.SoundEvents;import net.minecraft.util.math.BlockPos;import net.minecraft.world.World;import net.minecraft.world.server.ServerWorld;import net.minecraftforge.api.distmarker.Dist;import net.minecraftforge.api.distmarker.OnlyIn;import javax.annotation.Nullable;publicclassSpongeSheepEntity extends AnimalEntity{/**
* Ingredient : Définis par quel ingrédients l'entité vas être attiré
* IS_SHEARED : Crée un booléen qui vas servir a mettre en place le fait d'enlever la laine
*/publicstatic final Ingredient TEMPTATION_ITEMS =Ingredient.fromItems(Items.SPONGE,Items.WET_SPONGE);//private static final DataParameter<Boolean> IS_SHEARED = EntityDataManager.createKey(SpongeSheepEntity.class, DataSerializers.BOOLEAN);privateint sheepTimer;privateEatGrassGoal eatGrassGoal;publicSpongeSheepEntity(EntityType<? extends SpongeSheepEntity> type,World worldIn){
super(type, worldIn);}/**
* Définis ses paramètres de base (dans cette exemple, sa vie maximum et sa vitesse)
*///func_233666_p_ ---> registerAttributes()publicstaticAttributeModifierMap.MutableAttribute setCustomAttributes(){returnMobEntity.func_233666_p_().createMutableAttribute(Attributes.MAX_HEALTH,10.0D).createMutableAttribute(Attributes.MOVEMENT_SPEED,0.25D);}//@OverridepublicAgeableEntity createChild(AgeableEntity ageable){returnModEntityTypes.SPONGE_SHEEP.get().create(this.world);}/**
* Définis les paramètres de cette entité, ex: sa vitesse en cas de panique est de 1,25D
*/protectedvoid registerGoals(){
super.registerGoals();this.eatGrassGoal =newEatGrassGoal(this);this.goalSelector.addGoal(0,newSwimGoal(this));// La vitesse qu'il prend quand il nagethis.goalSelector.addGoal(1,newPanicGoal(this,1.25D));// La vitesse qu'il prend quand il à peurthis.goalSelector.addGoal(2,newBreedGoal(this,1.0D));this.goalSelector.addGoal(3,newTemptGoal(this,1.1D, TEMPTATION_ITEMS,false));this.goalSelector.addGoal(4,newFollowParentGoal(this,1.1D));this.goalSelector.addGoal(5,this.eatGrassGoal);this.goalSelector.addGoal(6,newWaterAvoidingRandomWalkingGoal(this,1.0D));this.goalSelector.addGoal(7,newLookAtGoal(this,PlayerEntity.class,6.0F));this.goalSelector.addGoal(8,newLookRandomlyGoal(this));}/**
* Définis l'expérience que le joueur obtiens lorsque l'entité est tuée
*/@Overrideprotectedint getExperiencePoints(PlayerEntity player){return1+this.world.rand.nextInt(4);}/**
* Configure tous les sons de l'entité
*/@OverrideprotectedSoundEvent getAmbientSound(){returnSoundEvents.ENTITY_SHEEP_AMBIENT;}@OverrideprotectedSoundEvent getHurtSound(DamageSource damageSourceIn){returnSoundEvents.ENTITY_SHEEP_HURT;}@OverrideprotectedSoundEvent getDeathSound(){returnSoundEvents.ENTITY_SHEEP_DEATH;}@Overrideprotectedvoid playStepSound(BlockPos pos,BlockState blockIn){this.playSound(SoundEvents.ENTITY_SHEEP_STEP,0.15F,1.0F);}/**
* Met à jour les tâches de l'AI, exemple: eatGrassGoal
*/@Overrideprotectedvoid updateAITasks(){this.sheepTimer =this.eatGrassGoal.getEatingGrassTimer();
super.updateAITasks();}@Nullable@OverridepublicAgeableEntity func_241840_a(ServerWorld p_241840_1_,AgeableEntity p_241840_2_){return null;}/**
* Appelé fréquemment pour que l'entité puisse mettre à jour son état chaque fois que nécessaire. Par exemple, les zombies et les squelettes
* l'utilise pour réagir à la lumière du soleil et commencer à brûler.
*/publicvoid livingTick(){if(this.world.isRemote){this.sheepTimer =Math.max(0,this.sheepTimer -1);}
super.livingTick();}/**
* Handler pour {@link World#setEntityState}
*/@OnlyIn(Dist.CLIENT)publicvoid handleStatusUpdate(byte id){if(id ==10){this.sheepTimer =40;}else{
super.handleStatusUpdate(id);}}/*
public ActionResultType func_230254_b_(PlayerEntity p_230254_1_, Hand p_230254_2_) {
ItemStack itemstack = p_230254_1_.getHeldItem(p_230254_2_);
if (false && itemstack.getItem() == Items.SHEARS) { //Forge: Moved to onSheared
if (!this.world.isRemote && this.isShearable()) {
this.shear(SoundCategory.PLAYERS);
itemstack.damageItem(1, p_230254_1_, (p_213613_1_) -> p_213613_1_.sendBreakAnimation(p_230254_2_));
return ActionResultType.SUCCESS;
} else {
return ActionResultType.CONSUME;
}
} else {
return super.func_230254_b_(p_230254_1_, p_230254_2_);
}
}
public void shear(SoundCategory category) {
this.world.playMovingSound(null, this, SoundEvents.ENTITY_SHEEP_SHEAR, category, 1.0F, 1.0F);
this.setSheared(true);
//if (SpongeMode == "Sponge") {
this.entityDropItem(Items.SPONGE);
//} else {
// this.entityDropItem(Items.WET_SPONGE);
//}
}
public boolean isShearable() {
return this.isAlive() && this.getSheared() && !this.isChild();
}
//@Override
public boolean getSheared() {
return this.dataManager.get(IS_SHEARED);
}
/**
* make a sheep sheared if set to true
*//*
public void setSheared(boolean sheared) {
//boolean bol = this.dataManager.get(IS_SHEARED);
this.dataManager.set(IS_SHEARED, sheared);
}
public void eatGrassBonus() {
//this.setSheared(false);
if (this.isChild()) {
this.addGrowth(60);
}
}
@Nullable
public ILivingEntityData onInitialSpawn(IServerWorld worldIn, DifficultyInstance difficultyIn, SpawnReason reason, @Nullable ILivingEntityData spawnDataIn, @Nullable CompoundNBT dataTag) {
return super.onInitialSpawn(worldIn, difficultyIn, reason, spawnDataIn, dataTag);
}
/*
public AgeableEntity func_241840_a(ServerWorld p_241840_1_, AgeableEntity p_241840_2_) {
return null;
}
}
protected float getStandingEyeHeight(Pose poseIn, EntitySize sizeIn) {
return 0.95F * sizeIn.height;
}
}
*/}
[1.16.3] My game crash when my entity is spawned
in Modder Support
Posted
Hello ! I have a problem with my entity, when i use the command "/summon betterthings:sponge_sheep" my game crash :
The crash log :
This all script contain any informations about my entity :
Main :
ClientEventBusSubscriber :
ModEntityTypes :
SpongeSheepEntity :
SpongeSheepRenderer :
SpongeSheepModel :
Thank you for the little look ! bye !