Skip to content

Commit

Permalink
fix storage esp breaking at high distances (MeteorDevelopment#4932)
Browse files Browse the repository at this point in the history
  • Loading branch information
RacoonDog authored Oct 6, 2024
1 parent 06c5422 commit 3e5ae3a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
import net.minecraft.client.render.VertexConsumerProvider;

public interface IVertexConsumerProvider extends VertexConsumerProvider {
void setOffset(float offsetX, float offsetY, float offsetZ);
void setOffset(int offsetX, int offsetY, int offsetZ);
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,18 @@ public void setColor(Color color) {
}

@Override
public void setOffset(float offsetX, float offsetY, float offsetZ) {
public void setOffset(int offsetX, int offsetY, int offsetZ) {
vertexConsumer.setOffset(offsetX, offsetY, offsetZ);
}

public static class MeshVertexConsumer implements VertexConsumer {
private final Mesh mesh;

private float offsetX, offsetY, offsetZ;
private int offsetX, offsetY, offsetZ;

private final float[] xs = new float[4];
private final float[] ys = new float[4];
private final float[] zs = new float[4];
private final double[] xs = new double[4];
private final double[] ys = new double[4];
private final double[] zs = new double[4];
private final Color color = new Color();

private int i;
Expand All @@ -47,17 +47,17 @@ public MeshVertexConsumer(Mesh mesh) {
this.mesh = mesh;
}

public void setOffset(float offsetX, float offsetY, float offsetZ) {
public void setOffset(int offsetX, int offsetY, int offsetZ) {
this.offsetX = offsetX;
this.offsetY = offsetY;
this.offsetZ = offsetZ;
}

@Override
public VertexConsumer vertex(float x, float y, float z) {
xs[i] = offsetX + x;
ys[i] = offsetY + y;
zs[i] = offsetZ + z;
xs[i] = (double) offsetX + x;
ys[i] = (double) offsetY + y;
zs[i] = (double) offsetZ + z;

if (++i >= 4) {
mesh.quad(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ private SimpleBlockRenderer() {
}

public static void renderWithBlockEntity(BlockEntity blockEntity, float tickDelta, IVertexConsumerProvider vertexConsumerProvider) {
vertexConsumerProvider.setOffset(blockEntity.getPos().getX(), blockEntity.getPos().getY(), blockEntity.getPos().getZ());
SimpleBlockRenderer.render(blockEntity.getPos(), blockEntity.getCachedState(), vertexConsumerProvider);

vertexConsumerProvider.setOffset(blockEntity.getPos().getX(), blockEntity.getPos().getY(), blockEntity.getPos().getZ());
BlockEntityRenderer<BlockEntity> renderer = mc.getBlockEntityRenderDispatcher().get(blockEntity);
if (renderer != null && blockEntity.hasWorld() && blockEntity.getType().supports(blockEntity.getCachedState())) renderer.render(blockEntity, tickDelta, MATRICES, vertexConsumerProvider, LightmapTextureManager.MAX_LIGHT_COORDINATE, OverlayTexture.DEFAULT_UV);
vertexConsumerProvider.setOffset(0, 0, 0);
Expand All @@ -47,13 +47,12 @@ public static void render(BlockPos pos, BlockState state, VertexConsumerProvider
BakedModel model = mc.getBlockRenderManager().getModel(state);
Vec3d offset = state.getModelOffset(mc.world, pos);

float offsetX = (float) (pos.getX() + offset.x);
float offsetY = (float) (pos.getY() + offset.y);
float offsetZ = (float) (pos.getZ() + offset.z);
float offsetX = (float) offset.x;
float offsetY = (float) offset.y;
float offsetZ = (float) offset.z;

//noinspection ForLoopReplaceableByForEach
for (int i = 0; i < DIRECTIONS.length; i++) {
List<BakedQuad> list = model.getQuads(state, DIRECTIONS[i], RANDOM);
for (Direction direction : DIRECTIONS) {
List<BakedQuad> list = model.getQuads(state, direction, RANDOM);
if (!list.isEmpty()) renderQuads(list, offsetX, offsetY, offsetZ, consumer);
}

Expand All @@ -62,9 +61,8 @@ public static void render(BlockPos pos, BlockState state, VertexConsumerProvider
}

private static void renderQuads(List<BakedQuad> quads, float offsetX, float offsetY, float offsetZ, VertexConsumer consumer) {
//noinspection ForLoopReplaceableByForEach
for (int i = 0; i < quads.size(); i++) {
IBakedQuad quad = (IBakedQuad) quads.get(i);
for (BakedQuad bakedQuad : quads) {
IBakedQuad quad = (IBakedQuad) bakedQuad;

for (int j = 0; j < 4; j++) {
float x = quad.meteor$getX(j);
Expand Down

0 comments on commit 3e5ae3a

Please sign in to comment.