Skip to content

Commit

Permalink
move emissive code to OrientedOverlayRenderer
Browse files Browse the repository at this point in the history
  • Loading branch information
serenibyss committed Sep 4, 2021
1 parent 498c58d commit b6a09ed
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 28 deletions.
13 changes: 0 additions & 13 deletions src/main/java/gregtech/api/metatileentity/MetaTileEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -195,19 +195,6 @@ public void renderMetaTileEntity(CCRenderState renderState, Matrix4 translation,
}
}

/**
* Renders this meta tile entity (Emissive texture)
* Note that you shouldn't refer to world-related information in this method, because it
* will be called on ItemStacks too
*
* @param renderState render state (either chunk batched or item)
* @param pipeline default set of pipeline transformations
*/
@SideOnly(Side.CLIENT)
public void renderEmissiveMetaTileEntity(CCRenderState renderState, Matrix4 translation, IVertexOperation[] pipeline) {

}

@SideOnly(Side.CLIENT)
public boolean canRenderInLayer(BlockRenderLayer renderLayer) {
return renderLayer == BlockRenderLayer.CUTOUT_MIPPED;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,6 @@ public void renderMetaTileEntity(CCRenderState renderState, Matrix4 translation,
}
}

@Override
public void renderEmissiveMetaTileEntity(CCRenderState renderState, Matrix4 translation, IVertexOperation[] pipeline) {
super.renderEmissiveMetaTileEntity(renderState, translation, pipeline);
if (workable.isActive()) {
renderer.render(renderState, translation, pipeline, getFrontFacing(), true);
}
}

