Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Faboslav committed Nov 28, 2024
1 parent dd337a7 commit a592d80
Show file tree
Hide file tree
Showing 49 changed files with 1,001 additions and 227 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ help: ## Prints help for targets with comments
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'

build-project: ## Builds project
./gradlew build
./gradlew build -Xmaxerrs

refresh: ## Refresh dependencies
./gradlew --refresh-dependencies
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,29 @@
package com.faboslav.friendsandfoes.common.client.render.entity.model;

import com.faboslav.friendsandfoes.common.client.render.entity.animation.animator.ModelAnimator;
import com.faboslav.friendsandfoes.common.client.render.entity.state.GlareEntityRenderState;
import com.faboslav.friendsandfoes.common.entity.animation.AnimatedEntity;
import com.faboslav.friendsandfoes.common.mixin.ModelPartAccessor;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.model.Model;
import net.minecraft.client.model.ModelPart;
import net.minecraft.client.model.ModelTransform;
import net.minecraft.client.render.RenderLayer;
import net.minecraft.client.render.entity.state.EntityRenderState;
import net.minecraft.entity.Entity;
import net.minecraft.util.Identifier;

import java.util.HashMap;
import java.util.Map;
import java.util.function.Function;

@Environment(EnvType.CLIENT)
public abstract class AnimatedEntityModel<E extends Entity> extends BaseEntityModel<E>
/*? >=1.21.2 {*/
public abstract class AnimatedEntityModel<T extends EntityRenderState> extends Model<T>
/*?} else {*/
/*public abstract class AnimatedEntityModel<E extends Entity> extends BaseEntityModel<E>
*//*?}*/
{
protected final Map<String, ModelTransform> defaultModelTransforms;

Expand All @@ -28,6 +38,12 @@ protected AnimatedEntityModel(ModelPart root) {
);
}

public AnimatedEntityModel(ModelPart root, Function<Identifier, RenderLayer> layerFactory) {
super(root, layerFactory);

this.defaultModelTransforms = new HashMap<>();
}

