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
|
|
|
|
2023-01-19 16:27:56 +01:00
|
|
|
import com.mojang.blaze3d.systems.RenderSystem;
|
2024-03-12 02:32:04 +01:00
|
|
|
import com.mojang.blaze3d.vertex.DefaultVertexFormat;
|
2024-03-02 21:23:08 +01:00
|
|
|
import com.mojang.blaze3d.vertex.PoseStack;
|
|
|
|
import com.mojang.blaze3d.vertex.Tesselator;
|
|
|
|
import com.mojang.blaze3d.vertex.VertexConsumer;
|
2024-03-12 02:32:04 +01:00
|
|
|
import com.mojang.blaze3d.vertex.VertexFormat;
|
2024-03-03 01:20:53 +01:00
|
|
|
import com.mojang.math.Axis;
|
2018-05-10 11:38:58 +02:00
|
|
|
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
|
2022-02-12 17:27:49 +01:00
|
|
|
import de.ellpeck.actuallyadditions.mod.blocks.render.RenderTypes;
|
2022-01-19 02:11:23 +01:00
|
|
|
import de.ellpeck.actuallyadditions.mod.network.PacketHandler;
|
|
|
|
import de.ellpeck.actuallyadditions.mod.network.PacketServerToClient;
|
2024-03-12 02:32:04 +01:00
|
|
|
import de.ellpeck.actuallyadditions.mod.particle.ParticleBeam;
|
2016-11-20 13:46:35 +01:00
|
|
|
import de.ellpeck.actuallyadditions.mod.tile.TileEntityBase;
|
2024-03-12 02:32:04 +01:00
|
|
|
import net.minecraft.client.Camera;
|
2015-08-24 17:57:11 +02:00
|
|
|
import net.minecraft.client.Minecraft;
|
2024-03-02 21:23:08 +01:00
|
|
|
import net.minecraft.client.gui.Font;
|
2024-03-03 01:20:53 +01:00
|
|
|
import net.minecraft.client.gui.GuiGraphics;
|
2024-03-12 02:32:04 +01:00
|
|
|
import net.minecraft.client.renderer.GameRenderer;
|
2024-03-02 21:23:08 +01:00
|
|
|
import net.minecraft.client.renderer.LightTexture;
|
|
|
|
import net.minecraft.client.renderer.MultiBufferSource;
|
|
|
|
import net.minecraft.client.renderer.entity.ItemRenderer;
|
|
|
|
import net.minecraft.client.renderer.texture.TextureAtlas;
|
2024-03-04 23:33:15 +01:00
|
|
|
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
2023-01-19 16:27:56 +01:00
|
|
|
import net.minecraft.client.renderer.texture.TextureManager;
|
2024-03-02 21:23:08 +01:00
|
|
|
import net.minecraft.client.resources.language.I18n;
|
|
|
|
import net.minecraft.client.resources.model.BakedModel;
|
2024-03-13 01:50:37 +01:00
|
|
|
import net.minecraft.core.BlockPos;
|
2024-03-02 21:23:08 +01:00
|
|
|
import net.minecraft.core.NonNullList;
|
|
|
|
import net.minecraft.nbt.CompoundTag;
|
|
|
|
import net.minecraft.resources.ResourceLocation;
|
2024-03-13 01:50:37 +01:00
|
|
|
import net.minecraft.util.Mth;
|
|
|
|
import net.minecraft.world.entity.Entity;
|
2024-03-03 01:20:53 +01:00
|
|
|
import net.minecraft.world.item.ItemDisplayContext;
|
2024-03-02 21:23:08 +01:00
|
|
|
import net.minecraft.world.item.ItemStack;
|
|
|
|
import net.minecraft.world.level.Level;
|
2024-03-13 01:50:37 +01:00
|
|
|
import net.minecraft.world.level.block.state.BlockState;
|
2024-03-02 21:23:08 +01:00
|
|
|
import net.minecraft.world.phys.Vec3;
|
2024-03-13 01:50:37 +01:00
|
|
|
import net.minecraft.world.phys.shapes.CollisionContext;
|
|
|
|
import net.minecraft.world.phys.shapes.VoxelShape;
|
2024-03-04 20:21:48 +01:00
|
|
|
import net.neoforged.api.distmarker.Dist;
|
|
|
|
import net.neoforged.api.distmarker.OnlyIn;
|
|
|
|
import net.neoforged.neoforge.client.ClientHooks;
|
|
|
|
import net.neoforged.neoforge.network.PacketDistributor;
|
2024-03-03 01:20:53 +01:00
|
|
|
import org.joml.Matrix4f;
|
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");
|
2024-03-04 23:33:15 +01:00
|
|
|
private static final ResourceLocation FORGE_WHITE = new ResourceLocation("forge", "white");
|
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)
|
2024-03-03 01:20:53 +01:00
|
|
|
public static void displayNameString(GuiGraphics guiGraphics, Font font, int xSize, int yPositionOfMachineText, String text) {
|
|
|
|
guiGraphics.drawString(font, text, xSize / 2f - font.width(text) / 2f, yPositionOfMachineText, 0xFFFFFF, false);
|
2016-07-03 21:57:33 +02:00
|
|
|
}
|
|
|
|
|
2021-02-26 22:15:48 +01:00
|
|
|
@OnlyIn(Dist.CLIENT)
|
2024-03-03 01:20:53 +01:00
|
|
|
public static void displayNameString(GuiGraphics guiGraphics, Font font, int xSize, int yPositionOfMachineText, TileEntityBase tile) {
|
|
|
|
displayNameString(guiGraphics, font, xSize, yPositionOfMachineText, I18n.get(tile.getNameForTranslation()));
|
2015-04-19 01:50:02 +02:00
|
|
|
}
|
2015-08-24 17:57:11 +02:00
|
|
|
|
2021-02-28 12:33:01 +01:00
|
|
|
// public static void renderBlockInWorld(Block block, int meta) {
|
|
|
|
// 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)
|
2024-03-02 21:23:08 +01:00
|
|
|
public static void renderItemInWorld(ItemStack stack, int combinedLight, int combinedOverlay, PoseStack matrices, MultiBufferSource buffer) {
|
2022-06-24 21:23:43 +02:00
|
|
|
if (!stack.isEmpty()) {
|
2021-08-22 17:09:06 +02:00
|
|
|
Minecraft.getInstance().getItemRenderer().renderStatic(
|
2024-03-03 01:20:53 +01:00
|
|
|
stack, ItemDisplayContext.FIXED, combinedLight, combinedOverlay, matrices, buffer, null, 0
|
2021-02-28 11:35:10 +01:00
|
|
|
);
|
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-28 12:33:01 +01:00
|
|
|
// @OnlyIn(Dist.CLIENT)
|
|
|
|
// public static void renderStateInWorld(BlockState state, IWorldReader world, BlockPos pos, float brightness) {
|
|
|
|
// Minecraft.getInstance().getTextureManager().bindTexture(PlayerContainer.LOCATION_BLOCKS_TEXTURE);
|
|
|
|
// IBakedModel model = Minecraft.getInstance().getBlockRendererDispatcher().getModelForState(state);
|
|
|
|
// GlStateManager.rotate(90.0F, 0.0F, 1.0F, 0.0F);
|
|
|
|
// int i = Minecraft.getInstance().getBlockColors().colorMultiplier(state, world, pos, 0);
|
|
|
|
//
|
|
|
|
// float r = (i >> 16 & 255) / 255F;
|
|
|
|
// float g = (i >> 8 & 255) / 255F;
|
|
|
|
// float b = (i & 255) / 255F;
|
|
|
|
//
|
|
|
|
// Minecraft.getInstance().getBlockRendererDispatcher().getBlockModelRenderer().renderModelBrightnessColor(state, model, brightness, r, g, b);
|
|
|
|
// }
|
2015-08-24 17:57:11 +02:00
|
|
|
|
2021-02-26 22:15:48 +01:00
|
|
|
@OnlyIn(Dist.CLIENT)
|
2024-03-02 21:23:08 +01:00
|
|
|
public static void renderItemWithoutScrewingWithColors(ItemStack stack, PoseStack matrices, int combinedOverlay, int combinedLight) {
|
2023-01-19 16:27:56 +01:00
|
|
|
if (StackUtil.isValid(stack)) {
|
2021-02-26 22:15:48 +01:00
|
|
|
Minecraft mc = Minecraft.getInstance();
|
2021-08-22 23:19:57 +02:00
|
|
|
ItemRenderer renderer = mc.getItemRenderer();
|
2016-12-27 17:40:27 +01:00
|
|
|
TextureManager manager = mc.getTextureManager();
|
2024-03-02 21:23:08 +01:00
|
|
|
MultiBufferSource.BufferSource bufferSource = mc.renderBuffers().bufferSource();
|
2023-01-19 16:27:56 +01:00
|
|
|
|
2024-03-02 21:23:08 +01:00
|
|
|
BakedModel model = renderer.getModel(stack, null, null, 0);
|
|
|
|
manager.bindForSetup(TextureAtlas.LOCATION_BLOCKS); //bind
|
|
|
|
manager.getTexture(TextureAtlas.LOCATION_BLOCKS).setBlurMipmap(false, false);
|
|
|
|
// RenderSystem.enableRescaleNormal();
|
2023-01-19 16:27:56 +01:00
|
|
|
RenderSystem.enableBlend();
|
2024-03-02 21:23:08 +01:00
|
|
|
// RenderSystem.pushMatrix();
|
|
|
|
matrices.pushPose();
|
2024-03-04 20:21:48 +01:00
|
|
|
model = ClientHooks.handleCameraTransforms(matrices, model, ItemDisplayContext.FIXED, false);
|
2024-03-03 01:20:53 +01:00
|
|
|
renderer.render(stack, ItemDisplayContext.FIXED, false, matrices, bufferSource,
|
2023-01-19 16:27:56 +01:00
|
|
|
combinedOverlay, combinedLight, model);
|
2024-03-02 21:23:08 +01:00
|
|
|
// RenderSystem.popMatrix();
|
|
|
|
matrices.popPose();
|
|
|
|
// RenderSystem.disableRescaleNormal();
|
2023-01-19 16:27:56 +01:00
|
|
|
RenderSystem.disableBlend();
|
2024-03-02 21:23:08 +01:00
|
|
|
manager.bindForSetup(TextureAtlas.LOCATION_BLOCKS); //bind
|
|
|
|
manager.getTexture(TextureAtlas.LOCATION_BLOCKS).restoreLastBlurMipmap();
|
|
|
|
bufferSource.endBatch();
|
2023-01-19 16:27:56 +01:00
|
|
|
}
|
2016-12-27 17:40:27 +01:00
|
|
|
}
|
|
|
|
|
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) {
|
2021-11-21 20:49:33 +01:00
|
|
|
/* GlStateManager._pushMatrix();
|
2021-08-22 17:09:06 +02:00
|
|
|
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();
|
2021-08-22 17:09:06 +02:00
|
|
|
GlStateManager._enableRescaleNormal();
|
2016-01-08 15:21:05 +01:00
|
|
|
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();
|
2021-08-22 17:09:06 +02:00
|
|
|
boolean flagBefore = mc.font.getUnicodeFlag();
|
|
|
|
mc.font.setUnicodeFlag(false);
|
2021-02-26 22:15:48 +01:00
|
|
|
Minecraft.getInstance().getRenderItem().renderItemAndEffectIntoGUI(stack, 0, 0);
|
2021-08-22 17:09:06 +02:00
|
|
|
Minecraft.getInstance().getRenderItem().renderItemOverlayIntoGUI(mc.font, stack, 0, 0, null);
|
|
|
|
mc.font.setUnicodeFlag(flagBefore);
|
2015-12-22 14:55:10 +01:00
|
|
|
|
2021-08-22 17:09:06 +02:00
|
|
|
RenderHelper.turnOff();
|
2021-11-21 20:49:33 +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) {
|
2021-11-21 20:49:33 +01:00
|
|
|
/* float f = (startColor >> 24 & 255) / 255.0F;
|
2019-05-02 09:10:29 +02:00
|
|
|
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();
|
2021-08-22 17:09:06 +02:00
|
|
|
GlStateManager._enableBlend();
|
2016-01-07 21:41:28 +01:00
|
|
|
GlStateManager.disableAlpha();
|
|
|
|
GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0);
|
2021-08-22 17:09:06 +02:00
|
|
|
GlStateManager._shadeModel(7425);
|
2016-01-07 21:41:28 +01:00
|
|
|
Tessellator tessellator = Tessellator.getInstance();
|
2021-08-22 17:09:06 +02:00
|
|
|
BufferBuilder renderer = tessellator.getBuilder();
|
2016-03-18 23:47:22 +01:00
|
|
|
renderer.begin(7, DefaultVertexFormats.POSITION_COLOR);
|
2021-08-22 17:09:06 +02:00
|
|
|
renderer.vertex(left, top, zLevel).color(f1, f2, f3, f).endVertex();
|
|
|
|
renderer.vertex(left, bottom, zLevel).color(f1, f2, f3, f).endVertex();
|
|
|
|
renderer.vertex(right, bottom, zLevel).color(f5, f6, f7, f4).endVertex();
|
|
|
|
renderer.vertex(right, top, zLevel).color(f5, f6, f7, f4).endVertex();
|
|
|
|
tessellator.end();
|
|
|
|
GlStateManager._shadeModel(7424);
|
|
|
|
GlStateManager._disableBlend();
|
2016-01-07 21:41:28 +01:00
|
|
|
GlStateManager.enableAlpha();
|
2021-11-21 20:49:33 +01:00
|
|
|
GlStateManager.enableTexture2D();*/
|
2015-10-23 19:05:02 +02:00
|
|
|
}
|
2016-02-17 23:15:56 +01:00
|
|
|
|
2021-11-13 19:30:58 +01:00
|
|
|
// @OnlyIn(Dist.CLIENT)
|
|
|
|
// public static void renderNameTag(String tag, double x, double y, double z) {
|
|
|
|
// FontRenderer fontrenderer = Minecraft.getInstance().font;
|
|
|
|
// float f = 1.6F;
|
|
|
|
// float f1 = 0.016666668F * f;
|
|
|
|
// GlStateManager._pushMatrix();
|
|
|
|
// GlStateManager.translate(x, y, z);
|
|
|
|
// GL11.glNormal3f(0.0F, 1.0F, 0.0F);
|
|
|
|
// GlStateManager.rotate(-Minecraft.getInstance().getEntityRenderDispatcher().playerViewY, 0.0F, 1.0F, 0.0F);
|
|
|
|
// GlStateManager.rotate(Minecraft.getInstance().getEntityRenderDispatcher().playerViewX, 1.0F, 0.0F, 0.0F);
|
|
|
|
// GlStateManager.scale(-f1, -f1, f1);
|
|
|
|
// GlStateManager._disableLighting();
|
|
|
|
// GlStateManager._depthMask(false);
|
|
|
|
// GlStateManager.disableDepth();
|
|
|
|
// GlStateManager._enableBlend();
|
|
|
|
// GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0);
|
|
|
|
// Tessellator tessellator = Tessellator.getInstance();
|
|
|
|
// BufferBuilder renderer = tessellator.getBuilder();
|
|
|
|
// int i = 0;
|
|
|
|
// int j = fontrenderer.width(tag) / 2;
|
|
|
|
// GlStateManager.disableTexture2D();
|
|
|
|
// renderer.begin(7, DefaultVertexFormats.POSITION_COLOR);
|
|
|
|
// renderer.vertex(-j - 1, -1 + i, 0.0D).color(0.0F, 0.0F, 0.0F, 0.25F).endVertex();
|
|
|
|
// renderer.vertex(-j - 1, 8 + i, 0.0D).color(0.0F, 0.0F, 0.0F, 0.25F).endVertex();
|
|
|
|
// renderer.vertex(j + 1, 8 + i, 0.0D).color(0.0F, 0.0F, 0.0F, 0.25F).endVertex();
|
|
|
|
// renderer.vertex(j + 1, -1 + i, 0.0D).color(0.0F, 0.0F, 0.0F, 0.25F).endVertex();
|
|
|
|
// tessellator.end();
|
|
|
|
// GlStateManager.enableTexture2D();
|
|
|
|
// fontrenderer.draw(tag, -fontrenderer.width(tag) / 2, i, 553648127);
|
|
|
|
// GlStateManager.enableDepth();
|
|
|
|
// GlStateManager._depthMask(true);
|
|
|
|
// fontrenderer.draw(tag, -fontrenderer.width(tag) / 2, i, -1);
|
|
|
|
// GlStateManager._enableLighting();
|
|
|
|
// GlStateManager._disableBlend();
|
|
|
|
// GlStateManager.color3arg(1.0F, 1.0F, 1.0F, 1.0F);
|
|
|
|
// GlStateManager._popMatrix();
|
|
|
|
// }
|
2016-06-15 16:43:59 +02:00
|
|
|
|
2024-03-02 21:23:08 +01:00
|
|
|
public static void spawnLaserWithTimeServer(Level world, double startX, double startY, double startZ, double endX, double endY, double endZ, int color, int maxAge, double rotationTime, float size, float alpha) {
|
2021-08-22 17:09:06 +02:00
|
|
|
if (!world.isClientSide) {
|
2024-03-02 21:23:08 +01:00
|
|
|
CompoundTag data = new CompoundTag();
|
2021-11-13 19:30:58 +01:00
|
|
|
data.putDouble("StartX", startX);
|
|
|
|
data.putDouble("StartY", startY);
|
|
|
|
data.putDouble("StartZ", startZ);
|
|
|
|
data.putDouble("EndX", endX);
|
|
|
|
data.putDouble("EndY", endY);
|
|
|
|
data.putDouble("EndZ", endZ);
|
2022-07-06 19:14:19 +02:00
|
|
|
data.putInt("Color", color);
|
2021-11-13 19:30:58 +01:00
|
|
|
data.putDouble("RotationTime", rotationTime);
|
|
|
|
data.putFloat("Size", size);
|
|
|
|
data.putInt("MaxAge", maxAge);
|
|
|
|
data.putFloat("Alpha", alpha);
|
2024-03-04 22:37:11 +01:00
|
|
|
PacketDistributor.NEAR.with(new PacketDistributor.TargetPoint(startX, startY, startZ, 96, world.dimension())).send(new PacketServerToClient(data, PacketHandler.LASER_HANDLER));
|
2016-06-15 16:43:59 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-26 22:15:48 +01:00
|
|
|
@OnlyIn(Dist.CLIENT)
|
2022-07-06 19:14:19 +02:00
|
|
|
public static void spawnLaserWithTimeClient(double startX, double startY, double startZ, double endX, double endY, double endZ, int color, int maxAge, double rotationTime, float size, float alpha) {
|
2021-02-26 22:15:48 +01:00
|
|
|
Minecraft mc = Minecraft.getInstance();
|
2024-03-12 18:49:18 +01:00
|
|
|
if (mc.player != null && mc.player.distanceToSqr(startX, startY, startZ) <= 64 || mc.player.distanceToSqr(endX, endY, endZ) <= 64) {
|
|
|
|
mc.level.addParticle(ParticleBeam.Factory.createData(endX, endY, endZ, color, alpha, maxAge, rotationTime, size), startX, startY, startZ, 0, 0, 0);
|
2024-03-12 02:32:04 +01:00
|
|
|
}
|
2022-02-12 17:27:49 +01:00
|
|
|
}
|
|
|
|
/* @OnlyIn(Dist.CLIENT)
|
|
|
|
public static void renderLaser(MatrixStack matrixStack, IRenderTypeBuffer buffer, float x, float y, float z, float tx, float ty, float tz, float rotation, int color, float beamWidth) {
|
|
|
|
|
|
|
|
|
|
|
|
}*/
|
|
|
|
|
|
|
|
@OnlyIn(Dist.CLIENT)
|
2024-03-02 21:23:08 +01:00
|
|
|
public static void renderLaser(PoseStack matrixStack, MultiBufferSource buffer, float offX, float offY, float offZ, float yaw, float pitch, float length, float rotationTime, int color, float alpha, float beamWidth) {
|
|
|
|
Level world = Minecraft.getInstance().level;
|
2024-03-04 23:33:15 +01:00
|
|
|
/* int r = (color >> 16) & 0xFF;
|
2022-02-12 17:27:49 +01:00
|
|
|
int g = (color >> 8) & 0xFF;
|
|
|
|
int b = color & 0xFF;
|
2024-03-04 23:33:15 +01:00
|
|
|
int a = (int) (alpha * 255);*/
|
|
|
|
int r = (int)(((color >> 16) & 0xFF) * alpha);
|
|
|
|
int g = (int)(((color >> 8) & 0xFF) * alpha);
|
|
|
|
int b = (int)((color & 0xFF) * alpha);
|
|
|
|
int a = 255;
|
2022-02-12 17:27:49 +01:00
|
|
|
|
|
|
|
int lightmap = LightTexture.pack(MAX_LIGHT_X, MAX_LIGHT_Y);
|
|
|
|
|
|
|
|
float roll = rotationTime > 0.0f ? 360.0f * (world.getGameTime() % rotationTime / rotationTime) : 0.0f;
|
|
|
|
|
2024-03-02 21:23:08 +01:00
|
|
|
VertexConsumer builder = buffer.getBuffer(RenderTypes.LASER);
|
2022-02-12 17:27:49 +01:00
|
|
|
matrixStack.pushPose();
|
|
|
|
matrixStack.translate(0.5f, 0.5f, 0.5f);
|
|
|
|
matrixStack.translate(offX, offY, offZ);
|
|
|
|
|
2024-03-03 01:20:53 +01:00
|
|
|
matrixStack.mulPose(Axis.YP.rotationDegrees(yaw));
|
|
|
|
matrixStack.mulPose(Axis.XP.rotationDegrees(pitch));
|
|
|
|
matrixStack.mulPose(Axis.ZP.rotationDegrees(roll));
|
2022-02-12 17:27:49 +01:00
|
|
|
|
|
|
|
Matrix4f matrix = matrixStack.last().pose();
|
|
|
|
|
2024-03-04 23:33:15 +01:00
|
|
|
TextureAtlasSprite sprite = Minecraft.getInstance().getTextureAtlas(TextureAtlas.LOCATION_BLOCKS).apply(FORGE_WHITE);
|
|
|
|
float minU = sprite.getU0();
|
|
|
|
float maxU = sprite.getU1();
|
|
|
|
float minV = sprite.getV0();
|
|
|
|
float maxV = sprite.getV1();
|
|
|
|
|
2022-02-12 17:27:49 +01:00
|
|
|
//Draw laser tube faces
|
2024-03-04 23:33:15 +01:00
|
|
|
for (int i = 1; i < 4; i++) {
|
2022-02-12 17:27:49 +01:00
|
|
|
float width = beamWidth * (i / 4.0f);
|
|
|
|
//top
|
2024-03-04 23:33:15 +01:00
|
|
|
builder.vertex(matrix, -width, width, 0.0f).color(r, g, b, a).uv(minU, maxV).uv2(lightmap).endVertex();
|
|
|
|
builder.vertex(matrix, width, width, 0.0f).color(r, g, b, a).uv(maxU, maxV).uv2(lightmap).endVertex();
|
|
|
|
builder.vertex(matrix, width, width, -length).color(r, g, b, a).uv(maxU, minV).uv2(lightmap).endVertex();
|
|
|
|
builder.vertex(matrix, -width, width, -length).color(r, g, b, a).uv(minU, minV).uv2(lightmap).endVertex();
|
2022-02-12 17:27:49 +01:00
|
|
|
//bottom
|
2024-03-04 23:33:15 +01:00
|
|
|
builder.vertex(matrix, -width, -width, 0.0f).color(r, g, b, a).uv(minU, maxV).uv2(lightmap).endVertex();
|
|
|
|
builder.vertex(matrix, -width, -width, -length).color(r, g, b, a).uv(minU, minV).uv2(lightmap).endVertex();
|
|
|
|
builder.vertex(matrix, width, -width, -length).color(r, g, b, a).uv(maxU, minV).uv2(lightmap).endVertex();
|
|
|
|
builder.vertex(matrix, width, -width, 0.0f).color(r, g, b, a).uv(maxU, maxV).uv2(lightmap).endVertex();
|
2022-02-12 17:27:49 +01:00
|
|
|
//left
|
2024-03-04 23:33:15 +01:00
|
|
|
builder.vertex(matrix, -width, width, 0.0f).color(r, g, b, a).uv(maxU, maxV).uv2(lightmap).endVertex();
|
|
|
|
builder.vertex(matrix, -width, -width, 0.0f).color(r, g, b, a).uv(maxU, maxV).uv2(lightmap).endVertex();
|
|
|
|
builder.vertex(matrix, -width, -width, -length).color(r, g, b, a).uv(minU, minV).uv2(lightmap).endVertex();
|
|
|
|
builder.vertex(matrix, -width, width, -length).color(r, g, b, a).uv(minU, minV).uv2(lightmap).endVertex();
|
2022-02-12 17:27:49 +01:00
|
|
|
//right
|
2024-03-04 23:33:15 +01:00
|
|
|
builder.vertex(matrix, width, width, 0.0f).color(r, g, b, a).uv(maxU, maxV).uv2(lightmap).endVertex();
|
|
|
|
builder.vertex(matrix, width, -width, 0.0f).color(r, g, b, a).uv(maxU, maxV).uv2(lightmap).endVertex();
|
|
|
|
builder.vertex(matrix, width, -width, -length).color(r, g, b, a).uv(minU, minV).uv2(lightmap).endVertex();
|
|
|
|
builder.vertex(matrix, width, width, -length).color(r, g, b, a).uv(minU, minV).uv2(lightmap).endVertex();
|
2016-06-15 16:43:59 +02:00
|
|
|
}
|
2022-02-12 17:27:49 +01:00
|
|
|
|
|
|
|
|
|
|
|
matrixStack.popPose();
|
2016-06-15 16:43:59 +02:00
|
|
|
}
|
2016-11-08 08:53:30 +01:00
|
|
|
|
2024-03-02 21:23:08 +01:00
|
|
|
public static void renderLaser(PoseStack matrixStack, MultiBufferSource buffer, Vec3 startOffset, Vec3 endOffset, float rotationTime, int color, float alpha, float beamWidth) {
|
|
|
|
Vec3 combined = endOffset.subtract(startOffset);
|
2022-04-02 00:51:55 +02:00
|
|
|
|
|
|
|
double pitch = Math.toDegrees(Math.atan2(combined.y, Math.sqrt(combined.x * combined.x + combined.z * combined.z)));
|
|
|
|
double yaw = Math.toDegrees(Math.atan2(-combined.z, combined.x));
|
|
|
|
double length = combined.length();
|
|
|
|
|
|
|
|
renderLaser(matrixStack, buffer, (float) startOffset.x, (float) startOffset.y, (float) startOffset.z, (float) yaw, (float) pitch, (float) length, rotationTime, color, alpha, beamWidth);
|
|
|
|
}
|
|
|
|
|
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)
|
2024-03-12 02:32:04 +01:00
|
|
|
public static void renderLaserParticle(VertexConsumer builder, Camera camera, double firstX, double firstY, double firstZ, double secondX, double secondY, double secondZ, float rotationTime, float a, float beamWidth, float[] color) {
|
2024-03-02 21:23:08 +01:00
|
|
|
Level world = Minecraft.getInstance().level;
|
2016-11-08 08:53:30 +01:00
|
|
|
|
2024-03-12 02:32:04 +01:00
|
|
|
Vec3 cam = camera.getPosition();
|
2016-11-08 08:53:30 +01:00
|
|
|
float r = color[0];
|
|
|
|
float g = color[1];
|
|
|
|
float b = color[2];
|
|
|
|
|
2024-03-02 21:23:08 +01:00
|
|
|
Vec3 vec1 = new Vec3(firstX, firstY, firstZ);
|
|
|
|
Vec3 vec2 = new Vec3(secondX, secondY, secondZ);
|
|
|
|
Vec3 combinedVec = vec2.subtract(vec1);
|
2016-11-08 08:53:30 +01:00
|
|
|
|
2024-03-12 02:32:04 +01:00
|
|
|
int lightmap = LightTexture.pack(MAX_LIGHT_X, MAX_LIGHT_Y);
|
2016-11-08 08:53:30 +01:00
|
|
|
|
2024-03-12 02:32:04 +01:00
|
|
|
double roll = rotationTime > 0 ? 360D * (world.getGameTime() % rotationTime / rotationTime) : 0;
|
|
|
|
double pitch = Math.toDegrees(Math.atan2(combinedVec.y, Math.sqrt(combinedVec.x * combinedVec.x + combinedVec.z * combinedVec.z)));
|
|
|
|
double yaw = Math.toDegrees(Math.atan2(-combinedVec.z, combinedVec.x)) - 90;
|
2016-11-08 08:53:30 +01:00
|
|
|
|
2024-03-12 02:32:04 +01:00
|
|
|
float length = (float) combinedVec.length();
|
2016-11-08 08:53:30 +01:00
|
|
|
|
2024-03-12 02:32:04 +01:00
|
|
|
PoseStack matrixStack = new PoseStack();
|
|
|
|
matrixStack.pushPose();
|
2016-12-07 13:59:30 +01:00
|
|
|
|
2024-03-12 02:32:04 +01:00
|
|
|
matrixStack.translate(firstX - cam.x, firstY - cam.y, firstZ - cam.z);
|
2016-11-08 08:53:30 +01:00
|
|
|
|
2024-03-12 02:32:04 +01:00
|
|
|
matrixStack.mulPose(Axis.YP.rotationDegrees((float)yaw));
|
|
|
|
matrixStack.mulPose(Axis.XP.rotationDegrees((float)pitch));
|
|
|
|
matrixStack.mulPose(Axis.ZP.rotationDegrees((float)roll));
|
|
|
|
|
|
|
|
Matrix4f matrix = matrixStack.last().pose();
|
|
|
|
|
|
|
|
RenderSystem.setShader(GameRenderer::getPositionColorLightmapShader);
|
|
|
|
Tesselator.getInstance().getBuilder().begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR_LIGHTMAP);
|
|
|
|
|
|
|
|
TextureAtlasSprite sprite = Minecraft.getInstance().getTextureAtlas(TextureAtlas.LOCATION_BLOCKS).apply(FORGE_WHITE);
|
|
|
|
float minU = sprite.getU0();
|
|
|
|
float maxU = sprite.getU1();
|
|
|
|
float minV = sprite.getV0();
|
|
|
|
float maxV = sprite.getV1();
|
|
|
|
|
|
|
|
//Draw laser tube faces
|
|
|
|
for (int i = 1; i < 4; i++) {
|
|
|
|
float width = beamWidth * (i / 4.0f);
|
|
|
|
//top
|
|
|
|
builder.vertex(matrix, -width, width, 0.0f).color(r, g, b, a).uv(minU, maxV).uv2(lightmap).endVertex();
|
|
|
|
builder.vertex(matrix, width, width, 0.0f).color(r, g, b, a).uv(maxU, maxV).uv2(lightmap).endVertex();
|
|
|
|
builder.vertex(matrix, width, width, -length).color(r, g, b, a).uv(maxU, minV).uv2(lightmap).endVertex();
|
|
|
|
builder.vertex(matrix, -width, width, -length).color(r, g, b, a).uv(minU, minV).uv2(lightmap).endVertex();
|
|
|
|
//bottom
|
|
|
|
builder.vertex(matrix, -width, -width, 0.0f).color(r, g, b, a).uv(minU, maxV).uv2(lightmap).endVertex();
|
|
|
|
builder.vertex(matrix, -width, -width, -length).color(r, g, b, a).uv(minU, minV).uv2(lightmap).endVertex();
|
|
|
|
builder.vertex(matrix, width, -width, -length).color(r, g, b, a).uv(maxU, minV).uv2(lightmap).endVertex();
|
|
|
|
builder.vertex(matrix, width, -width, 0.0f).color(r, g, b, a).uv(maxU, maxV).uv2(lightmap).endVertex();
|
|
|
|
//left
|
|
|
|
builder.vertex(matrix, -width, width, 0.0f).color(r, g, b, a).uv(maxU, maxV).uv2(lightmap).endVertex();
|
|
|
|
builder.vertex(matrix, -width, -width, 0.0f).color(r, g, b, a).uv(maxU, maxV).uv2(lightmap).endVertex();
|
|
|
|
builder.vertex(matrix, -width, -width, -length).color(r, g, b, a).uv(minU, minV).uv2(lightmap).endVertex();
|
|
|
|
builder.vertex(matrix, -width, width, -length).color(r, g, b, a).uv(minU, minV).uv2(lightmap).endVertex();
|
|
|
|
//right
|
|
|
|
builder.vertex(matrix, width, width, 0.0f).color(r, g, b, a).uv(maxU, maxV).uv2(lightmap).endVertex();
|
|
|
|
builder.vertex(matrix, width, -width, 0.0f).color(r, g, b, a).uv(maxU, maxV).uv2(lightmap).endVertex();
|
|
|
|
builder.vertex(matrix, width, -width, -length).color(r, g, b, a).uv(minU, minV).uv2(lightmap).endVertex();
|
|
|
|
builder.vertex(matrix, width, width, -length).color(r, g, b, a).uv(minU, minV).uv2(lightmap).endVertex();
|
|
|
|
}
|
|
|
|
matrixStack.popPose();
|
|
|
|
Tesselator.getInstance().end();
|
2016-11-08 08:53:30 +01:00
|
|
|
}
|
2016-11-26 15:09:15 +01:00
|
|
|
|
2022-02-16 02:36:31 +01:00
|
|
|
@OnlyIn(Dist.CLIENT)
|
2024-03-03 01:20:53 +01:00
|
|
|
public static void renderTextInWorld(GuiGraphics guiGraphics, double offsetX, double offsetY, double offsetZ, NonNullList<String> text, int color) {
|
|
|
|
PoseStack matrices = guiGraphics.pose();
|
|
|
|
matrices.pushPose();
|
|
|
|
matrices.translate(offsetX,offsetY,offsetZ);
|
|
|
|
matrices.scale(-1, -1, 1);
|
|
|
|
matrices.mulPose(Axis.YP.rotationDegrees(Minecraft.getInstance().cameraEntity.getYRot()));
|
|
|
|
matrices.scale(0.01F, 0.01F, 0.01F);
|
2022-02-16 02:36:31 +01:00
|
|
|
|
2024-03-02 21:23:08 +01:00
|
|
|
Font font = Minecraft.getInstance().font;
|
2022-02-16 02:36:31 +01:00
|
|
|
|
|
|
|
int y = 0;
|
|
|
|
for (String s : text) {
|
2024-03-03 01:20:53 +01:00
|
|
|
guiGraphics.drawString(font, s, 0, y, color);
|
2022-02-16 02:36:31 +01:00
|
|
|
y+= 10;
|
|
|
|
}
|
|
|
|
|
2024-03-03 01:20:53 +01:00
|
|
|
matrices.popPose();
|
2022-02-16 02:36:31 +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
|
|
|
}
|
2024-03-13 01:50:37 +01:00
|
|
|
|
|
|
|
@OnlyIn(Dist.CLIENT)
|
|
|
|
public static void renderHitOutline(PoseStack poseStack, VertexConsumer consumer, Entity entity,
|
|
|
|
double camX, double camY, double camZ, Level level, BlockPos pos, BlockState state) {
|
|
|
|
renderShape(poseStack, consumer, state.getShape(level, pos, CollisionContext.of(entity)),
|
|
|
|
(double) pos.getX() - camX,
|
|
|
|
(double) pos.getY() - camY,
|
|
|
|
(double) pos.getZ() - camZ,
|
|
|
|
0.0F,
|
|
|
|
0.0F,
|
|
|
|
0.0F,
|
|
|
|
0.4F
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
@OnlyIn(Dist.CLIENT)
|
|
|
|
private static void renderShape(PoseStack poseStack, VertexConsumer consumer, VoxelShape shape,
|
|
|
|
double x, double y, double z, float red, float green, float blue, float alpha) {
|
|
|
|
PoseStack.Pose posestack$pose = poseStack.last();
|
|
|
|
shape.forAllEdges(
|
|
|
|
(minX, minY, minZ, maxX, maxY, maxZ) -> {
|
|
|
|
float f = (float) (maxX - minX);
|
|
|
|
float f1 = (float) (maxY - minY);
|
|
|
|
float f2 = (float) (maxZ - minZ);
|
|
|
|
float f3 = Mth.sqrt(f * f + f1 * f1 + f2 * f2);
|
|
|
|
f /= f3;
|
|
|
|
f1 /= f3;
|
|
|
|
f2 /= f3;
|
|
|
|
consumer.vertex(posestack$pose.pose(), (float) (minX + x), (float) (minY + y), (float) (minZ + z))
|
|
|
|
.color(red, green, blue, alpha)
|
|
|
|
.normal(posestack$pose.normal(), f, f1, f2)
|
|
|
|
.endVertex();
|
|
|
|
consumer.vertex(posestack$pose.pose(), (float) (maxX + x), (float) (maxY + y), (float) (maxZ + z))
|
|
|
|
.color(red, green, blue, alpha)
|
|
|
|
.normal(posestack$pose.normal(), f, f1, f2)
|
|
|
|
.endVertex();
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
2015-03-29 15:29:05 +02:00
|
|
|
}
|