Advertisement
Guest User

SafeOrient - SafePlayer.java

a guest
Dec 12th, 2012
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.42 KB | None | 0 0
  1. package net.isageek.joethornton.Orientation;
  2.  
  3. import net.minecraft.server.ControllerLook;
  4. import net.minecraft.server.ControllerMove;
  5. import net.minecraft.server.EntityPlayer;
  6. import net.minecraft.server.ItemInWorldManager;
  7. import net.minecraft.server.NBTTagCompound;
  8. import net.minecraft.server.NetServerHandler;
  9.  
  10.  
  11. public class SafePlayer extends EntityPlayer {
  12.    
  13.     protected Float realPitch = 0.0F;
  14.     protected Float realYaw = 90.0F;
  15.     private SafeControllerMove mController;
  16.     private SafeControllerLook lController;
  17.    
  18.     public SafePlayer(EntityPlayer entityplayer) {
  19.         super(entityplayer.server, entityplayer.world, entityplayer.name,
  20.                 new ItemInWorldManager(entityplayer.world) /*entityplayer.itemInWorldManager*/);
  21.         this.inventory.items = entityplayer.inventory.getContents();
  22.         this.inventory.armor = entityplayer.inventory.getArmorContents();
  23.         this.inventory.itemInHandIndex = entityplayer.inventory.itemInHandIndex;
  24.         this.inventory.setCarried(entityplayer.inventory.getCarried());
  25.         this.inventory.update();
  26.         this.health = entityplayer.getHealth();
  27.         this.foodData = entityplayer.getFoodData();
  28.         this.expLevel = entityplayer.expLevel;
  29.         this.expTotal = entityplayer.expTotal;
  30.         this.exp = entityplayer.exp;
  31.         this.q = entityplayer.q;
  32.         this.id = entityplayer.id;
  33.         this.locX = entityplayer.locX;
  34.         this.locY = entityplayer.locY;
  35.         this.locZ = entityplayer.locZ;
  36.         this.dimension = entityplayer.dimension;
  37.         this.abilities = entityplayer.abilities;
  38.         this.mController = new SafeControllerMove(this);
  39.         this.lController = new SafeControllerLook(this);
  40.         this.bukkitEntity = entityplayer.getBukkitEntity();
  41.         this.netServerHandler = new NetServerHandler(
  42.                 this.server, entityplayer.netServerHandler.networkManager, this);
  43.         this.setRot(this.pitch, this.yaw);
  44.     }
  45.  
  46.     public void setRot(float p, float y) {
  47.         if (Float.isInfinite(p) || Float.isNaN(p)) {
  48.             if (Float.isInfinite(this.lastPitch) || Float.isNaN(this.lastPitch)) {
  49.                 this.lastPitch = this.realPitch;
  50.                 this.pitch = this.realPitch;
  51.             }
  52.             this.pitch = this.lastPitch = this.realPitch;
  53.         }
  54.         this.lastPitch = this.pitch = p;
  55.        
  56.         if (Float.isInfinite(y) || Float.isNaN(y)) {
  57.             if (Float.isInfinite(this.lastYaw) || Float.isNaN(this.lastYaw)) {
  58.                 this.lastYaw = this.realYaw;
  59.                 this.yaw = this.realYaw;
  60.             }
  61.             this.yaw = this.lastYaw = this.realYaw;
  62.         }
  63.         this.lastYaw = this.yaw = y;       
  64.     }
  65.    
  66.     public void setPitch(float p) {
  67.         if (Float.isInfinite(p) || Float.isNaN(p)) {
  68.             if (Float.isInfinite(this.lastPitch) || Float.isNaN(this.lastPitch)) {
  69.                 this.lastPitch = this.realPitch;
  70.                 this.pitch = this.realPitch;
  71.             }
  72.             this.pitch = this.lastPitch = this.realPitch;
  73.         }
  74.         this.lastPitch = this.pitch = p;       
  75.     }
  76.    
  77.     public void setYaw(float y) {
  78.         if (Float.isInfinite(y) || Float.isNaN(y)) {
  79.             if (Float.isInfinite(this.lastYaw) || Float.isNaN(this.lastYaw)) {
  80.                 this.lastYaw = this.realYaw;
  81.                 this.yaw = this.realYaw;
  82.             }
  83.             this.yaw = this.lastYaw = this.realYaw;
  84.         }
  85.         this.lastYaw = this.yaw = y;       
  86.     }
  87.        
  88.     @Override
  89.     public ControllerMove getControllerMove() {
  90.         return this.mController;
  91.     }
  92.    
  93.     @Override
  94.     public ControllerLook getControllerLook() {
  95.         return this.lController;
  96.     }
  97.    
  98.     /*
  99.     public Navigation getNavigation() {
  100.         return this.navigation;
  101.     }*/
  102.    
  103.     @Override
  104.     protected void b(float f, float f1) {        
  105.         setRot(f1,f);
  106.     }
  107.    
  108.     @Override
  109.     public void setLocation(double d0, double d1, double d2, float f, float f1) {
  110.         this.lastX = this.locX = d0;
  111.         this.lastY = this.locY = d1;
  112.         this.lastZ = this.locZ = d2;
  113.         setRot(f1, f);
  114.         this.V = 0.0F;
  115.         double d3 = (double) (this.lastYaw - this.yaw);
  116.  
  117.         if (d3 < -180.0D) {
  118.             this.lastYaw += 360.0F;
  119.         }
  120.  
  121.         if (d3 >= 180.0D) {
  122.             this.lastYaw -= 360.0F;
  123.         }
  124.  
  125.         this.setPosition(this.locX, this.locY, this.locZ);
  126.         this.b(f, f1);
  127.     }
  128.    
  129.     @Override
  130.     public void setPositionRotation(double d0, double d1, double d2, float f, float f1) {
  131.         this.bL = this.lastX = this.locX = d0;
  132.         this.bM = this.lastY = this.locY = d1 + (double) this.height;
  133.         this.bN = this.lastZ = this.locZ = d2;
  134.         setRot(f1, f);
  135.         this.setPosition(this.locX, this.locY, this.locZ);
  136.     }
  137.    
  138.     @Override
  139.     public void d(NBTTagCompound nbttagcompound) {
  140.         nbttagcompound.set("Pos", this.a(new double[] { this.locX, this.locY + (double) this.V, this.locZ}));
  141.         nbttagcompound.set("Motion", this.a(new double[] { this.motX, this.motY, this.motZ}));
  142.  
  143.         setRot(this.pitch, this.yaw);
  144.  
  145.         nbttagcompound.set("Rotation", this.a(new float[] { this.yaw, this.pitch}));
  146.         nbttagcompound.setFloat("FallDistance", this.fallDistance);
  147.         nbttagcompound.setShort("Fire", (short) this.fireTicks);
  148.         nbttagcompound.setShort("Air", (short) this.getAirTicks());
  149.         nbttagcompound.setBoolean("OnGround", this.onGround);
  150.         // CraftBukkit start
  151.         nbttagcompound.setLong("WorldUUIDLeast", this.world.getDataManager().getUUID().getLeastSignificantBits());
  152.         nbttagcompound.setLong("WorldUUIDMost", this.world.getDataManager().getUUID().getMostSignificantBits());
  153.         nbttagcompound.setLong("UUIDLeast", this.uniqueId.getLeastSignificantBits());
  154.         nbttagcompound.setLong("UUIDMost", this.uniqueId.getMostSignificantBits());
  155.         // CraftBukkit end
  156.         this.b(nbttagcompound);
  157.     }
  158. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement