use of pl.asie.charset.api.laser.LaserColor in project Charset by CharsetMC.
the class ProxyClient method bakeModels.
@SubscribeEvent
@SideOnly(Side.CLIENT)
public void bakeModels(ModelBakeEvent event) {
if (prismModel != null) {
for (Orientation o : Orientation.values()) {
ModelResourceLocation location = new ModelResourceLocation("charset:laser_prism", "orientation=" + o.name().toLowerCase());
IBakedModel model = prismModel.bake(o.toTransformation(), DefaultVertexFormats.BLOCK, ModelLoader.defaultTextureGetter());
event.getModelRegistry().putObject(location, model);
}
}
// Patch jars to glow
for (EnumFacing facing : EnumFacing.VALUES) {
for (LaserColor color : LaserColor.VALUES) {
if (color == LaserColor.NONE)
continue;
IBlockState state = CharsetLaser.blockJar.getDefaultState().withProperty(CharsetLaser.LASER_COLOR, color).withProperty(Properties.FACING, facing);
ModelResourceLocation location = new ModelResourceLocation("charset:light_jar", "color=" + color.getName() + ",facing=" + facing.getName());
IBakedModel model = event.getModelRegistry().getObject(location);
VertexFormat format = new VertexFormat(DefaultVertexFormats.ITEM);
format.addElement(DefaultVertexFormats.TEX_2S);
if (model != null) {
SimpleMultiLayerBakedModel result = new SimpleMultiLayerBakedModel(model);
BlockRenderLayer layerPre = MinecraftForgeClient.getRenderLayer();
for (BlockRenderLayer layer : BlockRenderLayer.values()) {
if (CharsetLaser.blockJar.canRenderInLayer(CharsetLaser.blockJar.getDefaultState(), layer)) {
ForgeHooksClient.setRenderLayer(layer);
for (int i = 0; i <= 6; i++) {
EnumFacing facingIn = (i < 6) ? EnumFacing.getFront(i) : null;
for (BakedQuad quadIn : model.getQuads(state, facingIn, 0)) {
result.addQuad(layer, facingIn, ModelTransformer.transform(quadIn, (quad, element, data) -> {
if (quad.getTintIndex() == 1 && element == DefaultVertexFormats.TEX_2S) {
return new float[] { 15f * 0x20 / 0xFFFF, 0, 0, 0 };
}
return data;
}, (bakedQuad -> {
if (bakedQuad.getTintIndex() == 1) {
return format;
} else {
return bakedQuad.getFormat();
}
})));
}
}
}
}
ForgeHooksClient.setRenderLayer(layerPre);
event.getModelRegistry().putObject(location, result);
}
}
}
}
use of pl.asie.charset.api.laser.LaserColor in project Charset by CharsetMC.
the class ProjectorRenderer method onRender.
@SubscribeEvent
public void onRender(RenderWorldLastEvent event) {
Minecraft.getMinecraft().mcProfiler.startSection("projectors");
GlStateManager.enableBlend();
GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE);
GlStateManager.glBlendEquation(GL14.GL_FUNC_ADD);
GlStateManager.enableTexture2D();
GlStateManager.enableAlpha();
Tessellator tessellator = Tessellator.getInstance();
BufferBuilder worldrenderer = tessellator.getBuffer();
worldrenderer.setTranslation(0, 0, 0);
Entity cameraEntity = Minecraft.getMinecraft().getRenderViewEntity();
Vec3d cameraPos = EntityUtils.interpolate(cameraEntity, event.getPartialTicks());
ICamera camera = new Frustum();
camera.setPosition(cameraPos.x, cameraPos.y, cameraPos.z);
GlStateManager.pushMatrix();
GlStateManager.translate(-cameraPos.x, -cameraPos.y, -cameraPos.z);
for (TileEntity tileEntity : Minecraft.getMinecraft().world.loadedTileEntityList) {
if (tileEntity instanceof TileProjector) {
LaserColor color = LaserColor.NONE;
Orientation orientation = ((TileProjector) tileEntity).getOrientation();
if (CharsetProjector.useLasers) {
for (int d = 0; d < 6; d++) {
LaserColor color2 = ((TileProjector) tileEntity).colors[d];
if (color2 != null && color2 != LaserColor.NONE) {
if (d == orientation.facing.getOpposite().ordinal()) {
// not rendering anything - laser in the way
color = LaserColor.NONE;
break;
} else {
color = color.union(color2);
}
}
}
} else {
color = ((TileProjector) tileEntity).redstoneLevel > 0 ? LaserColor.WHITE : LaserColor.NONE;
}
if (color != LaserColor.NONE) {
ItemStack stack = ((TileProjector) tileEntity).getStack();
IProjectorHandler<ItemStack> handler = CharsetProjector.getHandler(stack);
if (handler == null) {
continue;
}
Surface surface = getSurface(tileEntity.getWorld(), tileEntity.getPos(), orientation, 0.5f, handler.getAspectRatio(stack));
if (surface == null) {
continue;
}
if (!camera.isBoundingBoxInFrustum(new AxisAlignedBB(surface.cornerStart, surface.cornerEnd))) {
continue;
}
surface.r = color.red ? 1.0f : 0.0f;
surface.g = color.green ? 1.0f : 0.0f;
surface.b = color.blue ? 1.0f : 0.0f;
surface.a = 0.5f;
if (!CharsetProjector.useLasers) {
surface.a *= ((TileProjector) tileEntity).redstoneLevel / 15.0f;
}
EnumDyeColor dyeColor = null;
BlockPos inFrontPos = tileEntity.getPos().offset(((TileProjector) tileEntity).getOrientation().facing);
IBlockState state = tileEntity.getWorld().getBlockState(inFrontPos);
if (state.getBlock() instanceof BlockStainedGlass) {
dyeColor = state.getValue(BlockStainedGlass.COLOR);
}
if (dyeColor != null) {
float[] v = dyeColor.getColorComponentValues();
surface.r *= v[0];
surface.g *= v[1];
surface.b *= v[2];
}
surface.restoreGLColor();
handler.render(stack, (IProjector) tileEntity, surface);
}
}
}
GlStateManager.popMatrix();
GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
GlStateManager.glBlendEquation(GL14.GL_FUNC_ADD);
GlStateManager.disableBlend();
Minecraft.getMinecraft().mcProfiler.endSection();
}
use of pl.asie.charset.api.laser.LaserColor in project Charset by CharsetMC.
the class TileJar method recalculateOutputColor.
private void recalculateOutputColor() {
LaserColor newOutputColor = LaserColor.NONE;
boolean set = false;
EnumFacing jarFacing = getJarFacing();
for (EnumFacing facing : EnumFacing.VALUES) {
if (facing.getAxis() != jarFacing.getAxis()) {
newOutputColor = newOutputColor.union(colors[facing.ordinal()]);
if (colors[facing.ordinal()] != LaserColor.NONE) {
set = true;
}
}
}
newOutputColor = newOutputColor.difference(colors[jarFacing.getOpposite().ordinal()]);
if (colors[jarFacing.getOpposite().ordinal()] != LaserColor.NONE) {
set = true;
}
if (set && outputColor != newOutputColor) {
outputColor = newOutputColor;
markBlockForUpdate();
CharsetLaser.laserStorage.markLaserForUpdate(TileJar.this, getJarFacing());
}
}
use of pl.asie.charset.api.laser.LaserColor in project Charset by CharsetMC.
the class TilePrism method recalcColors.
private void recalcColors() {
LaserColor[] oldColors = new LaserColor[6];
for (int i = 0; i < 6; i++) {
oldColors[i] = colors[i];
colors[i] = LaserColor.NONE;
}
for (int i = 0; i < 6; i++) {
LaserColor source = sourceColors[i];
if (source != LaserColor.NONE) {
EnumFacing face = EnumFacing.getFront(i);
FaceBehaviour b = getFaceBehaviour(face);
if (b == FaceBehaviour.PASS) {
colors[i ^ 1] = colors[i ^ 1].union(source);
} else {
// TODO: Optimize
boolean isRed = (source.ordinal() & 4) != 0;
boolean isGreen = (source.ordinal() & 2) != 0;
boolean isBlue = (source.ordinal() & 1) != 0;
if (isGreen) {
colors[i ^ 1] = colors[i ^ 1].union(LaserColor.GREEN);
}
if (isRed || isBlue) {
for (EnumFacing target : EnumFacing.VALUES) {
FaceBehaviour targetB = getFaceBehaviour(target);
if (targetB != FaceBehaviour.PASS) {
if (isRed && targetB != b) {
colors[target.ordinal()] = colors[target.ordinal()].union(LaserColor.RED);
}
if (isBlue && targetB == b) {
colors[target.ordinal()] = colors[target.ordinal()].union(LaserColor.BLUE);
}
}
}
}
}
}
}
for (int i = 0; i < 6; i++) {
if (colors[i] != oldColors[i]) {
CharsetLaser.laserStorage.markLaserForUpdate(this, EnumFacing.getFront(i));
}
}
}
use of pl.asie.charset.api.laser.LaserColor in project Charset by CharsetMC.
the class TileReflector method updateSourceColor.
public void updateSourceColor(int i) {
IBlockState state = world.getBlockState(pos);
EnumFacing rotation = state.getValue(BlockReflector.ROTATION);
if ((rotation.ordinal() & (~1)) != (i & (~1))) {
boolean isSplitter = state.getValue(BlockReflector.SPLITTER);
LaserColor colorFiltered = sourceColors[i].intersection(this.color);
LaserColor colorRemaining = isSplitter ? sourceColors[i] : sourceColors[i].difference(this.color);
int ri = BlockReflector.getTargetFacing(EnumFacing.getFront(i), rotation).ordinal();
if (colorFiltered != bouncedColors[ri]) {
bouncedColors[ri] = colorFiltered;
updateColor(ri);
}
ri = i ^ 1;
if (colorRemaining != passedColors[ri]) {
passedColors[ri] = colorRemaining;
updateColor(ri);
}
} else {
bouncedColors[i ^ 1] = LaserColor.NONE;
if (passedColors[i ^ 1] != sourceColors[i]) {
passedColors[i ^ 1] = sourceColors[i];
updateColor(i ^ 1);
}
}
}
Aggregations