Skip to content

Commit

Permalink
restore entity models, krill water balloons
Browse files Browse the repository at this point in the history
  • Loading branch information
TropheusJ committed Jun 21, 2024
1 parent 191deea commit ccbff5e
Show file tree
Hide file tree
Showing 15 changed files with 467 additions and 131 deletions.
28 changes: 16 additions & 12 deletions src/main/java/one/devos/nautical/up_and_away/UpAndAwayClient.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package one.devos.nautical.up_and_away;

import java.util.Collection;
import java.util.Map;
import java.util.stream.Stream;

import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.rendering.v1.BuiltinItemRendererRegistry;
import net.fabricmc.fabric.api.client.rendering.v1.ColorProviderRegistry;
import net.fabricmc.fabric.api.client.rendering.v1.EntityModelLayerRegistry;
import net.fabricmc.fabric.api.client.rendering.v1.EntityRendererRegistry;
Expand All @@ -13,24 +10,31 @@
import one.devos.nautical.up_and_away.content.balloon.entity.renderer.BalloonCartModel;
import one.devos.nautical.up_and_away.content.balloon.entity.renderer.BalloonCartRenderer;
import one.devos.nautical.up_and_away.content.balloon.entity.renderer.BalloonRenderer;
import one.devos.nautical.up_and_away.content.balloon.entity.renderer.model.CubeBalloonModel;
import one.devos.nautical.up_and_away.content.balloon.entity.renderer.model.DogBalloonModel;
import one.devos.nautical.up_and_away.content.balloon.entity.renderer.model.HeartBalloonModel;
import one.devos.nautical.up_and_away.content.balloon.entity.renderer.model.LongBalloonModel;
import one.devos.nautical.up_and_away.content.balloon.entity.renderer.model.RoundBalloonModel;
import one.devos.nautical.up_and_away.content.balloon.item.BalloonItemColor;
import net.minecraft.world.item.Item;
import one.devos.nautical.up_and_away.content.balloon.item.BalloonItemRenderer;
import net.minecraft.world.level.ItemLike;