@Override
protected IItemHandlerModifiable createImportItemHandler() {
if (workable == null) return new ItemStackHandler(0);
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/gregtech/api/render/MetaTileEntityRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,6 @@ public boolean renderBlock(IBlockAccess world, BlockPos pos, IBlockState state,
renderState.lightMatrix.locate(world, pos);
IVertexOperation[] pipeline = new IVertexOperation[]{renderState.lightMatrix};
metaTileEntity.renderMetaTileEntity(renderState, translation.copy(), pipeline);
pipeline = new IVertexOperation[]{new LightMapOperation(240, 240)};
metaTileEntity.renderEmissiveMetaTileEntity(renderState, translation.copy(), pipeline);
}
Matrix4 coverTranslation = new Matrix4().translate(pos.getX(), pos.getY(), pos.getZ());
metaTileEntity.renderCovers(renderState, coverTranslation, renderLayer);
Expand Down
49 changes: 45 additions & 4 deletions src/main/java/gregtech/api/render/OrientedOverlayRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import org.apache.commons.lang3.ArrayUtils;

import java.util.HashMap;
import java.util.Map;
Expand All @@ -36,6 +37,7 @@ public static OverlayFace bySide(EnumFacing side, EnumFacing frontFacing) {

private final String basePath;
private final OverlayFace[] faces;
private final boolean hasEmissive;

@SideOnly(Side.CLIENT)
private Map<OverlayFace, ActivePredicate> sprites;
Expand All @@ -46,33 +48,64 @@ private static class ActivePredicate {
private final TextureAtlasSprite normalSprite;
private final TextureAtlasSprite activeSprite;

private final TextureAtlasSprite normalSpriteEmissive;
private final TextureAtlasSprite activeSpriteEmissive;

public ActivePredicate(TextureAtlasSprite normalSprite, TextureAtlasSprite activeSprite) {
this(normalSprite, activeSprite, null, null);
}

public ActivePredicate(TextureAtlasSprite normalSprite,
TextureAtlasSprite activeSprite,
TextureAtlasSprite normalSpriteEmissive,
TextureAtlasSprite activeSpriteEmissive) {
this.normalSprite = normalSprite;
this.activeSprite = activeSprite;
this.normalSpriteEmissive = normalSpriteEmissive;
this.activeSpriteEmissive = activeSpriteEmissive;
}

public TextureAtlasSprite getSprite(boolean active) {
return active ? activeSprite : normalSprite;
}

public TextureAtlasSprite getEmissiveSprite(boolean active) {
return active ? activeSpriteEmissive : normalSpriteEmissive;
}
}

public OrientedOverlayRenderer(String basePath, OverlayFace... faces) {
public OrientedOverlayRenderer(String basePath, boolean hasEmissive, OverlayFace... faces) {
this.basePath = basePath;
this.faces = faces;
this.hasEmissive = hasEmissive;
Textures.iconRegisters.add(this);
}

public OrientedOverlayRenderer(String basePath, OverlayFace... faces) {
this(basePath, false, faces);
}

@Override
@SideOnly(Side.CLIENT)
public void registerIcons(TextureMap textureMap) {
this.sprites = new HashMap<>();
for (OverlayFace overlayFace : faces) {
String faceName = overlayFace.name().toLowerCase();

ResourceLocation normalLocation = new ResourceLocation(GTValues.MODID, String.format("blocks/%s/overlay_%s", basePath, faceName));
ResourceLocation activeLocation = new ResourceLocation(GTValues.MODID, String.format("blocks/%s/overlay_%s_active", basePath, faceName));
TextureAtlasSprite normalSprite = textureMap.registerSprite(normalLocation);
ResourceLocation activeLocation = new ResourceLocation(GTValues.MODID, String.format("blocks/%s/overlay_%s_active", basePath, faceName));
TextureAtlasSprite activeSprite = textureMap.registerSprite(activeLocation);
sprites.put(overlayFace, new ActivePredicate(normalSprite, activeSprite));

if (hasEmissive) {
ResourceLocation normalLocationEmissive = new ResourceLocation(GTValues.MODID, String.format("blocks/%s/overlay_%s_emissive", basePath, faceName));
TextureAtlasSprite normalSpriteEmissive = textureMap.registerSprite(normalLocationEmissive);
ResourceLocation activeLocationEmissive = new ResourceLocation(GTValues.MODID, String.format("blocks/%s/overlay_%s_active_emissive", basePath, faceName));
TextureAtlasSprite activeSpriteEmissive = textureMap.registerSprite(activeLocationEmissive);
sprites.put(overlayFace, new ActivePredicate(normalSprite, activeSprite, normalSpriteEmissive, activeSpriteEmissive));
} else {
sprites.put(overlayFace, new ActivePredicate(normalSprite, activeSprite));
}
}
}

Expand All @@ -81,8 +114,16 @@ public void render(CCRenderState renderState, Matrix4 translation, IVertexOperat
for (EnumFacing renderSide : EnumFacing.VALUES) {
OverlayFace overlayFace = OverlayFace.bySide(renderSide, frontFacing);
if (sprites.containsKey(overlayFace)) {
TextureAtlasSprite renderSprite = sprites.get(overlayFace).getSprite(isActive);
ActivePredicate predicate = sprites.get(overlayFace);

TextureAtlasSprite renderSprite = predicate.getSprite(isActive);
Textures.renderFace(renderState, translation, ops, renderSide, bounds, renderSprite);

TextureAtlasSprite emissiveSprite = predicate.getEmissiveSprite(isActive);
if (emissiveSprite != null) {
ops = ArrayUtils.add(ops, new LightMapOperation(240, 240));
Textures.renderFace(renderState, translation, ops, renderSide, bounds, emissiveSprite);
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/gregtech/api/render/Textures.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public class Textures {
public static final OrientedOverlayRenderer PRIMITIVE_BLAST_FURNACE_OVERLAY = new OrientedOverlayRenderer("machines/primitive_blast_furnace", FRONT);
public static final OrientedOverlayRenderer COKE_OVEN_OVERLAY = new OrientedOverlayRenderer("machines/coke_oven", FRONT);
public static final OrientedOverlayRenderer MULTIBLOCK_WORKABLE_OVERLAY = new OrientedOverlayRenderer("machines/multiblock_workable", FRONT);
public static final OrientedOverlayRenderer BLAST_FURNACE_OVERLAY = new OrientedOverlayRenderer("multiblock/blast_furnace", FRONT);
public static final OrientedOverlayRenderer BLAST_FURNACE_OVERLAY = new OrientedOverlayRenderer("multiblock/blast_furnace", true, FRONT);
public static final OrientedOverlayRenderer IMPLOSION_COMPRESSOR_OVERLAY = new OrientedOverlayRenderer("multiblock/implosion_compressor", FRONT);
public static final OrientedOverlayRenderer MULTI_FURNACE_OVERLAY = new OrientedOverlayRenderer("multiblock/multi_furnace", FRONT);
public static final OrientedOverlayRenderer PYROLYSE_OVEN_OVERLAY = new OrientedOverlayRenderer("multiblock/pyrolyse_oven", FRONT);
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit b6a09ed

Please sign in to comment.