Proper bounding boxes for mech MB parts
Added the missing bits of axle at the ends of the MB Added a versioning NBT tag to the mech MB to allow easy changing of the MB structure
This commit is contained in:
parent
184d12b7cb
commit
92a114d29d
|
@ -15,8 +15,27 @@
|
|||
|
||||
package malte0811.industrialWires.blocks;
|
||||
|
||||
import blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces;
|
||||
import blusunrize.immersiveengineering.common.util.chickenbones.Matrix4;
|
||||
import malte0811.industrialWires.util.MiscUtils;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
|
||||
public interface IBlockBoundsIW {
|
||||
AxisAlignedBB getBoundingBox();
|
||||
|
||||
interface IBlockBoundsDirectional extends IBlockBoundsIW, IEBlockInterfaces.IDirectionalTile {
|
||||
|
||||
@Override
|
||||
default AxisAlignedBB getBoundingBox() {
|
||||
EnumFacing dir = getFacing();
|
||||
Matrix4 mat = new Matrix4();
|
||||
mat.translate(.5, 0, .5);
|
||||
mat.rotate((-dir.getHorizontalAngle()+180)*Math.PI/180, 0, 1, 0);
|
||||
mat.translate(-.5, 0, -.5);
|
||||
return MiscUtils.apply(mat, getBoundingBoxNoRot());
|
||||
}
|
||||
|
||||
AxisAlignedBB getBoundingBoxNoRot();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@ import ic2.api.energy.tile.IEnergyEmitter;
|
|||
import ic2.api.energy.tile.IEnergySink;
|
||||
import ic2.api.energy.tile.IEnergySource;
|
||||
import malte0811.industrialWires.IndustrialWires;
|
||||
import malte0811.industrialWires.blocks.IBlockBoundsIW.IBlockBoundsDirectional;
|
||||
import malte0811.industrialWires.blocks.ISyncReceiver;
|
||||
import malte0811.industrialWires.blocks.TileEntityIWMultiblock;
|
||||
import malte0811.industrialWires.converter.*;
|
||||
|
@ -59,15 +60,14 @@ import static blusunrize.immersiveengineering.common.blocks.metal.BlockTypes_Met
|
|||
import static malte0811.industrialWires.converter.EUCapability.ENERGY_IC2;
|
||||
import static malte0811.industrialWires.util.MiscUtils.getOffset;
|
||||
import static malte0811.industrialWires.util.MiscUtils.offset;
|
||||
import static malte0811.industrialWires.util.NBTKeys.PARTS;
|
||||
import static malte0811.industrialWires.util.NBTKeys.SPEED;
|
||||
import static malte0811.industrialWires.util.NBTKeys.*;
|
||||
|
||||
@net.minecraftforge.fml.common.Optional.InterfaceList({
|
||||
@net.minecraftforge.fml.common.Optional.Interface(iface = "ic2.api.energy.tile.IEnergySource", modid = "ic2"),
|
||||
@Optional.Interface(iface = "ic2.api.energy.tile.IEnergySink", modid = "ic2")
|
||||
})
|
||||
public class TileEntityMultiblockConverter extends TileEntityIWMultiblock implements ITickable, ISyncReceiver,
|
||||
IEnergySource, IEnergySink, IPlayerInteraction, IRedstoneOutput {
|
||||
IEnergySource, IEnergySink, IPlayerInteraction, IRedstoneOutput, IBlockBoundsDirectional {
|
||||
private static final double DECAY_BASE = Math.exp(Math.log(.8)/(2*60*60*20));
|
||||
public static final double TICK_ANGLE_PER_SPEED = 180/20/Math.PI;
|
||||
private static final double SYNC_THRESHOLD = .95;
|
||||
|
@ -84,6 +84,8 @@ public class TileEntityMultiblockConverter extends TileEntityIWMultiblock implem
|
|||
public List<BakedQuad> rotatingModel;
|
||||
private boolean shouldInitWorld;
|
||||
private boolean firstTick = true;
|
||||
// To allow changing the MB structure later on without resulting in dupes/conversion
|
||||
private int structureVersion = 0;
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
|
@ -251,6 +253,7 @@ public class TileEntityMultiblockConverter extends TileEntityIWMultiblock implem
|
|||
out.setTag(PARTS, mechParts);
|
||||
out.setDouble(SPEED, energyState.getSpeed());
|
||||
}
|
||||
out.setInteger(STRUCTURE_VERSION, structureVersion);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -270,7 +273,9 @@ public class TileEntityMultiblockConverter extends TileEntityIWMultiblock implem
|
|||
shouldInitWorld = true;
|
||||
}
|
||||
}
|
||||
structureVersion = in.getInteger(STRUCTURE_VERSION);
|
||||
rBB = null;
|
||||
aabb = null;
|
||||
}
|
||||
|
||||
public void setMechanical(MechMBPart[] mech, double speed) {
|
||||
|
@ -556,4 +561,31 @@ public class TileEntityMultiblockConverter extends TileEntityIWMultiblock implem
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AxisAlignedBB getBoundingBoxNoRot() {
|
||||
Vec3i offset = getOffsetDir();
|
||||
TileEntityMultiblockConverter master = masterOr(this, this);
|
||||
int comp = getPart(offset.getZ(), master);
|
||||
if (comp<0) {
|
||||
if (offset.getZ()==0) {
|
||||
return new AxisAlignedBB(0, 0, .25, 1, 1, 1+offset.getY()*.25);
|
||||
} else {
|
||||
return new AxisAlignedBB(0, 0, -offset.getY()*.25, 1, 1, .75);
|
||||
}
|
||||
}
|
||||
MechMBPart part = master.mechanical[comp];
|
||||
BlockPos offsetPart = new BlockPos(offset.getX(), offset.getY(), offset.getZ()-master.offsets[comp]);
|
||||
return part.getBoundingBox(offsetPart);
|
||||
}
|
||||
|
||||
private AxisAlignedBB aabb = null;
|
||||
@Override
|
||||
public AxisAlignedBB getBoundingBox() {
|
||||
if (aabb==null)
|
||||
{
|
||||
aabb = IBlockBoundsDirectional.super.getBoundingBox();
|
||||
}
|
||||
return aabb;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,12 +18,10 @@ package malte0811.industrialWires.blocks.hv;
|
|||
import blusunrize.immersiveengineering.api.ApiUtils;
|
||||
import blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IDirectionalTile;
|
||||
import blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IPlayerInteraction;
|
||||
import blusunrize.immersiveengineering.common.util.chickenbones.Matrix4;
|
||||
import malte0811.industrialWires.IndustrialWires;
|
||||
import malte0811.industrialWires.blocks.IBlockBoundsIW;
|
||||
import malte0811.industrialWires.blocks.IBlockBoundsIW.IBlockBoundsDirectional;
|
||||
import malte0811.industrialWires.blocks.TileEntityIWBase;
|
||||
import malte0811.industrialWires.hv.IMarxTarget;
|
||||
import malte0811.industrialWires.util.MiscUtils;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
@ -36,7 +34,7 @@ import net.minecraft.util.text.TextComponentTranslation;
|
|||
import javax.annotation.Nonnull;
|
||||
|
||||
public class TileEntityDischargeMeter extends TileEntityIWBase implements IPlayerInteraction, IMarxTarget,
|
||||
IBlockBoundsIW, IDirectionalTile {
|
||||
IBlockBoundsDirectional, IDirectionalTile {
|
||||
private static final String HAS_WIRE = "hasWire";
|
||||
private static final String FACING = "facing";
|
||||
private static final String LAST_DISCHARGE = "last";
|
||||
|
@ -92,16 +90,16 @@ public class TileEntityDischargeMeter extends TileEntityIWBase implements IPlaye
|
|||
}
|
||||
|
||||
AxisAlignedBB aabb = null;
|
||||
@Override
|
||||
public AxisAlignedBB getBoundingBoxNoRot() {
|
||||
return new AxisAlignedBB(1F/16, 0, 5F/16,
|
||||
10F/16, (hasWire?15F:14F)/16, 11F/16);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AxisAlignedBB getBoundingBox() {
|
||||
//if (aabb==null)
|
||||
{
|
||||
Matrix4 mat = new Matrix4();
|
||||
mat.translate(.5, 0, .5);
|
||||
mat.rotate((-facing.getHorizontalAngle()+180)*Math.PI/180, 0, 1, 0);
|
||||
mat.translate(-.5, 0, -.5);
|
||||
aabb = MiscUtils.apply(mat, new AxisAlignedBB(1F/16, 0, 5F/16,
|
||||
10F/16, (hasWire?15F:14F)/16, 11F/16));
|
||||
if (aabb==null) {
|
||||
aabb = IBlockBoundsDirectional.super.getBoundingBox();
|
||||
}
|
||||
return aabb;
|
||||
}
|
||||
|
|
|
@ -72,12 +72,15 @@ import net.minecraftforge.client.model.ModelLoaderRegistry;
|
|||
import net.minecraftforge.client.model.obj.OBJLoader;
|
||||
import net.minecraftforge.fml.client.registry.ClientRegistry;
|
||||
import net.minecraftforge.fml.client.registry.RenderingRegistry;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.WeakHashMap;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class ClientProxy extends CommonProxy {
|
||||
@Override
|
||||
public void preInit() {
|
||||
|
|
|
@ -15,14 +15,24 @@
|
|||
|
||||
package malte0811.industrialWires.client;
|
||||
|
||||
import blusunrize.immersiveengineering.common.util.chickenbones.Matrix4;
|
||||
import malte0811.industrialWires.client.panelmodel.SmartLightingQuadIW;
|
||||
import malte0811.industrialWires.controlpanel.PanelUtils;
|
||||
import net.minecraft.client.renderer.BufferBuilder;
|
||||
import net.minecraft.client.renderer.block.model.BakedQuad;
|
||||
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
||||
import net.minecraft.client.renderer.vertex.VertexFormat;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.client.model.obj.OBJModel;
|
||||
import net.minecraftforge.client.model.pipeline.UnpackedBakedQuad;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import org.lwjgl.util.vector.Vector3f;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class ClientUtilsIW {
|
||||
/**
|
||||
* Base on {@link blusunrize.immersiveengineering.client.ClientUtils#renderModelTESRFast(List, BufferBuilder, World, BlockPos)}
|
||||
|
@ -50,4 +60,25 @@ public class ClientUtilsIW {
|
|||
|
||||
}
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public static BakedQuad bakeQuad(RawQuad raw, Matrix4 transform, Matrix4 transfNormal) {
|
||||
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;
|
||||
Vector3f normal = transfNormal.apply(raw.normal);
|
||||
OBJModel.Normal faceNormal = new OBJModel.Normal(normal.x, normal.y, normal.z);
|
||||
for (int i = 0; i < 4; i++) {
|
||||
PanelUtils.putVertexData(format, builder, transform.apply(vertices[i]), faceNormal, uvs[i][0], uvs[i][1], raw.tex,
|
||||
raw.colorA);
|
||||
}
|
||||
BakedQuad ret = builder.build();
|
||||
if (raw.light>0) {
|
||||
ret = new SmartLightingQuadIW(ret, raw.light);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,8 +16,13 @@
|
|||
package malte0811.industrialWires.client;
|
||||
|
||||
import blusunrize.immersiveengineering.common.util.chickenbones.Matrix4;
|
||||
import net.minecraft.client.renderer.block.model.BakedQuad;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.client.renderer.vertex.VertexFormat;
|
||||
import net.minecraft.client.renderer.vertex.VertexFormatElement;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import org.lwjgl.util.vector.Vector3f;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
@ -26,6 +31,7 @@ import java.util.Arrays;
|
|||
import static org.lwjgl.util.vector.Vector3f.cross;
|
||||
import static org.lwjgl.util.vector.Vector3f.sub;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class RawQuad {
|
||||
public final Vector3f[] vertices = new Vector3f[4];
|
||||
public final EnumFacing facing;
|
||||
|
@ -75,10 +81,56 @@ public class RawQuad {
|
|||
this.light = light;
|
||||
}
|
||||
|
||||
public static RawQuad unbake(BakedQuad q) {
|
||||
Vector3f[] vertices = new Vector3f[4];
|
||||
float[] color = new float[4];
|
||||
Vector3f normal = new Vector3f();
|
||||
float[][] uvs = new float[4][2];
|
||||
TextureAtlasSprite sprite = q.getSprite();
|
||||
VertexFormat format = q.getFormat();
|
||||
int pos = 0;
|
||||
for (int v = 0; v < 4; v++) {
|
||||
for (int e = 0; e < format.getElementCount(); e++) {
|
||||
switch (format.getElement(e).getUsage()) {
|
||||
case POSITION:
|
||||
int x = q.getVertexData()[pos];
|
||||
int y = q.getVertexData()[pos + 1];
|
||||
int z = q.getVertexData()[pos + 2];
|
||||
vertices[v] = new Vector3f(Float.intBitsToFloat(x),
|
||||
Float.intBitsToFloat(y),
|
||||
Float.intBitsToFloat(z));
|
||||
break;
|
||||
case COLOR:
|
||||
for (int i = 0; i < 4; i++) {
|
||||
color[i] = Float.intBitsToFloat(q.getVertexData()[pos + i]);
|
||||
}
|
||||
break;
|
||||
case UV:
|
||||
if (format.getElement(e).getType() == VertexFormatElement.EnumType.FLOAT) {
|
||||
uvs[v][0] = sprite.getUnInterpolatedU(Float.intBitsToFloat(q.getVertexData()[pos]));
|
||||
uvs[v][1] = sprite.getUnInterpolatedV(Float.intBitsToFloat(q.getVertexData()[pos + 1]));
|
||||
}
|
||||
break;
|
||||
case NORMAL:
|
||||
x = q.getVertexData()[pos];
|
||||
y = q.getVertexData()[pos + 1];
|
||||
z = q.getVertexData()[pos + 2];
|
||||
normal.set(Float.intBitsToFloat(x),
|
||||
Float.intBitsToFloat(y),
|
||||
Float.intBitsToFloat(z));
|
||||
break;
|
||||
}
|
||||
pos += format.getElement(e).getSize() / 4;
|
||||
}
|
||||
}
|
||||
return new RawQuad(vertices[0], vertices[1], vertices[2], vertices[3],
|
||||
q.getFace(), sprite, color, normal, uvs, -1);
|
||||
}
|
||||
|
||||
public RawQuad apply(Matrix4 mat) {
|
||||
Matrix4 matNormal = mat.copy().transpose();
|
||||
matNormal.invert();
|
||||
return new RawQuad(mat.apply(vertices[0]), mat.apply(vertices[1]), mat.apply(vertices[2]), mat.apply(vertices[3]),
|
||||
facing, tex, colorA, matNormal.apply(normal), uvs, light);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -33,6 +33,8 @@ import net.minecraft.item.ItemStack;
|
|||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.property.IExtendedBlockState;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import org.lwjgl.util.vector.Vector3f;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
@ -42,6 +44,7 @@ import java.util.List;
|
|||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class PanelModel implements IBakedModel {
|
||||
public final static Cache<PanelRenderProperties, AssembledBakedModel> modelCache = CacheBuilder.newBuilder()
|
||||
.maximumSize(100)
|
||||
|
|
|
@ -15,8 +15,12 @@
|
|||
|
||||
package malte0811.industrialWires.client.render;
|
||||
|
||||
import blusunrize.immersiveengineering.api.IEApi;
|
||||
import blusunrize.immersiveengineering.client.ClientUtils;
|
||||
import blusunrize.immersiveengineering.common.util.chickenbones.Matrix4;
|
||||
import malte0811.industrialWires.blocks.converter.TileEntityMultiblockConverter;
|
||||
import malte0811.industrialWires.client.ClientUtilsIW;
|
||||
import malte0811.industrialWires.client.RawQuad;
|
||||
import malte0811.industrialWires.converter.MechMBPart;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.BufferBuilder;
|
||||
|
@ -33,47 +37,25 @@ import net.minecraft.client.resources.IResourceManager;
|
|||
import net.minecraft.client.resources.IResourceManagerReloadListener;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.lwjgl.util.vector.Vector3f;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.*;
|
||||
|
||||
import static malte0811.industrialWires.blocks.converter.TileEntityMultiblockConverter.TICK_ANGLE_PER_SPEED;
|
||||
import static malte0811.industrialWires.converter.MechMBPart.SHAFT_KEY;
|
||||
|
||||
public class TileRenderMBConverter extends TileEntitySpecialRenderer<TileEntityMultiblockConverter> implements IResourceManagerReloadListener {
|
||||
public static final Map<ResourceLocation, IBakedModel> BASE_MODELS = new HashMap<>();
|
||||
public static final Set<TileEntityMultiblockConverter> TES_WITH_MODELS = Collections.newSetFromMap(new WeakHashMap<>());
|
||||
static {
|
||||
IEApi.renderCacheClearers.add(TileRenderMBConverter::clearCache);
|
||||
}
|
||||
@Override
|
||||
public void render(TileEntityMultiblockConverter te, double x, double y, double z, float partialTicks, int destroyStage, float alpha) {
|
||||
if (te.mechanical!=null) {
|
||||
if (te.rotatingModel == null)
|
||||
{
|
||||
te.rotatingModel = new ArrayList<>();
|
||||
int offset = 0;
|
||||
for (MechMBPart part : te.mechanical) {
|
||||
List<BakedQuad> quadsForPart = part.getRotatingQuads();
|
||||
if (offset != 0) {
|
||||
for (BakedQuad b : quadsForPart) {
|
||||
int[] data = Arrays.copyOf(b.getVertexData(), b.getVertexData().length);
|
||||
int pos = 0;
|
||||
for (VertexFormatElement ele : b.getFormat().getElements()) {
|
||||
if (ele.getUsage() == VertexFormatElement.EnumUsage.POSITION) {
|
||||
for (int i = 0;i<4;i++) {
|
||||
data[i*b.getFormat().getIntegerSize()+pos + 2] = Float.floatToRawIntBits(
|
||||
Float.intBitsToFloat(data[i*b.getFormat().getIntegerSize()+pos + 2]) + offset);
|
||||
}
|
||||
break;
|
||||
}
|
||||
pos += ele.getSize()/4;
|
||||
}
|
||||
BakedQuad translated = new BakedQuad(data, b.getTintIndex(), b.getFace(),
|
||||
b.getSprite(), b.shouldApplyDiffuseLighting(), b.getFormat());
|
||||
te.rotatingModel.add(translated);
|
||||
}
|
||||
} else {
|
||||
te.rotatingModel.addAll(quadsForPart);
|
||||
}
|
||||
offset += part.getLength();
|
||||
}
|
||||
TES_WITH_MODELS.add(te);
|
||||
if (te.mechanical != null) {
|
||||
if (te.rotatingModel == null) {
|
||||
generateModel(te);
|
||||
}
|
||||
GlStateManager.enableBlend();
|
||||
GlStateManager.blendFunc(770, 771);
|
||||
|
@ -81,10 +63,10 @@ public class TileRenderMBConverter extends TileEntitySpecialRenderer<TileEntityM
|
|||
Minecraft.getMinecraft().renderEngine.bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
|
||||
GlStateManager.pushMatrix();
|
||||
GlStateManager.translate(.5F + x, .5F + y, .5F + z);
|
||||
GlStateManager.rotate(180-te.facing.getHorizontalAngle(), 0, 1, 0);
|
||||
GlStateManager.rotate(180 - te.facing.getHorizontalAngle(), 0, 1, 0);
|
||||
GlStateManager.rotate((float) (te.angle + te.energyState.getSpeed() * TICK_ANGLE_PER_SPEED * partialTicks),
|
||||
0, 0, 1);
|
||||
GlStateManager.translate(-.5, -.5, .5);
|
||||
GlStateManager.translate(-.5, -.5, -.5);
|
||||
Tessellator tes = Tessellator.getInstance();
|
||||
BufferBuilder bb = tes.getBuffer();
|
||||
bb.begin(GL11.GL_QUADS, DefaultVertexFormats.BLOCK);
|
||||
|
@ -96,9 +78,77 @@ public class TileRenderMBConverter extends TileEntitySpecialRenderer<TileEntityM
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onResourceManagerReload(IResourceManager resourceManager) {
|
||||
for (TileEntityMultiblockConverter te:TES_WITH_MODELS)
|
||||
public void onResourceManagerReload(@Nonnull IResourceManager resourceManager) {
|
||||
clearCache();
|
||||
}
|
||||
|
||||
private static void clearCache() {
|
||||
for (TileEntityMultiblockConverter te : TES_WITH_MODELS)
|
||||
te.rotatingModel = null;
|
||||
TES_WITH_MODELS.clear();
|
||||
}
|
||||
|
||||
private void generateModel(TileEntityMultiblockConverter te) {
|
||||
te.rotatingModel = new ArrayList<>();
|
||||
int offset = 1;
|
||||
for (MechMBPart part : te.mechanical) {
|
||||
addQuadsForPart(part, offset, te.rotatingModel);
|
||||
offset += part.getLength();
|
||||
}
|
||||
//Add shaft model in the end blocks
|
||||
//TODO handle ends not being in the same indices for all quads
|
||||
List<BakedQuad> shaftQuads = MechMBPart.INSTANCES.get(SHAFT_KEY).getRotatingQuads();
|
||||
Vector3f tmp = new Vector3f();
|
||||
Matrix4 id = new Matrix4();
|
||||
Matrix4 translate = new Matrix4();
|
||||
translate.translate(0, 0, offset);
|
||||
for (BakedQuad q : shaftQuads) {
|
||||
RawQuad raw = RawQuad.unbake(q);
|
||||
Vector3f.add(raw.vertices[0], raw.vertices[1], tmp);
|
||||
tmp.scale(.5F);
|
||||
Vector3f middle0 = new Vector3f(tmp);
|
||||
Vector3f.add(raw.vertices[2], raw.vertices[3], tmp);
|
||||
tmp.scale(.5F);
|
||||
Vector3f middle1 = new Vector3f(tmp);
|
||||
RawQuad start = new RawQuad(raw.vertices[0], middle0, middle1, raw.vertices[3],
|
||||
raw.facing, raw.tex, raw.colorA, raw.normal, new float[][]{
|
||||
raw.uvs[0], {raw.uvs[1][0], .5F}, {raw.uvs[2][0], .5F}, raw.uvs[3]
|
||||
}, -1);
|
||||
te.rotatingModel.add(ClientUtilsIW.bakeQuad(start, id, id));
|
||||
RawQuad end = new RawQuad(middle0, raw.vertices[1], raw.vertices[2], middle1,
|
||||
raw.facing, raw.tex, raw.colorA, raw.normal, new float[][]{
|
||||
{raw.uvs[0][0], .5F}, raw.uvs[1], raw.uvs[2], {raw.uvs[3][0], .5F}
|
||||
}, -1);
|
||||
te.rotatingModel.add(ClientUtilsIW.bakeQuad(end, translate, id));
|
||||
}
|
||||
TES_WITH_MODELS.add(te);
|
||||
}
|
||||
|
||||
private void addQuadsForPart(MechMBPart part, int offset, List<BakedQuad> out) {
|
||||
List<BakedQuad> quadsForPart = part.getRotatingQuads();
|
||||
if (offset != 0) {
|
||||
for (BakedQuad b : quadsForPart) {
|
||||
out.add(translateQuadZ(b, offset));
|
||||
}
|
||||
} else {
|
||||
out.addAll(quadsForPart);
|
||||
}
|
||||
}
|
||||
|
||||
private BakedQuad translateQuadZ(BakedQuad b, float offset) {
|
||||
int[] data = Arrays.copyOf(b.getVertexData(), b.getVertexData().length);
|
||||
int pos = 0;
|
||||
for (VertexFormatElement ele : b.getFormat().getElements()) {
|
||||
if (ele.getUsage() == VertexFormatElement.EnumUsage.POSITION) {
|
||||
for (int i = 0; i < 4; i++) {
|
||||
data[i * b.getFormat().getIntegerSize() + pos + 2] = Float.floatToRawIntBits(
|
||||
Float.intBitsToFloat(data[i * b.getFormat().getIntegerSize() + pos + 2]) + offset);
|
||||
}
|
||||
break;
|
||||
}
|
||||
pos += ele.getSize() / 4;
|
||||
}
|
||||
return new BakedQuad(data, b.getTintIndex(), b.getFace(),
|
||||
b.getSprite(), b.shouldApplyDiffuseLighting(), b.getFormat());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,14 +20,13 @@ import blusunrize.immersiveengineering.common.util.chickenbones.Matrix4;
|
|||
import malte0811.industrialWires.IndustrialWires;
|
||||
import malte0811.industrialWires.blocks.controlpanel.BlockPanel;
|
||||
import malte0811.industrialWires.blocks.controlpanel.BlockTypes_Panel;
|
||||
import malte0811.industrialWires.client.ClientUtilsIW;
|
||||
import malte0811.industrialWires.client.RawQuad;
|
||||
import malte0811.industrialWires.client.panelmodel.SmartLightingQuadIW;
|
||||
import malte0811.industrialWires.controlpanel.PropertyComponents.PanelRenderProperties;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
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;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraft.item.EnumDyeColor;
|
||||
|
@ -83,7 +82,7 @@ public final class PanelUtils {
|
|||
Matrix4 m4Here = m4.copy().translate(pc.getX(), PanelComponent.Y_DELTA, pc.getY());
|
||||
List<RawQuad> compQuads = pc.getQuads();
|
||||
for (RawQuad bq : compQuads) {
|
||||
ret.add(bakeQuad(bq, m4Here, m4RotOnly));
|
||||
ret.add(ClientUtilsIW.bakeQuad(bq, m4Here, m4RotOnly));
|
||||
}
|
||||
}
|
||||
Matrix4 baseTrans = components.getPanelBaseTransform();
|
||||
|
@ -140,33 +139,12 @@ public final class PanelUtils {
|
|||
new Vector3f(xMax, height1, zMax), new Vector3f(xMin, height1, zMax),
|
||||
EnumFacing.UP, PANEL_TEXTURE, WHITE, null, new float[]{0, 0, vMax1, uMaxX}, -1));
|
||||
for (RawQuad bq : rawOut) {
|
||||
ret.add(bakeQuad(bq, baseTrans, baseNorm));
|
||||
ret.add(ClientUtilsIW.bakeQuad(bq, baseTrans, baseNorm));
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public static BakedQuad bakeQuad(RawQuad raw, Matrix4 transform, Matrix4 transfNormal) {
|
||||
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;
|
||||
Vector3f normal = transfNormal.apply(raw.normal);
|
||||
OBJModel.Normal faceNormal = new OBJModel.Normal(normal.x, normal.y, normal.z);
|
||||
for (int i = 0; i < 4; i++) {
|
||||
putVertexData(format, builder, transform.apply(vertices[i]), faceNormal, uvs[i][0], uvs[i][1], raw.tex,
|
||||
raw.colorA);
|
||||
}
|
||||
BakedQuad ret = builder.build();
|
||||
if (raw.light>0) {
|
||||
ret = new SmartLightingQuadIW(ret, raw.light);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
//mostly copied from IE's ClientUtils, it has protected access there...
|
||||
@SideOnly(Side.CLIENT)
|
||||
public static void putVertexData(VertexFormat format, UnpackedBakedQuad.Builder builder, Vector3f pos, OBJModel.Normal faceNormal, double u, double v, TextureAtlasSprite sprite, float[] colorA) {
|
||||
|
@ -272,6 +250,7 @@ public final class PanelUtils {
|
|||
}
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public static void addInfo(ItemStack stack, List<String> list, NBTTagCompound data) {
|
||||
switch (stack.getMetadata()) {
|
||||
case 0: //button
|
||||
|
@ -322,6 +301,7 @@ public final class PanelUtils {
|
|||
}
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public static void addCommonInfo(NBTTagCompound data, List<String> list, boolean color, boolean rs) {
|
||||
if (color && data.hasKey(COLOR)) {
|
||||
String hexCol = String.format("%6s", Integer.toHexString(data.getInteger(COLOR) & 0xffffff)).replace(' ', '0');
|
||||
|
|
|
@ -31,6 +31,7 @@ import net.minecraft.nbt.NBTTagCompound;
|
|||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
|
@ -105,6 +106,8 @@ public abstract class MechMBPart {
|
|||
|
||||
public static final BiMap<String, Class<? extends MechMBPart>> REGISTRY = HashBiMap.create();
|
||||
|
||||
public static final String SHAFT_KEY = "shaft";
|
||||
|
||||
public static final Comparator<MechMBPart> SORT_BY_COUNT = Comparator.comparingInt(
|
||||
(c)->-MiscUtils.count1Bits(c.getFormPattern())
|
||||
);
|
||||
|
@ -113,7 +116,7 @@ public abstract class MechMBPart {
|
|||
REGISTRY.put("singleCoil", MechPartSingleCoil.class);
|
||||
REGISTRY.put("twoElectrodes", MechPartTwoElectrodes.class);
|
||||
REGISTRY.put("commutator", MechPartCommutator.class);
|
||||
REGISTRY.put("shaft", MechPartShaft.class);
|
||||
REGISTRY.put(SHAFT_KEY, MechPartShaft.class);
|
||||
REGISTRY.put("speedometer", MechPartSpeedometer.class);
|
||||
REGISTRY.put("commFour", MechPartCommutator4Phase.class);
|
||||
REGISTRY.put("fourCoils", MechPartFourCoils.class);
|
||||
|
@ -205,4 +208,6 @@ public abstract class MechMBPart {
|
|||
public int getLength() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
public abstract AxisAlignedBB getBoundingBox(BlockPos offsetPart);
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@ import net.minecraft.nbt.NBTTagCompound;
|
|||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
import net.minecraftforge.energy.IEnergyStorage;
|
||||
|
@ -294,4 +295,8 @@ public class MechPartCommutator extends MechMBPart implements IMBPartElectric {
|
|||
return outputs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AxisAlignedBB getBoundingBox(BlockPos offsetPart) {
|
||||
return new AxisAlignedBB(0, .375-1/32D, 0, 1, 1, 1);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,8 +20,10 @@ import malte0811.industrialWires.IWConfig;
|
|||
import malte0811.industrialWires.IndustrialWires;
|
||||
import malte0811.industrialWires.blocks.converter.MechanicalMBBlockType;
|
||||
import malte0811.industrialWires.util.LocalSidedWorld;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import org.apache.commons.lang3.tuple.ImmutablePair;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
@ -89,4 +91,16 @@ public class MechPartCommutator4Phase extends MechPartCommutator {
|
|||
return outputs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AxisAlignedBB getBoundingBox(BlockPos offsetPart) {
|
||||
if (BlockPos.ORIGIN.equals(offsetPart)) {
|
||||
return super.getBoundingBox(offsetPart);
|
||||
}
|
||||
if (offsetPart.getY()==0) {
|
||||
return Block.FULL_BLOCK_AABB;
|
||||
}
|
||||
double xMin = offsetPart.getX()<=0?.5:0;
|
||||
double xMax = offsetPart.getX()>=0?.5:1;
|
||||
return new AxisAlignedBB(xMin, 0, 0, xMax, 1, 1);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@ import malte0811.industrialWires.IndustrialWires;
|
|||
import malte0811.industrialWires.blocks.converter.MechanicalMBBlockType;
|
||||
import malte0811.industrialWires.entities.EntityBrokenPart;
|
||||
import malte0811.industrialWires.util.LocalSidedWorld;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.block.model.BakedQuad;
|
||||
|
@ -31,8 +32,11 @@ import net.minecraft.item.ItemBlock;
|
|||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -81,6 +85,7 @@ public class MechPartFlywheel extends MechMBPart {
|
|||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public List<BakedQuad> getRotatingQuads() {
|
||||
List<BakedQuad> orig = super.getRotatingQuads();
|
||||
TextureAtlasSprite newTex = Minecraft.getMinecraft().getTextureMapBlocks().getAtlasSprite(material.blockTexture.toString());
|
||||
|
@ -169,4 +174,17 @@ public class MechPartFlywheel extends MechMBPart {
|
|||
public MechanicalMBBlockType getType() {
|
||||
return MechanicalMBBlockType.FLYWHEEL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AxisAlignedBB getBoundingBox(BlockPos offsetPart) {
|
||||
if (BlockPos.ORIGIN.equals(offsetPart)) {
|
||||
return Block.FULL_BLOCK_AABB;
|
||||
}
|
||||
final double small = .375;
|
||||
double xMin = offsetPart.getX()<=0?0:small;
|
||||
double xMax = offsetPart.getX()>=0?1:1-small;
|
||||
double yMin = offsetPart.getY()>=0?0:small;
|
||||
double yMax = offsetPart.getY()<=0?1:1-small;
|
||||
return new AxisAlignedBB(xMin, yMin, .0625, xMax, yMax, .9375);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -92,4 +92,5 @@ public class MechPartFourCoils extends MechPartSingleCoil {
|
|||
public double getMaxSpeed() {
|
||||
return 500;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -20,8 +20,10 @@ import malte0811.industrialWires.IWConfig;
|
|||
import malte0811.industrialWires.IndustrialWires;
|
||||
import malte0811.industrialWires.blocks.converter.MechanicalMBBlockType;
|
||||
import malte0811.industrialWires.util.LocalSidedWorld;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import org.apache.commons.lang3.tuple.ImmutablePair;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
@ -88,4 +90,18 @@ public class MechPartFourElectrodes extends MechPartTwoElectrodes {
|
|||
public double getMaxSpeed() {
|
||||
return IWConfig.MechConversion.allowMBFE()?600:-1;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public AxisAlignedBB getBoundingBox(BlockPos offsetPart) {
|
||||
if (BlockPos.ORIGIN.equals(offsetPart)) {
|
||||
return super.getBoundingBox(offsetPart);
|
||||
}
|
||||
if (offsetPart.getY()==0) {
|
||||
return Block.FULL_BLOCK_AABB;
|
||||
}
|
||||
double xMin = offsetPart.getX()<=0?.5:0;
|
||||
double xMax = offsetPart.getX()>=0?.5:1;
|
||||
return new AxisAlignedBB(xMin, 0, 0, xMax, 1, 1);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@ import malte0811.industrialWires.blocks.converter.MechanicalMBBlockType;
|
|||
import malte0811.industrialWires.util.LocalSidedWorld;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
import static malte0811.industrialWires.blocks.converter.MechanicalMBBlockType.SHAFT_BASIC;
|
||||
|
@ -76,4 +77,9 @@ public class MechPartShaft extends MechMBPart {
|
|||
public MechanicalMBBlockType getType() {
|
||||
return SHAFT_BASIC;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AxisAlignedBB getBoundingBox(BlockPos offsetPart) {
|
||||
return new AxisAlignedBB(.375, .375, 0, .625, .625, 1);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,9 +19,11 @@ import blusunrize.immersiveengineering.common.blocks.metal.BlockTypes_MetalDecor
|
|||
import malte0811.industrialWires.IndustrialWires;
|
||||
import malte0811.industrialWires.blocks.converter.MechanicalMBBlockType;
|
||||
import malte0811.industrialWires.util.LocalSidedWorld;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
import static blusunrize.immersiveengineering.common.IEContent.blockMetalDecoration0;
|
||||
|
@ -179,4 +181,13 @@ public class MechPartSingleCoil extends MechMBPart implements IMBPartElectric {
|
|||
protected boolean has4Phases() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AxisAlignedBB getBoundingBox(BlockPos offsetPart) {
|
||||
if (BlockPos.ORIGIN.equals(offsetPart)) {
|
||||
return Block.FULL_BLOCK_AABB;
|
||||
} else {
|
||||
return new AxisAlignedBB(0, 0, .0625, 1, 1, .9375);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,6 +30,8 @@ import net.minecraft.nbt.NBTTagCompound;
|
|||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.text.TextComponentTranslation;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
@ -173,4 +175,9 @@ public class MechPartSpeedometer extends MechMBPart implements IPlayerInteractio
|
|||
public boolean canConnectRedstone(@Nonnull IBlockState state, @Nonnull EnumFacing side) {
|
||||
return side.getAxis() == X;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AxisAlignedBB getBoundingBox(BlockPos offsetPart) {
|
||||
return new AxisAlignedBB(0, .1875, 0, 1, .8125, 1);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@ import net.minecraft.block.state.IBlockState;
|
|||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
import net.minecraftforge.energy.CapabilityEnergy;
|
||||
|
@ -234,4 +235,9 @@ public class MechPartTwoElectrodes extends MechMBPart implements IMBPartElectric
|
|||
protected boolean has4Phases() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AxisAlignedBB getBoundingBox(BlockPos offsetPart) {
|
||||
return new AxisAlignedBB(0, .375, 0, 1, 1, 1);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -94,7 +94,6 @@ public class MultiblockConverter implements MultiblockHandler.IMultiblock {
|
|||
instances.sort(MechMBPart.SORT_BY_COUNT);
|
||||
int lastCount = 0;
|
||||
for (MechMBPart part:instances) {
|
||||
IndustrialWires.logger.info(w.getRealPos(BlockPos.ORIGIN)+", "+part);
|
||||
int newCount = MiscUtils.count1Bits(part.getFormPattern());
|
||||
if (newCount==1&&lastCount>1&&checkEnd(w, mutPos)) {
|
||||
foundAll = true;
|
||||
|
|
|
@ -24,6 +24,7 @@ public final class NBTKeys {
|
|||
public static final String TYPE = "type";
|
||||
public static final String BUFFER_IN = "inBuffer";
|
||||
public static final String BUFFER_OUT = "outBuffer";
|
||||
public static final String STRUCTURE_VERSION = "structureVersion";
|
||||
|
||||
//Control panels
|
||||
public static final String HEIGHT = "height";
|
||||
|
|
Loading…
Reference in a new issue