123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353 |
- 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);
- }
- }
|