Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Koopa Shells #96

Draft
wants to merge 23 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@

import fr.hugman.mubble.Mubble;
import fr.hugman.mubble.client.render.entity.model.GoombaModel;
import fr.hugman.mubble.client.render.entity.model.KoopaShellModel;
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 final EntityModelLayer KOOPA_SHELL = createModelLayer("koopa_shell");

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

private static EntityModelLayer createModelLayer(String name) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@

import fr.hugman.mubble.block.MubbleBlockEntityTypes;
import fr.hugman.mubble.client.render.entity.GoombaRenderer;
import fr.hugman.mubble.client.render.entity.KoopaShellRenderer;
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);
EntityRendererRegistry.register(MubbleEntityTypes.GREEN_KOOPA_SHELL, KoopaShellRenderer::new);
EntityRendererRegistry.register(MubbleEntityTypes.RED_KOOPA_SHELL, KoopaShellRenderer::new);
}

public static void registerBlockEntities() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package fr.hugman.mubble.client.render.entity;

import fr.hugman.mubble.client.render.MubbleRenderLayers;
import fr.hugman.mubble.client.render.entity.model.KoopaShellModel;
import fr.hugman.mubble.client.render.entity.state.KoopaShellEntityRenderState;
import fr.hugman.mubble.entity.KoopaShellEntity;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.render.OverlayTexture;
import net.minecraft.client.render.RenderLayer;
import net.minecraft.client.render.VertexConsumer;
import net.minecraft.client.render.VertexConsumerProvider;
import net.minecraft.client.render.entity.EntityRenderer;
import net.minecraft.client.render.entity.EntityRendererFactory;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.util.math.MathHelper;
import org.jetbrains.annotations.Nullable;

