- 1
- 0
Всем здравствуйте!
Пишу свой мод по этому туториалу. Делаю сущность крокодила.
Делаю все, как в туториале.
Мой код:
Но при использовании яйца ничего не происходит. Пробовал команду summon - выдаётся ошибка "не удалось создать сущность", но программа не падала. И никаких краш-логов не было.
Что я неправильно делаю? И в чём принципиальная разница в версиях 1.19.4 и 1.20.0?
Пишу свой мод по этому туториалу. Делаю сущность крокодила.
Делаю все, как в туториале.
Мой код:
EntityInitialize:
public class ModEntities {
public static final DeferredRegister<EntityType<?>> ENTITIES = DeferredRegister.create(
ForgeRegistries.ENTITY_TYPES, BiornMod.MOD_ID);
public static final RegistryObject<EntityType<FirstEntity>> FIRST_ENTITY = ENTITIES.register("first_entity",
()->EntityType.Builder.<FirstEntity>of(FirstEntity::new, MobCategory.CREATURE)
.sized(3f, 1.0f)
.build(new ResourceLocation(BiornMod.MOD_ID + "first_entity").toString()));
}
EntityClass:
public class FirstEntity extends Animal {
public FirstEntity(EntityType<FirstEntity> type, Level level) {
super(type, level);
}
public FirstEntity(Level level, double x, double y, double z) {
this(ModEntities.FIRST_ENTITY.get(), level);
setPos(x, y, z);
}
public FirstEntity(Level level, BlockPos position) {
this(level, position.getX(), position.getY(), position.getZ());
}
@Nullable
@Override
public AgeableMob getBreedOffspring(ServerLevel level, AgeableMob parent) {
return new FirstEntity(level, this.blockPosition());
}
@Override
protected void registerGoals() {
this.goalSelector.addGoal(0, new FloatGoal(this));
this.goalSelector.addGoal(1, new PanicGoal(this, 1.25D));
this.goalSelector.addGoal(3, new BreedGoal(this, 1.0D));
this.goalSelector.addGoal(5, new FollowParentGoal(this, 1.1D));
this.goalSelector.addGoal(6, new WaterAvoidingRandomStrollGoal(this, 1.0D));
this.goalSelector.addGoal(7, new LookAtPlayerGoal(this, Player.class, 6.0F));
this.goalSelector.addGoal(8, new RandomLookAroundGoal(this));
this.goalSelector.addGoal(9, new TemptGoal(this, 1.0D, Ingredient.of(ModItems.MANDARIN.get()), false));
}
public static AttributeSupplier.Builder createAttributes() {
return Animal.createLivingAttributes().add(Attributes.MAX_HEALTH, 16)
.add(Attributes.MOVEMENT_SPEED, 4);
}
public static boolean canSpawn(EntityType<FirstEntity> entityType, LevelAccessor level, MobSpawnType spawnType, BlockPos position, RandomSource random) {
return Animal.checkAnimalSpawnRules(entityType, level, spawnType, position, random) && level.getLevelData().isRaining();
}
}
Render:
public class FirstEntityRenderer extends MobRenderer<FirstEntity, FirstEntityModel<FirstEntity>> {
private static final ResourceLocation TEXTURE = new ResourceLocation(BiornMod.MOD_ID, "textures/entity/first_entity.png");
public FirstEntityRenderer(EntityRendererProvider.Context context) {
super(context, new FirstEntityModel<>(context.bakeLayer(FirstEntityModel.LAYER_LOCATION)), 1.0f);
}
@Override
public ResourceLocation getTextureLocation(FirstEntity p_114482_) {
return TEXTURE;
}
}
Model:
public class FirstEntityModel<T extends FirstEntity> extends EntityModel<T> {
public static final ModelLayerLocation LAYER_LOCATION = new ModelLayerLocation(new ResourceLocation(BiornMod.MOD_ID, "first_entity"), "main");
private final ModelPart body;
public FirstEntityModel(ModelPart root) {
this.body = root.getChild("body");
}
public static LayerDefinition createBodyLayer() {
MeshDefinition meshdefinition = new MeshDefinition();
PartDefinition partdefinition = meshdefinition.getRoot();
PartDefinition body = partdefinition.addOrReplaceChild("body", CubeListBuilder.create(), PartPose.offset(0.0F, 24.0F, 0.0F));
PartDefinition legs = body.addOrReplaceChild("legs", CubeListBuilder.create(), PartPose.offset(0.0F, 0.0F, 0.0F));
PartDefinition frontRight = legs.addOrReplaceChild("frontRight", CubeListBuilder.create().texOffs(32, 0).addBox(-6.0F, -3.3F, -7.0F, 2.0F, 2.0F, 2.0F, new CubeDeformation(0.0F))
.texOffs(7, 7).addBox(-9.1F, -2.0F, -9.0F, 2.0F, 2.0F, 3.0F, new CubeDeformation(0.0F)), PartPose.offset(0.0F, 0.0F, 0.0F));
PartDefinition cube_r1 = frontRight.addOrReplaceChild("cube_r1", CubeListBuilder.create().texOffs(21, 25).addBox(-0.9F, -0.4F, -1.5F, 3.0F, 2.0F, 2.0F, new CubeDeformation(0.0F)), PartPose.offsetAndRotation(-8.0F, -2.0F, -6.0F, 0.0F, -0.3491F, -0.5236F));
PartDefinition frontLeft = legs.addOrReplaceChild("frontLeft", CubeListBuilder.create().texOffs(7, 2).addBox(7.1F, -2.0F, -9.0F, 2.0F, 2.0F, 3.0F, new CubeDeformation(0.0F))
.texOffs(31, 25).addBox(4.0F, -3.3F, -7.0F, 2.0F, 2.0F, 2.0F, new CubeDeformation(0.0F)), PartPose.offset(-1.0F, 0.0F, 0.0F));
PartDefinition cube_r2 = frontLeft.addOrReplaceChild("cube_r2", CubeListBuilder.create().texOffs(0, 25).addBox(-2.1F, -0.4F, -1.5F, 3.0F, 2.0F, 2.0F, new CubeDeformation(0.0F)), PartPose.offsetAndRotation(8.0F, -2.0F, -6.0F, 0.0F, 0.3491F, 0.5236F));
PartDefinition backRight = legs.addOrReplaceChild("backRight", CubeListBuilder.create().texOffs(0, 29).addBox(-6.0F, -3.3F, 5.0F, 2.0F, 2.0F, 2.0F, new CubeDeformation(0.0F))
.texOffs(0, 0).addBox(-9.1F, -2.0F, 6.0F, 2.0F, 2.0F, 3.0F, new CubeDeformation(0.0F)), PartPose.offset(0.0F, 0.0F, 0.0F));
PartDefinition cube_r3 = backRight.addOrReplaceChild("cube_r3", CubeListBuilder.create().texOffs(0, 12).addBox(-0.9F, -0.4F, -0.5F, 3.0F, 2.0F, 2.0F, new CubeDeformation(0.0F)), PartPose.offsetAndRotation(-8.0F, -2.0F, 6.0F, 0.0F, 0.3491F, -0.5236F));
PartDefinition backLeft = legs.addOrReplaceChild("backLeft", CubeListBuilder.create().texOffs(0, 5).addBox(6.1F, -2.0F, 6.0F, 2.0F, 2.0F, 3.0F, new CubeDeformation(0.0F))
.texOffs(21, 29).addBox(3.0F, -3.3F, 5.0F, 2.0F, 2.0F, 2.0F, new CubeDeformation(0.0F)), PartPose.offset(0.0F, 0.0F, 0.0F));
PartDefinition cube_r4 = backLeft.addOrReplaceChild("cube_r4", CubeListBuilder.create().texOffs(8, 14).addBox(-2.1F, -0.4F, -0.5F, 3.0F, 2.0F, 2.0F, new CubeDeformation(0.0F)), PartPose.offsetAndRotation(7.0F, -2.0F, 6.0F, 0.0F, -0.3491F, 0.5236F));
PartDefinition head = body.addOrReplaceChild("head", CubeListBuilder.create().texOffs(42, 25).addBox(-3.0F, -6.0F, -16.0F, 5.0F, 6.0F, 5.0F, new CubeDeformation(0.0F))
.texOffs(0, 25).addBox(-3.0F, -3.0F, -22.0F, 5.0F, 3.0F, 11.0F, new CubeDeformation(0.0F)), PartPose.offset(0.0F, 0.0F, 0.0F));
PartDefinition full_body = body.addOrReplaceChild("full_body", CubeListBuilder.create().texOffs(0, 0).addBox(-4.0F, -7.0F, -11.0F, 7.0F, 7.0F, 18.0F, new CubeDeformation(0.0F))
.texOffs(22, 29).addBox(-3.0F, -5.0F, 3.0F, 5.0F, 5.0F, 10.0F, new CubeDeformation(0.0F))
.texOffs(32, 0).addBox(-2.0F, -3.0F, 7.0F, 3.0F, 3.0F, 10.0F, new CubeDeformation(0.0F))
.texOffs(0, 39).addBox(-1.0F, -1.0F, 9.0F, 1.0F, 1.0F, 10.0F, new CubeDeformation(0.0F))
.texOffs(0, 39).addBox(-1.0F, -8.0F, -9.0F, 1.0F, 1.0F, 2.0F, new CubeDeformation(0.0F))
.texOffs(36, 14).addBox(-1.0F, -8.0F, -6.0F, 1.0F, 1.0F, 2.0F, new CubeDeformation(0.0F))
.texOffs(21, 33).addBox(-1.0F, -8.0F, -3.0F, 1.0F, 1.0F, 2.0F, new CubeDeformation(0.0F))
.texOffs(36, 5).addBox(-1.0F, -8.0F, 0.0F, 1.0F, 1.0F, 2.0F, new CubeDeformation(0.0F))
.texOffs(32, 13).addBox(-1.0F, -8.0F, 3.0F, 1.0F, 1.0F, 2.0F, new CubeDeformation(0.0F))
.texOffs(0, 33).addBox(-1.0F, -6.0F, 8.0F, 1.0F, 1.0F, 2.0F, new CubeDeformation(0.0F))
.texOffs(32, 7).addBox(-1.0F, -6.0F, 11.0F, 1.0F, 1.0F, 2.0F, new CubeDeformation(0.0F))
.texOffs(32, 4).addBox(-1.0F, -4.0F, 14.0F, 1.0F, 1.0F, 2.0F, new CubeDeformation(0.0F)), PartPose.offset(0.0F, 0.0F, 0.0F));
return LayerDefinition.create(meshdefinition, 64, 64);
}
@Override
public void setupAnim(T entity, float limbSwing, float limbSwingAmount, float ageInTicks, float netHeadYaw, float headPitch) {
}
@Override
public void renderToBuffer(PoseStack poseStack, VertexConsumer vertexConsumer, int packedLight, int packedOverlay, float red, float green, float blue, float alpha) {
body.render(poseStack, vertexConsumer, packedLight, packedOverlay, red, green, blue, alpha);
}
}
CommonModEvents:
@Mod.EventBusSubscriber(modid = BiornMod.MOD_ID, bus = Mod.EventBusSubscriber.Bus.MOD)
public class CommonModEvents {
@SubscribeEvent
public static void entityAttributes(EntityAttributeCreationEvent event){
event.put(ModEntities.FIRST_ENTITY.get(), FirstEntity.createAttributes().build());
}
@SubscribeEvent
public static void registerSpawnPlacements(SpawnPlacementRegisterEvent event){
event.register(ModEntities.FIRST_ENTITY.get(), SpawnPlacements.Type.ON_GROUND,
Heightmap.Types.WORLD_SURFACE, FirstEntity::canSpawn, SpawnPlacementRegisterEvent.Operation.OR);
}
}
ClientModEvents:
@Mod.EventBusSubscriber(modid = BiornMod.MOD_ID, bus = Mod.EventBusSubscriber.Bus.MOD, value = Dist.CLIENT)
public class ClientModEvents {
@SubscribeEvent
public static void registerRenderers(EntityRenderersEvent.RegisterRenderers event){
event.registerEntityRenderer(ModEntities.FIRST_ENTITY.get(), FirstEntityRenderer::new);
}
@SubscribeEvent
public static void registerLayerDefinitions(EntityRenderersEvent.RegisterLayerDefinitions event){
event.registerLayerDefinition(FirstEntityModel.LAYER_LOCATION, FirstEntityModel::createBodyLayer);
}
}
spawnEggInit:
public class ModItems {
public static final DeferredRegister<Item> ITEMS =
DeferredRegister.create(ForgeRegistries.ITEMS, BiornMod.MOD_ID);
public static final RegistryObject<ForgeSpawnEggItem> FIRST_ENTITY_SPAWN_EGG = ITEMS.register("first_entity_spawn_egg",
()->new ForgeSpawnEggItem(ModEntities.FIRST_ENTITY, 0x5A753C, 0x00C876, new Item.Properties()));
}
BiornMod:
@Mod(BiornMod.MOD_ID)
public class BiornMod
{
// Define mod id in a common place for everything to reference
public static final String MOD_ID = "biornmod";
// Directly reference a slf4j logger
private static final Logger LOGGER = LogUtils.getLogger();
public BiornMod()
{
IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus();
ModEntities.ENTITIES.register(modEventBus);
// Register the commonSetup method for modloading
modEventBus.addListener(this::commonSetup);
// Register ourselves for server and other game events we are interested in
MinecraftForge.EVENT_BUS.register(this);
modEventBus.addListener(this::addCreative);
}
private void commonSetup(final FMLCommonSetupEvent event)
{
}
private void addCreative(CreativeModeTabEvent.BuildContents event){
if (event.getTab()== ModCreativeTab.tab){
event.accept(ModItems.FIRST_ENTITY_SPAWN_EGG);
}
}
// You can use EventBusSubscriber to automatically register all static methods in the class annotated with @SubscribeEvent
@Mod.EventBusSubscriber(modid = MOD_ID, bus = Mod.EventBusSubscriber.Bus.MOD, value = Dist.CLIENT)
public static class ClientModEvents
{
@SubscribeEvent
public static void onClientSetup(FMLClientSetupEvent event)
{
}
}
}
CreativeModeTab:
@Mod.EventBusSubscriber(modid = BiornMod.MOD_ID, bus = Mod.EventBusSubscriber.Bus.MOD)
public class ModCreativeTab {
public static CreativeModeTab tab;
@SubscribeEvent
public static void regTab(CreativeModeTabEvent.Register e){
tab = e.registerCreativeModeTab(new ResourceLocation(BiornMod.MOD_ID),
builder -> builder.icon(()->new ItemStack(ModItems.MANDARIN.get())).
title(Component.translatable("creativemodetab.tab")));
}
}
first_entity_spawn_egg:
{
"parent": "minecraft:item/template_spawn_egg"
}
biomModifier:
{
"type": "forge:add_spawns",
"biomes": "#minecraft:is_overworld",
"spawners": {
"type": "biornmod:first_entity",
"weight": 75,
"minCount": 2,
"maxCount": 8
}
}
Что я неправильно делаю? И в чём принципиальная разница в версиях 1.19.4 и 1.20.0?
Вложения
Последнее редактирование: