Skip to content

Commit

Permalink
variant schooling, start the switch to geckolib
Browse files Browse the repository at this point in the history
  • Loading branch information
Coda1552 committed Oct 12, 2024
1 parent 55d05e6 commit ee4587f
Show file tree
Hide file tree
Showing 184 changed files with 861 additions and 452 deletions.
26 changes: 4 additions & 22 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ plugins {
id 'idea'
id 'maven-publish'
id 'net.minecraftforge.gradle' version '[6.0,6.2)'
id 'org.spongepowered.mixin' version '0.7.+'
}

version = mod_version
Expand Down Expand Up @@ -112,14 +113,7 @@ minecraft {
sourceSets.main.resources { srcDir 'src/generated/resources' }

repositories {
// Put repositories for dependencies here
// ForgeGradle automatically adds the Forge maven and Maven Central for you

// If you have mod jar dependencies in ./libs, you can declare them as a repository like so.
// See https://docs.gradle.org/current/userguide/declaring_repositories.html#sub:flat_dir_resolver
// flatDir {
// dir 'libs'
// }
maven { url 'https://dl.cloudsmith.io/public/geckolib3/geckolib/maven/' }
}

dependencies {
Expand All @@ -130,20 +124,8 @@ dependencies {
// then special handling is done to allow a setup of a vanilla dependency without the use of an external repository.
minecraft "net.minecraftforge:forge:${minecraft_version}-${forge_version}"

// Example mod dependency with JEI - using fg.deobf() ensures the dependency is remapped to your development mappings
// The JEI API is declared for compile time use, while the full JEI artifact is used at runtime
// compileOnly fg.deobf("mezz.jei:jei-${mc_version}-common-api:${jei_version}")
// compileOnly fg.deobf("mezz.jei:jei-${mc_version}-forge-api:${jei_version}")
// runtimeOnly fg.deobf("mezz.jei:jei-${mc_version}-forge:${jei_version}")

// Example mod dependency using a mod jar from ./libs with a flat dir repository
// This maps to ./libs/coolmod-${mc_version}-${coolmod_version}.jar
// The group id is ignored when searching -- in this case, it is "blank"
// implementation fg.deobf("blank:coolmod-${mc_version}:${coolmod_version}")

// For more info:
// http://www.gradle.org/docs/current/userguide/artifact_dependencies_tutorial.html
// http://www.gradle.org/docs/current/userguide/dependency_management.html
implementation fg.deobf('software.bernie.geckolib:geckolib-forge-1.20.1:4.4.9')
annotationProcessor 'org.spongepowered:mixin:0.8.5:processor'
}

// This block of code expands all declared replace properties in the specified resource targets.
Expand Down
1 change: 1 addition & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ pluginManagement {
name = 'MinecraftForge'
url = 'https://maven.minecraftforge.net/'
}
maven { url = 'https://repo.spongepowered.org/repository/maven-public/' }
}
}

Expand Down
50 changes: 43 additions & 7 deletions src/main/java/codyhuh/unusualfishmod/client/ClientEvents.java
Original file line number Diff line number Diff line change
@@ -1,21 +1,32 @@
package codyhuh.unusualfishmod.client;

import codyhuh.unusualfishmod.UnusualFishMod;
import codyhuh.unusualfishmod.client.model.*;
import codyhuh.unusualfishmod.client.model.item.PrismarineSpearModel;
import codyhuh.unusualfishmod.client.render.*;
import codyhuh.unusualfishmod.client.render.item.FallingTreeBlockRenderer;
import codyhuh.unusualfishmod.client.render.item.SeaSpikeRenderer;
import codyhuh.unusualfishmod.client.render.item.ThrownPrismarineSpearRenderer;
import codyhuh.unusualfishmod.client.geo.GenericGeoModel;
import codyhuh.unusualfishmod.client.geo.GenericGeoRenderer;
import codyhuh.unusualfishmod.client.geo.TextureVariantModel;
import codyhuh.unusualfishmod.client.old.UFModelLayers;
import codyhuh.unusualfishmod.client.old.model.*;
import codyhuh.unusualfishmod.client.old.model.item.PrismarineSpearModel;
import codyhuh.unusualfishmod.client.old.render.*;
import codyhuh.unusualfishmod.client.old.render.item.FallingTreeBlockRenderer;
import codyhuh.unusualfishmod.client.old.render.item.SeaSpikeRenderer;
import codyhuh.unusualfishmod.client.old.render.item.ThrownPrismarineSpearRenderer;
import codyhuh.unusualfishmod.common.entity.DualityDamselfish;
import codyhuh.unusualfishmod.core.registry.UFEntities;
import codyhuh.unusualfishmod.core.registry.UFItems;
import net.minecraft.client.renderer.entity.EntityRenderers;
import net.minecraft.client.renderer.item.ItemProperties;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity;
import net.minecraftforge.client.event.EntityRenderersEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventBusSubscriber.Bus;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
import software.bernie.geckolib.model.DefaultedEntityGeoModel;

import java.util.ArrayList;

@Mod.EventBusSubscriber(modid = UnusualFishMod.MOD_ID, bus = Bus.MOD)
public final class ClientEvents {
Expand All @@ -32,9 +43,34 @@ public static void clientSetup(FMLClientSetupEvent e) {
ItemProperties.register(UFItems.DEMON_HERRING_BUCKET.get(), new ResourceLocation(UnusualFishMod.MOD_ID, "variant"), (stack, world, player, i) -> stack.hasTag() ? stack.getOrCreateTag().getInt("Variant") : 0);
}

private static void make(EntityType type, String name){
EntityRenderers.register(type, (ctx) -> new GenericGeoRenderer<>(ctx, () -> new GenericGeoModel<>(name)));
}

@SubscribeEvent
public static void registerRenderers(EntityRenderersEvent.RegisterRenderers e) {
e.registerEntityRenderer(UFEntities.DUALITY_DAMSELFISH.get(), DualityDamselfishRenderer::new);
EntityType<?>[] simpleEntities = new EntityType[]{
UFEntities.AERO_MONO.get(),
};
for (EntityType<?> type : simpleEntities) {
make(type, type.getDescriptionId().substring("entity.unusualfishmod.".length()));
}

EntityRenderers.register(UFEntities.DUALITY_DAMSELFISH.get(), (ctx) -> {
GenericGeoRenderer<DualityDamselfish> render = new GenericGeoRenderer<>(ctx, () -> {
TextureVariantModel<DualityDamselfish> model = new TextureVariantModel<>("duality_damselfish");
ArrayList<ResourceLocation> textures = new ArrayList<>();
for (int i = 1; i <= 2; i++){
textures.add(new ResourceLocation(UnusualFishMod.MOD_ID, "textures/entity/duality_damselfish/duality_damselfish_" + i + ".png"));
}
model.setTextures(DualityDamselfish::getVariant, textures);
return model;
});
return render;
});


//e.registerEntityRenderer(UFEntities.DUALITY_DAMSELFISH.get(), DualityDamselfishRenderer::new);
e.registerEntityRenderer(UFEntities.MOSSTHORN.get(), MossthornRenderer::new);
e.registerEntityRenderer(UFEntities.RIPPER.get(), RipperRenderer::new);
e.registerEntityRenderer(UFEntities.SPINDLEFISH.get(), SpindlefishRenderer::new);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package codyhuh.unusualfishmod.client.geo;

import codyhuh.unusualfishmod.UnusualFishMod;
import codyhuh.unusualfishmod.common.entity.util.misc.IFlopper;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.LivingEntity;
import software.bernie.geckolib.animatable.GeoEntity;
import software.bernie.geckolib.core.animatable.model.CoreGeoBone;
import software.bernie.geckolib.core.animation.AnimationState;
import software.bernie.geckolib.model.GeoModel;

public class GenericGeoModel<E extends LivingEntity & GeoEntity> extends GeoModel<E> {
private final String model;
private final String texture;
private final String anim;

public GenericGeoModel(String name) {
this(name, name, name);
}

public GenericGeoModel(String model, String texture, String anim) {
this.model = model;
this.texture = texture;
this.anim = anim;
}


@Override
public ResourceLocation getModelResource(E object) {
return new ResourceLocation(UnusualFishMod.MOD_ID, "geo/entity/" + model + ".geo.json");
}

@Override
public ResourceLocation getTextureResource(E object) {
return new ResourceLocation(UnusualFishMod.MOD_ID, "textures/entity/" + texture + ".png");
}

@Override
public ResourceLocation getAnimationResource(E object) {
return new ResourceLocation(UnusualFishMod.MOD_ID, "animations/entity/" + anim + ".animation.json");
}

@Override
public void setCustomAnimations(E entity, long instanceId, AnimationState<E> customPredicate) {
super.setCustomAnimations(entity, instanceId, customPredicate);

CoreGeoBone root = getAnimationProcessor().getBone("root");

if (entity instanceof IFlopper) {
if (!entity.isInWater()) {
root.setRotZ(1.5708F);
}
else {
root.setRotZ(0.0F);
}
}
// if (entity instanceof ISwimmer) {
// if (entity.isInWater()) {
//
// EntityModelData extraData = customPredicate.getData(DataTickets.ENTITY_MODEL_DATA);
//
// root.setRotX(extraData.headPitch() * ((float)Math.PI / 180F));
// root.setRotY(extraData.netHeadYaw() * ((float)Math.PI / 180F));
// }
// else {
// root.setRotX(0.0F);
// root.setRotY(0.0F);
// }
// }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package codyhuh.unusualfishmod.client.geo;

import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.entity.EntityRendererProvider;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.AgeableMob;
import net.minecraft.world.entity.LivingEntity;
import software.bernie.geckolib.animatable.GeoEntity;
import software.bernie.geckolib.cache.object.BakedGeoModel;
import software.bernie.geckolib.model.GeoModel;
import software.bernie.geckolib.renderer.GeoEntityRenderer;

import java.util.function.Supplier;

public class GenericGeoRenderer<T extends LivingEntity & GeoEntity> extends GeoEntityRenderer<T> {
private float scale = 1F;

public GenericGeoRenderer(EntityRendererProvider.Context renderManager, Supplier<GeoModel<T>> model) {
super(renderManager, model.get());
this.shadowRadius = 0.3F;
}

public GenericGeoRenderer(EntityRendererProvider.Context renderManager, Supplier<GeoModel<T>> model, float scale) {
this(renderManager, model.get(), scale);
this.scale = scale;
}

public GenericGeoRenderer(EntityRendererProvider.Context mgr, GeoModel<T> modelProvider) {
super(mgr, modelProvider);
}

public GenericGeoRenderer(EntityRendererProvider.Context mgr, GeoModel<T> modelProvider, float scale) {
this(mgr, modelProvider);
this.scale = scale;
}

@Override
public void render(T entity, float entityYaw, float partialTicks, PoseStack stack, MultiBufferSource bufferIn, int packedLightIn) {
if (scale != 1F) {
stack.scale(scale, scale, scale);
}

if (entity instanceof AgeableMob mob && mob.isBaby()) {
stack.scale(0.5F, 0.5F, 0.5F);
}

super.render(entity, entityYaw, partialTicks, stack, bufferIn, packedLightIn);
}

@Override
public void preRender(PoseStack poseStack, T animatable, BakedGeoModel bakedGeoModel, MultiBufferSource bufferSource, VertexConsumer buffer, boolean isReRender, float partialTick, int packedLight, int packedOverlay, float red, float green, float blue, float alpha) {
super.preRender(poseStack, animatable, bakedGeoModel, bufferSource, buffer, isReRender, partialTick, packedLight, packedOverlay, red, green, blue, alpha);
}

@Override
public RenderType getRenderType(T animatable, ResourceLocation texture, @org.jetbrains.annotations.Nullable MultiBufferSource bufferSource, float partialTick) {
return RenderType.entityTranslucent(texture);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package codyhuh.unusualfishmod.client.geo;

import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.LivingEntity;
import software.bernie.geckolib.animatable.GeoEntity;

import java.util.List;
import java.util.function.Function;

public class TextureVariantModel<E extends LivingEntity & GeoEntity> extends GenericGeoModel<E> {
List<ResourceLocation> textures;
Function<E, Integer> whichTexture;

public TextureVariantModel(String name) {
super(name);
}

public TextureVariantModel<E> setTextures(Function<E, Integer> whichTexture, List<ResourceLocation> textures){
this.whichTexture = whichTexture;
this.textures = textures;
return this;
}

@Override
public ResourceLocation getTextureResource(E object) {
if (this.textures == null || this.whichTexture == null) return null;
return this.textures.get(this.whichTexture.apply(object));
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package codyhuh.unusualfishmod.client;
package codyhuh.unusualfishmod.client.old;

import codyhuh.unusualfishmod.UnusualFishMod;
import net.minecraft.client.model.geom.ModelLayerLocation;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package codyhuh.unusualfishmod.client.model;
package codyhuh.unusualfishmod.client.old.model;

import codyhuh.unusualfishmod.common.entity.AeroMono;
import com.google.common.collect.ImmutableList;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package codyhuh.unusualfishmod.client.model;
package codyhuh.unusualfishmod.client.old.model;

import codyhuh.unusualfishmod.common.entity.AmberGoby;
import com.mojang.blaze3d.vertex.PoseStack;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package codyhuh.unusualfishmod.client.model;
package codyhuh.unusualfishmod.client.old.model;

import codyhuh.unusualfishmod.common.entity.BarkAngelfish;
import com.google.common.collect.ImmutableList;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package codyhuh.unusualfishmod.client.model;
package codyhuh.unusualfishmod.client.old.model;

import codyhuh.unusualfishmod.common.entity.BeakedHerring;
import com.google.common.collect.ImmutableList;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package codyhuh.unusualfishmod.client.model;
package codyhuh.unusualfishmod.client.old.model;

import codyhuh.unusualfishmod.common.entity.BlackCapSnail;
import com.mojang.blaze3d.vertex.PoseStack;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package codyhuh.unusualfishmod.client.model;
package codyhuh.unusualfishmod.client.old.model;

import codyhuh.unusualfishmod.common.entity.BlindSailfin;
import com.mojang.blaze3d.vertex.PoseStack;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package codyhuh.unusualfishmod.client.model;
package codyhuh.unusualfishmod.client.old.model;

import codyhuh.unusualfishmod.common.entity.BlizzardfinTuna;
import com.google.common.collect.ImmutableList;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package codyhuh.unusualfishmod.client.model;
package codyhuh.unusualfishmod.client.old.model;

import codyhuh.unusualfishmod.common.entity.BrickSnail;
import com.mojang.blaze3d.vertex.PoseStack;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package codyhuh.unusualfishmod.client.model;
package codyhuh.unusualfishmod.client.old.model;

import codyhuh.unusualfishmod.common.entity.CelestialFish;
import com.google.common.collect.ImmutableList;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package codyhuh.unusualfishmod.client.model;
package codyhuh.unusualfishmod.client.old.model;

import codyhuh.unusualfishmod.common.entity.CircusFish;
import com.google.common.collect.ImmutableList;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package codyhuh.unusualfishmod.client.model;
package codyhuh.unusualfishmod.client.old.model;

import codyhuh.unusualfishmod.common.entity.ClownthornShark;
import com.google.common.collect.ImmutableList;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package codyhuh.unusualfishmod.client.model;
package codyhuh.unusualfishmod.client.old.model;

import codyhuh.unusualfishmod.common.entity.CopperflameAnthias;
import com.google.common.collect.ImmutableList;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package codyhuh.unusualfishmod.client.model;
package codyhuh.unusualfishmod.client.old.model;

import codyhuh.unusualfishmod.common.entity.CoralSkrimp;
import codyhuh.unusualfishmod.common.entity.Skrimp;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer;
import net.minecraft.client.model.EntityModel;
Expand All @@ -9,7 +9,7 @@
import net.minecraft.client.model.geom.builders.*;
import net.minecraft.util.Mth;

public class CoralSkrimpModel<T extends CoralSkrimp> extends EntityModel<T> {
public class CoralSkrimpModel<T extends Skrimp> extends EntityModel<T> {
private final ModelPart Head;
private final ModelPart Claw1;
private final ModelPart Claw2;
Expand Down
Loading

0 comments on commit ee4587f

Please sign in to comment.