public class UpAndAwayClient implements ClientModInitializer {
@Override
public void onInitializeClient() {
EntityModelLayerRegistry.registerModelLayer(DogBalloonModel.LAYER_LOCATION, DogBalloonModel::createBodyLayer);
EntityModelLayerRegistry.registerModelLayer(CubeBalloonModel.LAYER_LOCATION, CubeBalloonModel::createBodyLayer);
EntityModelLayerRegistry.registerModelLayer(HeartBalloonModel.LAYER_LOCATION, HeartBalloonModel::createBodyLayer);
EntityModelLayerRegistry.registerModelLayer(LongBalloonModel.LAYER_LOCATION, LongBalloonModel::createBodyLayer);
EntityModelLayerRegistry.registerModelLayer(RoundBalloonModel.LAYER_LOCATION, RoundBalloonModel::createBodyLayer);

EntityModelLayerRegistry.registerModelLayer(BalloonCartModel.LAYER_LOCATION, BalloonCartModel::createBodyLayer);

EntityRendererRegistry.register(UpAndAwayEntities.AIR_BALLOON, BalloonRenderer::new);
EntityRendererRegistry.register(UpAndAwayEntities.FLOATY_BALLOON, BalloonRenderer::new);
EntityRendererRegistry.register(UpAndAwayEntities.WATER_BALLOON, BalloonRenderer::new);
EntityRendererRegistry.register(UpAndAwayEntities.BALLOON_CART, BalloonCartRenderer::new);

Item[] allBalloons = Stream.of(
UpAndAwayItems.DEFLATED_BALLOONS, UpAndAwayItems.AIR_BALLOONS,
UpAndAwayItems.FLOATY_BALLOONS, UpAndAwayItems.WATER_BALLOONS
).map(Map::values).flatMap(Collection::stream).toArray(Item[]::new);

ColorProviderRegistry.ITEM.register(new BalloonItemColor(), allBalloons);
ColorProviderRegistry.ITEM.register(new BalloonItemColor(), UpAndAwayItems.ALL_BALLOONS.toArray(ItemLike[]::new));
UpAndAwayItems.ALL_BALLOONS.forEach(item -> BuiltinItemRendererRegistry.INSTANCE.register(item, BalloonItemRenderer.INSTANCE));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import one.devos.nautical.up_and_away.content.balloon.entity.AirBalloon;
import one.devos.nautical.up_and_away.content.balloon.entity.BalloonCart;
import one.devos.nautical.up_and_away.content.balloon.entity.FloatyBalloon;
import one.devos.nautical.up_and_away.content.balloon.entity.WaterBalloon;
import net.minecraft.core.Registry;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.world.entity.Entity;
Expand All @@ -24,12 +23,6 @@ public class UpAndAwayEntities {
.build()
);

public static final EntityType<WaterBalloon> WATER_BALLOON = register(
"water_balloon", EntityType.Builder.of(WaterBalloon::createClient, MobCategory.MISC)
.sized(1, 1)
.build()
);

public static final EntityType<BalloonCart> BALLOON_CART = register(
"balloon_cart", EntityType.Builder.of(BalloonCart::new, MobCategory.MISC)
.build()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package one.devos.nautical.up_and_away.content;

import java.util.Collection;
import java.util.ArrayList;
import java.util.EnumMap;
import java.util.List;
import java.util.Map;
import java.util.function.Predicate;
import java.util.stream.Stream;

import net.fabricmc.fabric.api.itemgroup.v1.FabricItemGroup;
import one.devos.nautical.up_and_away.UpAndAway;
Expand All @@ -15,7 +14,6 @@
import one.devos.nautical.up_and_away.content.balloon.item.BalloonItem;
import one.devos.nautical.up_and_away.content.balloon.item.DeflatedBalloonItem;
import one.devos.nautical.up_and_away.content.balloon.item.filled.FloatyBalloonItem;
import one.devos.nautical.up_and_away.content.balloon.item.filled.WaterBalloonItem;
import net.minecraft.core.Registry;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.network.chat.Component;
Expand All @@ -28,11 +26,12 @@
import net.minecraft.world.item.component.DyedItemColor;

public class UpAndAwayItems {
public static final List<Item> ALL_BALLOONS = new ArrayList<>();

public static final Map<BalloonShape, Item>
DEFLATED_BALLOONS = balloons("%s_deflated_balloon", UpAndAwayItems::noAnimals, DeflatedBalloonItem::new),
AIR_BALLOONS = balloons("%s_air_balloon", UpAndAwayItems::all, AirBalloonItem::new),
FLOATY_BALLOONS = balloons("%s_floaty_balloon", UpAndAwayItems::all, FloatyBalloonItem::new),
WATER_BALLOONS = balloons("%s_water_balloon", UpAndAwayItems::noAnimals, WaterBalloonItem::new);
FLOATY_BALLOONS = balloons("%s_floaty_balloon", UpAndAwayItems::all, FloatyBalloonItem::new);

public static final Item BALLOON_CART = register("balloon_cart", new BalloonCartItem(new Properties()));

Expand All @@ -45,9 +44,7 @@ public class UpAndAwayItems {
new ItemStack(FLOATY_BALLOONS.get(BalloonShape.ROUND)), List.of((DyeItem) Items.RED_DYE)
))
.displayItems((params, output) -> {
Stream.of(
DEFLATED_BALLOONS, AIR_BALLOONS, FLOATY_BALLOONS, WATER_BALLOONS
).map(Map::values).flatMap(Collection::stream).forEach(output::accept);
ALL_BALLOONS.forEach(output::accept);
output.accept(BALLOON_CART);
})
.build()
Expand All @@ -58,7 +55,9 @@ private static Map<BalloonShape, Item> balloons(String template, Predicate<Ballo
for (BalloonShape shape : BalloonShape.values()) {
if (test.test(shape)) {
String name = template.formatted(shape);
map.put(shape, register(name, factory.create(shape, new Properties())));
BalloonItem item = factory.create(shape, new Properties());
ALL_BALLOONS.add(item);
map.put(shape, register(name, item));
}
}
return map;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

import one.devos.nautical.up_and_away.content.balloon.entity.attachment.BalloonAttachmentHolder;

import one.devos.nautical.up_and_away.content.balloon.item.BalloonItem;

import org.jetbrains.annotations.Nullable;

import net.minecraft.nbt.CompoundTag;
Expand All @@ -16,7 +18,6 @@
import net.minecraft.network.syncher.SynchedEntityData;
import net.minecraft.network.syncher.SynchedEntityData.Builder;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.Entity.MovementEmission;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.MoverType;
import net.minecraft.world.item.ItemStack;
Expand Down Expand Up @@ -142,6 +143,11 @@ public ItemStack item() {
return this.entityData.get(ITEM);
}

public BalloonShape shape() {
// TODO: this is bad
return ((BalloonItem) this.item().getItem()).shape;
}

@Nullable
public BalloonAttachment attachment() {
return this.attachmentHolder.get(this.level());
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package one.devos.nautical.up_and_away.content.balloon.entity.renderer;

import one.devos.nautical.up_and_away.content.balloon.BalloonShape;
import one.devos.nautical.up_and_away.content.balloon.entity.AbstractBalloon;
import one.devos.nautical.up_and_away.content.balloon.entity.renderer.model.DogBalloonModel;
import one.devos.nautical.up_and_away.content.balloon.entity.renderer.model.CubeBalloonModel;
import one.devos.nautical.up_and_away.content.balloon.entity.renderer.model.HeartBalloonModel;
import one.devos.nautical.up_and_away.content.balloon.entity.renderer.model.LongBalloonModel;
import one.devos.nautical.up_and_away.content.balloon.entity.renderer.model.RoundBalloonModel;
import net.minecraft.client.model.EntityModel;
import net.minecraft.client.model.geom.ModelLayerLocation;
import net.minecraft.client.model.geom.ModelPart;

public class BalloonModels {
private final CubeBalloonModel cubeModel;
private final DogBalloonModel dogModel;
private final HeartBalloonModel heartModel;
private final LongBalloonModel longModel;
private final RoundBalloonModel roundModel;

public BalloonModels(EntityModelBakery bakery) {
this.cubeModel = new CubeBalloonModel(bakery.bake(CubeBalloonModel.LAYER_LOCATION));
this.dogModel = new DogBalloonModel(bakery.bake(DogBalloonModel.LAYER_LOCATION));
this.heartModel = new HeartBalloonModel(bakery.bake(HeartBalloonModel.LAYER_LOCATION));
this.longModel = new LongBalloonModel(bakery.bake(LongBalloonModel.LAYER_LOCATION));
this.roundModel = new RoundBalloonModel(bakery.bake(RoundBalloonModel.LAYER_LOCATION));
}

public EntityModel<AbstractBalloon> choose(BalloonShape shape) {
return switch (shape) {
case CUBE -> this.cubeModel;
case DOG -> this.dogModel;
case HEART -> this.heartModel;
case LONG -> this.longModel;
case ROUND -> this.roundModel;
};
}

public interface EntityModelBakery {
ModelPart bake(ModelLayerLocation layer);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package one.devos.nautical.up_and_away.content.balloon.entity.renderer;


import com.mojang.math.Axis;

import one.devos.nautical.up_and_away.UpAndAway;
import one.devos.nautical.up_and_away.content.balloon.entity.AbstractBalloon;

import one.devos.nautical.up_and_away.content.balloon.entity.attachment.BalloonAttachment;
Expand All @@ -10,42 +13,39 @@
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer;

import net.minecraft.client.model.EntityModel;
import net.minecraft.client.renderer.LightTexture;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.entity.EntityRenderer;
import net.minecraft.client.renderer.entity.EntityRendererProvider.Context;
import net.minecraft.client.renderer.entity.ItemRenderer;
import net.minecraft.client.renderer.texture.OverlayTexture;
import net.minecraft.core.BlockPos;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.FastColor;
import net.minecraft.util.Mth;
import net.minecraft.world.inventory.InventoryMenu;
import net.minecraft.world.item.ItemDisplayContext;
import net.minecraft.world.level.LightLayer;
import net.minecraft.world.phys.Vec3;

public class BalloonRenderer extends EntityRenderer<AbstractBalloon> {
private final ItemRenderer itemRenderer;
public static final ResourceLocation TEXTURE = UpAndAway.id("textures/entity/balloon/balloon.png");

private final BalloonModels models;

public BalloonRenderer(Context context) {
super(context);
this.itemRenderer = context.getItemRenderer();
this.models = new BalloonModels(context::bakeLayer);
}

@Override
public void render(AbstractBalloon balloon, float yRot, float partialTicks, PoseStack matrices, MultiBufferSource buffers, int light) {
super.render(balloon, yRot, partialTicks, matrices, buffers, light);
matrices.pushPose();
matrices.scale(2, 2, 2);
this.itemRenderer.renderStatic(
balloon.item(),
ItemDisplayContext.GROUND,
light, OverlayTexture.NO_OVERLAY,
matrices, buffers,
null, 0
);
matrices.translate(0, 1.5, 0);
matrices.mulPose(Axis.XP.rotationDegrees(180));
EntityModel<AbstractBalloon> model = this.models.choose(balloon.shape());
VertexConsumer vertices = buffers.getBuffer(RenderType.entityTranslucent(this.getTextureLocation(balloon)));
model.renderToBuffer(matrices, vertices, light, OverlayTexture.NO_OVERLAY);
matrices.popPose();

BalloonAttachment attachment = balloon.attachment();
Expand All @@ -56,7 +56,7 @@ public void render(AbstractBalloon balloon, float yRot, float partialTicks, Pose

@Override
public ResourceLocation getTextureLocation(AbstractBalloon balloon) {
return InventoryMenu.BLOCK_ATLAS;
return TEXTURE;
}

// based on EntityRenderer lead rendering
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package one.devos.nautical.up_and_away.content.balloon.entity.renderer.model;

import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer;

import net.minecraft.client.model.EntityModel;
import net.minecraft.client.model.geom.ModelLayerLocation;
import net.minecraft.client.model.geom.ModelPart;
import net.minecraft.client.model.geom.PartPose;
import net.minecraft.client.model.geom.builders.CubeDeformation;
import net.minecraft.client.model.geom.builders.CubeListBuilder;
import net.minecraft.client.model.geom.builders.LayerDefinition;
import net.minecraft.client.model.geom.builders.MeshDefinition;
import net.minecraft.client.model.geom.builders.PartDefinition;
import one.devos.nautical.up_and_away.UpAndAway;
import one.devos.nautical.up_and_away.content.balloon.entity.AbstractBalloon;

public class CubeBalloonModel extends EntityModel<AbstractBalloon> {
public static final ModelLayerLocation LAYER_LOCATION = new ModelLayerLocation(UpAndAway.id("cube_balloon"), "main");

private final ModelPart balloon;
private final ModelPart tie;

public CubeBalloonModel(ModelPart root) {
this.balloon = root.getChild("balloon");
this.tie = root.getChild("tie");
}

public static LayerDefinition createBodyLayer() {
MeshDefinition meshdefinition = new MeshDefinition();
PartDefinition partdefinition = meshdefinition.getRoot();

PartDefinition balloon = partdefinition.addOrReplaceChild("balloon", CubeListBuilder.create().texOffs(0, 34).addBox(-7.0F, -14.0F, -7.0F, 14.0F, 14.0F, 14.0F, new CubeDeformation(0.0F)), PartPose.offset(0.0F, 22.0F, 0.0F));

PartDefinition tie = partdefinition.addOrReplaceChild("tie", CubeListBuilder.create(), PartPose.offset(0.0F, 23.0F, 0.0F));

PartDefinition cube_r1 = tie.addOrReplaceChild("cube_r1", CubeListBuilder.create().texOffs(0, 34).mirror().addBox(-1.5F, -1.0F, 0.0F, 3.0F, 2.0F, 0.0F, new CubeDeformation(0.0F)).mirror(false), PartPose.offsetAndRotation(0.0F, 0.0F, 0.0F, 0.0F, -0.7854F, 0.0F));

PartDefinition cube_r2 = tie.addOrReplaceChild("cube_r2", CubeListBuilder.create().texOffs(0, 34).addBox(-1.5F, -1.0F, 0.0F, 3.0F, 2.0F, 0.0F, new CubeDeformation(0.0F)), PartPose.offsetAndRotation(0.0F, 0.0F, 0.0F, 0.0F, 0.7854F, 0.0F));

return LayerDefinition.create(meshdefinition, 128, 128);
}


@Override
public void setupAnim(AbstractBalloon entity, float f, float g, float h, float i, float j) {
}

@Override
public void renderToBuffer(PoseStack poseStack, VertexConsumer vertexConsumer, int i, int j, int k) {
balloon.render(poseStack, vertexConsumer, i, j, k);
tie.render(poseStack, vertexConsumer, i, j, k);
}
}
Loading

0 comments on commit ccbff5e

Please sign in to comment.