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
|
|
|
|
*
|
2016-05-16 22:54:42 +02:00
|
|
|
* © 2015-2016 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
|
|
|
|
2016-06-15 16:43:59 +02:00
|
|
|
import de.ellpeck.actuallyadditions.mod.misc.ParticleColored;
|
|
|
|
import de.ellpeck.actuallyadditions.mod.network.PacketHandler;
|
|
|
|
import de.ellpeck.actuallyadditions.mod.network.PacketServerToClient;
|
2015-08-24 17:57:11 +02:00
|
|
|
import net.minecraft.block.Block;
|
|
|
|
import net.minecraft.client.Minecraft;
|
2015-04-19 01:50:02 +02:00
|
|
|
import net.minecraft.client.gui.FontRenderer;
|
2016-01-07 21:41:28 +01:00
|
|
|
import net.minecraft.client.renderer.GlStateManager;
|
2016-01-07 18:20:59 +01:00
|
|
|
import net.minecraft.client.renderer.RenderHelper;
|
|
|
|
import net.minecraft.client.renderer.Tessellator;
|
2016-03-18 23:47:22 +01:00
|
|
|
import net.minecraft.client.renderer.VertexBuffer;
|
2016-01-08 23:36:35 +01:00
|
|
|
import net.minecraft.client.renderer.block.model.ItemCameraTransforms.TransformType;
|
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;
|
2016-06-15 16:43:59 +02:00
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
2015-03-29 15:29:05 +02:00
|
|
|
import net.minecraft.util.ResourceLocation;
|
2016-06-15 16:43:59 +02:00
|
|
|
import net.minecraft.util.math.BlockPos;
|
|
|
|
import net.minecraft.util.math.Vec3d;
|
|
|
|
import net.minecraft.world.World;
|
|
|
|
import net.minecraftforge.fml.common.network.NetworkRegistry;
|
2016-01-07 18:20:59 +01:00
|
|
|
import net.minecraftforge.fml.relauncher.Side;
|
|
|
|
import net.minecraftforge.fml.relauncher.SideOnly;
|
2015-10-23 19:05:02 +02:00
|
|
|
import org.lwjgl.opengl.GL11;
|
2015-03-29 15:29:05 +02:00
|
|
|
|
|
|
|
public class AssetUtil{
|
|
|
|
|
2015-10-03 10:16:18 +02:00
|
|
|
public static final ResourceLocation GUI_INVENTORY_LOCATION = getGuiLocation("guiInventory");
|
2015-11-13 18:56:15 +01:00
|
|
|
|
2015-03-29 15:29:05 +02:00
|
|
|
public static ResourceLocation getGuiLocation(String file){
|
2016-04-20 21:39:03 +02:00
|
|
|
return new ResourceLocation(ModUtil.MOD_ID, "textures/gui/"+file+".png");
|
2015-03-29 15:29:05 +02:00
|
|
|
}
|
|
|
|
|
2015-10-30 20:07:36 +01:00
|
|
|
public static ResourceLocation getBookletGuiLocation(String file){
|
2016-04-20 21:39:03 +02:00
|
|
|
return new ResourceLocation(ModUtil.MOD_ID, "textures/gui/booklet/"+file+".png");
|
2015-10-30 20:07:36 +01:00
|
|
|
}
|
|
|
|
|
2015-05-20 22:39:43 +02:00
|
|
|
public static void displayNameString(FontRenderer font, int xSize, int yPositionOfMachineText, String machineName){
|
2015-08-01 00:40:29 +02:00
|
|
|
String localMachineName = StringUtil.localize(machineName+".name");
|
2015-10-02 16:48:01 +02:00
|
|
|
font.drawString(localMachineName, xSize/2-font.getStringWidth(localMachineName)/2, yPositionOfMachineText, StringUtil.DECIMAL_COLOR_WHITE);
|
2015-04-19 01:50:02 +02:00
|
|
|
}
|
2015-08-24 17:57:11 +02:00
|
|
|
|
2016-02-01 17:49:55 +01:00
|
|
|
@SideOnly(Side.CLIENT)
|
|
|
|
public static void renderBlockInWorld(Block block, int meta){
|
|
|
|
renderItemInWorld(new ItemStack(block, 1, meta));
|
|
|
|
}
|
|
|
|
|
2015-08-24 17:57:11 +02:00
|
|
|
@SideOnly(Side.CLIENT)
|
2016-01-08 23:36:35 +01:00
|
|
|
public static void renderItemInWorld(ItemStack stack){
|
|
|
|
GlStateManager.pushMatrix();
|
|
|
|
GlStateManager.disableLighting();
|
|
|
|
GlStateManager.pushAttrib();
|
|
|
|
RenderHelper.enableStandardItemLighting();
|
|
|
|
Minecraft.getMinecraft().getRenderItem().renderItem(stack, TransformType.FIXED);
|
|
|
|
RenderHelper.disableStandardItemLighting();
|
|
|
|
GlStateManager.popAttrib();
|
|
|
|
GlStateManager.enableLighting();
|
|
|
|
GlStateManager.popMatrix();
|
2015-08-24 17:57:11 +02:00
|
|
|
}
|
|
|
|
|
2015-12-22 14:55:10 +01:00
|
|
|
@SideOnly(Side.CLIENT)
|
|
|
|
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
|
|
|
|
|
|
|
Minecraft mc = Minecraft.getMinecraft();
|
2016-01-07 21:41:28 +01:00
|
|
|
boolean flagBefore = mc.fontRendererObj.getUnicodeFlag();
|
|
|
|
mc.fontRendererObj.setUnicodeFlag(false);
|
|
|
|
Minecraft.getMinecraft().getRenderItem().renderItemAndEffectIntoGUI(stack, 0, 0);
|
|
|
|
Minecraft.getMinecraft().getRenderItem().renderItemOverlayIntoGUI(mc.fontRendererObj, stack, 0, 0, null);
|
|
|
|
mc.fontRendererObj.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
|
2016-01-07 21:41:28 +01:00
|
|
|
public static void drawHorizontalGradientRect(int left, int top, int right, int bottom, int startColor, int endColor, float zLevel){
|
|
|
|
float f = (float)(startColor >> 24 & 255)/255.0F;
|
|
|
|
float f1 = (float)(startColor >> 16 & 255)/255.0F;
|
|
|
|
float f2 = (float)(startColor >> 8 & 255)/255.0F;
|
|
|
|
float f3 = (float)(startColor & 255)/255.0F;
|
|
|
|
float f4 = (float)(endColor >> 24 & 255)/255.0F;
|
|
|
|
float f5 = (float)(endColor >> 16 & 255)/255.0F;
|
|
|
|
float f6 = (float)(endColor >> 8 & 255)/255.0F;
|
|
|
|
float f7 = (float)(endColor & 255)/255.0F;
|
|
|
|
GlStateManager.disableTexture2D();
|
|
|
|
GlStateManager.enableBlend();
|
|
|
|
GlStateManager.disableAlpha();
|
|
|
|
GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0);
|
|
|
|
GlStateManager.shadeModel(7425);
|
|
|
|
Tessellator tessellator = Tessellator.getInstance();
|
2016-03-18 23:47:22 +01:00
|
|
|
VertexBuffer renderer = tessellator.getBuffer();
|
|
|
|
renderer.begin(7, DefaultVertexFormats.POSITION_COLOR);
|
|
|
|
renderer.pos((double)left, (double)top, (double)zLevel).color(f1, f2, f3, f).endVertex();
|
|
|
|
renderer.pos((double)left, (double)bottom, (double)zLevel).color(f1, f2, f3, f).endVertex();
|
|
|
|
renderer.pos((double)right, (double)bottom, (double)zLevel).color(f5, f6, f7, f4).endVertex();
|
|
|
|
renderer.pos((double)right, (double)top, (double)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
|
|
|
|
2016-03-18 15:42:06 +01:00
|
|
|
public static void renderNameTag(String tag, double x, double y, double z){
|
2016-02-17 23:15:56 +01:00
|
|
|
FontRenderer fontrenderer = Minecraft.getMinecraft().fontRendererObj;
|
|
|
|
float f = 1.6F;
|
2016-02-20 16:16:41 +01: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);
|
|
|
|
GlStateManager.rotate(-Minecraft.getMinecraft().getRenderManager().playerViewY, 0.0F, 1.0F, 0.0F);
|
|
|
|
GlStateManager.rotate(Minecraft.getMinecraft().getRenderManager().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();
|
2016-03-18 23:47:22 +01:00
|
|
|
VertexBuffer renderer = tessellator.getBuffer();
|
2016-02-17 23:15:56 +01:00
|
|
|
int i = 0;
|
2016-02-20 16:16:41 +01: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);
|
|
|
|
renderer.pos((double)(-j-1), (double)(-1+i), 0.0D).color(0.0F, 0.0F, 0.0F, 0.25F).endVertex();
|
|
|
|
renderer.pos((double)(-j-1), (double)(8+i), 0.0D).color(0.0F, 0.0F, 0.0F, 0.25F).endVertex();
|
|
|
|
renderer.pos((double)(j+1), (double)(8+i), 0.0D).color(0.0F, 0.0F, 0.0F, 0.25F).endVertex();
|
|
|
|
renderer.pos((double)(j+1), (double)(-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();
|
2016-02-20 16:16:41 +01:00
|
|
|
fontrenderer.drawString(tag, -fontrenderer.getStringWidth(tag)/2, i, 553648127);
|
2016-02-17 23:15:56 +01:00
|
|
|
GlStateManager.enableDepth();
|
|
|
|
GlStateManager.depthMask(true);
|
2016-02-20 16:16:41 +01: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
|
|
|
|
|
|
|
public static void shootParticles(World world, double startX, double startY, double startZ, double endX, double endY, double endZ, float[] color, int particleAmount, float particleSize){
|
|
|
|
if(!world.isRemote){
|
|
|
|
NBTTagCompound data = new NBTTagCompound();
|
|
|
|
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]);
|
|
|
|
data.setInteger("ParticleAmount", particleAmount);
|
|
|
|
data.setFloat("ParticleSize", particleSize);
|
|
|
|
data.setFloat("AgeMultiplier", 1F);
|
|
|
|
PacketHandler.theNetwork.sendToAllAround(new PacketServerToClient(data, PacketHandler.PARTICLE_HANDLER), new NetworkRegistry.TargetPoint(world.provider.getDimension(), startX, startY, startZ, 96));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@SideOnly(Side.CLIENT)
|
|
|
|
public static void renderParticlesFromAToB(double startX, double startY, double startZ, double endX, double endY, double endZ, int particleAmount, float particleSize, float[] color, float ageMultiplier){
|
|
|
|
World world = Minecraft.getMinecraft().theWorld;
|
|
|
|
|
|
|
|
if(Minecraft.getMinecraft().thePlayer.getDistance(startX, startY, startZ) <= 64 || Minecraft.getMinecraft().thePlayer.getDistance(endX, endY, endZ) <= 64){
|
|
|
|
double difX = startX-endX;
|
|
|
|
double difY = startY-endY;
|
|
|
|
double difZ = startZ-endZ;
|
|
|
|
double distance = new Vec3d(startX, startY, startZ).distanceTo(new Vec3d(endX, endY, endZ));
|
|
|
|
|
|
|
|
for(int times = 0; times < Math.max(particleAmount/2, 1); times++){
|
|
|
|
for(double i = 0; i <= 1; i += 1/(distance*particleAmount)){
|
|
|
|
ParticleColored fx = new ParticleColored(world, (difX*i)+endX+0.5, (difY*i)+endY+0.5, (difZ*i)+endZ+0.5, particleSize, color[0], color[1], color[2], ageMultiplier);
|
|
|
|
Minecraft.getMinecraft().effectRenderer.addEffect(fx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-03-29 15:29:05 +02:00
|
|
|
}
|