Nessiesson

Untitled

Mar 15th, 2019
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.51 KB | None | 0 0
  1. package nessiesson.uselessmod.mixins;
  2.  
  3. import com.mojang.authlib.GameProfile;
  4. import net.minecraft.client.entity.AbstractClientPlayer;
  5. import net.minecraft.client.entity.EntityPlayerSP;
  6. import net.minecraft.util.math.BlockPos;
  7. import net.minecraft.world.World;
  8. import org.spongepowered.asm.mixin.Mixin;
  9. import org.spongepowered.asm.mixin.Overwrite;
  10. import org.spongepowered.asm.mixin.Shadow;
  11. import org.spongepowered.asm.mixin.injection.At;
  12. import org.spongepowered.asm.mixin.injection.Inject;
  13. import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
  14.  
  15. @Mixin(EntityPlayerSP.class)
  16. public abstract class MixinEntityPlayerSP extends AbstractClientPlayer {
  17.     @Shadow
  18.     protected abstract boolean isOpenBlockSpace(BlockPos pos);
  19.  
  20.     public MixinEntityPlayerSP(World worldIn, GameProfile playerProfile) {
  21.         super(worldIn, playerProfile);
  22.     }
  23.  
  24.     @Inject(method = "isOpenBlockSpace", at = @At("HEAD"), cancellable = true)
  25.     private void adjustIsOpenBlockSpace(BlockPos pos, CallbackInfoReturnable<Boolean> cir) {
  26.         cir.setReturnValue(!this.world.getBlockState(pos).isNormalCube());
  27.     }
  28.  
  29.     private boolean isHeadspaceFree(BlockPos pos, int height) {
  30.         for (int y = 0; y < height; ++y) {
  31.             if (!this.isOpenBlockSpace(pos.add(0, y, 0))) {
  32.                 return false;
  33.             }
  34.         }
  35.         return true;
  36.     }
  37.  
  38.     @SuppressWarnings("OverwriteAuthorRequired")
  39.     @Overwrite
  40.     protected boolean pushOutOfBlocks(double x, double y, double z) {
  41.         if (this.noClip) {
  42.             return false;
  43.         } else {
  44.             BlockPos blockpos = new BlockPos(x, y, z);
  45.             double d0 = x - (double) blockpos.getX();
  46.             double d1 = z - (double) blockpos.getZ();
  47.             int entHeight = Math.max((int) Math.ceil(this.height), 1);
  48.             boolean inTranslucentBlock = !this.isHeadspaceFree(blockpos, entHeight);
  49.  
  50.             if (inTranslucentBlock) {
  51.                 int i = -1;
  52.                 double d2 = 9999.0D;
  53.  
  54.                 if (this.isHeadspaceFree(blockpos.west(), entHeight) && d0 < d2) {
  55.                     d2 = d0;
  56.                     i = 0;
  57.                 }
  58.  
  59.                 if (this.isHeadspaceFree(blockpos.east(), entHeight) && 1.0D - d0 < d2) {
  60.                     d2 = 1.0D - d0;
  61.                     i = 1;
  62.                 }
  63.  
  64.                 if (this.isHeadspaceFree(blockpos.north(), entHeight) && d1 < d2) {
  65.                     d2 = d1;
  66.                     i = 4;
  67.                 }
  68.  
  69.                 if (this.isHeadspaceFree(blockpos.south(), entHeight) && 1.0D - d1 < d2) {
  70.                     i = 5;
  71.                 }
  72.  
  73.                 float f = 0.1F;
  74.  
  75.                 if (i == 0) {
  76.                     this.motionX = -f;
  77.                 }
  78.  
  79.                 if (i == 1) {
  80.                     this.motionX = f;
  81.                 }
  82.  
  83.                 if (i == 4) {
  84.                     this.motionZ = -f;
  85.                 }
  86.  
  87.                 if (i == 5) {
  88.                     this.motionZ = f;
  89.                 }
  90.             }
  91.  
  92.             return false;
  93.         }
  94.     }
  95. }
Advertisement
Add Comment
Please, Sign In to add comment