[Feature] Raft Support
This commit is contained in:
parent
e2bc392a90
commit
dd13f09bd2
4 changed files with 51 additions and 22 deletions
|
@ -6,7 +6,8 @@ import org.betterx.bclib.items.boat.CustomBoatTypeOverride;
|
|||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import com.mojang.blaze3d.vertex.VertexConsumer;
|
||||
import com.mojang.math.Axis;
|
||||
import net.minecraft.client.model.BoatModel;
|
||||
import net.minecraft.client.model.ListModel;
|
||||
import net.minecraft.client.model.WaterPatchModel;
|
||||
import net.minecraft.client.renderer.MultiBufferSource;
|
||||
import net.minecraft.client.renderer.RenderType;
|
||||
import net.minecraft.client.renderer.texture.OverlayTexture;
|
||||
|
@ -54,7 +55,7 @@ public class BoatRenderer {
|
|||
));
|
||||
}
|
||||
ResourceLocation resourceLocation = hasChest ? type.chestBoatTexture : type.boatTexture;
|
||||
BoatModel boatModel = type.getBoatModel(hasChest);
|
||||
ListModel<Boat> boatModel = type.getBoatModel(hasChest);
|
||||
poseStack.scale(-1.0f, -1.0f, 1.0f);
|
||||
poseStack.mulPose(Axis.YP.rotationDegrees(90.0f));
|
||||
boatModel.setupAnim(boat, g, 0.0f, -0.1f, 0.0f, 0.0f);
|
||||
|
@ -66,7 +67,9 @@ public class BoatRenderer {
|
|||
);
|
||||
if (!boat.isUnderWater()) {
|
||||
VertexConsumer vertexConsumer2 = multiBufferSource.getBuffer(RenderType.waterMask());
|
||||
boatModel.waterPatch().render(poseStack, vertexConsumer2, i, OverlayTexture.NO_OVERLAY);
|
||||
if (boatModel instanceof WaterPatchModel waterPatchModel) {
|
||||
waterPatchModel.waterPatch().render(poseStack, vertexConsumer2, i, OverlayTexture.NO_OVERLAY);
|
||||
}
|
||||
}
|
||||
poseStack.popPose();
|
||||
|
||||
|
|
|
@ -49,7 +49,7 @@ public class WoodenComplexMaterial extends ComplexMaterialSet<WoodenComplexMater
|
|||
public final MapColor planksColor;
|
||||
public final MapColor woodColor;
|
||||
@Nullable
|
||||
private BoatTypeOverride boatType;
|
||||
protected BoatTypeOverride boatType;
|
||||
|
||||
public final BCLWoodTypeWrapper woodType;
|
||||
|
||||
|
@ -60,7 +60,7 @@ public class WoodenComplexMaterial extends ComplexMaterialSet<WoodenComplexMater
|
|||
MapColor woodColor,
|
||||
MapColor planksColor
|
||||
) {
|
||||
this(modID, baseName, receipGroupPrefix, woodColor, planksColor, false);
|
||||
this(modID, baseName, receipGroupPrefix, woodColor, planksColor, null);
|
||||
}
|
||||
|
||||
public WoodenComplexMaterial(
|
||||
|
@ -69,13 +69,13 @@ public class WoodenComplexMaterial extends ComplexMaterialSet<WoodenComplexMater
|
|||
String receipGroupPrefix,
|
||||
MapColor woodColor,
|
||||
MapColor planksColor,
|
||||
boolean withBoats
|
||||
BoatTypeOverride boatType
|
||||
) {
|
||||
super(modID, baseName, receipGroupPrefix);
|
||||
this.planksColor = planksColor;
|
||||
this.woodColor = woodColor;
|
||||
this.woodType = createWoodTypeBuilder().build();
|
||||
this.boatType = null;
|
||||
this.boatType = boatType;
|
||||
}
|
||||
|
||||
protected BCLWoodTypeWrapper.Builder createWoodTypeBuilder() {
|
||||
|
@ -139,16 +139,20 @@ public class WoodenComplexMaterial extends ComplexMaterialSet<WoodenComplexMater
|
|||
}
|
||||
|
||||
|
||||
public void initBoatType() {
|
||||
public final void initBoatType() {
|
||||
if (getBoatType() == null) {
|
||||
boatType = BoatTypeOverride.create(
|
||||
getModID(),
|
||||
getBaseName(),
|
||||
getBlock(WoodSlots.PLANKS)
|
||||
);
|
||||
boatType = supplyBoatType();
|
||||
}
|
||||
}
|
||||
|
||||
protected BoatTypeOverride supplyBoatType() {
|
||||
return BoatTypeOverride.create(
|
||||
getModID(),
|
||||
getBaseName(),
|
||||
getBlock(WoodSlots.PLANKS)
|
||||
);
|
||||
}
|
||||
|
||||
public BoatTypeOverride getBoatType() {
|
||||
return boatType;
|
||||
}
|
||||
|
|
|
@ -2,11 +2,11 @@ package org.betterx.bclib.items.boat;
|
|||
|
||||
import org.betterx.bclib.BCLib;
|
||||
|
||||
import net.minecraft.client.model.BoatModel;
|
||||
import net.minecraft.client.model.ChestBoatModel;
|
||||
import net.minecraft.client.model.*;
|
||||
import net.minecraft.client.model.geom.ModelLayerLocation;
|
||||
import net.minecraft.client.renderer.entity.EntityRendererProvider;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.entity.vehicle.Boat;
|
||||
import net.minecraft.world.item.BoatItem;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
|
@ -32,10 +32,15 @@ public final class BoatTypeOverride {
|
|||
public final ModelLayerLocation boatModelName;
|
||||
public final ModelLayerLocation chestBoatModelName;
|
||||
@Environment(value = EnvType.CLIENT)
|
||||
private BoatModel boatModel, chestBoatModel;
|
||||
private ListModel<Boat> boatModel, chestBoatModel;
|
||||
private BoatItem boat, chestBoat;
|
||||
public final boolean isRaft;
|
||||
|
||||
BoatTypeOverride(String modID, String name, Block planks) {
|
||||
this(modID, name, planks, false);
|
||||
}
|
||||
|
||||
BoatTypeOverride(String modID, String name, Block planks, boolean isRaft) {
|
||||
this.id = new ResourceLocation(modID, name);
|
||||
this.name = name;
|
||||
this.planks = planks;
|
||||
|
@ -47,6 +52,7 @@ public final class BoatTypeOverride {
|
|||
if (nr >= 0 && nr <= 1000) nr += 1000;
|
||||
}
|
||||
this.ordinal = nr;
|
||||
this.isRaft = isRaft;
|
||||
if (BCLib.isClient()) {
|
||||
this.boatModelName = createBoatModelName(id.getNamespace(), id.getPath());
|
||||
this.chestBoatModelName = createChestBoatModelName(id.getNamespace(), id.getPath());
|
||||
|
@ -63,15 +69,20 @@ public final class BoatTypeOverride {
|
|||
}
|
||||
|
||||
@Environment(value = EnvType.CLIENT)
|
||||
public BoatModel getBoatModel(boolean chest) {
|
||||
public ListModel<Boat> getBoatModel(boolean chest) {
|
||||
return chest ? chestBoatModel : boatModel;
|
||||
}
|
||||
|
||||
@Environment(value = EnvType.CLIENT)
|
||||
public void createBoatModels(EntityRendererProvider.Context context) {
|
||||
if (BCLib.isClient() && boatModel == null) {
|
||||
boatModel = new BoatModel(context.bakeLayer(boatModelName));
|
||||
chestBoatModel = new ChestBoatModel(context.bakeLayer(chestBoatModelName));
|
||||
if (isRaft) {
|
||||
boatModel = new RaftModel(context.bakeLayer(boatModelName));
|
||||
chestBoatModel = new ChestRaftModel(context.bakeLayer(chestBoatModelName));
|
||||
} else {
|
||||
boatModel = new BoatModel(context.bakeLayer(boatModelName));
|
||||
chestBoatModel = new ChestBoatModel(context.bakeLayer(chestBoatModelName));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -115,7 +126,11 @@ public final class BoatTypeOverride {
|
|||
}
|
||||
|
||||
public static BoatTypeOverride create(String modID, String name, Block planks) {
|
||||
BoatTypeOverride t = new BoatTypeOverride(modID, name, planks);
|
||||
return create(modID, name, planks, false);
|
||||
}
|
||||
|
||||
public static BoatTypeOverride create(String modID, String name, Block planks, boolean isRaft) {
|
||||
BoatTypeOverride t = new BoatTypeOverride(modID, name, planks, isRaft);
|
||||
|
||||
return t;
|
||||
}
|
||||
|
|
|
@ -5,6 +5,8 @@ import org.betterx.bclib.items.boat.BoatTypeOverride;
|
|||
|
||||
import net.minecraft.client.model.BoatModel;
|
||||
import net.minecraft.client.model.ChestBoatModel;
|
||||
import net.minecraft.client.model.ChestRaftModel;
|
||||
import net.minecraft.client.model.RaftModel;
|
||||
import net.minecraft.client.model.geom.builders.LayerDefinition;
|
||||
|
||||
import net.fabricmc.api.EnvType;
|
||||
|
@ -19,10 +21,15 @@ public class BaseBlockEntityRenders {
|
|||
|
||||
LayerDefinition boatModel = BoatModel.createBodyModel();
|
||||
LayerDefinition chestBoatModel = ChestBoatModel.createBodyModel();
|
||||
LayerDefinition raftModel = RaftModel.createBodyModel();
|
||||
LayerDefinition chestRaftModel = ChestRaftModel.createBodyModel();
|
||||
|
||||
BoatTypeOverride.values().forEach(type -> {
|
||||
EntityModelLayerRegistry.registerModelLayer(type.boatModelName, () -> boatModel);
|
||||
EntityModelLayerRegistry.registerModelLayer(type.chestBoatModelName, () -> chestBoatModel);
|
||||
EntityModelLayerRegistry.registerModelLayer(type.boatModelName, () -> type.isRaft ? raftModel : boatModel);
|
||||
EntityModelLayerRegistry.registerModelLayer(
|
||||
type.chestBoatModelName,
|
||||
() -> type.isRaft ? chestRaftModel : chestBoatModel
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue