Skip to content

Commit

Permalink
Add Goombas (#94)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hugman76 authored Sep 27, 2024
2 parents 08c291a + 0a40347 commit 1b43cfc
Show file tree
Hide file tree
Showing 45 changed files with 1,132 additions and 10 deletions.
5 changes: 5 additions & 0 deletions src/main/java/fr/hugman/mubble/Mubble.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
import com.google.common.reflect.Reflection;
import fr.hugman.mubble.block.MubbleBlockEntityTypes;
import fr.hugman.mubble.block.MubbleBlocks;
import fr.hugman.mubble.entity.MubbleEntityTypes;
import fr.hugman.mubble.item.MubbleItemGroups;
import fr.hugman.mubble.item.MubbleItems;
import fr.hugman.mubble.registry.MubbleRegistries;
import fr.hugman.mubble.screen.MubbleScreenHandlerTypes;
import fr.hugman.mubble.sound.MubbleSounds;
import fr.hugman.mubble.world.MubbleGamerules;
Expand All @@ -24,10 +26,13 @@ public void onInitialize() {
Reflection.initialize(MubbleItems.class);
Reflection.initialize(MubbleSounds.class);
Reflection.initialize(MubbleScreenHandlerTypes.class);
MubbleEntityTypes.registerAttributes();

MubbleItemGroups.appendItemGroups();

MubbleGamerules.init();

MubbleRegistries.register();
}

public static Identifier id(String path) {
Expand Down
13 changes: 5 additions & 8 deletions src/main/java/fr/hugman/mubble/MubbleClient.java
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
package fr.hugman.mubble;

import fr.hugman.mubble.block.MubbleBlockEntityTypes;
import fr.hugman.mubble.block.MubbleBlocks;
import fr.hugman.mubble.client.gui.screen.BumpableScreen;
import fr.hugman.mubble.client.render.BumpableBlockEntityRenderer;
import fr.hugman.mubble.client.render.MubbleRenderLayers;
import fr.hugman.mubble.client.render.MubbleRenderers;
import fr.hugman.mubble.screen.MubbleScreenHandlerTypes;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.blockrenderlayer.v1.BlockRenderLayerMap;
import net.minecraft.client.gui.screen.ingame.HandledScreens;
import net.minecraft.client.render.RenderLayer;
import net.minecraft.client.render.block.entity.BlockEntityRendererFactories;

@Environment(EnvType.CLIENT)
public class MubbleClient implements ClientModInitializer {
@Override
public void onInitializeClient() {
registerBlockRenderLayers();
registerHandledScreens();
registerBlockEntityRenderers();
MubbleRenderers.registerEntities();
MubbleRenderers.registerBlockEntities();
MubbleRenderLayers.registerLayers();
}

private static void registerBlockRenderLayers() {
Expand All @@ -30,8 +31,4 @@ private static void registerBlockRenderLayers() {
private static void registerHandledScreens() {
HandledScreens.register(MubbleScreenHandlerTypes.BUMPABLE_BLOCK, BumpableScreen::new);
}

private static void registerBlockEntityRenderers() {
BlockEntityRendererFactories.register(MubbleBlockEntityTypes.BUMPABLE_BLOCK, BumpableBlockEntityRenderer::new);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package fr.hugman.mubble.client.render;

import fr.hugman.mubble.Mubble;
import fr.hugman.mubble.client.render.entity.model.GoombaModel;
import net.fabricmc.fabric.api.client.rendering.v1.EntityModelLayerRegistry;
import net.minecraft.client.render.entity.model.EntityModelLayer;

public class MubbleRenderLayers {
public static final EntityModelLayer GOOMBA = createModelLayer("goomba");

public static void registerLayers() {
EntityModelLayerRegistry.registerModelLayer(GOOMBA, GoombaModel::getTexturedModelData);
}

private static EntityModelLayer createModelLayer(String name) {
return new EntityModelLayer(Mubble.id(name), "main");
}

private static EntityModelLayer createModelLayer(String name, String layer) {
return new EntityModelLayer(Mubble.id(name), layer);
}
}
17 changes: 17 additions & 0 deletions src/main/java/fr/hugman/mubble/client/render/MubbleRenderers.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package fr.hugman.mubble.client.render;

import fr.hugman.mubble.block.MubbleBlockEntityTypes;
import fr.hugman.mubble.client.render.entity.GoombaRenderer;
import fr.hugman.mubble.entity.MubbleEntityTypes;
import net.fabricmc.fabric.api.client.rendering.v1.EntityRendererRegistry;
import net.minecraft.client.render.block.entity.BlockEntityRendererFactories;

public class MubbleRenderers {
public static void registerEntities() {
EntityRendererRegistry.register(MubbleEntityTypes.GOOMBA, GoombaRenderer::new);
}

public static void registerBlockEntities() {
BlockEntityRendererFactories.register(MubbleBlockEntityTypes.BUMPABLE_BLOCK, BumpableBlockEntityRenderer::new);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package fr.hugman.mubble.client.render.entity;

import fr.hugman.mubble.client.render.MubbleRenderLayers;
import fr.hugman.mubble.client.render.entity.model.GoombaModel;
import fr.hugman.mubble.entity.GoombaEntity;
import net.minecraft.client.render.VertexConsumerProvider;
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;

public class GoombaRenderer extends MobEntityRenderer<GoombaEntity, GoombaModel> {
public GoombaRenderer(EntityRendererFactory.Context context) {
super(context, new GoombaModel(context.getPart(MubbleRenderLayers.GOOMBA)), 0.4f);
}

@Override
public Identifier getTexture(GoombaEntity entity) {
return entity.getTexture();
}

@Override
public void render(GoombaEntity goomba, float f, float g, MatrixStack matrixStack, VertexConsumerProvider vertexConsumerProvider, int i) {
if(goomba.isSurprised()) {
this.forceRotation(goomba);
}
super.render(goomba, f, g, matrixStack, vertexConsumerProvider, i);
}

private void forceRotation(GoombaEntity goomba) {
goomba.prevHeadYaw = goomba.headYaw;
goomba.bodyYaw = goomba.headYaw;
goomba.prevBodyYaw = goomba.bodyYaw;
goomba.prevPitch = goomba.getPitch();
goomba.prevYaw = goomba.getYaw();
}
}
Loading

0 comments on commit 1b43cfc

Please sign in to comment.