Skip to content

Commit

Permalink
Adds layer example/cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
AzureZhen committed Dec 21, 2021
1 parent 47c0a74 commit d22a9c2
Show file tree
Hide file tree
Showing 18 changed files with 1,122 additions and 530 deletions.
2 changes: 2 additions & 0 deletions src/main/java/software/bernie/example/ClientListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import software.bernie.example.client.renderer.armor.PotatoArmorRenderer;
import software.bernie.example.client.renderer.entity.BikeGeoRenderer;
import software.bernie.example.client.renderer.entity.ExampleGeoRenderer;
import software.bernie.example.client.renderer.entity.LERenderer;
import software.bernie.example.client.renderer.entity.ReplacedCreeperRenderer;
import software.bernie.example.client.renderer.entity.RocketRender;
import software.bernie.example.client.renderer.item.JackInTheBoxRenderer;
Expand All @@ -55,6 +56,7 @@ public void onInitializeClient() {
if (FabricLoader.getInstance().isDevelopmentEnvironment() && !GeckoLibMod.DISABLE_IN_DEV) {
EntityRendererRegistry.register(EntityRegistry.GEO_EXAMPLE_ENTITY, ExampleGeoRenderer::new);
EntityRendererRegistry.register(EntityRegistry.BIKE_ENTITY, (context) -> new BikeGeoRenderer(context));
EntityRendererRegistry.register(EntityRegistry.GEOLAYERENTITY, LERenderer::new);
GeoItemRenderer.registerItemRenderer(ItemRegistry.JACK_IN_THE_BOX, new JackInTheBoxRenderer());
GeoItemRenderer.registerItemRenderer(ItemRegistry.PISTOL, new PistolRender());

Expand Down
2 changes: 2 additions & 0 deletions src/main/java/software/bernie/example/GeckoLibMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public void onInitialize() {
EntityUtils.createGenericEntityAttributes());
FabricDefaultAttributeRegistry.register(EntityRegistry.BIKE_ENTITY,
EntityUtils.createGenericEntityAttributes());
FabricDefaultAttributeRegistry.register(EntityRegistry.GEOLAYERENTITY,
EntityUtils.createGenericEntityAttributes());
new ItemRegistry();
new TileRegistry();
new BlockRegistry();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package software.bernie.example.client.model.entity;

import net.minecraft.util.Identifier;
import software.bernie.example.entity.LEEntity;
import software.bernie.geckolib3.GeckoLib;
import software.bernie.geckolib3.model.AnimatedTickingGeoModel;

public class LEModel extends AnimatedTickingGeoModel<LEEntity> {

@Override
public Identifier getModelLocation(LEEntity object) {
return new Identifier(GeckoLib.ModID, "geo/le.geo.json");
}

@Override
public Identifier getTextureLocation(LEEntity object) {
return new Identifier(GeckoLib.ModID, "textures/entity/le.png");
}

@Override
public Identifier getAnimationFileLocation(LEEntity animatable) {
return new Identifier(GeckoLib.ModID, "animations/le.animations.json");
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package software.bernie.example.client.renderer.entity;

import net.minecraft.client.render.entity.EntityRendererFactory;
import software.bernie.example.client.model.entity.LEModel;
import software.bernie.example.client.renderer.entity.layer.GeoExampleLayer;
import software.bernie.example.entity.LEEntity;
import software.bernie.geckolib3.renderers.geo.GeoEntityRenderer;

public class LERenderer extends GeoEntityRenderer<LEEntity> {

@SuppressWarnings("unchecked")
public LERenderer(EntityRendererFactory.Context renderManager) {
super(renderManager, new LEModel());
this.addLayer(new GeoExampleLayer(this));
this.shadowRadius = 0.25f;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package software.bernie.example.client.renderer.entity.layer;

import net.minecraft.client.render.OverlayTexture;
import net.minecraft.client.render.RenderLayer;
import net.minecraft.client.render.VertexConsumerProvider;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.entity.Entity;
import net.minecraft.util.Identifier;
import software.bernie.geckolib3.GeckoLib;
import software.bernie.geckolib3.renderers.geo.GeoLayerRenderer;
import software.bernie.geckolib3.renderers.geo.IGeoRenderer;

@SuppressWarnings("rawtypes")
public class GeoExampleLayer extends GeoLayerRenderer {
// A resource location for the texture of the layer. This will be applied onto pre-existing cubes on the model
private static final Identifier LAYER = new Identifier(GeckoLib.ModID, "textures/entity/le_glasses.png");
// A resource location for the model of the entity. This model is put on top of the normal one, which is then given the texture
private static final Identifier MODEL = new Identifier(GeckoLib.ModID, "geo/le.geo.json");

@SuppressWarnings("unchecked")
public GeoExampleLayer(IGeoRenderer<?> entityRendererIn) {
super(entityRendererIn);
}

@SuppressWarnings("unchecked")
@Override
public void render(MatrixStack matrixStackIn, VertexConsumerProvider bufferIn, int packedLightIn, Entity entityLivingBaseIn, float limbSwing, float limbSwingAmount, float partialTicks, float ageInTicks, float netHeadYaw, float headPitch) {
RenderLayer cameo = RenderLayer.getArmorCutoutNoCull(LAYER);
matrixStackIn.push();
//Move or scale the model as you see fit
matrixStackIn.scale(1.0f, 1.0f, 1.0f);
matrixStackIn.translate(0.0d, 0.0d, 0.0d);
this.getRenderer().render(this.getEntityModel().getModel(MODEL), entityLivingBaseIn, partialTicks, cameo, matrixStackIn, bufferIn,
bufferIn.getBuffer(cameo), packedLightIn, OverlayTexture.DEFAULT_UV, 1f, 1f, 1f, 1f);
matrixStackIn.pop();
}
}
49 changes: 49 additions & 0 deletions src/main/java/software/bernie/example/entity/LEEntity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package software.bernie.example.entity;

import net.minecraft.entity.EntityType;
import net.minecraft.entity.ai.goal.LookAtEntityGoal;
import net.minecraft.entity.mob.PathAwareEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.world.World;
import software.bernie.geckolib3.core.IAnimatable;
import software.bernie.geckolib3.core.IAnimationTickable;
import software.bernie.geckolib3.core.PlayState;
import software.bernie.geckolib3.core.builder.AnimationBuilder;
import software.bernie.geckolib3.core.controller.AnimationController;
import software.bernie.geckolib3.core.event.predicate.AnimationEvent;
import software.bernie.geckolib3.core.manager.AnimationData;
import software.bernie.geckolib3.core.manager.AnimationFactory;

public class LEEntity extends PathAwareEntity implements IAnimatable, IAnimationTickable {
private AnimationFactory factory = new AnimationFactory(this);

private <E extends IAnimatable> PlayState predicate(AnimationEvent<E> event) {
event.getController().setAnimation(new AnimationBuilder().addAnimation("animation.geoLayerEntity.idle", true));
return PlayState.CONTINUE;
}

public LEEntity(EntityType<? extends PathAwareEntity> type, World worldIn) {
super(type, worldIn);
}

@Override
public void registerControllers(AnimationData data) {
data.addAnimationController(new AnimationController<LEEntity>(this, "controller", 5, this::predicate));
}

@Override
public AnimationFactory getFactory() {
return this.factory;
}

@Override
protected void initGoals() {
this.goalSelector.add(6, new LookAtEntityGoal(this, PlayerEntity.class, 6.0F));
super.initGoals();
}

@Override
public int tickTimer() {
return age;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import net.minecraft.util.Identifier;
import software.bernie.example.entity.BikeEntity;
import software.bernie.example.entity.GeoExampleEntity;
import software.bernie.example.entity.LEEntity;
import software.bernie.example.entity.RocketProjectile;
import software.bernie.geckolib3.GeckoLib;

Expand All @@ -21,6 +22,8 @@ public class EntityRegistry {
GeoExampleEntity.class, .7F, 1.3F, SpawnGroup.CREATURE);
public static final EntityType<BikeEntity> BIKE_ENTITY = buildEntity(BikeEntity::new, BikeEntity.class, 0.5f, 0.6F,
SpawnGroup.CREATURE);
public static final EntityType<LEEntity> GEOLAYERENTITY = buildEntity(LEEntity::new, LEEntity.class, 0.45F, 1.0F,
SpawnGroup.CREATURE);
public static EntityType<RocketProjectile> ROCKET = buildEntity(RocketProjectile::new, RocketProjectile.class, 0.5F,
0.5F, SpawnGroup.MISC);

Expand Down
50 changes: 25 additions & 25 deletions src/main/resources/assets/geckolib3/animations/bike.animation.json
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
{
"format_version": "1.8.0",
"animations": {
"animation.bike.idle": {
"loop": true,
"bones": {
"body": {
"rotation": ["math.cos(query.anim_time * 200) * 0.5", 0, "(math.sin(query.anim_time * 200) * 0.5) + math.clamp(query.yaw_speed * -20, -20, 20)"],
"position": [0, "math.cos(query.anim_time * 100) * 0.5", 0],
"scale": ["Math.clamp(query.distance_from_camera / 5, 1, 6)", "Math.clamp(query.distance_from_camera / 5, 1, 6)", "Math.clamp(query.distance_from_camera / 5, 1, 6)"]
},
"lfin1": {
"rotation": [0, 0, "-35+math.sin(query.anim_time*400*query.actor_count)*25"]
},
"lfin2": {
"rotation": [0, 0, "-35+math.sin(query.anim_time*300*query.actor_count)*20"]
},
"rfin1": {
"rotation": [0, 0, "35+math.sin(query.anim_time*400*query.actor_count)*-25"]
},
"rfin2": {
"rotation": [0, 0, "35+math.sin(query.anim_time*300*query.actor_count)*-20"]
}
}
}
}
"format_version": "1.8.0",
"animations": {
"animation.bike.idle": {
"loop": true,
"bones": {
"body": {
"rotation": ["math.cos(query.anim_time * 200) * 0.5", 0, "(math.sin(query.anim_time * 200) * 0.5) + math.clamp(query.yaw_speed * -20, -20, 20)"],
"position": [0, "math.cos(query.anim_time * 100) * 0.5", 0],
"scale": ["Math.clamp(query.distance_from_camera / 5, 1, 6)", "Math.clamp(query.distance_from_camera / 5, 1, 6)", "Math.clamp(query.distance_from_camera / 5, 1, 6)"]
},
"lfin1": {
"rotation": [0, 0, "-35+math.sin(query.anim_time*400*query.actor_count)*25"]
},
"lfin2": {
"rotation": [0, 0, "-35+math.sin(query.anim_time*300*query.actor_count)*20"]
},
"rfin1": {
"rotation": [0, 0, "35+math.sin(query.anim_time*400*query.actor_count)*-25"]
},
"rfin2": {
"rotation": [0, 0, "35+math.sin(query.anim_time*300*query.actor_count)*-20"]
}
}
}
}
}
Loading

0 comments on commit d22a9c2

Please sign in to comment.