public class KoopaShellRenderer<K extends KoopaShellEntity> extends EntityRenderer<K, KoopaShellEntityRenderState> {
protected KoopaShellModel model;

public KoopaShellRenderer(EntityRendererFactory.Context context) {
super(context);
this.model = new KoopaShellModel(context.getPart(MubbleRenderLayers.KOOPA_SHELL));
this.shadowRadius = 0.5f;
}

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

@Override
public void render(KoopaShellEntityRenderState state, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light) {
matrices.push();

matrices.scale(-1.0F, -1.0F, 1.0F);
matrices.translate(0.0F, -1.501F, 0.0F);
this.model.setAngles(state);

boolean showBody = !state.invisible;
boolean translucent = !showBody && !state.invisibleToPlayer;
RenderLayer renderLayer = this.getRenderLayer(state, showBody, translucent, state.hasOutline);
if (renderLayer != null) {
VertexConsumer vertexConsumer = vertexConsumers.getBuffer(renderLayer);
int q = OverlayTexture.packUv(OverlayTexture.getU(0.0f), OverlayTexture.getV(false));
this.model.render(matrices, vertexConsumer, light, q, translucent ? 654311423 : -1);
}

matrices.pop();
super.render(state, matrices, vertexConsumers, light);
}

@Nullable
protected RenderLayer getRenderLayer(KoopaShellEntityRenderState state, boolean showBody, boolean translucent, boolean showOutline) {
if (translucent) {
return RenderLayer.getItemEntityTranslucentCull(state.texture);
} else if (showBody) {
return this.model.getLayer(state.texture);
} else {
return showOutline ? RenderLayer.getOutline(state.texture) : null;
}
}

@Override
public void updateRenderState(K entity, KoopaShellEntityRenderState state, float tickDelta) {
super.updateRenderState(entity, state, tickDelta);

state.texture = entity.getTexture();

MinecraftClient minecraftClient = MinecraftClient.getInstance();
state.invisibleToPlayer = state.invisible && entity.isInvisibleTo(minecraftClient.player);
state.hasOutline = minecraftClient.hasOutline(entity);

state.horizontalRotation = MathHelper.lerp(tickDelta, entity.getPreviousHorizontalRotation(), entity.getHorizontalRotation());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package fr.hugman.mubble.client.render.entity.model;

import fr.hugman.mubble.client.render.entity.state.KoopaShellEntityRenderState;
import net.minecraft.client.model.*;
import net.minecraft.client.render.entity.model.EntityModel;
import net.minecraft.client.render.entity.model.EntityModelPartNames;

public class KoopaShellModel extends EntityModel<KoopaShellEntityRenderState> {
public KoopaShellModel(ModelPart part) {
super(part.getChild(EntityModelPartNames.CUBE));
}

public static TexturedModelData getTexturedModelData() {
ModelData modelData = new ModelData();
ModelPartData modelPartData = modelData.getRoot();
modelPartData.addChild(EntityModelPartNames.CUBE,
ModelPartBuilder.create()
.uv(0, 0)
.cuboid(-5.0F, -3.25F, -5.0F, 10.0F, 7.0F, 10.0F)
.uv(0, 17)
.cuboid(-6.0F, -1.25F, -6.0F, 12.0F, 2.0F, 12.0F),
ModelTransform.pivot(0.0F, 20.25F, 0.0F)
);
return TexturedModelData.of(modelData, 64, 32);
}

@Override
public void setAngles(KoopaShellEntityRenderState state) {
super.setAngles(state);
this.root.yaw = state.horizontalRotation;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package fr.hugman.mubble.client.render.entity.state;

import fr.hugman.mubble.Mubble;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.render.entity.state.EntityRenderState;
import net.minecraft.util.Identifier;

@Environment(EnvType.CLIENT)
public class KoopaShellEntityRenderState extends EntityRenderState {
private static final Identifier DEFAULT_TEXTURE = Mubble.id("textures/entity/koopa_shell/green.png");

public Identifier texture = DEFAULT_TEXTURE;
public boolean invisibleToPlayer;
public boolean hasOutline;
public float horizontalRotation = 0.0f;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package fr.hugman.mubble.client.sound;

import fr.hugman.mubble.entity.KoopaShellEntity;
import fr.hugman.mubble.sound.MubbleSounds;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.sound.MovingSoundInstance;
import net.minecraft.client.sound.SoundInstance;
import net.minecraft.sound.SoundCategory;
import net.minecraft.util.math.MathHelper;

@Environment(EnvType.CLIENT)
public class MovingKoopaShellSoundInstance extends MovingSoundInstance {
private final KoopaShellEntity shell;
private float distance = 0.0F;

public MovingKoopaShellSoundInstance(KoopaShellEntity shell) {
super(MubbleSounds.KOOPA_SHELL_SLIDE, SoundCategory.NEUTRAL, SoundInstance.createRandom());
this.shell = shell;
this.repeat = true;
this.repeatDelay = 0;
this.volume = 0.3F;
}


@Override
public boolean canPlay() {
return !this.shell.isSilent();
}

@Override
public boolean shouldAlwaysPlay() {
return true;
}

@Override
public void tick() {
if (this.shell.isRemoved()) {
this.setDone();
} else {
this.x = ((float) this.shell.getX());
this.y = ((float) this.shell.getY());
this.z = ((float) this.shell.getZ());
float f = (float) this.shell.getVelocity().horizontalLength();
if (f >= 0.01F && this.shell.getWorld().getTickManager().shouldTick()) {
this.distance = MathHelper.clamp(this.distance + 0.0025F, 0.0F, 1.0F);
this.volume = MathHelper.lerp(MathHelper.clamp(f, 0.0F, 0.5F), 0.0F, 0.7F);
} else {
this.distance = 0.0F;
this.volume = 0.0F;
}
}
}
}
29 changes: 18 additions & 11 deletions src/main/java/fr/hugman/mubble/entity/GoombaEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
import com.mojang.serialization.MapCodec;
import fr.hugman.mubble.entity.ai.control.StunnableMoveControl;
import fr.hugman.mubble.entity.ai.goal.SurprisedActiveTargetGoal;
import fr.hugman.mubble.entity.damage.MubbleDamageTypeTags;
import fr.hugman.mubble.entity.data.MubbleTrackedData;
import fr.hugman.mubble.registry.MubbleRegistryKeys;
import fr.hugman.mubble.sound.MubbleSounds;
import net.minecraft.block.BlockState;
import net.minecraft.command.argument.EntityAnchorArgumentType;
import net.minecraft.entity.AnimationState;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.VariantHolder;
Expand All @@ -23,13 +25,14 @@
import net.minecraft.nbt.NbtCompound;
import net.minecraft.nbt.NbtOps;
import net.minecraft.registry.entry.RegistryEntry;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.sound.SoundEvent;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;

public class GoombaEntity extends StompableHostileEntity implements Surprisable, Stunnable, VariantHolder<RegistryEntry<GoombaVariant>> {
public class GoombaEntity extends SuperMarioEnemyEntity implements Surprisable, Stunnable, VariantHolder<RegistryEntry<GoombaVariant>> {
public static final String VARIANT_KEY = "variant";

public static final MapCodec<RegistryEntry<GoombaVariant>> VARIANT_MAP_CODEC = GoombaVariant.ENTRY_CODEC.fieldOf(VARIANT_KEY);
Expand Down Expand Up @@ -100,13 +103,23 @@ public boolean isStunned() {
}

@Override
public void onDeath(DamageSource damageSource) {
super.onDeath(damageSource);
if (this.isStomped()) {
this.crushAnimationState.startIfNotRunning(this.age);
public void onSurprised() {
this.playSound(MubbleSounds.GOOMBA_FIND_TARGET, 1.0F, 1.0F);
if(null != this.getTarget()) {
this.lookAt(EntityAnchorArgumentType.EntityAnchor.EYES, this.getTarget().getPos());
}
}

@Override
public AnimationState getStompDeathAnimationState() {
return this.crushAnimationState;
}

@Override
public boolean damage(ServerWorld world, DamageSource source, float amount) {
return super.damage(world, source, source.isIn(MubbleDamageTypeTags.INSTANT_KILLS_GOOMBAS) ? Float.MAX_VALUE : amount);
}

// SOUNDS

@Override
Expand Down Expand Up @@ -147,12 +160,6 @@ public void onTrackedDataSet(TrackedData<?> data) {
this.surprisedAnimationState.start(this.age);
}
}
if (STOMPED.equals(data)) {
if (this.isStomped() && this.dead) {
this.crushAnimationState.startIfNotRunning(this.age);
}
}

super.onTrackedDataSet(data);
}

Expand Down
35 changes: 35 additions & 0 deletions src/main/java/fr/hugman/mubble/entity/GreenKoopaShellEntity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package fr.hugman.mubble.entity;

import fr.hugman.mubble.Mubble;
import fr.hugman.mubble.item.MubbleItems;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.LivingEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Identifier;
import net.minecraft.world.World;

public class GreenKoopaShellEntity extends KoopaShellEntity {
private static final Identifier TEXTURE = Mubble.id("textures/entity/koopa_shell/green.png");

public GreenKoopaShellEntity(EntityType<? extends GreenKoopaShellEntity> entityType, World world) {
super(entityType, world);
}

public GreenKoopaShellEntity(World world, double x, double y, double z) {
super(MubbleEntityTypes.GREEN_KOOPA_SHELL, world, x, y, z);
}

public GreenKoopaShellEntity(World world, LivingEntity owner) {
super(MubbleEntityTypes.GREEN_KOOPA_SHELL, world, owner);
}

@Override
public ItemStack getPickBlockStack() {
return new ItemStack(MubbleItems.GREEN_KOOPA_SHELL);
}

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