2015-08-29 14:33:25 +02:00
|
|
|
/*
|
2016-05-16 22:52:27 +02:00
|
|
|
* This file ("AssetUtil.java") is part of the Actually Additions mod for Minecraft.
|
2015-08-29 14:33:25 +02:00
|
|
|
* It is created and owned by Ellpeck and distributed
|
|
|
|
* under the Actually Additions License to be found at
|
2016-05-16 22:52:27 +02:00
|
|
|
* http://ellpeck.de/actaddlicense
|
2015-08-29 14:33:25 +02:00
|
|
|
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
|
|
|
|
*
|
2017-01-01 16:23:26 +01:00
|
|
|
* © 2015-2017 Ellpeck
|
2015-08-29 14:33:25 +02:00
|
|
|
*/
|
|
|
|
|
2016-01-05 04:47:35 +01:00
|
|
|
package de.ellpeck.actuallyadditions.mod.util;
|
2015-03-29 15:29:05 +02:00
|
|
|
|
2021-02-28 11:35:10 +01:00
|
|
|
import com.mojang.blaze3d.matrix.MatrixStack;
|
|
|
|
import com.mojang.blaze3d.platform.GlStateManager;
|
2018-05-10 11:38:58 +02:00
|
|
|
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
|
2016-06-15 16:43:59 +02:00
|
|
|
import de.ellpeck.actuallyadditions.mod.network.PacketHandler;
|
|
|
|
import de.ellpeck.actuallyadditions.mod.network.PacketServerToClient;
|
2016-12-27 17:40:27 +01:00
|
|
|
import de.ellpeck.actuallyadditions.mod.particle.ParticleBeam;
|
2016-11-20 13:46:35 +01:00
|
|
|
import de.ellpeck.actuallyadditions.mod.tile.TileEntityBase;
|
2015-08-24 17:57:11 +02:00
|
|
|
import net.minecraft.block.Block;
|
2021-02-28 11:35:10 +01:00
|
|
|
import net.minecraft.block.BlockState;
|
2015-08-24 17:57:11 +02:00
|
|
|
import net.minecraft.client.Minecraft;
|
2015-04-19 01:50:02 +02:00
|
|
|
import net.minecraft.client.gui.FontRenderer;
|
2016-12-09 21:36:43 +01:00
|
|
|
import net.minecraft.client.particle.Particle;
|
2018-06-24 02:44:47 +02:00
|
|
|
import net.minecraft.client.renderer.BufferBuilder;
|
2016-12-07 13:59:30 +01:00
|
|
|
import net.minecraft.client.renderer.GlStateManager.DestFactor;
|
|
|
|
import net.minecraft.client.renderer.GlStateManager.SourceFactor;
|
2021-02-28 11:35:10 +01:00
|
|
|
import net.minecraft.client.renderer.IRenderTypeBuffer;
|
2018-06-24 02:44:47 +02:00
|
|
|
import net.minecraft.client.renderer.RenderHelper;
|
|
|
|
import net.minecraft.client.renderer.Tessellator;
|
2016-12-27 17:40:27 +01:00
|
|
|
import net.minecraft.client.renderer.block.model.IBakedModel;
|
2016-01-08 23:36:35 +01:00
|
|
|
import net.minecraft.client.renderer.block.model.ItemCameraTransforms.TransformType;
|
2021-02-28 11:35:10 +01:00
|
|
|
import net.minecraft.client.renderer.model.ItemCameraTransforms;
|
2016-12-27 17:40:27 +01:00
|
|
|
import net.minecraft.client.renderer.texture.TextureManager;
|
|
|
|
import net.minecraft.client.renderer.texture.TextureMap;
|
2016-11-08 08:53:30 +01:00
|
|
|
import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher;
|
2016-01-07 21:41:28 +01:00
|
|
|
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
2015-08-24 17:57:11 +02:00
|
|
|
import net.minecraft.item.ItemStack;
|
2021-02-26 22:15:48 +01:00
|
|
|
import net.minecraft.nbt.CompoundNBT;
|
2015-03-29 15:29:05 +02:00
|
|
|
import net.minecraft.util.ResourceLocation;
|
2018-06-24 02:44:47 +02:00
|
|
|
import net.minecraft.util.math.BlockPos;
|
2016-06-15 16:43:59 +02:00
|
|
|
import net.minecraft.util.math.Vec3d;
|
2018-06-24 02:44:47 +02:00
|
|
|
import net.minecraft.world.IBlockAccess;
|
2016-06-15 16:43:59 +02:00
|
|
|
import net.minecraft.world.World;
|
2021-02-28 11:35:10 +01:00
|
|
|
import net.minecraftforge.api.distmarker.Dist;
|
2016-12-27 17:40:27 +01:00
|
|
|
import net.minecraftforge.client.ForgeHooksClient;
|
2016-06-15 16:43:59 +02:00
|
|
|
import net.minecraftforge.fml.common.network.NetworkRegistry;
|
2021-02-26 22:15:48 +01:00
|
|
|
import net.minecraftforge.fml.relauncher.OnlyIn;
|
|
|
|
import org.lwjgl.opengl.GL11;
|
2015-03-29 15:29:05 +02:00
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
public final class AssetUtil {
|
2016-12-07 13:59:30 +01:00
|
|
|
|
|
|
|
public static final int MAX_LIGHT_X = 0xF000F0;
|
|
|
|
public static final int MAX_LIGHT_Y = 0xF000F0;
|
2015-03-29 15:29:05 +02:00
|
|
|
|
2016-11-19 23:12:22 +01:00
|
|
|
public static final ResourceLocation GUI_INVENTORY_LOCATION = getGuiLocation("gui_inventory");
|
2015-11-13 18:56:15 +01:00
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
public static ResourceLocation getGuiLocation(String file) {
|
|
|
|
return new ResourceLocation(ActuallyAdditions.MODID, "textures/gui/" + file + ".png");
|
2015-03-29 15:29:05 +02:00
|
|
|
}
|
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
public static ResourceLocation getBookletGuiLocation(String file) {
|
|
|
|
return getGuiLocation("booklet/" + file);
|
2015-10-30 20:07:36 +01:00
|
|
|
}
|
|
|
|
|
2021-02-26 22:15:48 +01:00
|
|
|
@OnlyIn(Dist.CLIENT)
|
2019-05-02 09:10:29 +02:00
|
|
|
public static void displayNameString(FontRenderer font, int xSize, int yPositionOfMachineText, String text) {
|
|
|
|
font.drawString(text, xSize / 2 - font.getStringWidth(text) / 2, yPositionOfMachineText, StringUtil.DECIMAL_COLOR_WHITE);
|
2016-07-03 21:57:33 +02:00
|
|
|
}
|
|
|
|
|
2021-02-26 22:15:48 +01:00
|
|
|
@OnlyIn(Dist.CLIENT)
|
2019-05-02 09:10:29 +02:00
|
|
|
public static void displayNameString(FontRenderer font, int xSize, int yPositionOfMachineText, TileEntityBase tile) {
|
2017-07-28 22:17:52 +02:00
|
|
|
displayNameString(font, xSize, yPositionOfMachineText, StringUtil.localize(tile.getNameForTranslation()));
|
2015-04-19 01:50:02 +02:00
|
|
|
}
|
2015-08-24 17:57:11 +02:00
|
|
|
|
2021-02-26 22:15:48 +01:00
|
|
|
@OnlyIn(Dist.CLIENT)
|
2019-05-02 09:10:29 +02:00
|
|
|
public static void renderBlockInWorld(Block block, int meta) {
|
2021-02-28 11:35:10 +01:00
|
|
|
renderItemInWorld(new ItemStack(block, 1, meta), combinedLightIn, combinedOverlayIn, matrices, buffer);
|
2016-02-01 17:49:55 +01:00
|
|
|
}
|
|
|
|
|
2021-02-26 22:15:48 +01:00
|
|
|
@OnlyIn(Dist.CLIENT)
|
2021-02-28 11:35:10 +01:00
|
|
|
public static void renderItemInWorld(ItemStack stack, int combinedLight, int combinedOverlay, MatrixStack matrices, IRenderTypeBuffer buffer) {
|
2019-05-02 09:10:29 +02:00
|
|
|
if (StackUtil.isValid(stack)) {
|
2021-02-28 11:35:10 +01:00
|
|
|
Minecraft.getInstance().getItemRenderer().renderItem(
|
|
|
|
stack, ItemCameraTransforms.TransformType.FIXED, combinedLight, combinedOverlay, matrices, buffer
|
|
|
|
);
|
2016-08-14 23:38:32 +02:00
|
|
|
}
|
2015-08-24 17:57:11 +02:00
|
|
|
}
|
2019-02-27 19:53:05 +01:00
|
|
|
|
2021-02-26 22:15:48 +01:00
|
|
|
@OnlyIn(Dist.CLIENT)
|
|
|
|
public static void renderStateInWorld(BlockState state, IBlockAccess world, BlockPos pos, float brightness) {
|
|
|
|
Minecraft.getInstance().getTextureManager().bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
|
|
|
|
IBakedModel model = Minecraft.getInstance().getBlockRendererDispatcher().getModelForState(state);
|
2018-06-24 02:44:47 +02:00
|
|
|
GlStateManager.rotate(90.0F, 0.0F, 1.0F, 0.0F);
|
2021-02-26 22:15:48 +01:00
|
|
|
int i = Minecraft.getInstance().getBlockColors().colorMultiplier(state, world, pos, 0);
|
2018-06-24 02:44:47 +02:00
|
|
|
|
2019-02-27 19:53:05 +01:00
|
|
|
float r = (i >> 16 & 255) / 255F;
|
|
|
|
float g = (i >> 8 & 255) / 255F;
|
|
|
|
float b = (i & 255) / 255F;
|
2018-06-24 02:44:47 +02:00
|
|
|
|
2021-02-26 22:15:48 +01:00
|
|
|
Minecraft.getInstance().getBlockRendererDispatcher().getBlockModelRenderer().renderModelBrightnessColor(state, model, brightness, r, g, b);
|
2018-06-24 02:44:47 +02:00
|
|
|
}
|
2015-08-24 17:57:11 +02:00
|
|
|
|
2021-02-26 22:15:48 +01:00
|
|
|
@OnlyIn(Dist.CLIENT)
|
2019-05-02 09:10:29 +02:00
|
|
|
public static void renderItemWithoutScrewingWithColors(ItemStack stack) {
|
|
|
|
if (StackUtil.isValid(stack)) {
|
2021-02-26 22:15:48 +01:00
|
|
|
Minecraft mc = Minecraft.getInstance();
|
2016-12-27 17:40:27 +01:00
|
|
|
RenderItem renderer = mc.getRenderItem();
|
|
|
|
TextureManager manager = mc.getTextureManager();
|
|
|
|
|
|
|
|
IBakedModel model = renderer.getItemModelWithOverrides(stack, null, null);
|
|
|
|
|
|
|
|
manager.bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
|
|
|
|
manager.getTexture(TextureMap.LOCATION_BLOCKS_TEXTURE).setBlurMipmap(false, false);
|
|
|
|
GlStateManager.enableRescaleNormal();
|
|
|
|
GlStateManager.enableBlend();
|
|
|
|
GlStateManager.pushMatrix();
|
|
|
|
model = ForgeHooksClient.handleCameraTransforms(model, TransformType.FIXED, false);
|
|
|
|
renderer.renderItem(stack, model);
|
|
|
|
GlStateManager.cullFace(GlStateManager.CullFace.BACK);
|
|
|
|
GlStateManager.popMatrix();
|
|
|
|
GlStateManager.disableRescaleNormal();
|
|
|
|
GlStateManager.disableBlend();
|
|
|
|
manager.bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
|
|
|
|
manager.getTexture(TextureMap.LOCATION_BLOCKS_TEXTURE).restoreLastBlurMipmap();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-26 22:15:48 +01:00
|
|
|
@OnlyIn(Dist.CLIENT)
|
2019-05-02 09:10:29 +02:00
|
|
|
public static void renderStackToGui(ItemStack stack, int x, int y, float scale) {
|
2016-01-08 15:21:05 +01:00
|
|
|
GlStateManager.pushMatrix();
|
|
|
|
GlStateManager.enableBlend();
|
|
|
|
GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
|
2015-12-22 14:55:10 +01:00
|
|
|
RenderHelper.enableGUIStandardItemLighting();
|
2016-01-08 15:21:05 +01:00
|
|
|
GlStateManager.enableDepth();
|
|
|
|
GlStateManager.enableRescaleNormal();
|
|
|
|
GlStateManager.translate(x, y, 0);
|
|
|
|
GlStateManager.scale(scale, scale, scale);
|
2015-12-22 14:55:10 +01:00
|
|
|
|
2021-02-26 22:15:48 +01:00
|
|
|
Minecraft mc = Minecraft.getInstance();
|
2017-06-29 18:30:02 +02:00
|
|
|
boolean flagBefore = mc.fontRenderer.getUnicodeFlag();
|
|
|
|
mc.fontRenderer.setUnicodeFlag(false);
|
2021-02-26 22:15:48 +01:00
|
|
|
Minecraft.getInstance().getRenderItem().renderItemAndEffectIntoGUI(stack, 0, 0);
|
|
|
|
Minecraft.getInstance().getRenderItem().renderItemOverlayIntoGUI(mc.fontRenderer, stack, 0, 0, null);
|
2017-06-29 18:30:02 +02:00
|
|
|
mc.fontRenderer.setUnicodeFlag(flagBefore);
|
2015-12-22 14:55:10 +01:00
|
|
|
|
2016-05-01 22:34:40 +02:00
|
|
|
RenderHelper.disableStandardItemLighting();
|
2016-01-08 15:21:05 +01:00
|
|
|
GlStateManager.popMatrix();
|
2015-12-22 14:55:10 +01:00
|
|
|
}
|
|
|
|
|
2015-10-23 19:05:02 +02:00
|
|
|
//Copied from Gui.class and changed
|
2021-02-26 22:15:48 +01:00
|
|
|
@OnlyIn(Dist.CLIENT)
|
2019-05-02 09:10:29 +02:00
|
|
|
public static void drawHorizontalGradientRect(int left, int top, int right, int bottom, int startColor, int endColor, float zLevel) {
|
|
|
|
float f = (startColor >> 24 & 255) / 255.0F;
|
|
|
|
float f1 = (startColor >> 16 & 255) / 255.0F;
|
|
|
|
float f2 = (startColor >> 8 & 255) / 255.0F;
|
|
|
|
float f3 = (startColor & 255) / 255.0F;
|
|
|
|
float f4 = (endColor >> 24 & 255) / 255.0F;
|
|
|
|
float f5 = (endColor >> 16 & 255) / 255.0F;
|
|
|
|
float f6 = (endColor >> 8 & 255) / 255.0F;
|
|
|
|
float f7 = (endColor & 255) / 255.0F;
|
2016-01-07 21:41:28 +01:00
|
|
|
GlStateManager.disableTexture2D();
|
|
|
|
GlStateManager.enableBlend();
|
|
|
|
GlStateManager.disableAlpha();
|
|
|
|
GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0);
|
|
|
|
GlStateManager.shadeModel(7425);
|
|
|
|
Tessellator tessellator = Tessellator.getInstance();
|
2017-06-17 00:48:49 +02:00
|
|
|
BufferBuilder renderer = tessellator.getBuffer();
|
2016-03-18 23:47:22 +01:00
|
|
|
renderer.begin(7, DefaultVertexFormats.POSITION_COLOR);
|
2019-02-27 19:53:05 +01:00
|
|
|
renderer.pos(left, top, zLevel).color(f1, f2, f3, f).endVertex();
|
|
|
|
renderer.pos(left, bottom, zLevel).color(f1, f2, f3, f).endVertex();
|
|
|
|
renderer.pos(right, bottom, zLevel).color(f5, f6, f7, f4).endVertex();
|
|
|
|
renderer.pos(right, top, zLevel).color(f5, f6, f7, f4).endVertex();
|
2015-10-23 19:05:02 +02:00
|
|
|
tessellator.draw();
|
2016-01-07 21:41:28 +01:00
|
|
|
GlStateManager.shadeModel(7424);
|
|
|
|
GlStateManager.disableBlend();
|
|
|
|
GlStateManager.enableAlpha();
|
|
|
|
GlStateManager.enableTexture2D();
|
2015-10-23 19:05:02 +02:00
|
|
|
}
|
2016-02-17 23:15:56 +01:00
|
|
|
|
2021-02-26 22:15:48 +01:00
|
|
|
@OnlyIn(Dist.CLIENT)
|
2019-05-02 09:10:29 +02:00
|
|
|
public static void renderNameTag(String tag, double x, double y, double z) {
|
2021-02-26 22:15:48 +01:00
|
|
|
FontRenderer fontrenderer = Minecraft.getInstance().fontRenderer;
|
2016-02-17 23:15:56 +01:00
|
|
|
float f = 1.6F;
|
2019-05-02 09:10:29 +02:00
|
|
|
float f1 = 0.016666668F * f;
|
2016-02-17 23:15:56 +01:00
|
|
|
GlStateManager.pushMatrix();
|
|
|
|
GlStateManager.translate(x, y, z);
|
|
|
|
GL11.glNormal3f(0.0F, 1.0F, 0.0F);
|
2021-02-26 22:15:48 +01:00
|
|
|
GlStateManager.rotate(-Minecraft.getInstance().getRenderManager().playerViewY, 0.0F, 1.0F, 0.0F);
|
|
|
|
GlStateManager.rotate(Minecraft.getInstance().getRenderManager().playerViewX, 1.0F, 0.0F, 0.0F);
|
2016-02-17 23:15:56 +01:00
|
|
|
GlStateManager.scale(-f1, -f1, f1);
|
|
|
|
GlStateManager.disableLighting();
|
|
|
|
GlStateManager.depthMask(false);
|
|
|
|
GlStateManager.disableDepth();
|
|
|
|
GlStateManager.enableBlend();
|
|
|
|
GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0);
|
|
|
|
Tessellator tessellator = Tessellator.getInstance();
|
2017-06-17 00:48:49 +02:00
|
|
|
BufferBuilder renderer = tessellator.getBuffer();
|
2016-02-17 23:15:56 +01:00
|
|
|
int i = 0;
|
2019-05-02 09:10:29 +02:00
|
|
|
int j = fontrenderer.getStringWidth(tag) / 2;
|
2016-02-17 23:15:56 +01:00
|
|
|
GlStateManager.disableTexture2D();
|
2016-03-18 23:47:22 +01:00
|
|
|
renderer.begin(7, DefaultVertexFormats.POSITION_COLOR);
|
2019-05-02 09:10:29 +02:00
|
|
|
renderer.pos(-j - 1, -1 + i, 0.0D).color(0.0F, 0.0F, 0.0F, 0.25F).endVertex();
|
|
|
|
renderer.pos(-j - 1, 8 + i, 0.0D).color(0.0F, 0.0F, 0.0F, 0.25F).endVertex();
|
|
|
|
renderer.pos(j + 1, 8 + i, 0.0D).color(0.0F, 0.0F, 0.0F, 0.25F).endVertex();
|
|
|
|
renderer.pos(j + 1, -1 + i, 0.0D).color(0.0F, 0.0F, 0.0F, 0.25F).endVertex();
|
2016-02-17 23:15:56 +01:00
|
|
|
tessellator.draw();
|
|
|
|
GlStateManager.enableTexture2D();
|
2019-05-02 09:10:29 +02:00
|
|
|
fontrenderer.drawString(tag, -fontrenderer.getStringWidth(tag) / 2, i, 553648127);
|
2016-02-17 23:15:56 +01:00
|
|
|
GlStateManager.enableDepth();
|
|
|
|
GlStateManager.depthMask(true);
|
2019-05-02 09:10:29 +02:00
|
|
|
fontrenderer.drawString(tag, -fontrenderer.getStringWidth(tag) / 2, i, -1);
|
2016-02-17 23:15:56 +01:00
|
|
|
GlStateManager.enableLighting();
|
|
|
|
GlStateManager.disableBlend();
|
|
|
|
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
|
|
|
|
GlStateManager.popMatrix();
|
|
|
|
}
|
2016-06-15 16:43:59 +02:00
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
public static void spawnLaserWithTimeServer(World world, double startX, double startY, double startZ, double endX, double endY, double endZ, float[] color, int maxAge, double rotationTime, float size, float alpha) {
|
|
|
|
if (!world.isRemote) {
|
2021-02-26 22:15:48 +01:00
|
|
|
CompoundNBT data = new CompoundNBT();
|
2016-06-15 16:43:59 +02:00
|
|
|
data.setDouble("StartX", startX);
|
|
|
|
data.setDouble("StartY", startY);
|
|
|
|
data.setDouble("StartZ", startZ);
|
|
|
|
data.setDouble("EndX", endX);
|
|
|
|
data.setDouble("EndY", endY);
|
|
|
|
data.setDouble("EndZ", endZ);
|
|
|
|
data.setFloat("Color1", color[0]);
|
|
|
|
data.setFloat("Color2", color[1]);
|
|
|
|
data.setFloat("Color3", color[2]);
|
2016-12-09 21:36:43 +01:00
|
|
|
data.setDouble("RotationTime", rotationTime);
|
|
|
|
data.setFloat("Size", size);
|
|
|
|
data.setInteger("MaxAge", maxAge);
|
|
|
|
data.setFloat("Alpha", alpha);
|
2021-02-27 16:33:00 +01:00
|
|
|
PacketHandler.THE_NETWORK.sendToAllAround(new PacketServerToClient(data, PacketHandler.LASER_HANDLER), new NetworkRegistry.TargetPoint(world.provider.getDimension(), startX, startY, startZ, 96));
|
2016-06-15 16:43:59 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-26 22:15:48 +01:00
|
|
|
@OnlyIn(Dist.CLIENT)
|
2019-05-02 09:10:29 +02:00
|
|
|
public static void spawnLaserWithTimeClient(double startX, double startY, double startZ, double endX, double endY, double endZ, float[] color, int maxAge, double rotationTime, float size, float alpha) {
|
2021-02-26 22:15:48 +01:00
|
|
|
Minecraft mc = Minecraft.getInstance();
|
2016-06-15 16:43:59 +02:00
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
if (mc.player.getDistance(startX, startY, startZ) <= 64 || mc.player.getDistance(endX, endY, endZ) <= 64) {
|
2016-12-09 21:36:43 +01:00
|
|
|
Particle fx = new ParticleBeam(mc.world, startX, startY, startZ, endX, endY, endZ, color, maxAge, rotationTime, size, alpha);
|
|
|
|
mc.effectRenderer.addEffect(fx);
|
2016-06-15 16:43:59 +02:00
|
|
|
}
|
|
|
|
}
|
2016-11-08 08:53:30 +01:00
|
|
|
|
|
|
|
//Thanks to feldim2425 for this.
|
|
|
|
//I can't do rendering code. Ever.
|
2021-02-26 22:15:48 +01:00
|
|
|
@OnlyIn(Dist.CLIENT)
|
2019-05-02 09:10:29 +02:00
|
|
|
public static void renderLaser(double firstX, double firstY, double firstZ, double secondX, double secondY, double secondZ, double rotationTime, float alpha, double beamWidth, float[] color) {
|
2016-11-08 08:53:30 +01:00
|
|
|
Tessellator tessy = Tessellator.getInstance();
|
2017-06-17 00:48:49 +02:00
|
|
|
BufferBuilder render = tessy.getBuffer();
|
2021-02-26 22:15:48 +01:00
|
|
|
World world = Minecraft.getInstance().world;
|
2016-11-08 08:53:30 +01:00
|
|
|
|
|
|
|
float r = color[0];
|
|
|
|
float g = color[1];
|
|
|
|
float b = color[2];
|
|
|
|
|
|
|
|
Vec3d vec1 = new Vec3d(firstX, firstY, firstZ);
|
|
|
|
Vec3d vec2 = new Vec3d(secondX, secondY, secondZ);
|
|
|
|
Vec3d combinedVec = vec2.subtract(vec1);
|
|
|
|
|
2021-02-26 22:15:48 +01:00
|
|
|
double rot = rotationTime > 0
|
|
|
|
? 360D * (world.getTotalWorldTime() % rotationTime / rotationTime)
|
|
|
|
: 0;
|
2019-05-02 09:10:29 +02:00
|
|
|
double pitch = Math.atan2(combinedVec.y, Math.sqrt(combinedVec.x * combinedVec.x + combinedVec.z * combinedVec.z));
|
2017-06-29 18:30:02 +02:00
|
|
|
double yaw = Math.atan2(-combinedVec.z, combinedVec.x);
|
2016-11-08 08:53:30 +01:00
|
|
|
|
2018-08-04 04:22:20 +02:00
|
|
|
double length = combinedVec.length();
|
2016-11-08 08:53:30 +01:00
|
|
|
|
|
|
|
GlStateManager.pushMatrix();
|
|
|
|
|
|
|
|
GlStateManager.disableLighting();
|
|
|
|
GlStateManager.enableBlend();
|
2016-12-07 13:56:17 +01:00
|
|
|
GlStateManager.blendFunc(SourceFactor.SRC_ALPHA, DestFactor.ONE);
|
2016-12-07 13:59:30 +01:00
|
|
|
int func = GL11.glGetInteger(GL11.GL_ALPHA_TEST_FUNC);
|
|
|
|
float ref = GL11.glGetFloat(GL11.GL_ALPHA_TEST_REF);
|
|
|
|
GlStateManager.alphaFunc(GL11.GL_ALWAYS, 0);
|
2019-05-02 09:10:29 +02:00
|
|
|
GlStateManager.translate(firstX - TileEntityRendererDispatcher.staticPlayerX, firstY - TileEntityRendererDispatcher.staticPlayerY, firstZ - TileEntityRendererDispatcher.staticPlayerZ);
|
|
|
|
GlStateManager.rotate((float) (180 * yaw / Math.PI), 0, 1, 0);
|
|
|
|
GlStateManager.rotate((float) (180 * pitch / Math.PI), 0, 0, 1);
|
|
|
|
GlStateManager.rotate((float) rot, 1, 0, 0);
|
2016-11-08 08:53:30 +01:00
|
|
|
|
|
|
|
/*if(r != r2 || g != g2 || b != b2){
|
|
|
|
render.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX_COLOR);
|
2021-02-26 22:15:48 +01:00
|
|
|
Minecraft.getInstance().renderEngine.bindTexture(ClientUtil.LIGHT_BEAM_GRADIENT);
|
2019-05-02 10:43:27 +02:00
|
|
|
|
2016-11-08 08:53:30 +01:00
|
|
|
render.pos(length, -beamWidth, beamWidth).tex(0, 0).color(r, g, b, alpha).endVertex();
|
|
|
|
render.pos(length, beamWidth, beamWidth).tex(0, 1).color(r, g, b, alpha).endVertex();
|
|
|
|
render.pos(0, beamWidth, beamWidth).tex(1, 1).color(r, g, b, alpha).endVertex();
|
|
|
|
render.pos(0, -beamWidth, beamWidth).tex(1, 0).color(r, g, b, alpha).endVertex();
|
2019-05-02 10:43:27 +02:00
|
|
|
|
2016-11-08 08:53:30 +01:00
|
|
|
render.pos(length, -beamWidth, beamWidth).tex(1, 0).color(r2, g2, b2, alpha).endVertex();
|
|
|
|
render.pos(length, beamWidth, beamWidth).tex(1, 1).color(r2, g2, b2, alpha).endVertex();
|
|
|
|
render.pos(0, beamWidth, beamWidth).tex(0, 1).color(r2, g2, b2, alpha).endVertex();
|
|
|
|
render.pos(0, -beamWidth, beamWidth).tex(0, 0).color(r2, g2, b2, alpha).endVertex();
|
2019-05-02 10:43:27 +02:00
|
|
|
|
2016-11-08 08:53:30 +01:00
|
|
|
render.pos(length, beamWidth, -beamWidth).tex(0, 0).color(r, g, b, alpha).endVertex();
|
|
|
|
render.pos(length, -beamWidth, -beamWidth).tex(0, 1).color(r, g, b, alpha).endVertex();
|
|
|
|
render.pos(0, -beamWidth, -beamWidth).tex(1, 1).color(r, g, b, alpha).endVertex();
|
|
|
|
render.pos(0, beamWidth, -beamWidth).tex(1, 0).color(r, g, b, alpha).endVertex();
|
2019-05-02 10:43:27 +02:00
|
|
|
|
2016-11-08 08:53:30 +01:00
|
|
|
render.pos(length, beamWidth, -beamWidth).tex(1, 0).color(r2, g2, b2, alpha).endVertex();
|
|
|
|
render.pos(length, -beamWidth, -beamWidth).tex(1, 1).color(r2, g2, b2, alpha).endVertex();
|
|
|
|
render.pos(0, -beamWidth, -beamWidth).tex(0, 1).color(r2, g2, b2, alpha).endVertex();
|
|
|
|
render.pos(0, beamWidth, -beamWidth).tex(0, 0).color(r2, g2, b2, alpha).endVertex();
|
2019-05-02 10:43:27 +02:00
|
|
|
|
2016-11-08 08:53:30 +01:00
|
|
|
render.pos(length, beamWidth, beamWidth).tex(0, 0).color(r, g, b, alpha).endVertex();
|
|
|
|
render.pos(length, beamWidth, -beamWidth).tex(0, 1).color(r, g, b, alpha).endVertex();
|
|
|
|
render.pos(0, beamWidth, -beamWidth).tex(1, 1).color(r, g, b, alpha).endVertex();
|
|
|
|
render.pos(0, beamWidth, beamWidth).tex(1, 0).color(r, g, b, alpha).endVertex();
|
2019-05-02 10:43:27 +02:00
|
|
|
|
2016-11-08 08:53:30 +01:00
|
|
|
render.pos(length, beamWidth, beamWidth).tex(1, 0).color(r2, g2, b2, alpha).endVertex();
|
|
|
|
render.pos(length, beamWidth, -beamWidth).tex(1, 1).color(r2, g2, b2, alpha).endVertex();
|
|
|
|
render.pos(0, beamWidth, -beamWidth).tex(0, 1).color(r2, g2, b2, alpha).endVertex();
|
|
|
|
render.pos(0, beamWidth, beamWidth).tex(0, 0).color(r2, g2, b2, alpha).endVertex();
|
2019-05-02 10:43:27 +02:00
|
|
|
|
2016-11-08 08:53:30 +01:00
|
|
|
render.pos(length, -beamWidth, -beamWidth).tex(0, 0).color(r, g, b, alpha).endVertex();
|
|
|
|
render.pos(length, -beamWidth, beamWidth).tex(0, 1).color(r, g, b, alpha).endVertex();
|
|
|
|
render.pos(0, -beamWidth, beamWidth).tex(1, 1).color(r, g, b, alpha).endVertex();
|
|
|
|
render.pos(0, -beamWidth, -beamWidth).tex(1, 0).color(r, g, b, alpha).endVertex();
|
2019-05-02 10:43:27 +02:00
|
|
|
|
2016-11-08 08:53:30 +01:00
|
|
|
render.pos(length, -beamWidth, -beamWidth).tex(1, 0).color(r2, g2, b2, alpha).endVertex();
|
|
|
|
render.pos(length, -beamWidth, beamWidth).tex(1, 1).color(r2, g2, b2, alpha).endVertex();
|
|
|
|
render.pos(0, -beamWidth, beamWidth).tex(0, 1).color(r2, g2, b2, alpha).endVertex();
|
|
|
|
render.pos(0, -beamWidth, -beamWidth).tex(0, 0).color(r2, g2, b2, alpha).endVertex();
|
|
|
|
tessy.draw();
|
|
|
|
}
|
|
|
|
else{*/
|
2016-11-08 20:04:36 +01:00
|
|
|
GlStateManager.disableTexture2D();
|
2016-12-07 13:56:17 +01:00
|
|
|
render.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX_LMAP_COLOR);
|
2019-05-02 09:10:29 +02:00
|
|
|
for (double i = 0; i < 4; i++) {
|
|
|
|
double width = beamWidth * (i / 4.0);
|
2016-12-07 13:59:30 +01:00
|
|
|
render.pos(length, width, width).tex(0, 0).lightmap(MAX_LIGHT_X, MAX_LIGHT_Y).color(r, g, b, alpha).endVertex();
|
|
|
|
render.pos(0, width, width).tex(0, 0).lightmap(MAX_LIGHT_X, MAX_LIGHT_Y).color(r, g, b, alpha).endVertex();
|
|
|
|
render.pos(0, -width, width).tex(0, 0).lightmap(MAX_LIGHT_X, MAX_LIGHT_Y).color(r, g, b, alpha).endVertex();
|
|
|
|
render.pos(length, -width, width).tex(0, 0).lightmap(MAX_LIGHT_X, MAX_LIGHT_Y).color(r, g, b, alpha).endVertex();
|
|
|
|
|
|
|
|
render.pos(length, -width, -width).tex(0, 0).lightmap(MAX_LIGHT_X, MAX_LIGHT_Y).color(r, g, b, alpha).endVertex();
|
|
|
|
render.pos(0, -width, -width).tex(0, 0).lightmap(MAX_LIGHT_X, MAX_LIGHT_Y).color(r, g, b, alpha).endVertex();
|
|
|
|
render.pos(0, width, -width).tex(0, 0).lightmap(MAX_LIGHT_X, MAX_LIGHT_Y).color(r, g, b, alpha).endVertex();
|
|
|
|
render.pos(length, width, -width).tex(0, 0).lightmap(MAX_LIGHT_X, MAX_LIGHT_Y).color(r, g, b, alpha).endVertex();
|
|
|
|
|
|
|
|
render.pos(length, width, -width).tex(0, 0).lightmap(MAX_LIGHT_X, MAX_LIGHT_Y).color(r, g, b, alpha).endVertex();
|
|
|
|
render.pos(0, width, -width).tex(0, 0).lightmap(MAX_LIGHT_X, MAX_LIGHT_Y).color(r, g, b, alpha).endVertex();
|
|
|
|
render.pos(0, width, width).tex(0, 0).lightmap(MAX_LIGHT_X, MAX_LIGHT_Y).color(r, g, b, alpha).endVertex();
|
|
|
|
render.pos(length, width, width).tex(0, 0).lightmap(MAX_LIGHT_X, MAX_LIGHT_Y).color(r, g, b, alpha).endVertex();
|
|
|
|
|
|
|
|
render.pos(length, -width, width).tex(0, 0).lightmap(MAX_LIGHT_X, MAX_LIGHT_Y).color(r, g, b, alpha).endVertex();
|
|
|
|
render.pos(0, -width, width).tex(0, 0).lightmap(MAX_LIGHT_X, MAX_LIGHT_Y).color(r, g, b, alpha).endVertex();
|
|
|
|
render.pos(0, -width, -width).tex(0, 0).lightmap(MAX_LIGHT_X, MAX_LIGHT_Y).color(r, g, b, alpha).endVertex();
|
|
|
|
render.pos(length, -width, -width).tex(0, 0).lightmap(MAX_LIGHT_X, MAX_LIGHT_Y).color(r, g, b, alpha).endVertex();
|
|
|
|
}
|
2016-11-08 20:04:36 +01:00
|
|
|
tessy.draw();
|
2016-12-07 13:59:30 +01:00
|
|
|
|
2016-11-08 20:04:36 +01:00
|
|
|
GlStateManager.enableTexture2D();
|
2016-11-08 08:53:30 +01:00
|
|
|
//}
|
|
|
|
|
2016-12-07 13:59:30 +01:00
|
|
|
GlStateManager.alphaFunc(func, ref);
|
|
|
|
GlStateManager.blendFunc(SourceFactor.SRC_ALPHA, DestFactor.ONE_MINUS_SRC_ALPHA);
|
2016-11-08 08:53:30 +01:00
|
|
|
GlStateManager.disableBlend();
|
|
|
|
GlStateManager.enableLighting();
|
|
|
|
GlStateManager.popMatrix();
|
|
|
|
}
|
2016-11-26 15:09:15 +01:00
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
public static float[] getWheelColor(float pos) {
|
2021-02-26 22:15:48 +01:00
|
|
|
if (pos < 85.0f) {
|
|
|
|
return new float[]{pos * 3.0F, 255.0f - pos * 3.0f, 0.0f};
|
|
|
|
}
|
|
|
|
if (pos < 170.0f) {
|
|
|
|
return new float[]{255.0f - (pos -= 85.0f) * 3.0f, 0.0f, pos * 3.0f};
|
|
|
|
}
|
|
|
|
return new float[]{0.0f, (pos -= 170.0f) * 3.0f, 255.0f - pos * 3.0f};
|
2016-11-26 15:09:15 +01:00
|
|
|
}
|
2015-03-29 15:29:05 +02:00
|
|
|
}
|