|
@@ -0,0 +1,353 @@
|
|
|
+package com.zjinja.mcmod.decor.utils.model_dir_util;
|
|
|
+
|
|
|
+import com.zjinja.mcmod.decor.ZJinJaDecoration;
|
|
|
+import net.minecraft.entity.EntityLivingBase;
|
|
|
+import net.minecraft.item.ItemStack;
|
|
|
+import net.minecraft.util.MathHelper;
|
|
|
+import net.minecraft.util.Vec3;
|
|
|
+import net.minecraft.world.World;
|
|
|
+import org.lwjgl.opengl.GL11;
|
|
|
+
|
|
|
+public class ModelDirectionUtil {
|
|
|
+ public RotationVector RotationMetaTable[];
|
|
|
+ public BoundingBoxVector RelBoundingBox;
|
|
|
+ public BoundingBoxVector AbsBoundingBoxMetaTable[];
|
|
|
+
|
|
|
+ public ModelDirectionUtil(){
|
|
|
+ RotationMetaTable = new RotationVector[16];
|
|
|
+ for(int i = 0; i < 16; i++){
|
|
|
+ RotationMetaTable[i] = new RotationVector();
|
|
|
+ }
|
|
|
+ RelBoundingBox = new BoundingBoxVector();
|
|
|
+ AbsBoundingBoxMetaTable = new BoundingBoxVector[16];
|
|
|
+ for(int i = 0; i < 16; i++){
|
|
|
+ AbsBoundingBoxMetaTable[i] = new BoundingBoxVector();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void DefineMetaRotation(int Meta, RotationVector rv){
|
|
|
+ int index = Meta % 16;
|
|
|
+ RotationMetaTable[index] = rv;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void DefineRelBoundingBox(BoundingBoxVector rbbv){
|
|
|
+ RelBoundingBox = rbbv;
|
|
|
+ for(int i = 0; i < 16; i++){
|
|
|
+ AbsBoundingBoxMetaTable[i] = CalcMetaBoundingBoxTableItem(i);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public RotationVector GetRotationByMeta(int meta){
|
|
|
+ int rmeta = meta % 16;
|
|
|
+ RotationVector rrv = RotationMetaTable[rmeta];
|
|
|
+ return rrv;
|
|
|
+ }
|
|
|
+
|
|
|
+ private BoundingBoxVector CalcMetaBoundingBoxTableItem(int meta){
|
|
|
+ RotationVector rrv = GetRotationByMeta(meta);
|
|
|
+ int rx,ry,rz;
|
|
|
+ float tx1,tx2,ty1,ty2,tz1,tz2;
|
|
|
+ float ux1,ux2,uy1,uy2,uz1,uz2;
|
|
|
+ rx = rrv.RotateX % 4;
|
|
|
+ ry = rrv.RotateY % 4;
|
|
|
+ rz = rrv.RotateZ % 4;
|
|
|
+
|
|
|
+ if(ZJinJaDecoration.DebugMode){
|
|
|
+ ZJinJaDecoration.logger.warn(
|
|
|
+ String.format("Rotation @ Meta=%d: (%d,%d,%d)",
|
|
|
+ meta, rx, ry, rz
|
|
|
+ )
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ // Coordinate Transformation Before Rotation
|
|
|
+ tx1 = RelBoundingBox.x1 - 0.5F;
|
|
|
+ tx2 = RelBoundingBox.x2 - 0.5F;
|
|
|
+ ty1 = RelBoundingBox.y1 - 0.5F;
|
|
|
+ ty2 = RelBoundingBox.y2 - 0.5F;
|
|
|
+ tz1 = RelBoundingBox.z1 - 0.5F;
|
|
|
+ tz2 = RelBoundingBox.z2 - 0.5F;
|
|
|
+
|
|
|
+ if(ZJinJaDecoration.DebugMode){
|
|
|
+ ZJinJaDecoration.logger.warn(
|
|
|
+ String.format("Coordinate Transformation: Meta=%d: Pos1=(%f,%f,%f), Pos2=(%f,%f,%f)",
|
|
|
+ meta, tx1, ty1, tz1, tx2, ty2, tz2
|
|
|
+ )
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ //Rotating X Axis
|
|
|
+ switch (rx){
|
|
|
+ default:
|
|
|
+ ux1 = tx1;
|
|
|
+ ux2 = tx2;
|
|
|
+ uy1 = ty1;
|
|
|
+ uy2 = ty2;
|
|
|
+ uz1 = tz1;
|
|
|
+ uz2 = tz2;
|
|
|
+ break;
|
|
|
+ case 1:
|
|
|
+ ux1 = tx1;
|
|
|
+ ux2 = tx2;
|
|
|
+ uy1 = -tz1;
|
|
|
+ uy2 = -tz2;
|
|
|
+ uz1 = ty1;
|
|
|
+ uz2 = ty2;
|
|
|
+ break;
|
|
|
+ case 2:
|
|
|
+ ux1 = tx1;
|
|
|
+ ux2 = tx2;
|
|
|
+ uy1 = -ty1;
|
|
|
+ uy2 = -ty2;
|
|
|
+ uz1 = -tz1;
|
|
|
+ uz2 = -tz2;
|
|
|
+ break;
|
|
|
+ case 3:
|
|
|
+ ux1 = tx1;
|
|
|
+ ux2 = tx2;
|
|
|
+ uy1 = tz1;
|
|
|
+ uy2 = tz2;
|
|
|
+ uz1 = -ty1;
|
|
|
+ uz2 = -ty2;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(ZJinJaDecoration.DebugMode){
|
|
|
+ ZJinJaDecoration.logger.warn(
|
|
|
+ String.format("After X Axis Trans: Meta=%d: Pos1=(%f,%f,%f), Pos2=(%f,%f,%f)",
|
|
|
+ meta, ux1, uy1, uz1, ux2, uy2, uz2
|
|
|
+ )
|
|
|
+ );
|
|
|
+ }
|
|
|
+ //Rotating Y Axis
|
|
|
+ switch (ry){
|
|
|
+ default:
|
|
|
+ tx1 = ux1;
|
|
|
+ tx2 = ux2;
|
|
|
+ ty1 = uy1;
|
|
|
+ ty2 = uy2;
|
|
|
+ tz1 = uz1;
|
|
|
+ tz2 = uz2;
|
|
|
+ break;
|
|
|
+ case 1:
|
|
|
+ tx1 = -uz1;
|
|
|
+ tx2 = -uz2;
|
|
|
+ ty1 = uy1;
|
|
|
+ ty2 = uy2;
|
|
|
+ tz1 = ux1;
|
|
|
+ tz2 = ux2;
|
|
|
+ break;
|
|
|
+ case 2:
|
|
|
+ tx1 = -ux1;
|
|
|
+ tx2 = -ux2;
|
|
|
+ ty1 = uy1;
|
|
|
+ ty2 = uy2;
|
|
|
+ tz1 = -uz1;
|
|
|
+ tz2 = -uz2;
|
|
|
+ break;
|
|
|
+ case 3:
|
|
|
+ tx1 = uz1;
|
|
|
+ tx2 = uz2;
|
|
|
+ ty1 = uy1;
|
|
|
+ ty2 = uy2;
|
|
|
+ tz1 = -ux1;
|
|
|
+ tz2 = -ux2;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ if(ZJinJaDecoration.DebugMode){
|
|
|
+ ZJinJaDecoration.logger.warn(
|
|
|
+ String.format("After Y Axis Trans: Meta=%d: Pos1=(%f,%f,%f), Pos2=(%f,%f,%f)",
|
|
|
+ meta, tx1, ty1, tz1, tx2, ty2, tz2
|
|
|
+ )
|
|
|
+ );
|
|
|
+ }
|
|
|
+ //Rotating Z Axis
|
|
|
+ switch (rz){
|
|
|
+ default:
|
|
|
+ ux1 = tx1;
|
|
|
+ ux2 = tx2;
|
|
|
+ uy1 = ty1;
|
|
|
+ uy2 = ty2;
|
|
|
+ uz1 = tz1;
|
|
|
+ uz2 = tz2;
|
|
|
+ break;
|
|
|
+ case 1:
|
|
|
+ ux1 = -ty1;
|
|
|
+ ux2 = -ty2;
|
|
|
+ uy1 = tx1;
|
|
|
+ uy2 = tx2;
|
|
|
+ uz1 = tz1;
|
|
|
+ uz2 = tz2;
|
|
|
+ break;
|
|
|
+ case 2:
|
|
|
+ ux1 = -tx1;
|
|
|
+ ux2 = -tx2;
|
|
|
+ uy1 = -ty1;
|
|
|
+ uy2 = -ty2;
|
|
|
+ uz1 = tz1;
|
|
|
+ uz2 = tz2;
|
|
|
+ break;
|
|
|
+ case 3:
|
|
|
+ ux1 = ty1;
|
|
|
+ ux2 = ty2;
|
|
|
+ uy1 = -tx1;
|
|
|
+ uy2 = -tx2;
|
|
|
+ uz1 = tz1;
|
|
|
+ uz2 = tz2;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ if(ZJinJaDecoration.DebugMode){
|
|
|
+ ZJinJaDecoration.logger.warn(
|
|
|
+ String.format("After Z Axis Trans: Meta=%d: Pos1=(%f,%f,%f), Pos2=(%f,%f,%f)",
|
|
|
+ meta, ux1, uy1, uz1, ux2, uy2, uz2
|
|
|
+ )
|
|
|
+ );
|
|
|
+ }
|
|
|
+ float minx,miny,minz,maxx,maxy,maxz;
|
|
|
+ minx = Math.min(ux1 + 0.5F, ux2 + 0.5F);
|
|
|
+ maxx = Math.max(ux1 + 0.5F, ux2 + 0.5F);
|
|
|
+ miny = Math.min(uy1 + 0.5F, uy2 + 0.5F);
|
|
|
+ maxy = Math.max(uy1 + 0.5F, uy2 + 0.5F);
|
|
|
+ minz = Math.min(uz1 + 0.5F, uz2 + 0.5F);
|
|
|
+ maxz = Math.max(uz1 + 0.5F, uz2 + 0.5F);
|
|
|
+ // Coordinate Transformation After Rotation
|
|
|
+ BoundingBoxVector abbv = new BoundingBoxVector(minx, miny, minz, maxx, maxy, maxz);
|
|
|
+ if(ZJinJaDecoration.DebugMode){
|
|
|
+ ZJinJaDecoration.logger.warn(
|
|
|
+ String.format("BoundingBox @ Meta=%d: Pos1=(%f,%f,%f), Pos2=(%f,%f,%f)",
|
|
|
+ meta, minx, miny, minz, maxx, maxy, maxz)
|
|
|
+ );
|
|
|
+ }
|
|
|
+ return abbv;
|
|
|
+ }
|
|
|
+
|
|
|
+ public BoundingBoxVector GetAbsBoundingBoxByMeta(int meta){
|
|
|
+ int rmeta = meta % 16;
|
|
|
+ return AbsBoundingBoxMetaTable[rmeta];
|
|
|
+ }
|
|
|
+
|
|
|
+ public void GLTransformByMeta(int meta){
|
|
|
+ RotationVector rv = GetRotationByMeta(meta);
|
|
|
+ float ax,ay,az;
|
|
|
+ ax = rv.RotateX % 4 * 90.0F;
|
|
|
+ ay = rv.RotateY % 4 * 90.0F;
|
|
|
+ az = rv.RotateZ % 4 * 90.0F;
|
|
|
+ GL11.glPushMatrix();
|
|
|
+ GL11.glRotatef(ax, -1.0F, 0.0F, 0.0F);
|
|
|
+ GL11.glPushMatrix();
|
|
|
+ GL11.glRotatef(ay, 0.0F, -1.0F, 0.0F);
|
|
|
+ GL11.glPushMatrix();
|
|
|
+ GL11.glRotatef(az, 0.0F, 0.0F, -1.0F);
|
|
|
+ }
|
|
|
+
|
|
|
+ public OffsetVector CalcOffsetFromRelOffset(int meta, float OffsetX, float OffsetY, float OffsetZ){
|
|
|
+ RotationVector rrv = GetRotationByMeta(meta);
|
|
|
+ int rx,ry,rz;
|
|
|
+ float tx,ty,tz, ux, uy, uz;
|
|
|
+ rx = rrv.RotateX % 4;
|
|
|
+ ry = rrv.RotateY % 4;
|
|
|
+ rz = rrv.RotateZ % 4;
|
|
|
+
|
|
|
+ //Rotating X Axis
|
|
|
+ switch (rx){
|
|
|
+ default:
|
|
|
+ ux = OffsetX;
|
|
|
+ uy = OffsetY;
|
|
|
+ uz = OffsetZ;
|
|
|
+ break;
|
|
|
+ case 1:
|
|
|
+ ux = OffsetX;
|
|
|
+ uy = -OffsetZ;
|
|
|
+ uz = OffsetY;
|
|
|
+ break;
|
|
|
+ case 2:
|
|
|
+ ux = OffsetX;
|
|
|
+ uy = -OffsetY;
|
|
|
+ uz = -OffsetZ;
|
|
|
+ break;
|
|
|
+ case 3:
|
|
|
+ ux = OffsetX;
|
|
|
+ uy = OffsetZ;
|
|
|
+ uz = -OffsetY;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ //Rotating Y Axis
|
|
|
+ switch (ry){
|
|
|
+ default:
|
|
|
+ tx = ux;
|
|
|
+ ty = uy;
|
|
|
+ tz = uz;
|
|
|
+ break;
|
|
|
+ case 1:
|
|
|
+ tx = -uz;
|
|
|
+ ty = uy;
|
|
|
+ tz = ux;
|
|
|
+ break;
|
|
|
+ case 2:
|
|
|
+ tx = -ux;
|
|
|
+ ty = uy;
|
|
|
+ tz = -uz;
|
|
|
+ break;
|
|
|
+ case 3:
|
|
|
+ tx = uz;
|
|
|
+ ty = uy;
|
|
|
+ tz = -ux;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ //Rotating Z Axis
|
|
|
+ switch (rz){
|
|
|
+ default:
|
|
|
+ ux = tx;
|
|
|
+ uy = ty;
|
|
|
+ uz = tz;
|
|
|
+ break;
|
|
|
+ case 1:
|
|
|
+ ux = -ty;
|
|
|
+ uy = tx;
|
|
|
+ uz = tz;
|
|
|
+ break;
|
|
|
+ case 2:
|
|
|
+ ux = -tx;
|
|
|
+ uy = -ty;
|
|
|
+ uz = tz;
|
|
|
+ break;
|
|
|
+ case 3:
|
|
|
+ ux = ty;
|
|
|
+ uy = -tx;
|
|
|
+ uz = tz;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ return new OffsetVector(ux, uy, uz);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void FastDefine_4Dir(){
|
|
|
+ DefineMetaRotation(0, new RotationVector(0,0,0));
|
|
|
+ DefineMetaRotation(1, new RotationVector(0,1,0));
|
|
|
+ DefineMetaRotation(2, new RotationVector(0,2,0));
|
|
|
+ DefineMetaRotation(3, new RotationVector(0,3,0));
|
|
|
+ DefineMetaRotation(4, new RotationVector(0,0,0));
|
|
|
+ DefineMetaRotation(5, new RotationVector(0,1,0));
|
|
|
+ DefineMetaRotation(6, new RotationVector(0,2,0));
|
|
|
+ DefineMetaRotation(7, new RotationVector(0,3,0));
|
|
|
+ DefineMetaRotation(8, new RotationVector(0,0,0));
|
|
|
+ DefineMetaRotation(9, new RotationVector(0,1,0));
|
|
|
+ DefineMetaRotation(10, new RotationVector(0,2,0));
|
|
|
+ DefineMetaRotation(11, new RotationVector(0,3,0));
|
|
|
+ DefineMetaRotation(12, new RotationVector(0,0,0));
|
|
|
+ DefineMetaRotation(13, new RotationVector(0,1,0));
|
|
|
+ DefineMetaRotation(14, new RotationVector(0,2,0));
|
|
|
+ DefineMetaRotation(15, new RotationVector(0,3,0));
|
|
|
+ }
|
|
|
+
|
|
|
+ public void FastPlaceConv_4Dir(World world, int x, int y, int z, EntityLivingBase player, ItemStack itemStack){
|
|
|
+ int side = world.getBlockMetadata(x, y, z);
|
|
|
+ int l = MathHelper.floor_double((double)(player.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;
|
|
|
+ int ro = PlaceSideEnum.TransToRotation(PlaceSideEnum.valueOf(side));
|
|
|
+ if(ro == -1){
|
|
|
+ ro = PlaceSideEnum.TransToRotation(PlaceSideEnum.fromYaw(l));
|
|
|
+ }
|
|
|
+ world.setBlockMetadataWithNotify(x, y, z, ro, 2);
|
|
|
+ }
|
|
|
+
|
|
|
+}
|