Make monolith's solid again and move like the old days.

This commit is contained in:
Waterpicker 2024-01-20 23:53:16 -06:00
parent e1f389f568
commit c0ef07beb1
61 changed files with 103 additions and 64 deletions

View file

@ -4,6 +4,7 @@ import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer; import com.mojang.blaze3d.vertex.VertexConsumer;
import net.fabricmc.api.EnvType; import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment; import net.fabricmc.api.Environment;
import net.minecraft.client.Minecraft;
import net.minecraft.client.model.EntityModel; import net.minecraft.client.model.EntityModel;
import net.minecraft.client.model.geom.ModelPart; import net.minecraft.client.model.geom.ModelPart;
import net.minecraft.client.model.geom.PartPose; import net.minecraft.client.model.geom.PartPose;
@ -17,6 +18,8 @@ import org.dimdev.dimdoors.entity.MonolithEntity;
@Environment(EnvType.CLIENT) @Environment(EnvType.CLIENT)
public class MonolithModel extends EntityModel<MonolithEntity> { public class MonolithModel extends EntityModel<MonolithEntity> {
private final ModelPart body; private final ModelPart body;
private int aggro;
private int id;
public MonolithModel(EntityRendererProvider.Context context) { public MonolithModel(EntityRendererProvider.Context context) {
super(MyRenderLayer::getMonolith); super(MyRenderLayer::getMonolith);
@ -26,54 +29,38 @@ public class MonolithModel extends EntityModel<MonolithEntity> {
public static LayerDefinition getTexturedModelData() { public static LayerDefinition getTexturedModelData() {
MeshDefinition modelData = new MeshDefinition(); MeshDefinition modelData = new MeshDefinition();
PartDefinition modelPartData = modelData.getRoot(); PartDefinition modelPartData = modelData.getRoot();
modelPartData.addOrReplaceChild("body", CubeListBuilder.create().texOffs(0, 0).addBox(-23.5F, -23.5F, 0, 49.0F, 49.0F, 1.0F, false), PartPose.ZERO); modelPartData.addOrReplaceChild("body", CubeListBuilder.create().texOffs(1, 0).addBox(-23.5F, -54, -6, 47, 108, 12, false), PartPose.ZERO);
return LayerDefinition.create(modelData, 102, 51); return LayerDefinition.create(modelData, 128, 128);
} }
@Override @Override
public void renderToBuffer(PoseStack matrixStack, VertexConsumer consumer, int packedLight, int packedOverlay, float red, float green, float blue, float alpha) { public void renderToBuffer(PoseStack matrixStack, VertexConsumer consumer, int packedLight, int packedOverlay, float red, float green, float blue, float alpha) {
matrixStack.pushPose();
matrixStack.scale(3.0625f, 3.0625f, 3.0625f);
PoseStack.Pose entry = matrixStack.last(); final float minScaling = 0;
final float maxScaling = 0.001f;
consumer.vertex(entry.pose(), -1, -0.5f, 0) // Use linear interpolation to scale how much jitter we want for our given aggro level
.color(red, green, blue, alpha) float aggroScaling = minScaling + (maxScaling - minScaling) * aggro;
.uv(0,0)
.overlayCoords(packedOverlay)
.uv2(packedLight)
.normal(entry.normal(), 0, 0, 1)
.endVertex();
consumer.vertex(entry.pose(), -1, 0.5f, 0)
.color(red, green, blue, alpha)
.uv(0, 1)
.overlayCoords(packedOverlay)
.uv2(packedLight)
.normal(entry.normal(), 0, 0, 1)
.endVertex();
consumer.vertex(entry.pose(), 1, 0.5f, 0)
.color(red, green, blue, alpha)
.uv(1,1)
.overlayCoords(packedOverlay)
.uv2(packedLight)
.normal(entry.normal(), 0, 0, 1)
.endVertex();
consumer.vertex(entry.pose(), 1, -0.5f, 0)
.color(red, green, blue, alpha)
.uv(1, 0)
.overlayCoords(packedOverlay)
.uv2(packedLight)
.normal(entry.normal(), 0, 0, 1)
.endVertex();
matrixStack.popPose(); // Calculate jitter - include entity ID to give Monoliths individual jitters
float time = ((Minecraft.getInstance().getFrameTimeNs() + 0xF1234568 * id) % 200000) / 50.0F;
// We use random constants here on purpose just to get different wave forms
var jitterX = (float) (aggroScaling * Math.sin(1.1f * time) * Math.sin(0.8f * time));
var jitterY = (float) (aggroScaling * Math.sin(1.2f * time) * Math.sin(0.9f * time));
var jitterZ = (float) (aggroScaling * Math.sin(1.3f * time) * Math.sin(0.7f * time));
// this.body.render(matrixStack, consumer, packedLight, packedOverlay); matrixStack.pushPose();
matrixStack.translate(jitterX, jitterY, jitterZ);
this.body.render(matrixStack, consumer, packedLight, packedOverlay);
matrixStack.popPose();
} }
@Override @Override
public void setupAnim(MonolithEntity entity, float limbSwing, float limbSwingAmount, float ageInTicks, float netHeadYaw, float headPitch) { public void setupAnim(MonolithEntity monolith, float limbSwing, float limbSwingAmount, float ageInTicks, float netHeadYaw, float headPitch) {
this.body.yRot = netHeadYaw * 0.017453292F; this.body.yRot = netHeadYaw * 0.017453292F;
this.body.xRot = headPitch * 0.017453292F; this.body.xRot = headPitch * 0.017453292F;
this.aggro = monolith.getAggro();
this.id = monolith.getId();
} }
} }

View file

@ -3,6 +3,7 @@ package org.dimdev.dimdoors.client;
import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.PoseStack;
import net.fabricmc.api.EnvType; import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment; import net.fabricmc.api.Environment;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.entity.EntityRendererProvider; import net.minecraft.client.renderer.entity.EntityRendererProvider;
import net.minecraft.client.renderer.entity.MobRenderer; import net.minecraft.client.renderer.entity.MobRenderer;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
@ -15,28 +16,52 @@ import java.util.stream.Stream;
@Environment(EnvType.CLIENT) @Environment(EnvType.CLIENT)
public class MonolithRenderer extends MobRenderer<MonolithEntity, MonolithModel> { public class MonolithRenderer extends MobRenderer<MonolithEntity, MonolithModel> {
public static final List<ResourceLocation> MONOLITH_TEXTURES = Stream.of( public static final List<ResourceLocation> TRANSPARENT = Stream.of(
DimensionalDoors.id("textures/mob/monolith/monolith0.png"), DimensionalDoors.id("textures/mob/monolith/transparent/monolith_0.png"),
DimensionalDoors.id("textures/mob/monolith/monolith1.png"), DimensionalDoors.id("textures/mob/monolith/transparent/monolith_1.png"),
DimensionalDoors.id("textures/mob/monolith/monolith2.png"), DimensionalDoors.id("textures/mob/monolith/transparent/monolith_2.png"),
DimensionalDoors.id("textures/mob/monolith/monolith3.png"), DimensionalDoors.id("textures/mob/monolith/transparent/monolith_3.png"),
DimensionalDoors.id("textures/mob/monolith/monolith4.png"), DimensionalDoors.id("textures/mob/monolith/transparent/monolith_4.png"),
DimensionalDoors.id("textures/mob/monolith/monolith5.png"), DimensionalDoors.id("textures/mob/monolith/transparent/monolith_5.png"),
DimensionalDoors.id("textures/mob/monolith/monolith6.png"), DimensionalDoors.id("textures/mob/monolith/transparent/monolith_6.png"),
DimensionalDoors.id("textures/mob/monolith/monolith7.png"), DimensionalDoors.id("textures/mob/monolith/transparent/monolith_7.png"),
DimensionalDoors.id("textures/mob/monolith/monolith8.png"), DimensionalDoors.id("textures/mob/monolith/transparent/monolith_8.png"),
DimensionalDoors.id("textures/mob/monolith/monolith9.png"), DimensionalDoors.id("textures/mob/monolith/transparent/monolith_9.png"),
DimensionalDoors.id("textures/mob/monolith/monolith10.png"), DimensionalDoors.id("textures/mob/monolith/transparent/monolith_10.png"),
DimensionalDoors.id("textures/mob/monolith/monolith11.png"), DimensionalDoors.id("textures/mob/monolith/transparent/monolith_11.png"),
DimensionalDoors.id("textures/mob/monolith/monolith12.png"), DimensionalDoors.id("textures/mob/monolith/transparent/monolith_12.png"),
DimensionalDoors.id("textures/mob/monolith/monolith13.png"), DimensionalDoors.id("textures/mob/monolith/transparent/monolith_13.png"),
DimensionalDoors.id("textures/mob/monolith/monolith14.png"), DimensionalDoors.id("textures/mob/monolith/transparent/monolith_14.png"),
DimensionalDoors.id("textures/mob/monolith/monolith15.png"), DimensionalDoors.id("textures/mob/monolith/transparent/monolith_15.png"),
DimensionalDoors.id("textures/mob/monolith/monolith16.png"), DimensionalDoors.id("textures/mob/monolith/transparent/monolith_16.png"),
DimensionalDoors.id("textures/mob/monolith/monolith17.png"), DimensionalDoors.id("textures/mob/monolith/transparent/monolith_17.png"),
DimensionalDoors.id("textures/mob/monolith/monolith18.png") DimensionalDoors.id("textures/mob/monolith/transparent/monolith_18.png")
).collect(Collectors.toList()); ).collect(Collectors.toList());
public static final List<ResourceLocation> SOLID = Stream.of(
DimensionalDoors.id("textures/mob/monolith/solid/monolith_0.png"),
DimensionalDoors.id("textures/mob/monolith/solid/monolith_1.png"),
DimensionalDoors.id("textures/mob/monolith/solid/monolith_2.png"),
DimensionalDoors.id("textures/mob/monolith/solid/monolith_3.png"),
DimensionalDoors.id("textures/mob/monolith/solid/monolith_4.png"),
DimensionalDoors.id("textures/mob/monolith/solid/monolith_5.png"),
DimensionalDoors.id("textures/mob/monolith/solid/monolith_6.png"),
DimensionalDoors.id("textures/mob/monolith/solid/monolith_7.png"),
DimensionalDoors.id("textures/mob/monolith/solid/monolith_8.png"),
DimensionalDoors.id("textures/mob/monolith/solid/monolith_9.png"),
DimensionalDoors.id("textures/mob/monolith/solid/monolith_10.png"),
DimensionalDoors.id("textures/mob/monolith/solid/monolith_11.png"),
DimensionalDoors.id("textures/mob/monolith/solid/monolith_12.png"),
DimensionalDoors.id("textures/mob/monolith/solid/monolith_13.png"),
DimensionalDoors.id("textures/mob/monolith/solid/monolith_14.png"),
DimensionalDoors.id("textures/mob/monolith/solid/monolith_15.png"),
DimensionalDoors.id("textures/mob/monolith/solid/monolith_16.png"),
DimensionalDoors.id("textures/mob/monolith/solid/monolith_17.png"),
DimensionalDoors.id("textures/mob/monolith/solid/monolith_18.png")
).collect(Collectors.toList());
private static MonolithModel INSTANCE; private static MonolithModel INSTANCE;
public MonolithRenderer(EntityRendererProvider.Context ctx) { public MonolithRenderer(EntityRendererProvider.Context ctx) {
@ -52,13 +77,25 @@ public class MonolithRenderer extends MobRenderer<MonolithEntity, MonolithModel>
matrices.scale(entity.getScale(), entity.getScale(), entity.getScale()); matrices.scale(entity.getScale(), entity.getScale(), entity.getScale());
} }
@Override @Override
public void render(MonolithEntity entity, float entityYaw, float partialTicks, PoseStack poseStack, MultiBufferSource buffer, int packedLight) {
if(entity.getSolid()) {
poseStack.pushPose();
super.render(entity, entityYaw, partialTicks, poseStack, buffer, packedLight);
poseStack.popPose();
}
}
@Override
protected boolean shouldShowName(MonolithEntity mobEntity) { protected boolean shouldShowName(MonolithEntity mobEntity) {
return false; return false;
} }
@Override @Override
public ResourceLocation getTextureLocation(MonolithEntity entity) { public ResourceLocation getTextureLocation(MonolithEntity entity) {
return MonolithRenderer.MONOLITH_TEXTURES.get(entity.getTextureState()); return SOLID.get(entity.getTextureState());
} }
} }

View file

@ -1,6 +1,7 @@
package org.dimdev.dimdoors.client; package org.dimdev.dimdoors.client;
import com.flowpowered.math.vector.VectorNi; import com.flowpowered.math.vector.VectorNi;
import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.DefaultVertexFormat; import com.mojang.blaze3d.vertex.DefaultVertexFormat;
import com.mojang.blaze3d.vertex.VertexFormat; import com.mojang.blaze3d.vertex.VertexFormat;
@ -71,11 +72,10 @@ public class MyRenderLayer extends RenderType {
public static RenderType getMonolith(ResourceLocation texture) { public static RenderType getMonolith(ResourceLocation texture) {
RenderType.CompositeState multiPhaseParameters = RenderType.CompositeState.builder().setTextureState(new TextureStateShard(texture, false, false)) RenderType.CompositeState multiPhaseParameters = RenderType.CompositeState.builder().setTextureState(new TextureStateShard(texture, false, false))
.setShaderState(new ShaderStateShard(GameRenderer::getRendertypeEntityTranslucentShader)) .setShaderState(new ShaderStateShard(GameRenderer::getRendertypeEntitySolidShader))
.setTransparencyState(RenderStateShard.TRANSLUCENT_TRANSPARENCY) .setTransparencyState(RenderStateShard.NO_TRANSPARENCY)
.setCullState(RenderStateShard.NO_CULL) // .setCullState(RenderStateShard.NO_CULL)
.setLightmapState(RenderStateShard.LIGHTMAP) .setLightmapState(RenderStateShard.LIGHTMAP)
.setDepthTestState(RenderStateShard.NO_DEPTH_TEST)
.setOverlayState(RenderStateShard.OVERLAY).createCompositeState(false); .setOverlayState(RenderStateShard.OVERLAY).createCompositeState(false);
return RenderType.create("monolith", DefaultVertexFormat.NEW_ENTITY, VertexFormat.Mode.QUADS, 256, true, true, multiPhaseParameters); return RenderType.create("monolith", DefaultVertexFormat.NEW_ENTITY, VertexFormat.Mode.QUADS, 256, true, true, multiPhaseParameters);
} }

View file

@ -39,6 +39,8 @@ public class MonolithEntity extends Mob {
private static final EntityDataAccessor<Integer> AGGRO = SynchedEntityData.defineId(MonolithEntity.class, EntityDataSerializers.INT); private static final EntityDataAccessor<Integer> AGGRO = SynchedEntityData.defineId(MonolithEntity.class, EntityDataSerializers.INT);
private static final EntityDataAccessor<Float> SCALE = SynchedEntityData.defineId(MonolithEntity.class, EntityDataSerializers.FLOAT); private static final EntityDataAccessor<Float> SCALE = SynchedEntityData.defineId(MonolithEntity.class, EntityDataSerializers.FLOAT);
private static final EntityDataAccessor<Float> PITCH = SynchedEntityData.defineId(MonolithEntity.class, EntityDataSerializers.FLOAT); private static final EntityDataAccessor<Float> PITCH = SynchedEntityData.defineId(MonolithEntity.class, EntityDataSerializers.FLOAT);
private static final EntityDataAccessor<Boolean> SOLID = SynchedEntityData.defineId(MonolithEntity.class, EntityDataSerializers.BOOLEAN);
private static final float EYE_HEIGHT_PERCENTAGE = 0.55f; private static final float EYE_HEIGHT_PERCENTAGE = 0.55f;
private int soundTime = 0; private int soundTime = 0;
@ -113,6 +115,7 @@ public class MonolithEntity extends Mob {
this.entityData.define(AGGRO, 0); this.entityData.define(AGGRO, 0);
this.entityData.define(SCALE, 1f); this.entityData.define(SCALE, 1f);
this.entityData.define(PITCH, 1f); this.entityData.define(PITCH, 1f);
this.entityData.define(SOLID, true);
this.refreshDimensions(); this.refreshDimensions();
} }
@ -261,9 +264,21 @@ public class MonolithEntity extends Mob {
if (nbt.contains("pitch", Tag.TAG_FLOAT)) { if (nbt.contains("pitch", Tag.TAG_FLOAT)) {
setPitch(nbt.getFloat("pitch")); setPitch(nbt.getFloat("pitch"));
} }
if (nbt.contains("solid", Tag.TAG_BYTE)) {
setSolid(nbt.getBoolean("solid"));
}
} }
public int getAggro() { private void setSolid(boolean solid) {
this.entityData.set(SOLID, solid);
}
public boolean getSolid() {
return this.entityData.get(SOLID);
}
public int getAggro() {
return this.entityData.get(AGGRO); return this.entityData.get(AGGRO);
} }

Binary file not shown.

Before

Width:  |  Height:  |  Size: 558 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 746 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 774 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 842 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.5 KiB