-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
171 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
...n/java/com/github/ptom76/tutorialfabricmod/client/render/entity/BlueAppleEntityModel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.github.ptom76.tutorialfabricmod.client.render.entity; | ||
|
||
import com.github.ptom76.tutorialfabricmod.entity.BlueAppleEntity; | ||
import net.minecraft.client.model.*; | ||
import net.minecraft.client.render.VertexConsumer; | ||
import net.minecraft.client.render.entity.model.EntityModel; | ||
import net.minecraft.client.render.entity.model.EntityModelPartNames; | ||
import net.minecraft.client.util.math.MatrixStack; | ||
|
||
public class BlueAppleEntityModel extends EntityModel<BlueAppleEntity> { | ||
|
||
private final ModelPart base; | ||
|
||
public BlueAppleEntityModel(ModelPart base) { | ||
this.base = base; | ||
} | ||
|
||
@Override | ||
public void setAngles(BlueAppleEntity entity, float limbAngle, float limbDistance, float animationProgress, float headYaw, float headPitch) { | ||
|
||
} | ||
|
||
@Override | ||
public void render(MatrixStack matrices, VertexConsumer vertices, int light, int overlay, float red, float green, float blue, float alpha) { | ||
base.render(matrices, vertices, light, overlay, red, green, blue, alpha); | ||
} | ||
|
||
public static TexturedModelData getTexturedModelData() { | ||
ModelData modelData = new ModelData(); | ||
ModelPartData rootPart = modelData.getRoot(); | ||
|
||
// 頭と体のパーツを追加 | ||
rootPart.addChild(EntityModelPartNames.HEAD, ModelPartBuilder.create() | ||
.uv(0, 0) | ||
.cuboid(-4.0f, 4.0f, -4.0f, 8.0f, 8.0f, 8.0f), ModelTransform.NONE); | ||
|
||
rootPart.addChild(EntityModelPartNames.BODY, ModelPartBuilder.create() | ||
.uv(0, 20) | ||
.cuboid(-4.0f, 12.0f, -3.0f, 8.0f, 12.0f, 6.0f), ModelTransform.NONE); | ||
|
||
return TexturedModelData.of(modelData, 32, 48); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
...ava/com/github/ptom76/tutorialfabricmod/client/render/entity/BlueAppleEntityRenderer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.github.ptom76.tutorialfabricmod.client.render.entity; | ||
|
||
import com.github.ptom76.tutorialfabricmod.TutorialFabricMod; | ||
import com.github.ptom76.tutorialfabricmod.entity.BlueAppleEntity; | ||
import net.minecraft.client.render.entity.EntityRendererFactory; | ||
import net.minecraft.client.render.entity.MobEntityRenderer; | ||
import net.minecraft.util.Identifier; | ||
|
||
public class BlueAppleEntityRenderer extends MobEntityRenderer<BlueAppleEntity, BlueAppleEntityModel> { | ||
public BlueAppleEntityRenderer(EntityRendererFactory.Context context) { | ||
super(context, new BlueAppleEntityModel(context.getPart(EntityRenderers.MODEL_BLUE_APPLE_LAYER)), 0.5f); | ||
} | ||
|
||
@Override | ||
public Identifier getTexture(BlueAppleEntity entity) { | ||
return TutorialFabricMod.id("textures/entity/blue_apple_mob/blue_apple_mob.png"); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/main/java/com/github/ptom76/tutorialfabricmod/client/render/entity/EntityRenderers.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.github.ptom76.tutorialfabricmod.client.render.entity; | ||
|
||
import com.github.ptom76.tutorialfabricmod.TutorialFabricMod; | ||
import com.github.ptom76.tutorialfabricmod.entity.Entities; | ||
import net.fabricmc.fabric.api.client.rendering.v1.EntityModelLayerRegistry; | ||
import net.fabricmc.fabric.api.client.rendering.v1.EntityRendererRegistry; | ||
import net.minecraft.client.render.entity.model.EntityModelLayer; | ||
|
||
public class EntityRenderers { | ||
|
||
// EntityのModelレイヤー | ||
public static EntityModelLayer MODEL_BLUE_APPLE_LAYER = new EntityModelLayer(TutorialFabricMod.id("blue_apple_mob"), "main"); | ||
|
||
public static void init() { | ||
// EntityのRenderer(描画システム)の登録 | ||
EntityRendererRegistry.register(Entities.BLUE_APPLE_MOB, BlueAppleEntityRenderer::new); | ||
|
||
// Entityのモデル登録 | ||
EntityModelLayerRegistry.registerModelLayer(MODEL_BLUE_APPLE_LAYER, BlueAppleEntityModel::getTexturedModelData); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
src/main/java/com/github/ptom76/tutorialfabricmod/entity/BlueAppleEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.github.ptom76.tutorialfabricmod.entity; | ||
|
||
import com.github.ptom76.tutorialfabricmod.item.Items; | ||
import net.minecraft.entity.EntityType; | ||
import net.minecraft.entity.ExperienceOrbEntity; | ||
import net.minecraft.entity.damage.DamageSource; | ||
import net.minecraft.entity.mob.PathAwareEntity; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.server.world.ServerWorld; | ||
import net.minecraft.world.World; | ||
|
||
public class BlueAppleEntity extends PathAwareEntity { | ||
public BlueAppleEntity(EntityType<? extends PathAwareEntity> entityType, World world) { | ||
super(entityType, world); | ||
} | ||
|
||
// 死亡時呼び出される関数 | ||
@Override | ||
public void onDeath(DamageSource damageSource) { | ||
super.onDeath(damageSource); | ||
|
||
// クライアントではないとき | ||
if (!world.isClient) { | ||
// ドロップ品 (数: 1~3個) | ||
dropStack(new ItemStack(Items.TUTORIAL_ITEM, world.random.nextBetween(1, 3))); | ||
|
||
// 経験値ドロップ (量:5~20) | ||
ExperienceOrbEntity.spawn((ServerWorld) world, getPos(), world.random.nextBetween(5, 20)); | ||
} | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
src/main/java/com/github/ptom76/tutorialfabricmod/entity/Entities.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package com.github.ptom76.tutorialfabricmod.entity; | ||
|
||
import com.github.ptom76.tutorialfabricmod.TutorialFabricMod; | ||
import net.fabricmc.fabric.api.object.builder.v1.entity.FabricDefaultAttributeRegistry; | ||
import net.fabricmc.fabric.api.object.builder.v1.entity.FabricEntityTypeBuilder; | ||
import net.minecraft.entity.EntityDimensions; | ||
import net.minecraft.entity.EntityType; | ||
import net.minecraft.entity.SpawnGroup; | ||
import net.minecraft.entity.attribute.EntityAttributes; | ||
import net.minecraft.registry.Registries; | ||
import net.minecraft.registry.Registry; | ||
|
||
public class Entities { | ||
public static EntityType<BlueAppleEntity> BLUE_APPLE_MOB = FabricEntityTypeBuilder.create() | ||
// スポーングループ | ||
.spawnGroup(SpawnGroup.CREATURE) | ||
.entityFactory(BlueAppleEntity::new) | ||
|
||
// 当たり判定のサイズ | ||
.dimensions(EntityDimensions.fixed(0.5f, 1.25f)) | ||
.build(); | ||
|
||
public static void init() { | ||
// エンティティの登録 | ||
Registry.register(Registries.ENTITY_TYPE, TutorialFabricMod.id("blue_apple_mob"), BLUE_APPLE_MOB); | ||
|
||
attributeRegister(); | ||
} | ||
|
||
public static void attributeRegister() { | ||
// 属性の登録 | ||
FabricDefaultAttributeRegistry.register(BLUE_APPLE_MOB, BlueAppleEntity.createMobAttributes() | ||
// 体力 | ||
.add(EntityAttributes.GENERIC_MAX_HEALTH, 5.0) | ||
|
||
// 防護力 | ||
.add(EntityAttributes.GENERIC_ARMOR, 3.0)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
src/main/resources/assets/tutorialfabricmod/models/item/blue_apple_mob_spawn_egg.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"parent": "minecraft:item/template_spawn_egg" | ||
} |
Binary file added
BIN
+1.28 KB
...rces/assets/tutorialfabricmod/textures/entity/blue_apple_mob/blue_apple_mob.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.