Skip to content

Instantly share code, notes, and snippets.

@shartte
Created August 13, 2016 10:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shartte/fa9f595cc221453014388ab16c7a5498 to your computer and use it in GitHub Desktop.
Save shartte/fa9f595cc221453014388ab16c7a5498 to your computer and use it in GitHub Desktop.
FastTESR solution to fullbright overlay rendering
/**
* This TESR will render just the light overlay (powered on) or conflict light overlay (conflicted) as
* a full-bright overlay to the normal controller block. Fullbright here means that no lighting is applied,
* or rather, the overlay always appears as if it was fully lit, regardless of ambient lighting.
*/
@SideOnly(Side.CLIENT)
public class ControllerTESR extends FastTESR<TileController> implements AdditionalModelsTESR {
private static final ModelResourceLocation MODEL_BLOCK_LIGHTS
= new ModelResourceLocation("appliedenergistics2:controller/overlay_block_lights");
private static final ModelResourceLocation MODEL_COLUMN_LIGHTS
= new ModelResourceLocation("appliedenergistics2:controller/overlay_column_lights");
private static final ModelResourceLocation MODEL_BLOCK_CONFLICT
= new ModelResourceLocation("appliedenergistics2:controller/overlay_block_conflict");
private static final ModelResourceLocation MODEL_COLUMN_CONFLICT
= new ModelResourceLocation("appliedenergistics2:controller/overlay_column_conflict");
@Override
public ResourceLocation[] getResourceLocations() {
return new ResourceLocation[]{
MODEL_BLOCK_LIGHTS, MODEL_COLUMN_LIGHTS, MODEL_BLOCK_CONFLICT, MODEL_COLUMN_CONFLICT
};
}
@Override
public void renderTileEntityFast(TileController te, double x, double y, double z, float partialTicks, int destroyStage, VertexBuffer buffer) {
BlockRendererDispatcher dispatcher = Minecraft.getMinecraft().getBlockRendererDispatcher();
World world = te.getWorld();
IBlockState state = world.getBlockState(te.getPos());
if (world.getWorldType() != WorldType.DEBUG_WORLD) {
try {
state = state.getActualState(world, te.getPos());
} catch (Exception ignored) {
}
}
ModelResourceLocation modelName = getOverlayModel(state);
if (modelName != null) {
IBakedModel model = dispatcher.getBlockModelShapes().getModelManager().getModel(modelName);
BlockPos pos = te.getPos();
buffer.setTranslation(x - pos.getX(), y - pos.getY(), z - pos.getZ());
state = new FullbrightBlockStateDecorator(state);
dispatcher.getBlockModelRenderer().renderModelFlat(world, model, state, te.getPos(), buffer, false, 0);
}
}
private ModelResourceLocation getOverlayModel(IBlockState state) {
// Since we cannot bake in preInit() we do lazy baking of the model as soon as we need it
// for rendering
BlockController.ControllerRenderType type = state.getValue(BlockController.CONTROLLER_TYPE);
BlockController.ControllerBlockState status = state.getValue(BlockController.CONTROLLER_STATE);
if (type == BlockController.ControllerRenderType.column
&& status == BlockController.ControllerBlockState.online) {
return MODEL_COLUMN_LIGHTS;
} else if (type == BlockController.ControllerRenderType.block
&& status == BlockController.ControllerBlockState.online) {
return MODEL_BLOCK_LIGHTS;
} else if (type == BlockController.ControllerRenderType.column
&& status == BlockController.ControllerBlockState.conflicted) {
return MODEL_COLUMN_CONFLICT;
} else if (type == BlockController.ControllerRenderType.block
&& status == BlockController.ControllerBlockState.conflicted) {
return MODEL_BLOCK_CONFLICT;
} else {
return null;
}
}
}
/**
* This class is a short-lived decorator for a blockstate to convince the lighting code that the block is fully lit.
*/
public class FullbrightBlockStateDecorator extends AbstractBlockStateDecorator {
public FullbrightBlockStateDecorator(IBlockState delegate) {
super(delegate);
}
@Override
@SideOnly(Side.CLIENT)
public int getPackedLightmapCoords(IBlockAccess source, BlockPos pos) {
// Fake full sky and block brightness
return (0xF << 14) | (0xF << 4);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment