Outstanding Performance

- Fixed Chutes pulling from inventories causing major framerate drops
- Fixed Chutes sending update packets when idling
- Added a max range for filter slot rendering of blocks
- Synced TEs are no longer able to cause side-effects by calling sendData on the Render Thread
This commit is contained in:
simibubi 2021-08-07 16:24:57 +02:00
parent cc575a70c8
commit 8edb9121cc
5 changed files with 35 additions and 12 deletions

View file

@ -138,12 +138,13 @@ public class ChuteTileEntity extends SmartTileEntity implements IHaveGoggleInfor
if (!level.isClientSide) if (!level.isClientSide)
canPickUpItems = canDirectlyInsert(); canPickUpItems = canDirectlyInsert();
boolean clientSide = level != null && level.isClientSide && !isVirtual();
float itemMotion = getItemMotion(); float itemMotion = getItemMotion();
if (itemMotion != 0 && level != null && level.isClientSide) if (itemMotion != 0 && level != null && level.isClientSide)
spawnParticles(itemMotion); spawnParticles(itemMotion);
tickAirStreams(itemMotion); tickAirStreams(itemMotion);
if (item.isEmpty()) { if (item.isEmpty() && !clientSide) {
if (itemMotion < 0) if (itemMotion < 0)
handleInputFromAbove(); handleInputFromAbove();
if (itemMotion > 0) if (itemMotion > 0)
@ -158,7 +159,7 @@ public class ChuteTileEntity extends SmartTileEntity implements IHaveGoggleInfor
if (!handleDownwardOutput(true)) if (!handleDownwardOutput(true))
nextOffset = .5f; nextOffset = .5f;
else if (nextOffset < 0) { else if (nextOffset < 0) {
handleDownwardOutput(level.isClientSide && !isVirtual()); handleDownwardOutput(clientSide);
nextOffset = itemPosition.value; nextOffset = itemPosition.value;
} }
} }
@ -167,7 +168,7 @@ public class ChuteTileEntity extends SmartTileEntity implements IHaveGoggleInfor
if (!handleUpwardOutput(true)) if (!handleUpwardOutput(true))
nextOffset = .5f; nextOffset = .5f;
else if (nextOffset > 1) { else if (nextOffset > 1) {
handleUpwardOutput(level.isClientSide && !isVirtual()); handleUpwardOutput(clientSide);
nextOffset = itemPosition.value; nextOffset = itemPosition.value;
} }
} }
@ -341,6 +342,7 @@ public class ChuteTileEntity extends SmartTileEntity implements IHaveGoggleInfor
if (mode == ExtractionCountMode.UPTO || !ItemHelper.extract(inv, canAccept, mode, count, true) if (mode == ExtractionCountMode.UPTO || !ItemHelper.extract(inv, canAccept, mode, count, true)
.isEmpty()) { .isEmpty()) {
ItemStack extracted = ItemHelper.extract(inv, canAccept, mode, count, false); ItemStack extracted = ItemHelper.extract(inv, canAccept, mode, count, false);
if (!extracted.isEmpty())
setItem(extracted, startLocation); setItem(extracted, startLocation);
} }
} }
@ -496,8 +498,8 @@ public class ChuteTileEntity extends SmartTileEntity implements IHaveGoggleInfor
public void setItem(ItemStack stack, float insertionPos) { public void setItem(ItemStack stack, float insertionPos) {
item = stack; item = stack;
itemPosition.lastValue = itemPosition.value = insertionPos; itemPosition.lastValue = itemPosition.value = insertionPos;
setChanged(); if (!level.isClientSide)
sendData(); notifyUpdate();
} }
@Override @Override

View file

@ -13,6 +13,7 @@ public class CClient extends ConfigBase {
public ConfigBool explainRenderErrors = public ConfigBool explainRenderErrors =
b(false, "explainRenderErrors", "Log a stack-trace when rendering issues happen within a moving contraption."); b(false, "explainRenderErrors", "Log a stack-trace when rendering issues happen within a moving contraption.");
public ConfigFloat fanParticleDensity = f(.5f, 0, 1, "fanParticleDensity"); public ConfigFloat fanParticleDensity = f(.5f, 0, 1, "fanParticleDensity");
public ConfigFloat filterItemRenderDistance = f(10f, 1, "filterItemRenderDistance", "[in Blocks]", "Maximum Distance to the player at which items in Blocks' filter slots will be displayed");
public ConfigBool rainbowDebug = public ConfigBool rainbowDebug =
b(true, "enableRainbowDebug", "Show colourful debug information while the F3-Menu is open."); b(true, "enableRainbowDebug", "Show colourful debug information while the F3-Menu is open.");
public ConfigBool experimentalRendering = public ConfigBool experimentalRendering =

View file

@ -37,7 +37,7 @@ public abstract class SyncedTileEntity extends TileEntity {
} }
public void sendData() { public void sendData() {
if (level != null) if (level != null && !level.isClientSide)
level.sendBlockUpdated(getBlockPos(), getBlockState(), getBlockState(), 2 | 4 | 16); level.sendBlockUpdated(getBlockPos(), getBlockState(), getBlockState(), 2 | 4 | 16);
} }

View file

