Fix the crystal chest rendering clashing clients by swapping them to render a single item at once instead of stacks. (Also helps with FPS issues).

This commit is contained in:
Alexander Behrhof 2021-07-29 16:25:14 -04:00
parent 6206a33628
commit 5b8405b499
2 changed files with 5 additions and 36 deletions

View File

@ -43,9 +43,6 @@ public class IronChestTileEntityRenderer<T extends TileEntity & IChestLid> exten
private final ModelRenderer chestBottom; private final ModelRenderer chestBottom;
private final ModelRenderer chestLock; private final ModelRenderer chestLock;
private static ItemEntity customItem;
private static ItemRenderer itemRenderer;
private static final List<ModelItem> MODEL_ITEMS = Arrays.asList( private static final List<ModelItem> MODEL_ITEMS = Arrays.asList(
new ModelItem(new Vector3f(0.3F, 0.45F, 0.3F), 3.0F), new ModelItem(new Vector3f(0.3F, 0.45F, 0.3F), 3.0F),
new ModelItem(new Vector3f(0.7F, 0.45F, 0.3F), 3.0F), new ModelItem(new Vector3f(0.7F, 0.45F, 0.3F), 3.0F),
@ -120,13 +117,8 @@ public class IronChestTileEntityRenderer<T extends TileEntity & IChestLid> exten
float rotation = (float) (360D * (System.currentTimeMillis() & 0x3FFFL) / 0x3FFFL) - partialTicks; float rotation = (float) (360D * (System.currentTimeMillis() & 0x3FFFL) / 0x3FFFL) - partialTicks;
CrystalChestTileEntity crystalChestTileEntity = (CrystalChestTileEntity) tileEntity; CrystalChestTileEntity crystalChestTileEntity = (CrystalChestTileEntity) tileEntity;
if (customItem == null) {
assert world != null;
customItem = new ItemEntity(EntityType.ITEM, world);
}
for (int j = 0; j < MODEL_ITEMS.size() - 1; j++) { for (int j = 0; j < MODEL_ITEMS.size() - 1; j++) {
renderItem(matrixStackIn, bufferIn, crystalChestTileEntity.getTopItems().get(j), MODEL_ITEMS.get(j), rotation, combinedLightIn, partialTicks); renderItem(matrixStackIn, bufferIn, crystalChestTileEntity.getTopItems().get(j), MODEL_ITEMS.get(j), rotation, combinedLightIn);
} }
} }
} }
@ -149,12 +141,10 @@ public class IronChestTileEntityRenderer<T extends TileEntity & IChestLid> exten
* @param modelItem Model items for render information * @param modelItem Model items for render information
* @param light Model light * @param light Model light
*/ */
public static void renderItem(MatrixStack matrices, IRenderTypeBuffer buffer, ItemStack item, ModelItem modelItem, float rotation, int light, float partialTicks) { public static void renderItem(MatrixStack matrices, IRenderTypeBuffer buffer, ItemStack item, ModelItem modelItem, float rotation, int light) {
// if no stack, skip // if no stack, skip
if (item.isEmpty()) return; if (item.isEmpty()) return;
customItem.setItem(item);
// start rendering // start rendering
matrices.push(); matrices.push();
Vector3f center = modelItem.getCenter(); Vector3f center = modelItem.getCenter();
@ -166,27 +156,7 @@ public class IronChestTileEntityRenderer<T extends TileEntity & IChestLid> exten
float scale = modelItem.getSizeScaled(); float scale = modelItem.getSizeScaled();
matrices.scale(scale, scale, scale); matrices.scale(scale, scale, scale);
// render the actual item Minecraft.getInstance().getItemRenderer().renderItem(item, ItemCameraTransforms.TransformType.NONE, light, OverlayTexture.NO_OVERLAY, matrices, buffer);
if (itemRenderer == null) {
itemRenderer = new ItemRenderer(Minecraft.getInstance().getRenderManager(), Minecraft.getInstance().getItemRenderer()) {
@Override
public int getModelCount(ItemStack stack) {
return SignedBytes.saturatedCast(Math.min(stack.getCount() / 32, 15) + 1);
}
@Override
public boolean shouldBob() {
return false;
}
@Override
public boolean shouldSpreadItems() {
return true;
}
};
}
itemRenderer.render(customItem, 0F, partialTicks, matrices, buffer, light);
matrices.pop(); matrices.pop();
} }
} }

View File

@ -1,7 +1,6 @@
{ {
"pack": { "pack": {
"description": "Iron Chests Resources", "description": "Iron Chests Resources",
"pack_format": 5, "pack_format": 6
"_comment": "A pack_format of 5 requires json lang files. Note: we require v5 pack meta for all mods."
} }
} }