use of pl.asie.charset.lib.utils.Orientation 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.lib.utils.Orientation 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.lib.utils.Orientation in project Charset by CharsetMC.
the class TileProjectorRenderer method render.
@Override
public void render(TileProjector projector, double x, double y, double z, float partialTicks, int destroyStage, float alpha) {
if (projector == null || projector.getStack().isEmpty()) {
return;
}
ItemStack stack = projector.getStack();
GlStateManager.pushMatrix();
GlStateManager.translate(x, y, z);
Orientation bo = projector.getOrientation();
EnumFacing face = bo.top;
if (SpaceUtils.sign(face) == 1) {
GlStateManager.translate(face.getDirectionVec().getX(), face.getDirectionVec().getY(), face.getDirectionVec().getZ());
}
GlStateManager.translate(0.5 * (1 - Math.abs(face.getDirectionVec().getX())), 0.5 * (1 - Math.abs(face.getDirectionVec().getY())), 0.5 * (1 - Math.abs(face.getDirectionVec().getZ())));
Quaternion quat = Quaternion.fromOrientation(bo);
quat.glRotate();
GlStateManager.rotate(90, 0, 1, 0);
GlStateManager.translate(0.25, 0.25 - 1.0 / 16.0, 31.0 / 128.0);
GlStateManager.enableAlpha();
GlStateManager.enableLighting();
GlStateManager.alphaFunc(GL11.GL_GREATER, 0.0F);
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
handleRenderItem(stack, projector);
GlStateManager.popMatrix();
GlStateManager.disableBlend();
}
use of pl.asie.charset.lib.utils.Orientation in project Charset by CharsetMC.
the class ProjectorHandlerBook method render.
@Override
@SideOnly(Side.CLIENT)
public void render(ItemStack stack, IProjector projector, IProjectorSurface surface) {
// oh boy! text!
if (stack.hasTagCompound()) {
GlStateManager.pushMatrix();
GlStateManager.translate(((surface.getCornerStart().x + surface.getCornerEnd().x) / 2) + surface.getScreenFacing().getFrontOffsetX() * 0.001f, ((surface.getCornerStart().y + surface.getCornerEnd().y) / 2) + surface.getScreenFacing().getFrontOffsetY() * 0.001f, ((surface.getCornerStart().z + surface.getCornerEnd().z) / 2) + surface.getScreenFacing().getFrontOffsetZ() * 0.001f);
Orientation orientation = ProjectorHelper.INSTANCE.getOrientation(surface);
Quaternion.fromOrientation(orientation).glRotate();
GlStateManager.rotate(270.0f, 0, 0, 1);
GlStateManager.rotate(270.0f, 0, 1, 0);
GlStateManager.translate(0, 0, -ProjectorHelper.OFFSET);
float scaleVal = 2f * surface.getWidth() / 146f;
GlStateManager.scale(scaleVal, scaleVal, scaleVal);
FontRenderer renderer = Minecraft.getMinecraft().fontRenderer;
NBTTagList pages = stack.getTagCompound().getTagList("pages", Constants.NBT.TAG_STRING);
if (pages.tagCount() > projector.getPage()) {
String pageCount = I18n.format("book.pageIndicator", projector.getPage() + 1, pages.tagCount());
renderer.drawString(pageCount, -73 + 129 - renderer.getStringWidth(pageCount), -90 + 15, 0xFF000000);
String page = ((NBTTagString) pages.get(projector.getPage())).getString();
ITextComponent fullComponent = ITextComponent.Serializer.jsonToComponent(page);
if (fullComponent != null) {
List<ITextComponent> components = GuiUtilRenderComponents.splitText(fullComponent, 116, renderer, true, true);
for (int i = 0; i < components.size(); i++) {
renderer.drawString(components.get(i).getUnformattedText(), -73 + 16, -90 + 30 + i * renderer.FONT_HEIGHT, 0xFF000000);
}
}
}
GlStateManager.popMatrix();
surface.restoreGLColor();
}
Minecraft.getMinecraft().getTextureManager().bindTexture(new ResourceLocation("textures/gui/book.png"));
ProjectorHelper.INSTANCE.renderTexture(surface, 20, 20 + 146, 1, 1 + 180);
}
use of pl.asie.charset.lib.utils.Orientation in project Charset by CharsetMC.
the class TilePrism method rotateWrench.
@Override
public boolean rotateWrench(EnumFacing axis) {
Orientation newOrientation;
if (axis.getAxis() == orientation.facing.getAxis()) {
newOrientation = Orientation.getOrientation(Orientation.fromDirection(axis).ordinal() & (~3) | (orientation.ordinal() & 3)).getNextRotationOnTop();
} else if (axis.getAxis() == orientation.top.getAxis()) {
newOrientation = Orientation.getOrientation(Orientation.fromDirection(axis).ordinal() & (~3) | (orientation.ordinal() & 3));
} else {
newOrientation = orientation.getPrevRotationOnFace().getNextRotationOnTop().getNextRotationOnFace();
}
changeOrientation(newOrientation, false);
return true;
}
Aggregations