2017-03-24 17:40:05 +01:00
|
|
|
/*
|
|
|
|
* This file is part of Industrial Wires.
|
|
|
|
* Copyright (C) 2016-2017 malte0811
|
|
|
|
*
|
|
|
|
* Industrial Wires is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Industrial Wires is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with Industrial Wires. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2017-04-13 17:14:05 +02:00
|
|
|
package malte0811.industrialWires.controlpanel;
|
2017-03-24 17:40:05 +01:00
|
|
|
|
2017-04-13 17:14:05 +02:00
|
|
|
import blusunrize.immersiveengineering.api.Lib;
|
2017-03-28 18:15:41 +02:00
|
|
|
import blusunrize.immersiveengineering.common.util.chickenbones.Matrix4;
|
2017-05-01 18:40:29 +02:00
|
|
|
import ic2.api.item.IC2Items;
|
2017-04-13 17:14:05 +02:00
|
|
|
import malte0811.industrialWires.IndustrialWires;
|
2017-05-10 17:56:05 +02:00
|
|
|
import malte0811.industrialWires.blocks.controlpanel.BlockPanel;
|
|
|
|
import malte0811.industrialWires.blocks.controlpanel.BlockTypes_Panel;
|
2017-04-28 20:20:52 +02:00
|
|
|
import malte0811.industrialWires.blocks.controlpanel.PropertyComponents.PanelRenderProperties;
|
2017-03-24 17:40:05 +01:00
|
|
|
import malte0811.industrialWires.client.RawQuad;
|
2017-05-11 16:39:20 +02:00
|
|
|
import malte0811.industrialWires.client.panelmodel.SmartLightingQuadIW;
|
2017-05-10 17:56:05 +02:00
|
|
|
import net.minecraft.block.state.IBlockState;
|
2017-03-24 17:40:05 +01:00
|
|
|
import net.minecraft.client.Minecraft;
|
|
|
|
import net.minecraft.client.renderer.block.model.BakedQuad;
|
|
|
|
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
|
|
|
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
|
|
|
import net.minecraft.client.renderer.vertex.VertexFormat;
|
2017-04-13 17:14:05 +02:00
|
|
|
import net.minecraft.client.resources.I18n;
|
|
|
|
import net.minecraft.item.EnumDyeColor;
|
2017-05-01 18:40:29 +02:00
|
|
|
import net.minecraft.item.Item;
|
2017-04-13 17:14:05 +02:00
|
|
|
import net.minecraft.item.ItemStack;
|
2017-04-22 18:14:49 +02:00
|
|
|
import net.minecraft.nbt.NBTBase;
|
2017-04-13 17:14:05 +02:00
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
2017-04-22 18:14:49 +02:00
|
|
|
import net.minecraft.nbt.NBTTagFloat;
|
2017-04-28 20:20:52 +02:00
|
|
|
import net.minecraft.nbt.NBTTagList;
|
2017-03-24 17:40:05 +01:00
|
|
|
import net.minecraft.util.EnumFacing;
|
2017-04-23 17:23:10 +02:00
|
|
|
import net.minecraft.util.math.AxisAlignedBB;
|
2017-05-10 17:56:05 +02:00
|
|
|
import net.minecraft.util.math.BlockPos;
|
2017-03-24 17:40:05 +01:00
|
|
|
import net.minecraft.util.math.Vec3i;
|
2017-05-10 17:56:05 +02:00
|
|
|
import net.minecraft.world.World;
|
2017-03-24 17:40:05 +01:00
|
|
|
import net.minecraftforge.client.model.ModelLoader;
|
|
|
|
import net.minecraftforge.client.model.obj.OBJModel;
|
|
|
|
import net.minecraftforge.client.model.pipeline.UnpackedBakedQuad;
|
2017-05-08 21:29:45 +02:00
|
|
|
import net.minecraftforge.fml.relauncher.Side;
|
|
|
|
import net.minecraftforge.fml.relauncher.SideOnly;
|
2017-03-24 17:40:05 +01:00
|
|
|
import org.lwjgl.util.vector.Vector3f;
|
|
|
|
|
2017-04-28 20:20:52 +02:00
|
|
|
import javax.annotation.Nonnull;
|
2017-05-03 18:08:52 +02:00
|
|
|
import javax.annotation.Nullable;
|
2017-03-24 17:40:05 +01:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
2017-05-10 17:56:05 +02:00
|
|
|
import java.util.function.BiPredicate;
|
2017-03-24 17:40:05 +01:00
|
|
|
|
2017-04-13 17:14:05 +02:00
|
|
|
import static malte0811.industrialWires.controlpanel.PanelComponent.*;
|
2017-05-10 17:56:05 +02:00
|
|
|
import static malte0811.industrialWires.util.MiscUtils.discoverLocal;
|
2017-04-13 17:14:05 +02:00
|
|
|
|
2017-03-24 17:40:05 +01:00
|
|
|
public final class PanelUtils {
|
2017-04-17 19:35:14 +02:00
|
|
|
public static TextureAtlasSprite PANEL_TEXTURE;
|
2017-05-01 18:40:29 +02:00
|
|
|
public static final Item PANEL_ITEM = new ItemStack(IndustrialWires.panel).getItem();
|
|
|
|
private static ItemStack panelBase;
|
2017-04-22 18:14:49 +02:00
|
|
|
|
|
|
|
private PanelUtils() {
|
|
|
|
}
|
2017-03-24 17:40:05 +01:00
|
|
|
|
2017-05-08 21:29:45 +02:00
|
|
|
@SideOnly(Side.CLIENT)
|
2017-04-28 20:20:52 +02:00
|
|
|
public static List<BakedQuad> generateQuads(PanelRenderProperties components) {
|
2017-04-22 18:14:49 +02:00
|
|
|
if (PANEL_TEXTURE == null) {
|
|
|
|
PANEL_TEXTURE = Minecraft.getMinecraft().getTextureMapBlocks().getAtlasSprite(IndustrialWires.MODID + ":blocks/control_panel");
|
2017-04-01 17:33:58 +02:00
|
|
|
}
|
2017-03-24 17:40:05 +01:00
|
|
|
List<BakedQuad> ret = new ArrayList<>();
|
2017-04-01 17:33:58 +02:00
|
|
|
Matrix4 m4 = components.getPanelTopTransform();
|
|
|
|
Matrix4 m4RotOnly = m4.copy();
|
2017-03-28 18:15:41 +02:00
|
|
|
m4RotOnly.invert();
|
|
|
|
m4RotOnly.transpose();
|
2017-04-22 18:14:49 +02:00
|
|
|
for (PanelComponent pc : components) {
|
2017-05-27 17:00:26 +02:00
|
|
|
Matrix4 m4Here = m4.copy().translate(pc.getX(), .0001, pc.getY());
|
2017-03-24 17:40:05 +01:00
|
|
|
List<RawQuad> compQuads = pc.getQuads();
|
2017-04-22 18:14:49 +02:00
|
|
|
for (RawQuad bq : compQuads) {
|
2017-04-17 19:35:14 +02:00
|
|
|
ret.add(bakeQuad(bq, m4Here, m4RotOnly, false));
|
2017-03-24 17:40:05 +01:00
|
|
|
}
|
|
|
|
}
|
2017-04-01 17:33:58 +02:00
|
|
|
Matrix4 baseTrans = components.getPanelBaseTransform();
|
|
|
|
Matrix4 baseNorm = baseTrans.copy();
|
|
|
|
baseNorm.invert();
|
|
|
|
baseNorm.transpose();
|
|
|
|
|
|
|
|
List<RawQuad> rawOut = new ArrayList<>();
|
2017-04-17 19:35:14 +02:00
|
|
|
//addTexturedBox(new Vector3f(0, 0, 0), new Vector3f(1, components.height, 1), rawOut, UV_FULL, PANEL_TEXTURE);
|
2017-04-22 18:14:49 +02:00
|
|
|
float vMax = 16 * components.height;
|
2017-04-17 19:35:14 +02:00
|
|
|
addQuad(rawOut, new Vector3f(0, components.height, 0), new Vector3f(0, components.height, 1),
|
|
|
|
new Vector3f(1, components.height, 1), new Vector3f(1, components.height, 0),
|
2017-05-08 17:20:04 +02:00
|
|
|
EnumFacing.UP, WHITE, PANEL_TEXTURE, UV_FULL, null, false);
|
2017-04-17 19:35:14 +02:00
|
|
|
addQuad(rawOut, new Vector3f(0, 0, 0), new Vector3f(1, 0, 0),
|
|
|
|
new Vector3f(1, 0, 1), new Vector3f(0, 0, 1),
|
2017-05-08 17:20:04 +02:00
|
|
|
EnumFacing.DOWN, WHITE, PANEL_TEXTURE, new float[]{0, 16, 16, 0}, null, false);
|
2017-04-17 19:35:14 +02:00
|
|
|
addQuad(rawOut, new Vector3f(0, 0, 0), new Vector3f(0, 0, 1),
|
|
|
|
new Vector3f(0, components.height, 1), new Vector3f(0, components.height, 0),
|
2017-05-08 17:20:04 +02:00
|
|
|
EnumFacing.WEST, WHITE, PANEL_TEXTURE, new float[]{0, vMax, 16, 0}, null, false);
|
2017-04-17 19:35:14 +02:00
|
|
|
addQuad(rawOut, new Vector3f(1, 0, 0), new Vector3f(1, components.height, 0),
|
|
|
|
new Vector3f(1, components.height, 1), new Vector3f(1, 0, 1),
|
2017-05-08 17:20:04 +02:00
|
|
|
EnumFacing.EAST, WHITE, PANEL_TEXTURE, new float[]{16, vMax, 0, 0}, null, false);
|
2017-04-17 19:35:14 +02:00
|
|
|
addQuad(rawOut, new Vector3f(1, 0, 0), new Vector3f(0, 0, 0),
|
|
|
|
new Vector3f(0, components.height, 0), new Vector3f(1, components.height, 0),
|
2017-05-08 17:20:04 +02:00
|
|
|
EnumFacing.NORTH, WHITE, PANEL_TEXTURE, new float[]{0, vMax, 16, 0}, null, false);
|
2017-04-17 19:35:14 +02:00
|
|
|
addQuad(rawOut, new Vector3f(0, 0, 1), new Vector3f(1, 0, 1),
|
|
|
|
new Vector3f(1, components.height, 1), new Vector3f(0, components.height, 1),
|
2017-05-08 17:20:04 +02:00
|
|
|
EnumFacing.SOUTH, WHITE, PANEL_TEXTURE, new float[]{0, vMax, 16, 0}, null, false);
|
2017-04-22 18:14:49 +02:00
|
|
|
for (RawQuad bq : rawOut) {
|
|
|
|
ret.add(bakeQuad(bq, baseTrans, baseNorm, bq.facing != EnumFacing.EAST && bq.facing != EnumFacing.UP));//flip south and west
|
2017-04-01 17:33:58 +02:00
|
|
|
}
|
|
|
|
|
2017-03-24 17:40:05 +01:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-05-08 21:29:45 +02:00
|
|
|
@SideOnly(Side.CLIENT)
|
2017-04-17 19:35:14 +02:00
|
|
|
public static BakedQuad bakeQuad(RawQuad raw, Matrix4 transform, Matrix4 transfNormal, boolean flip) {
|
2017-03-24 17:40:05 +01:00
|
|
|
VertexFormat format = DefaultVertexFormats.ITEM;
|
|
|
|
UnpackedBakedQuad.Builder builder = new UnpackedBakedQuad.Builder(format);
|
|
|
|
builder.setQuadOrientation(raw.facing);
|
|
|
|
builder.setTexture(raw.tex);
|
|
|
|
Vector3f[] vertices = raw.vertices;
|
|
|
|
float[] uvs = raw.uvs;
|
2017-03-28 18:15:41 +02:00
|
|
|
Vector3f normal = transfNormal.apply(raw.normal);
|
|
|
|
OBJModel.Normal faceNormal = new OBJModel.Normal(normal.x, normal.y, normal.z);
|
|
|
|
putVertexData(format, builder, transform.apply(vertices[0]), faceNormal, uvs[0], uvs[1], raw.tex,
|
2017-03-24 17:40:05 +01:00
|
|
|
raw.colorA);
|
2017-04-22 18:14:49 +02:00
|
|
|
putVertexData(format, builder, transform.apply(vertices[1]), faceNormal, uvs[flip ? 2 : 0], uvs[flip ? 1 : 3], raw.tex,
|
2017-03-24 17:40:05 +01:00
|
|
|
raw.colorA);
|
2017-03-28 18:15:41 +02:00
|
|
|
putVertexData(format, builder, transform.apply(vertices[2]), faceNormal, uvs[2], uvs[3], raw.tex,
|
2017-03-24 17:40:05 +01:00
|
|
|
raw.colorA);
|
2017-04-22 18:14:49 +02:00
|
|
|
putVertexData(format, builder, transform.apply(vertices[3]), faceNormal, uvs[flip ? 0 : 2], uvs[flip ? 3 : 1], raw.tex,
|
2017-03-24 17:40:05 +01:00
|
|
|
raw.colorA);
|
2017-05-11 16:39:20 +02:00
|
|
|
BakedQuad ret = builder.build();
|
|
|
|
if (raw.light>0) {
|
|
|
|
ret = new SmartLightingQuadIW(ret, raw.light);
|
|
|
|
}
|
|
|
|
return ret;
|
2017-03-24 17:40:05 +01:00
|
|
|
}
|
2017-04-22 18:14:49 +02:00
|
|
|
|
2017-03-24 17:40:05 +01:00
|
|
|
//mostly copied from IE's ClientUtils, it has protected access there...
|
2017-05-08 21:29:45 +02:00
|
|
|
@SideOnly(Side.CLIENT)
|
2017-04-22 18:14:49 +02:00
|
|
|
public static void putVertexData(VertexFormat format, UnpackedBakedQuad.Builder builder, Vector3f pos, OBJModel.Normal faceNormal, double u, double v, TextureAtlasSprite sprite, float[] colorA) {
|
|
|
|
for (int e = 0; e < format.getElementCount(); e++)
|
|
|
|
switch (format.getElement(e).getUsage()) {
|
2017-03-24 17:40:05 +01:00
|
|
|
case POSITION:
|
|
|
|
builder.put(e, pos.getX(), pos.getY(), pos.getZ(), 0);
|
|
|
|
break;
|
|
|
|
case COLOR:
|
|
|
|
builder.put(e, colorA[0], colorA[1], colorA[2], colorA[3]);
|
|
|
|
break;
|
|
|
|
case UV:
|
2017-04-22 18:14:49 +02:00
|
|
|
if (sprite == null)//Double Safety. I have no idea how it even happens, but it somehow did .-.
|
2017-03-24 17:40:05 +01:00
|
|
|
sprite = Minecraft.getMinecraft().getTextureMapBlocks().getMissingSprite();
|
|
|
|
builder.put(e,
|
|
|
|
sprite.getInterpolatedU(u),
|
|
|
|
sprite.getInterpolatedV((v)),
|
|
|
|
0, 1);
|
|
|
|
break;
|
|
|
|
case NORMAL:
|
|
|
|
builder.put(e, faceNormal.x, faceNormal.y, faceNormal.z, 0);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
builder.put(e);
|
|
|
|
}
|
|
|
|
}
|
2017-04-22 18:14:49 +02:00
|
|
|
|
2017-04-01 17:33:58 +02:00
|
|
|
private static final float[] UV_FULL = {0, 0, 16, 16};
|
|
|
|
private static final float[] WHITE = {1, 1, 1, 1};
|
2017-04-22 18:14:49 +02:00
|
|
|
|
2017-05-08 21:29:45 +02:00
|
|
|
@SideOnly(Side.CLIENT)
|
2017-04-01 17:33:58 +02:00
|
|
|
public static void addTexturedBox(Vector3f min, Vector3f size, List<RawQuad> out, float[] uvs, TextureAtlasSprite tex) {
|
2017-05-08 17:20:04 +02:00
|
|
|
addBox(WHITE, WHITE, WHITE, min, size, out, true, uvs, tex, null, false);
|
2017-04-01 17:33:58 +02:00
|
|
|
}
|
2017-04-22 18:14:49 +02:00
|
|
|
|
2017-05-08 21:29:45 +02:00
|
|
|
@SideOnly(Side.CLIENT)
|
2017-03-24 17:40:05 +01:00
|
|
|
public static void addColoredBox(float[] colorTop, float[] colorSides, float[] colorBottom, Vector3f min, Vector3f size, List<RawQuad> out, boolean doBottom) {
|
2017-05-08 17:20:04 +02:00
|
|
|
addBox(colorTop, colorSides, colorBottom, min, size, out, doBottom, UV_FULL, ModelLoader.White.INSTANCE, null, false);
|
2017-04-01 17:33:58 +02:00
|
|
|
}
|
2017-04-22 18:14:49 +02:00
|
|
|
|
2017-05-08 21:29:45 +02:00
|
|
|
@SideOnly(Side.CLIENT)
|
2017-05-03 18:08:52 +02:00
|
|
|
public static void addColoredBox(float[] colorTop, float[] colorSides, float[] colorBottom, Vector3f min, Vector3f size, List<RawQuad> out, boolean doBottom, @Nullable Matrix4 mat) {
|
2017-05-08 17:20:04 +02:00
|
|
|
addBox(colorTop, colorSides, colorBottom, min, size, out, doBottom, UV_FULL, ModelLoader.White.INSTANCE, mat, false);
|
|
|
|
}
|
|
|
|
|
2017-05-08 21:29:45 +02:00
|
|
|
@SideOnly(Side.CLIENT)
|
2017-05-08 17:20:04 +02:00
|
|
|
public static void addColoredBox(float[] colorTop, float[] colorSides, float[] colorBottom, Vector3f min, Vector3f size, List<RawQuad> out, boolean doBottom, @Nullable Matrix4 mat, boolean inside) {
|
|
|
|
addBox(colorTop, colorSides, colorBottom, min, size, out, doBottom, UV_FULL, ModelLoader.White.INSTANCE, mat, inside);
|
2017-05-03 18:08:52 +02:00
|
|
|
}
|
|
|
|
|
2017-05-08 21:29:45 +02:00
|
|
|
@SideOnly(Side.CLIENT)
|
2017-05-03 18:08:52 +02:00
|
|
|
public static void addBox(float[] colorTop, float[] colorSides, float[] colorBottom, Vector3f min, Vector3f size, List<RawQuad> out, boolean doBottom, float[] uvs, TextureAtlasSprite tex,
|
2017-05-11 16:39:20 +02:00
|
|
|
@Nullable Matrix4 mat, boolean inside) {
|
2017-04-22 18:14:49 +02:00
|
|
|
addQuad(out, new Vector3f(min.x, min.y + size.y, min.z), new Vector3f(min.x, min.y + size.y, min.z + size.z),
|
|
|
|
new Vector3f(min.x + size.x, min.y + size.y, min.z + size.z), new Vector3f(min.x + size.x, min.y + size.y, min.z),
|
2017-05-08 17:20:04 +02:00
|
|
|
EnumFacing.UP, colorTop, tex, uvs, mat, inside);
|
2017-03-24 17:40:05 +01:00
|
|
|
if (doBottom) {
|
2017-04-22 18:14:49 +02:00
|
|
|
addQuad(out, new Vector3f(min.x, min.y, min.z), new Vector3f(min.x + size.x, min.y, min.z),
|
|
|
|
new Vector3f(min.x + size.x, min.y, min.z + size.z), new Vector3f(min.x, min.y, min.z + size.z),
|
2017-05-08 17:20:04 +02:00
|
|
|
EnumFacing.UP, colorBottom, tex, uvs, mat, inside);
|
2017-03-24 17:40:05 +01:00
|
|
|
}
|
2017-04-22 18:14:49 +02:00
|
|
|
addQuad(out, new Vector3f(min.x, min.y, min.z), new Vector3f(min.x, min.y, min.z + size.z),
|
|
|
|
new Vector3f(min.x, min.y + size.y, min.z + size.z), new Vector3f(min.x, min.y + size.y, min.z),
|
2017-05-08 17:20:04 +02:00
|
|
|
EnumFacing.WEST, colorSides, tex, uvs, mat, inside);
|
2017-04-22 18:14:49 +02:00
|
|
|
addQuad(out, new Vector3f(min.x + size.x, min.y, min.z), new Vector3f(min.x + size.x, min.y + size.y, min.z),
|
|
|
|
new Vector3f(min.x + size.x, min.y + size.y, min.z + size.z), new Vector3f(min.x + size.x, min.y, min.z + size.z),
|
2017-05-08 17:20:04 +02:00
|
|
|
EnumFacing.EAST, colorSides, tex, uvs, mat, inside);
|
2017-04-22 18:14:49 +02:00
|
|
|
addQuad(out, new Vector3f(min.x, min.y, min.z), new Vector3f(min.x, min.y + size.y, min.z),
|
|
|
|
new Vector3f(min.x + size.x, min.y + size.y, min.z), new Vector3f(min.x + size.x, min.y, min.z),
|
2017-05-08 17:20:04 +02:00
|
|
|
EnumFacing.NORTH, colorSides, tex, uvs, mat, inside);
|
2017-04-22 18:14:49 +02:00
|
|
|
addQuad(out, new Vector3f(min.x, min.y, min.z + size.z), new Vector3f(min.x + size.x, min.y, min.z + size.z),
|
|
|
|
new Vector3f(min.x + size.x, min.y + size.y, min.z + size.z), new Vector3f(min.x, min.y + size.y, min.z + size.z),
|
2017-05-08 17:20:04 +02:00
|
|
|
EnumFacing.SOUTH, colorSides, tex, uvs, mat, inside);
|
2017-03-24 17:40:05 +01:00
|
|
|
}
|
2017-04-22 18:14:49 +02:00
|
|
|
|
2017-05-08 21:29:45 +02:00
|
|
|
@SideOnly(Side.CLIENT)
|
2017-04-01 17:33:58 +02:00
|
|
|
public static void addColoredQuad(List<RawQuad> out, Vector3f v0, Vector3f v1, Vector3f v2, Vector3f v3, EnumFacing dir, float[] color) {
|
2017-05-08 17:20:04 +02:00
|
|
|
addQuad(out, v0, v1, v2, v3, dir, color, Minecraft.getMinecraft().getTextureMapBlocks().getTextureExtry(ModelLoader.White.LOCATION.toString()), UV_FULL, null, false);
|
2017-05-03 18:08:52 +02:00
|
|
|
}
|
|
|
|
|
2017-05-08 21:29:45 +02:00
|
|
|
@SideOnly(Side.CLIENT)
|
2017-05-03 18:08:52 +02:00
|
|
|
public static void addColoredQuad(List<RawQuad> out, Vector3f v0, Vector3f v1, Vector3f v2, Vector3f v3, EnumFacing dir, float[] color, @Nullable Matrix4 mat) {
|
2017-05-08 17:20:04 +02:00
|
|
|
addQuad(out, v0, v1, v2, v3, dir, color, Minecraft.getMinecraft().getTextureMapBlocks().getTextureExtry(ModelLoader.White.LOCATION.toString()), UV_FULL, mat, false);
|
2017-04-01 17:33:58 +02:00
|
|
|
}
|
|
|
|
|
2017-05-08 21:29:45 +02:00
|
|
|
@SideOnly(Side.CLIENT)
|
2017-05-08 17:20:04 +02:00
|
|
|
public static void addQuad(List<RawQuad> out, Vector3f v0, Vector3f v1, Vector3f v2, Vector3f v3, EnumFacing dir, float[] color, TextureAtlasSprite tex, float[] uvs, @Nullable Matrix4 mat, boolean bidirectional) {
|
2017-03-24 17:40:05 +01:00
|
|
|
Vec3i dirV = dir.getDirectionVec();
|
2017-05-03 18:08:52 +02:00
|
|
|
RawQuad quad = new RawQuad(v0, v1, v2, v3, dir, tex,
|
|
|
|
color, new Vector3f(dirV.getX(), dirV.getY(), dirV.getZ()), uvs);
|
2017-05-11 16:39:20 +02:00
|
|
|
if (mat != null) {
|
2017-05-03 18:08:52 +02:00
|
|
|
quad = quad.apply(mat);
|
|
|
|
}
|
|
|
|
out.add(quad);
|
2017-05-08 21:29:45 +02:00
|
|
|
if (bidirectional) {
|
|
|
|
dirV = dir.getOpposite().getDirectionVec();
|
|
|
|
quad = new RawQuad(v3, v2, v1, v0, dir, tex,
|
|
|
|
color, new Vector3f(dirV.getX(), dirV.getY(), dirV.getZ()), uvs);
|
|
|
|
if (mat != null) {
|
|
|
|
quad = quad.apply(mat);
|
|
|
|
}
|
|
|
|
out.add(quad);
|
2017-05-08 17:20:04 +02:00
|
|
|
}
|
2017-03-24 17:40:05 +01:00
|
|
|
}
|
2017-04-13 17:14:05 +02:00
|
|
|
|
|
|
|
public static void addInfo(ItemStack stack, List<String> list, NBTTagCompound data) {
|
|
|
|
switch (stack.getMetadata()) {
|
|
|
|
case 0: //button
|
|
|
|
addCommonInfo(data, list, true, true);
|
|
|
|
if (data.hasKey(LATCHING)) {
|
2017-04-22 18:14:49 +02:00
|
|
|
list.add(I18n.format(IndustrialWires.MODID + ".tooltip." + (data.getBoolean(LATCHING) ? "latching" : "instantaneous")));
|
2017-04-13 17:14:05 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 1: //label
|
|
|
|
if (data.hasKey(TEXT)) {
|
2017-04-22 18:14:49 +02:00
|
|
|
list.add(I18n.format(IndustrialWires.MODID + ".tooltip.text", data.getString(TEXT)));
|
2017-04-13 17:14:05 +02:00
|
|
|
}
|
|
|
|
addCommonInfo(data, list, true, false);
|
|
|
|
break;
|
|
|
|
case 2: //indicator light
|
|
|
|
addCommonInfo(data, list, true, true);
|
|
|
|
break;
|
|
|
|
case 3: //slider
|
|
|
|
addCommonInfo(data, list, true, true);
|
|
|
|
if (data.hasKey(HORIZONTAL)) {
|
2017-04-22 18:14:49 +02:00
|
|
|
list.add(I18n.format(IndustrialWires.MODID + ".tooltip." + (data.getBoolean(HORIZONTAL) ? "horizontal" : "vertical")));
|
2017-04-13 17:14:05 +02:00
|
|
|
}
|
2017-04-22 18:14:49 +02:00
|
|
|
if (data.hasKey(LENGTH)) {
|
|
|
|
list.add(I18n.format(IndustrialWires.MODID + ".tooltip.length", data.getFloat(LENGTH)));
|
|
|
|
}
|
|
|
|
|
2017-05-03 18:08:52 +02:00
|
|
|
break;
|
|
|
|
case 4://variac
|
|
|
|
addCommonInfo(data, list, false, true);
|
2017-04-13 17:14:05 +02:00
|
|
|
break;
|
2017-05-08 17:20:04 +02:00
|
|
|
case 5://Toggle switch
|
|
|
|
addCommonInfo(data, list, false, true);
|
|
|
|
break;
|
2017-05-08 21:29:45 +02:00
|
|
|
case 6://Covered toggle switch
|
|
|
|
addCommonInfo(data, list, true, true);
|
|
|
|
break;
|
2017-05-19 17:45:30 +02:00
|
|
|
case 7://Lock
|
|
|
|
addCommonInfo(data, list, false, true);
|
|
|
|
if (data.hasKey(LATCHING)) {
|
|
|
|
list.add(I18n.format(IndustrialWires.MODID + ".tooltip." + (data.getBoolean(LATCHING) ? "latching" : "instantaneous")));
|
|
|
|
}
|
|
|
|
break;
|
2017-05-27 17:00:26 +02:00
|
|
|
case 8://Panel meter
|
|
|
|
addCommonInfo(data, list, false, true);
|
|
|
|
if (data.hasKey(PanelMeter.WIDE)) {
|
|
|
|
list.add(I18n.format(IndustrialWires.MODID + ".tooltip." + (data.getBoolean(PanelMeter.WIDE) ? "wide" : "narrow")));
|
|
|
|
}
|
|
|
|
break;
|
2017-04-13 17:14:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void addCommonInfo(NBTTagCompound data, List<String> list, boolean color, boolean rs) {
|
2017-04-22 18:14:49 +02:00
|
|
|
if (color && data.hasKey(COLOR)) {
|
2017-04-23 17:23:10 +02:00
|
|
|
String hexCol = String.format("%6s", Integer.toHexString(data.getInteger(COLOR) & 0xffffff)).replace(' ', '0');
|
2017-04-22 18:14:49 +02:00
|
|
|
list.add(I18n.format(Lib.DESC_INFO + "colour", "<hexcol=" + hexCol + ":#" + hexCol + ">"));
|
2017-04-13 17:14:05 +02:00
|
|
|
}
|
2017-04-22 18:14:49 +02:00
|
|
|
if (rs && data.hasKey(RS_CHANNEL)) {
|
2017-04-13 17:14:05 +02:00
|
|
|
EnumDyeColor channColor = EnumDyeColor.byMetadata(data.getInteger(RS_CHANNEL));
|
|
|
|
String hexCol = Integer.toHexString(channColor.getMapColor().colorValue);
|
2017-04-22 18:14:49 +02:00
|
|
|
list.add(I18n.format("desc.immersiveengineering.info.redstoneChannel", "<hexcol=" + hexCol + ":" + channColor.getUnlocalizedName() + ">"));
|
2017-04-13 17:14:05 +02:00
|
|
|
}
|
2017-04-22 18:14:49 +02:00
|
|
|
if (rs && data.hasKey(RS_ID)) {
|
|
|
|
list.add(I18n.format(IndustrialWires.MODID + ".tooltip.rsId", data.getInteger(RS_ID)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static int setColor(int color, int id, NBTBase value) {
|
2017-04-23 17:23:10 +02:00
|
|
|
id = 2 - id;
|
2017-04-22 18:14:49 +02:00
|
|
|
color &= ~(0xff << (8 * id));
|
|
|
|
color |= (int) (2.55 * (((NBTTagFloat) value).getFloat())) << (8 * id);
|
|
|
|
return color;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static float[] getFloatColor(boolean active, int color) {
|
|
|
|
float[] ret = new float[4];
|
|
|
|
ret[3] = 1;
|
|
|
|
for (int i = 0; i < 3; i++) {
|
|
|
|
ret[i] = ((color >> (8 * (2 - i))) & 255) / 255F * (active ? 1 : .5F);
|
2017-04-13 17:14:05 +02:00
|
|
|
}
|
2017-04-22 18:14:49 +02:00
|
|
|
return ret;
|
2017-04-13 17:14:05 +02:00
|
|
|
}
|
2017-04-23 17:23:10 +02:00
|
|
|
|
|
|
|
public static boolean intersectXZ(AxisAlignedBB aabb1, AxisAlignedBB aabb2) {
|
|
|
|
return aabb1.minX < aabb2.maxX && aabb1.maxX > aabb2.minX && aabb1.minZ < aabb2.maxZ && aabb1.maxZ > aabb2.minZ;
|
|
|
|
}
|
2017-05-11 16:39:20 +02:00
|
|
|
|
2017-04-28 20:20:52 +02:00
|
|
|
public static void readListFromNBT(NBTTagList list, @Nonnull List<PanelComponent> base) {
|
|
|
|
base.clear();
|
|
|
|
for (int i = 0; i < list.tagCount(); i++) {
|
|
|
|
PanelComponent pc = PanelComponent.read(list.getCompoundTagAt(i));
|
|
|
|
if (pc != null) {
|
|
|
|
base.add(pc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-05-01 18:40:29 +02:00
|
|
|
|
|
|
|
public static ItemStack getPanelBase() {
|
2017-05-11 16:39:20 +02:00
|
|
|
if (panelBase == null) {
|
2017-05-01 18:40:29 +02:00
|
|
|
panelBase = IC2Items.getItem("resource", "machine");
|
|
|
|
}
|
|
|
|
return panelBase;
|
|
|
|
}
|
2017-05-10 17:56:05 +02:00
|
|
|
|
|
|
|
public static List<BlockPos> discoverPanelParts(World w, BlockPos here) {
|
|
|
|
BiPredicate<BlockPos, Integer> isValid = (pos, count) -> {
|
|
|
|
if (here.distanceSq(pos) > 25 || count > 100 || !w.isBlockLoaded(pos)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
IBlockState state = w.getBlockState(pos);
|
|
|
|
return state.getBlock() == IndustrialWires.panel && state.getValue(BlockPanel.type) != BlockTypes_Panel.CREATOR;
|
|
|
|
};
|
|
|
|
List<BlockPos> all = discoverLocal(w, here, isValid);
|
|
|
|
List<BlockPos> ret = new ArrayList<>();
|
|
|
|
for (BlockPos pos : all) {
|
|
|
|
if (w.getBlockState(pos).getValue(BlockPanel.type) != BlockTypes_Panel.DUMMY) {
|
|
|
|
ret.add(pos);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
2017-04-22 18:14:49 +02:00
|
|
|
}
|