@ -4,6 +4,7 @@ import com.mojang.blaze3d.matrix.MatrixStack;
import com.simibubi.create.AllSpecialTextures; import com.simibubi.create.AllSpecialTextures;
import com.simibubi.create.CreateClient; import com.simibubi.create.CreateClient;
import com.simibubi.create.content.logistics.item.filter.FilterItem; import com.simibubi.create.content.logistics.item.filter.FilterItem;
import com.simibubi.create.foundation.config.AllConfigs;
import com.simibubi.create.foundation.tileEntity.SmartTileEntity; import com.simibubi.create.foundation.tileEntity.SmartTileEntity;
import com.simibubi.create.foundation.tileEntity.TileEntityBehaviour; import com.simibubi.create.foundation.tileEntity.TileEntityBehaviour;
import com.simibubi.create.foundation.tileEntity.behaviour.ValueBox; import com.simibubi.create.foundation.tileEntity.behaviour.ValueBox;
@ -14,11 +15,13 @@ import com.simibubi.create.foundation.tileEntity.behaviour.ValueBoxTransform.Sid
import com.simibubi.create.foundation.utility.Iterate; import com.simibubi.create.foundation.utility.Iterate;
import com.simibubi.create.foundation.utility.Lang; import com.simibubi.create.foundation.utility.Lang;
import com.simibubi.create.foundation.utility.Pair; import com.simibubi.create.foundation.utility.Pair;
import com.simibubi.create.foundation.utility.VecHelper;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.client.renderer.IRenderTypeBuffer;
import net.minecraft.client.world.ClientWorld; import net.minecraft.client.world.ClientWorld;
import net.minecraft.entity.Entity;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.util.Direction; import net.minecraft.util.Direction;
import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.AxisAlignedBB;
@ -86,12 +89,19 @@ public class FilteringRenderer {
.highlightFace(result.getDirection()); .highlightFace(result.getDirection());
} }
public static void renderOnTileEntity(SmartTileEntity tileEntityIn, float partialTicks, MatrixStack ms, public static void renderOnTileEntity(SmartTileEntity te, float partialTicks, MatrixStack ms,
IRenderTypeBuffer buffer, int light, int overlay) { IRenderTypeBuffer buffer, int light, int overlay) {
if (tileEntityIn == null || tileEntityIn.isRemoved()) if (te == null || te.isRemoved())
return; return;
FilteringBehaviour behaviour = tileEntityIn.getBehaviour(FilteringBehaviour.TYPE);
Entity cameraEntity = Minecraft.getInstance().cameraEntity;
float max = AllConfigs.CLIENT.filterItemRenderDistance.getF();
if (!te.isVirtual() && cameraEntity != null && cameraEntity.position()
.distanceToSqr(VecHelper.getCenterOf(te.getBlockPos())) > (max * max))
return;
FilteringBehaviour behaviour = te.getBehaviour(FilteringBehaviour.TYPE);
if (behaviour == null) if (behaviour == null)
return; return;
if (!behaviour.isActive()) if (!behaviour.isActive())
@ -101,7 +111,7 @@ public class FilteringRenderer {
return; return;
ValueBoxTransform slotPositioning = behaviour.slotPositioning; ValueBoxTransform slotPositioning = behaviour.slotPositioning;
BlockState blockState = tileEntityIn.getBlockState(); BlockState blockState = te.getBlockState();
if (slotPositioning instanceof ValueBoxTransform.Sided) { if (slotPositioning instanceof ValueBoxTransform.Sided) {
ValueBoxTransform.Sided sided = (ValueBoxTransform.Sided) slotPositioning; ValueBoxTransform.Sided sided = (ValueBoxTransform.Sided) slotPositioning;

View file

@ -4,6 +4,7 @@ import com.mojang.blaze3d.matrix.MatrixStack;
import com.mojang.datafixers.util.Pair; import com.mojang.datafixers.util.Pair;
import com.simibubi.create.AllSpecialTextures; import com.simibubi.create.AllSpecialTextures;
import com.simibubi.create.CreateClient; import com.simibubi.create.CreateClient;
import com.simibubi.create.foundation.config.AllConfigs;
import com.simibubi.create.foundation.tileEntity.SmartTileEntity; import com.simibubi.create.foundation.tileEntity.SmartTileEntity;
import com.simibubi.create.foundation.tileEntity.TileEntityBehaviour; import com.simibubi.create.foundation.tileEntity.TileEntityBehaviour;
import com.simibubi.create.foundation.tileEntity.behaviour.ValueBox; import com.simibubi.create.foundation.tileEntity.behaviour.ValueBox;
@ -11,10 +12,12 @@ import com.simibubi.create.foundation.tileEntity.behaviour.ValueBoxRenderer;
import com.simibubi.create.foundation.tileEntity.behaviour.ValueBoxTransform; import com.simibubi.create.foundation.tileEntity.behaviour.ValueBoxTransform;
import com.simibubi.create.foundation.utility.Iterate; import com.simibubi.create.foundation.utility.Iterate;
import com.simibubi.create.foundation.utility.Lang; import com.simibubi.create.foundation.utility.Lang;
import com.simibubi.create.foundation.utility.VecHelper;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.client.renderer.IRenderTypeBuffer;
import net.minecraft.client.world.ClientWorld; import net.minecraft.client.world.ClientWorld;
import net.minecraft.entity.Entity;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
@ -63,6 +66,13 @@ public class LinkRenderer {
if (te == null || te.isRemoved()) if (te == null || te.isRemoved())
return; return;
Entity cameraEntity = Minecraft.getInstance().cameraEntity;
float max = AllConfigs.CLIENT.filterItemRenderDistance.getF();
if (!te.isVirtual() && cameraEntity != null && cameraEntity.position()
.distanceToSqr(VecHelper.getCenterOf(te.getBlockPos())) > (max * max))
return;
LinkBehaviour behaviour = te.getBehaviour(LinkBehaviour.TYPE); LinkBehaviour behaviour = te.getBehaviour(LinkBehaviour.TYPE);
if (behaviour == null) if (behaviour == null)
return; return;