Skip to content

Commit

Permalink
Cover TESR (#2)
Browse files Browse the repository at this point in the history
Add the ability for covers that are IFastRenderMetaTileEntity to be rendered for compatibility with addon mods
  • Loading branch information
Yefancy authored Mar 19, 2021
1 parent de5e6e4 commit 68eaa68
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import gregtech.api.GTValues;
import gregtech.api.GregTechAPI;
import gregtech.api.block.machines.BlockMachine;
import gregtech.api.cover.CoverBehavior;
import gregtech.api.gui.IUIHolder;
import gregtech.api.util.GTControlledRegistry;
import gregtech.api.util.GTLog;
Expand Down Expand Up @@ -248,6 +249,15 @@ public void mirror(Mirror mirrorIn) {

@Override
public boolean shouldRenderInPass(int pass) {
if (metaTileEntity == null) return false;
for (EnumFacing side: EnumFacing.VALUES){
CoverBehavior cover = metaTileEntity.getCoverAtSide(side);
if (cover instanceof IFastRenderMetaTileEntity && ((IFastRenderMetaTileEntity) cover).shouldRenderInPass(pass)) {
return true;
} else if(cover instanceof IRenderMetaTileEntity && ((IRenderMetaTileEntity) cover).shouldRenderInPass(pass)) {
return true;
}
}
if (metaTileEntity instanceof IRenderMetaTileEntity) {
return ((IRenderMetaTileEntity) metaTileEntity).shouldRenderInPass(pass);
} else if (metaTileEntity instanceof IFastRenderMetaTileEntity) {
Expand Down
56 changes: 50 additions & 6 deletions src/main/java/gregtech/api/render/MetaTileEntityTESR.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import codechicken.lib.render.CCRenderState;
import codechicken.lib.vec.Matrix4;
import gregtech.api.cover.CoverBehavior;
import gregtech.api.metatileentity.IFastRenderMetaTileEntity;
import gregtech.api.metatileentity.IRenderMetaTileEntity;
import gregtech.api.metatileentity.MetaTileEntity;
Expand All @@ -14,22 +15,65 @@
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.Tuple;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import org.lwjgl.opengl.GL11;

import java.util.ArrayList;
import java.util.List;

@SideOnly(Side.CLIENT)
public class MetaTileEntityTESR extends TileEntitySpecialRenderer<MetaTileEntityHolder> {

@Override
public void render(MetaTileEntityHolder te, double x, double y, double z, float partialTicks, int destroyStage, float alpha) {
if(te.getMetaTileEntity() instanceof IFastRenderMetaTileEntity) {
MetaTileEntity metaTileEntity = te.getMetaTileEntity();
if(metaTileEntity instanceof IFastRenderMetaTileEntity) {
renderTileEntityFastPart(te, x, y, z, partialTicks, destroyStage);
}
if(te instanceof IRenderMetaTileEntity) {
MetaTileEntity metaTileEntity = te.getMetaTileEntity();
if (metaTileEntity instanceof IRenderMetaTileEntity) {
((IRenderMetaTileEntity) metaTileEntity).renderMetaTileEntityDynamic(x, y, z, partialTicks);
if(metaTileEntity instanceof IRenderMetaTileEntity) {
((IRenderMetaTileEntity) metaTileEntity).renderMetaTileEntityDynamic(x, y, z, partialTicks);
}
if(metaTileEntity != null) {
List<Tuple<IFastRenderMetaTileEntity, EnumFacing>> coverFast = new ArrayList<>();
for (EnumFacing side: EnumFacing.VALUES){
CoverBehavior cover = metaTileEntity.getCoverAtSide(side);
if (cover instanceof IFastRenderMetaTileEntity) {
coverFast.add(new Tuple<>((IFastRenderMetaTileEntity) cover, side));
} else if (cover instanceof IRenderMetaTileEntity){
((IRenderMetaTileEntity) cover).renderMetaTileEntityDynamic(x, y, z, partialTicks);
}
}
if (coverFast.size() > 0) {
Matrix4 translation = (new Matrix4()).translate(x, y, z);
Tessellator tessellator = Tessellator.getInstance();
BufferBuilder buffer = tessellator.getBuffer();
this.bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
RenderHelper.disableStandardItemLighting();
GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
GlStateManager.enableBlend();

if (Minecraft.isAmbientOcclusionEnabled()) {
GlStateManager.shadeModel(GL11.GL_SMOOTH);
}
else {
GlStateManager.shadeModel(GL11.GL_FLAT);
}
buffer.begin(GL11.GL_QUADS, DefaultVertexFormats.BLOCK);

for (Tuple<IFastRenderMetaTileEntity, EnumFacing> tuple : coverFast) {
CCRenderState renderState = CCRenderState.instance();
renderState.reset();
renderState.bind(buffer);
renderState.setBrightness(te.getWorld(), te.getPos().offset(tuple.getSecond()));
tuple.getFirst().renderMetaTileEntityFast(renderState, translation, partialTicks);
}

buffer.setTranslation(0, 0, 0);
tessellator.draw();
RenderHelper.enableStandardItemLighting();
}
}
}
Expand All @@ -54,7 +98,7 @@ private void renderTileEntityFastPart(MetaTileEntityHolder te, double x, double
renderTileEntityFast(te, x, y, z, partialTicks, destroyStage, partialTicks, buffer);
buffer.setTranslation(0, 0, 0);
tessellator.draw();

GlStateManager.enableCull();
RenderHelper.enableStandardItemLighting();
}

Expand Down

0 comments on commit 68eaa68

Please sign in to comment.