protected void setCurrentModelTransforms(
String modelPartName,
ModelPart modelPart
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package com.faboslav.friendsandfoes.common.client.render.entity.model;
/*? <=1.21.1 {*/
/*package com.faboslav.friendsandfoes.common.client.render.entity.model;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.model.Model;
import net.minecraft.client.model.ModelPart;
import net.minecraft.client.render.entity.model.SinglePartEntityModel;
import net.minecraft.client.render.entity.state.EntityRenderState;
import net.minecraft.entity.Entity;
@Environment(EnvType.CLIENT)
Expand All @@ -15,9 +18,5 @@ public abstract class BaseEntityModel<E extends Entity> extends SinglePartEntity
protected BaseEntityModel(ModelPart root) {
this.root = root;
}

@Override
public ModelPart getPart() {
return this.root;
}
}
*//*?}*/
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
package com.faboslav.friendsandfoes.common.client.render.entity.model;

import com.faboslav.friendsandfoes.common.client.render.entity.animation.animator.ModelPartAnimator;
import com.faboslav.friendsandfoes.common.client.render.entity.state.GlareEntityRenderState;
import com.faboslav.friendsandfoes.common.entity.GlareEntity;
import com.faboslav.friendsandfoes.common.util.animation.AnimationMath;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.model.*;
import net.minecraft.client.render.entity.model.EntityModel;
import net.minecraft.client.render.entity.state.StriderEntityRenderState;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Vec2f;

@Environment(EnvType.CLIENT)
public final class GlareEntityModel<T extends GlareEntity> extends AnimatedEntityModel<T>
/*? >=1.21.2 {*/
public class GlareEntityModel extends AnimatedEntityModel<GlareEntityRenderState>
/*?} else {*/
/*public final class GlareEntityModel<T extends GlareEntity> extends AnimatedEntityModel<T>
*//*?}*/
{
private static final String MODEL_PART_ROOT = "root";
private static final String MODEL_PART_HEAD = "head";
Expand Down Expand Up @@ -72,15 +79,13 @@ public static TexturedModelData getTexturedModelData() {
}

@Override
public void setAngles(
T glare,
float limbAngle,
float limbDistance,
float animationProgress,
float headYaw,
float headPitch
) {
this.getPart().traverse().forEach(ModelPart::resetTransform);
/*? >=1.21.2 {*/
public void setAngles(GlareEntityRenderState glareEntityRenderState)
/*?} else {*/
/*public void setAngles(T glare, float limbAngle, float limbDistance, float animationProgress, float headYaw, float headPitch)
*//*?}*/
{
this.getRootPart().traverse().forEach(ModelPart::resetTransform);

this.animateEyes(glare);
this.animateFloating(glare, animationProgress);
Expand Down Expand Up @@ -118,27 +123,29 @@ public void animateModel(
}

private void animateFloating(
T glare,
float animationProgress
float animationProgress,
boolean isGrumpy,
boolean isSitting,
Vec2f eyesPositionOffset
) {
float verticalFloatingSpeed = glare.isGrumpy() ? 0.3F:0.1F;
float horizontalFloatingSpeed = glare.isGrumpy() ? 0.15F:0.05F;
float verticalFloatingSpeed = isGrumpy ? 0.3F:0.1F;
float horizontalFloatingSpeed = isGrumpy ? 0.15F:0.05F;

float verticalFloatingOffset;
float horizontalFloatingOffset;

if (glare.isSitting()) {
if (isSitting) {
verticalFloatingOffset = 0.5F;
horizontalFloatingOffset = 0.5F;
} else {
verticalFloatingOffset = 1.5F;
horizontalFloatingOffset = 1.0F;
}

float targetPivotY = glare.isSitting() ? 3.0F:0.11F;
float targetPivotY = isSitting ? 3.0F:0.11F;
animateModelPartYPositionBasedOnTicks(glare, this.root, targetPivotY, 10);

if (glare.isGrumpy()) {
if (isGrumpy) {
ModelPartAnimator.setXPosition(this.root, AnimationMath.sin(animationProgress, 0.5F));
ModelPartAnimator.setYPosition(this.root, AnimationMath.absSin(animationProgress, 0.1F));
ModelPartAnimator.setYRotation(this.root, AnimationMath.sin(animationProgress, 0.05F));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
package com.faboslav.friendsandfoes.common.client.render.entity.model;

import com.faboslav.friendsandfoes.common.client.render.entity.state.GlareEntityRenderState;
import com.faboslav.friendsandfoes.common.client.render.entity.state.TuffGolemEntityRenderState;
import com.faboslav.friendsandfoes.common.entity.TuffGolemEntity;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.model.*;
import net.minecraft.client.render.entity.model.EntityModel;

@Environment(EnvType.CLIENT)
public final class TuffGolemEntityModel<T extends TuffGolemEntity> extends AnimatedEntityModel<T>
/*? >=1.21.2 {*/
public class TuffGolemEntityModel extends AnimatedEntityModel<TuffGolemEntityRenderState>
/*?} else {*/
/*public final class TuffGolemEntityModel<T extends TuffGolemEntity> extends AnimatedEntityModel<T>
*//*?}*/
{
private static final String MODEL_PART_BODY = "body";
private static final String MODEL_PART_NOSE = "nose";
Expand Down Expand Up @@ -61,6 +68,22 @@ public static TexturedModelData getTexturedModelData() {
return TexturedModelData.of(modelData, 64, 64);
}

@Override
/*? >=1.21.2 {*/
public void setAngles(TuffGolemEntityRenderState tuffGolemEntityRenderState)
/*?} else {*/
/*public void setAngles(T glare, float limbAngle, float limbDistance, float animationProgress, float headYaw, float headPitch)
*//*?}*/ {
}

private void updateAnimations(
float limbAngle,
float limbDistance,
float animationProgress,
) {

}

@Override
public void setAngles(
T tuffGolem,
Expand All @@ -70,7 +93,7 @@ public void setAngles(
float headYaw,
float headPitch
) {
this.getPart().traverse().forEach(ModelPart::resetTransform);
this.getRootPart().traverse().forEach(ModelPart::resetTransform);
this.updateMovementKeyframeAnimations(tuffGolem, limbAngle, limbDistance, 4.0F * tuffGolem.getMovementSpeedModifier(), 4.0F * tuffGolem.getMovementSpeedModifier());
this.updateKeyframeAnimations(tuffGolem, animationProgress);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,65 @@
package com.faboslav.friendsandfoes.common.client.render.entity.renderer;

/*? >=1.21.2 {*/

import com.faboslav.friendsandfoes.common.FriendsAndFoes;
import com.faboslav.friendsandfoes.common.client.render.entity.feature.GlareFlowerFeatureRenderer;
import com.faboslav.friendsandfoes.common.client.render.entity.model.GlareEntityModel;
import com.faboslav.friendsandfoes.common.client.render.entity.state.GlareEntityRenderState;
import com.faboslav.friendsandfoes.common.entity.GlareEntity;
import com.faboslav.friendsandfoes.common.init.FriendsAndFoesEntityModelLayers;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.render.entity.EntityRendererFactory;
import net.minecraft.client.render.entity.MobEntityRenderer;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.util.Identifier;

@Environment(EnvType.CLIENT)
@SuppressWarnings({"rawtypes", "unchecked"})
public class GlareEntityRenderer extends MobEntityRenderer<GlareEntity, GlareEntityRenderState, GlareEntityModel>
{
private static final Identifier TEXTURE = FriendsAndFoes.makeID("textures/entity/glare/glare.png");

public GlareEntityRenderer(EntityRendererFactory.Context context) {
super(context, new GlareEntityModel(context.getPart(FriendsAndFoesEntityModelLayers.GLARE_LAYER)), 0.4F);
this.addFeature(new GlareFlowerFeatureRenderer(this));
}

@Override
public Identifier getTexture(GlareEntityRenderState state) {
return TEXTURE;
}

protected float getShadowRadius(GlareEntityRenderState glareEntityRenderState) {
float shadowRadius = super.getShadowRadius(glareEntityRenderState);
return glareEntityRenderState.baby ? shadowRadius * 0.5F : shadowRadius;
}

public GlareEntityRenderState createRenderState() {
return new GlareEntityRenderState();
}

public void updateRenderState(GlareEntity glareEntity, GlareEntityRenderState glareEntityRenderState, float f) {
super.updateRenderState(glareEntity, glareEntityRenderState, f);
glareEntityRenderState.isTamed = glareEntity.isTamed();
glareEntityRenderState.isGrumpy = glareEntity.isGrumpy();
glareEntityRenderState.isSitting = glareEntity.isSitting();
glareEntityRenderState.eyesPositionOffset = glareEntity.getTargetEyesPositionOffset();
}


@Override
protected void scale(GlareEntityRenderState renderState, MatrixStack matrixStack) {
float scale = renderState.ageScale;
matrixStack.scale(scale, scale, scale);
}
}

/*?} else {*/
/*import com.faboslav.friendsandfoes.common.FriendsAndFoes;
import com.faboslav.friendsandfoes.common.client.render.entity.feature.GlareFlowerFeatureRenderer;
import com.faboslav.friendsandfoes.common.client.render.entity.model.GlareEntityModel;
import com.faboslav.friendsandfoes.common.entity.GlareEntity;
import com.faboslav.friendsandfoes.common.init.FriendsAndFoesEntityModelLayers;
import net.fabricmc.api.EnvType;
Expand All @@ -22,16 +79,14 @@ public GlareEntityRenderer(EntityRendererFactory.Context context) {
}
@Override
protected void scale(GlareEntity glare, MatrixStack matrixStack, float amount) {
if (!glare.isBaby()) {
matrixStack.scale(0.8F, 0.8F, 0.8F);
} else {
matrixStack.scale(0.4F, 0.4F, 0.4F);
}
protected void scale(GlareEntity glareEntity, MatrixStack matrixStack, float f) {
float scaleFactor = glareEntity.getScaleFactor();
matrixStack.scale(scaleFactor, scaleFactor, scaleFactor);
}
@Override
public Identifier getTexture(GlareEntity entity) {
return FriendsAndFoes.makeID("textures/entity/glare/glare.png");
}
}
}
*//*?}*/
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,72 @@
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.render.VertexConsumerProvider;
import net.minecraft.client.render.entity.EntityRendererFactory.Context;
import net.minecraft.client.render.entity.EntityRendererFactory;
import net.minecraft.client.render.entity.IllagerEntityRenderer;
import net.minecraft.client.render.entity.feature.HeldItemFeatureRenderer;
import net.minecraft.client.render.entity.model.IllagerEntityModel;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.entity.mob.SpellcastingIllagerEntity;
import net.minecraft.util.Identifier;

/*? >=1.21.2 {*/
import net.minecraft.client.render.entity.state.EntityRenderState;
import net.minecraft.client.render.entity.state.LivingEntityRenderState;
import net.minecraft.client.render.entity.model.EntityModelLayers;
import net.minecraft.client.render.entity.EntityRendererFactory.Context;
import com.faboslav.friendsandfoes.common.client.render.entity.state.IceologerEntityRenderState;
/*?}*/

@Environment(EnvType.CLIENT)
public final class IceologerEntityRenderer<T extends SpellcastingIllagerEntity> extends IllagerEntityRenderer<T>
/*? >=1.21.2 {*/
public final class IceologerEntityRenderer<T extends SpellcastingIllagerEntity> extends IllagerEntityRenderer<T, IceologerEntityRenderState>
/*?} else {*/
/*public final class IceologerEntityRenderer<T extends SpellcastingIllagerEntity> extends IllagerEntityRenderer<T>
*//*?}*/
{
public IceologerEntityRenderer(Context context) {
public static final Identifier TEXTURE = FriendsAndFoes.makeID("textures/entity/illager/iceologer.png");

/*? >=1.21.2 {*/
public IceologerEntityRenderer(EntityRendererFactory.Context context) {
super(context, new IllagerEntityModel<>(context.getPart(FriendsAndFoesEntityModelLayers.ICEOLOGER_LAYER)), 0.5F);
this.model.getHat().visible = true;

this.addFeature(new HeldItemFeatureRenderer<>(this, context.getItemRenderer())
{
public void render(
MatrixStack matrixStack,
VertexConsumerProvider vertexConsumerProvider,
int i,
IceologerEntityRenderState iceologerEntityRenderState,
float f,
float g
) {
if (iceologerEntityRenderState.spellcasting) {
super.render(matrixStack, vertexConsumerProvider, i, iceologerEntityRenderState, f, g);
}

}
});
}

@Override
public Identifier getTexture(IceologerEntityRenderState iceologerEntityRenderState) {
return TEXTURE;
}

@Override
public IceologerEntityRenderState createRenderState() {
return new IceologerEntityRenderState();
}

public void updateRenderState(T spellcastingIllagerEntity, IceologerEntityRenderState iceologerEntityRenderState, float f) {
super.updateRenderState(spellcastingIllagerEntity, iceologerEntityRenderState, f);
iceologerEntityRenderState.spellcasting = spellcastingIllagerEntity.isSpellcasting();
}
/*?} else {*/
/*public IceologerEntityRenderer(EntityRendererFactory.Context context) {
super(context, new IllagerEntityModel<>(context.getPart(FriendsAndFoesEntityModelLayers.ICEOLOGER_LAYER)), 0.5F);
this.model.getHat().visible = true;
this.addFeature(new HeldItemFeatureRenderer<>(this, context.getHeldItemRenderer())
{
Expand All @@ -39,12 +92,11 @@ public void render(
}
});

this.model.getHat().visible = true;
}
@Override
public Identifier getTexture(T entity) {
return FriendsAndFoes.makeID("textures/entity/illager/iceologer.png");
return TEXTURE;
}
*//*?}*/
}
Loading

0 comments on commit a592d80

Please sign in to comment.