Skip to content

Commit

Permalink
Goldfish! (not done)
Browse files Browse the repository at this point in the history
  • Loading branch information
ExDrill committed Sep 21, 2024
1 parent 06dd24d commit 399b7ff
Show file tree
Hide file tree
Showing 28 changed files with 601 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"parent": "minecraft:item/generated",
"textures": {
"layer0": "rods_n_reels:item/goldfish"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"parent": "minecraft:item/generated",
"textures": {
"layer0": "rods_n_reels:item/goldfish_bucket"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"type": "minecraft:entity",
"pools": [
{
"bonus_rolls": 0.0,
"entries": [
{
"type": "minecraft:item",
"functions": [
{
"add": false,
"count": 1.0,
"function": "minecraft:set_count"
}
],
"name": "rods_n_reels:goldfish"
}
],
"rolls": 1.0
},
{
"bonus_rolls": 0.0,
"conditions": [
{
"chance": 0.05,
"condition": "minecraft:random_chance"
}
],
"entries": [
{
"type": "minecraft:item",
"name": "minecraft:bone_meal"
}
],
"rolls": 1.0
}
]
}
2 changes: 2 additions & 0 deletions src/main/java/com/teamabode/rodsnreels/RodsNReels.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ public class RodsNReels implements ModInitializer {
public void onInitialize() {
RNRItems.register();
RNRBlocks.register();
RNREntityTypes.register();
RNRFeatures.register();
RNRDecoratedPotPatterns.register();
RNRStructures.register();
RNRSoundEvents.register();

RNRPlacedFeatures.createBiomeModifications();
RNRLootTableEvents.modifyVanillaLootTables();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
package com.teamabode.rodsnreels.client;

import com.teamabode.rodsnreels.client.model.GoldfishModel;
import com.teamabode.rodsnreels.client.renderer.GoldfishRenderer;
import com.teamabode.rodsnreels.core.registry.RNRBlocks;
import com.teamabode.rodsnreels.core.registry.RNREntityTypes;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.blockrenderlayer.v1.BlockRenderLayerMap;
import net.fabricmc.fabric.api.client.rendering.v1.EntityModelLayerRegistry;
import net.fabricmc.fabric.api.client.rendering.v1.EntityRendererRegistry;
import net.minecraft.client.renderer.RenderType;

public class RodsNReelsClient implements ClientModInitializer {
Expand All @@ -12,6 +17,9 @@ public class RodsNReelsClient implements ClientModInitializer {
public void onInitializeClient() {
BlockRenderLayerMap.INSTANCE.putBlock(RNRBlocks.BUBBLEDEW_STEM_PLANT, RenderType.cutout());
BlockRenderLayerMap.INSTANCE.putBlock(RNRBlocks.BUBBLEDEW_STEM, RenderType.cutout());

EntityModelLayerRegistry.registerModelLayer(GoldfishModel.LAYER_LOCATION, GoldfishModel::createBodyLayer);
EntityRendererRegistry.register(RNREntityTypes.GOLDFISH, GoldfishRenderer::new);
}

public static float getOceanTrenchFogDistance(float y) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package com.teamabode.rodsnreels.client.model;

import com.teamabode.rodsnreels.RodsNReels;
import com.teamabode.rodsnreels.common.entity.goldfish.Goldfish;
import net.minecraft.client.model.HierarchicalModel;
import net.minecraft.client.model.geom.ModelLayerLocation;
import net.minecraft.client.model.geom.ModelPart;
import net.minecraft.client.model.geom.PartPose;
import net.minecraft.client.model.geom.builders.*;
import net.minecraft.util.Mth;

public class GoldfishModel extends HierarchicalModel<Goldfish> {
public static final ModelLayerLocation LAYER_LOCATION = new ModelLayerLocation(RodsNReels.id("goldfish"), "main");

private final ModelPart body;
private final ModelPart leftFin;
private final ModelPart rightFin;
private final ModelPart head;
private final ModelPart tailFin;

public GoldfishModel(ModelPart root) {
this.body = root.getChild("body");
this.leftFin = body.getChild("left_fin");
this.rightFin = body.getChild("right_fin");
this.head = body.getChild("head");
this.tailFin = body.getChild("tail_fin");
}

public static LayerDefinition createBodyLayer() {
MeshDefinition mesh = new MeshDefinition();
PartDefinition root = mesh.getRoot();

PartDefinition body = root.addOrReplaceChild("body", CubeListBuilder.create().texOffs(8, 10).addBox(0.0F, 3.0F, -1.0F, 0.0F, 2.0F, 3.0F, new CubeDeformation(0.0F))
.texOffs(0, 0).addBox(-2.0F, -2.0F, -4.0F, 4.0F, 5.0F, 8.0F, new CubeDeformation(0.0F)), PartPose.offset(0.0F, 20.0F, 0.0F));
PartDefinition leftFin = body.addOrReplaceChild("left_fin", CubeListBuilder.create()
.texOffs(0, 1).addBox(0.0F, 0.0F, 0.0F, 0.0F, 2.0F, 2.0F, new CubeDeformation(0.0F)), PartPose.offsetAndRotation(2.0F, 1.0F, -4.0F, 0.0F, 0.3927F, 0.0F));
PartDefinition rightFin = body.addOrReplaceChild("right_fin", CubeListBuilder.create()
.texOffs(0, -1).addBox(0.0F, 0.0F, 0.0F, 0.0F, 2.0F, 2.0F, new CubeDeformation(0.0F)), PartPose.offsetAndRotation(-2.0F, 1.0F, -4.0F, 0.0F, -0.3927F, 0.0F));
PartDefinition head = body.addOrReplaceChild("head", CubeListBuilder.create()
.texOffs(0, 17).addBox(-2.0F, -1.0F, -3.0F, 4.0F, 4.0F, 3.0F, new CubeDeformation(0.0F)), PartPose.offset(0.0F, 0.0F, -4.0F));
PartDefinition tailFin = body.addOrReplaceChild("tail_fin", CubeListBuilder.create()
.texOffs(14, 9).addBox(1.0F, -4.0F, 1.0F, 0.0F, 5.0F, 4.0F, new CubeDeformation(0.0F)), PartPose.offset(-1.0F, 2.0F, 3.0F));
return LayerDefinition.create(mesh, 32, 32);
}

@Override
public void setupAnim(Goldfish entity, float limbSwing, float limbSwingAmount, float ageInTicks, float netHeadYaw, float headPitch) {
float k = 1.0f;
if (!entity.isInWater()) {
k = 1.5f;
}
this.tailFin.yRot = -k * 0.45f * Mth.sin(0.6f * ageInTicks);
}

@Override
public ModelPart root() {
return this.body;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.teamabode.rodsnreels.client.renderer;

import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.math.Axis;
import com.teamabode.rodsnreels.RodsNReels;
import com.teamabode.rodsnreels.client.model.GoldfishModel;
import com.teamabode.rodsnreels.common.entity.goldfish.Goldfish;
import net.minecraft.client.renderer.entity.EntityRendererProvider;
import net.minecraft.client.renderer.entity.MobRenderer;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.Mth;

public class GoldfishRenderer extends MobRenderer<Goldfish, GoldfishModel> {
public static final ResourceLocation TEXTURE = RodsNReels.id("textures/entity/goldfish.png");

public GoldfishRenderer(EntityRendererProvider.Context context) {
super(context, new GoldfishModel(context.bakeLayer(GoldfishModel.LAYER_LOCATION)), 0.4f);
}

@Override
protected void setupRotations(Goldfish goldfish, PoseStack poseStack, float f, float g, float h, float i) {
super.setupRotations(goldfish, poseStack, f, g, h, i);

float rot = 4.3F * Mth.sin(0.6F * f);
poseStack.mulPose(Axis.YP.rotationDegrees(rot));

if (!goldfish.isInWater()) {
poseStack.translate(0.1F, 0.1F, -0.1F);
poseStack.mulPose(Axis.ZP.rotationDegrees(90.0F));
}
}

@Override
public ResourceLocation getTextureLocation(Goldfish entity) {
return TEXTURE;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
package com.teamabode.rodsnreels.common.entity.goldfish;

import com.teamabode.rodsnreels.common.entity.goldfish.goals.SwimTowardsOwnerGoal;
import com.teamabode.rodsnreels.core.registry.RNRItems;
import com.teamabode.rodsnreels.core.registry.RNRSoundEvents;
import net.minecraft.core.component.DataComponents;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.syncher.EntityDataAccessor;
import net.minecraft.network.syncher.EntityDataSerializers;
import net.minecraft.network.syncher.SynchedEntityData;
import net.minecraft.sounds.SoundEvent;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.OwnableEntity;
import net.minecraft.world.entity.ai.goal.PanicGoal;
import net.minecraft.world.entity.ai.goal.RandomSwimmingGoal;
import net.minecraft.world.entity.animal.AbstractFish;
import net.minecraft.world.entity.animal.Bucketable;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.component.CustomData;
import net.minecraft.world.level.Level;
import org.jetbrains.annotations.Nullable;

import java.util.Optional;
import java.util.UUID;

public class Goldfish extends AbstractFish implements OwnableEntity {
private static final EntityDataAccessor<Optional<UUID>> OWNER_ID = SynchedEntityData.defineId(Goldfish.class, EntityDataSerializers.OPTIONAL_UUID);

public Goldfish(EntityType<? extends Goldfish> entityType, Level level) {
super(entityType, level);
}

public void spawnHeartParticles() {
for(int i = 0; i < 7; i++) {
double d = this.random.nextGaussian() * 0.02;
double e = this.random.nextGaussian() * 0.02;
double f = this.random.nextGaussian() * 0.02;
this.level().addParticle(ParticleTypes.HEART, this.getRandomX(1.0), this.getRandomY() + 0.5, this.getRandomZ(1.0), d, e, f);
}
}

public boolean unableToFollowOwner() {
return this.isPassenger() || this.isPanicking() || this.getOwner() != null && this.getOwner().isSpectator();
}

@Override
public void handleEntityEvent(byte flag) {
if (flag == 7) {
this.spawnHeartParticles();
}
else {
super.handleEntityEvent(flag);
}
}

@Override
protected void defineSynchedData(SynchedEntityData.Builder builder) {
super.defineSynchedData(builder);
builder.define(OWNER_ID, Optional.empty());
}

@Override
public void addAdditionalSaveData(CompoundTag compoundTag) {
super.addAdditionalSaveData(compoundTag);
if (this.getOwnerUUID() != null) {
compoundTag.putUUID("owner", this.getOwnerUUID());
}
}

@Override
public void readAdditionalSaveData(CompoundTag compoundTag) {
super.readAdditionalSaveData(compoundTag);
if (compoundTag.hasUUID("owner")) {
this.setOwnerUUID(compoundTag.getUUID("owner"));
}
}

@Override
public void saveToBucketTag(ItemStack stack) {
Bucketable.saveDefaultDataToBucketTag(this, stack);
CustomData.update(DataComponents.BUCKET_ENTITY_DATA, stack, (tag) -> {
if (this.getOwnerUUID() != null) {
tag.putUUID("owner", this.getOwnerUUID());
}
});
}

@Override
public void loadFromBucketTag(CompoundTag tag) {
Bucketable.loadDefaultDataFromBucketTag(this, tag);
if (tag.contains("owner")) {
this.setOwnerUUID(tag.getUUID("owner"));
}
}

@Override
protected void registerGoals() {
this.goalSelector.addGoal(0, new PanicGoal(this, 1.25));
this.goalSelector.addGoal(2, new RandomSwimmingGoal(this, 1.0f, 40));
this.goalSelector.addGoal(4, new SwimTowardsOwnerGoal(this, 10));
}

@Override
public ItemStack getBucketItemStack() {
return new ItemStack(RNRItems.GOLDFISH_BUCKET);
}

@Override
public SoundEvent getAmbientSound() {
return RNRSoundEvents.ENTITY_GOLDFISH_AMBIENT;
}

@Override
public SoundEvent getDeathSound() {
return RNRSoundEvents.ENTITY_GOLDFISH_DEATH;
}

@Override
public SoundEvent getHurtSound(DamageSource damageSource) {
return RNRSoundEvents.ENTITY_GOLDFISH_HURT;
}

@Override
public SoundEvent getFlopSound() {
return RNRSoundEvents.ENTITY_GOLDFISH_FLOP;
}

@Nullable
@Override
public UUID getOwnerUUID() {
return this.entityData.get(OWNER_ID).orElse(null);
}

public void setOwnerUUID(UUID id) {
this.entityData.set(OWNER_ID, Optional.ofNullable(id));
}
}
Loading

0 comments on commit 399b7ff

Please sign in to comment.