Render Lags fix
This commit is contained in:
parent
457fb3a4ad
commit
0dcfc8e5f0
2 changed files with 40 additions and 30 deletions
|
@ -1,5 +1,6 @@
|
||||||
package gregtech.common.render.newblocks;
|
package gregtech.common.render.newblocks;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
import gregtech.api.enums.Textures;
|
import gregtech.api.enums.Textures;
|
||||||
import gregtech.api.interfaces.ITexture;
|
import gregtech.api.interfaces.ITexture;
|
||||||
import gregtech.api.items.GT_Generic_Block;
|
import gregtech.api.items.GT_Generic_Block;
|
||||||
|
@ -27,11 +28,18 @@ import net.minecraftforge.fml.relauncher.SideOnly;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@SideOnly(Side.CLIENT)
|
@SideOnly(Side.CLIENT)
|
||||||
public class BlockRenderer {
|
public class BlockRenderer {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Quads cache for standard icon provider blocks
|
||||||
|
* used for block and itemblock rendering
|
||||||
|
*/
|
||||||
|
public static HashMap<TextureAtlasSprite, HashMap<EnumFacing, ImmutableList<BakedQuad>>> quadsCache = new HashMap<>();
|
||||||
|
|
||||||
public static boolean shouldHook(IBlockState blockState) {
|
public static boolean shouldHook(IBlockState blockState) {
|
||||||
if(blockState.getBlock() instanceof IBlockIconProvider) {
|
if(blockState.getBlock() instanceof IBlockIconProvider) {
|
||||||
return true;
|
return true;
|
||||||
|
@ -64,7 +72,7 @@ public class BlockRenderer {
|
||||||
return new ItemblockIconProviderModel(stack, holder instanceof EntityPlayer ? (EntityPlayer) holder : null);
|
return new ItemblockIconProviderModel(stack, holder instanceof EntityPlayer ? (EntityPlayer) holder : null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class ItemblockIconProviderModel extends AbstractModel {
|
private static class ItemblockIconProviderModel extends AbstractIconProviderModel {
|
||||||
|
|
||||||
private final ItemStack itemStack;
|
private final ItemStack itemStack;
|
||||||
private final EntityPlayer holder;
|
private final EntityPlayer holder;
|
||||||
|
@ -77,42 +85,16 @@ public class BlockRenderer {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<BakedQuad> getQuads(@Nullable IBlockState state, @Nullable EnumFacing side, long rand) {
|
public TextureAtlasSprite getSideSprite(EnumFacing side, IBlockState state) {
|
||||||
if(side != null) {
|
|
||||||
TextureAtlasSprite sideIcon = getSideSprite(side);
|
|
||||||
if (sideIcon != null) {
|
|
||||||
BakedQuad faceQuad = RenderUtil.renderSide(DefaultVertexFormats.BLOCK, sideIcon, side, -1, 0.0F, -1, false);
|
|
||||||
if (faceQuad != null) {
|
|
||||||
return Collections.singletonList(faceQuad);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return Collections.emptyList();
|
|
||||||
}
|
|
||||||
|
|
||||||
public TextureAtlasSprite getSideSprite(EnumFacing side) {
|
|
||||||
IBlockIconProvider provider = (IBlockIconProvider) block;
|
IBlockIconProvider provider = (IBlockIconProvider) block;
|
||||||
return provider.getIcon(holder, itemStack, side);
|
return provider.getIcon(holder, itemStack, side);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class IconProviderModel extends AbstractModel {
|
private static class IconProviderModel extends AbstractIconProviderModel {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<BakedQuad> getQuads(@Nullable IBlockState state, @Nullable EnumFacing side, long rand) {
|
|
||||||
if(side != null && state != null) {
|
|
||||||
TextureAtlasSprite sideIcon = getSideSprite(side, state);
|
|
||||||
if (sideIcon != null) {
|
|
||||||
BakedQuad faceQuad = RenderUtil.renderSide(DefaultVertexFormats.BLOCK, sideIcon, side, -1, 0.0F, -1, false);
|
|
||||||
if (faceQuad != null) {
|
|
||||||
return Collections.singletonList(faceQuad);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return Collections.emptyList();
|
|
||||||
}
|
|
||||||
|
|
||||||
public TextureAtlasSprite getSideSprite(EnumFacing side, IBlockState blockState) {
|
public TextureAtlasSprite getSideSprite(EnumFacing side, IBlockState blockState) {
|
||||||
BlockPos pos = ((IExtendedBlockState) blockState).getValue(GT_Generic_Block.BLOCK_POS);
|
BlockPos pos = ((IExtendedBlockState) blockState).getValue(GT_Generic_Block.BLOCK_POS);
|
||||||
IBlockIconProvider provider = (IBlockIconProvider) blockState.getBlock();
|
IBlockIconProvider provider = (IBlockIconProvider) blockState.getBlock();
|
||||||
|
@ -121,6 +103,34 @@ public class BlockRenderer {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private static abstract class AbstractIconProviderModel extends AbstractModel {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<BakedQuad> getQuads(@Nullable IBlockState state, @Nullable EnumFacing side, long rand) {
|
||||||
|
if(side != null) {
|
||||||
|
TextureAtlasSprite sideIcon = getSideSprite(side, state);
|
||||||
|
if (sideIcon != null) {
|
||||||
|
HashMap<EnumFacing, ImmutableList<BakedQuad>> quads = quadsCache.get(sideIcon);
|
||||||
|
if(quads == null) {
|
||||||
|
quads = new HashMap<>();
|
||||||
|
quadsCache.put(sideIcon, quads);
|
||||||
|
}
|
||||||
|
ImmutableList<BakedQuad> faceQuad = quads.get(side);
|
||||||
|
if(faceQuad == null) {
|
||||||
|
faceQuad = ImmutableList.of(RenderUtil.renderSide(DefaultVertexFormats.BLOCK, sideIcon, side, -1, 0.0F, -1, false));
|
||||||
|
quads.put(side, faceQuad);
|
||||||
|
}
|
||||||
|
return faceQuad;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract TextureAtlasSprite getSideSprite(EnumFacing side, IBlockState blockState);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
private static class TextureProviderModel extends AbstractModel {
|
private static class TextureProviderModel extends AbstractModel {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -58,7 +58,7 @@ public class RenderUtil {
|
||||||
|
|
||||||
default:
|
default:
|
||||||
System.out.println("Can't render side " + side);
|
System.out.println("Can't render side " + side);
|
||||||
return null;
|
throw new IllegalArgumentException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue