Camellias_

Untitled

Aug 11th, 2019
428
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.56 KB | None | 0 0
  1. package com.camellias.stardust.common.entities.misc;
  2.  
  3. import net.minecraft.client.Minecraft;
  4. import net.minecraft.client.settings.GameSettings;
  5. import net.minecraft.entity.Entity;
  6. import net.minecraft.entity.EntityLivingBase;
  7. import net.minecraft.entity.MoverType;
  8. import net.minecraft.entity.player.EntityPlayer;
  9. import net.minecraft.nbt.NBTTagCompound;
  10. import net.minecraft.util.EnumActionResult;
  11. import net.minecraft.util.EnumHand;
  12. import net.minecraft.util.math.MathHelper;
  13. import net.minecraft.util.math.Vec3d;
  14. import net.minecraft.world.World;
  15.  
  16. public class EntitySpaceShip extends Entity
  17. {
  18.     Entity rider = getControllingPassenger();
  19.    
  20.     public EntitySpaceShip(World world)
  21.     {
  22.         super(world);
  23.     }
  24.    
  25.     @Override
  26.     protected void entityInit()
  27.     {
  28.         setSize(12F, 5F);
  29.         noClip = true;
  30.     }
  31.    
  32.     @Override
  33.     public boolean processInitialInteract(EntityPlayer player, EnumHand hand)
  34.     {
  35.         if(!world.isRemote && !isBeingRidden())
  36.         {
  37.             player.startRiding(this);
  38.             return true;
  39.         }
  40.         return false;
  41.     }
  42.    
  43.     @Override
  44.     public double getMountedYOffset()
  45.     {
  46.         return super.getMountedYOffset();
  47.     }
  48.    
  49.     @Override
  50.     public boolean canPassengerSteer()
  51.     {
  52.         return true;
  53.     }
  54.    
  55.     public boolean canBeSteered()
  56.     {
  57.         return getControllingPassenger() instanceof EntityLivingBase;
  58.     }
  59.    
  60.     @Override
  61.     public Entity getControllingPassenger()
  62.     {
  63.         return getPassengers().isEmpty() ? null : getPassengers().get(0);
  64.     }
  65.    
  66.     @Override
  67.     public void onUpdate()
  68.     {
  69.         super.onUpdate();
  70.         if(getControllingPassenger() != null)
  71.         {
  72.             motionX = rider.motionX;
  73.             motionZ = rider.motionZ;
  74.             if(rider.rotationPitch > rotationPitch + 25) rider.rotationPitch = (rotationPitch + 25);
  75.             if(rider.rotationPitch < rotationPitch - 25) rider.rotationPitch = (rotationPitch - 25);
  76.             if(rider.rotationYaw > rotationYaw + 15) rider.rotationYaw = (rotationYaw + 15);
  77.             if(rider.rotationYaw < rotationYaw - 15) rider.rotationYaw = (rotationYaw - 15);
  78.            
  79.             if(rider instanceof EntityPlayer)
  80.             {
  81.                 GameSettings settings = Minecraft.getMinecraft().gameSettings;
  82.                
  83.                 if(isAirBorne)
  84.                 {
  85.                     if(settings.isKeyDown(settings.keyBindJump))
  86.                     {
  87.                         motionY = MathHelper.clamp(motionY += 0.2D, -2D, 2D);
  88.                         rotationPitch = MathHelper.clamp(rotationPitch++, -90, 90);
  89.                     }
  90.                     else
  91.                     {
  92.                         motionY = MathHelper.clamp(motionY -= 0.2D, -2D, 2D);
  93.                         rotationPitch = MathHelper.clamp(rotationPitch--, -90, 90);
  94.                     }
  95.                    
  96.                     if(settings.isKeyDown(settings.keyBindRight))
  97.                     {
  98.                         rotationYaw = MathHelper.clamp(rotationYaw--, -30, 30);
  99.                     }
  100.                    
  101.                     if(settings.isKeyDown(settings.keyBindLeft))
  102.                     {
  103.                         rotationYaw = MathHelper.clamp(rotationYaw++, -30, 30);
  104.                     }
  105.                 }
  106.                 else if(onGround)
  107.                 {
  108.                     motionY = 0;
  109.                     rotationPitch = 0;
  110.                 }
  111.             }
  112.         }
  113.        
  114.         move(MoverType.SELF, motionX, motionY, motionZ);
  115.     }
  116.    
  117.     @Override
  118.     protected void readEntityFromNBT(NBTTagCompound nbt)
  119.     {
  120.         if(nbt.hasKey("posX")) posX = nbt.getDouble("posX");
  121.         if(nbt.hasKey("posY")) posY = nbt.getDouble("posY");
  122.         if(nbt.hasKey("posZ")) posZ = nbt.getDouble("posZ");
  123.        
  124.         if(nbt.hasKey("motionX")) motionX = nbt.getDouble("motionX");
  125.         if(nbt.hasKey("motionY")) motionY = nbt.getDouble("motionY");
  126.         if(nbt.hasKey("motionZ")) motionZ = nbt.getDouble("motionZ");
  127.     }
  128.    
  129.     @Override
  130.     protected void writeEntityToNBT(NBTTagCompound nbt)
  131.     {
  132.         nbt.setDouble("posX", posX);
  133.         nbt.setDouble("posY", posY);
  134.         nbt.setDouble("posZ", posZ);
  135.        
  136.         nbt.setDouble("motionX", motionX);
  137.         nbt.setDouble("motionY", motionY);
  138.         nbt.setDouble("motionZ", motionZ);
  139.     }
  140. }
Advertisement
Add Comment
Please, Sign In to add comment