Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package nessiesson.uselessmod.mixins;
- import com.mojang.authlib.GameProfile;
- import net.minecraft.client.entity.AbstractClientPlayer;
- import net.minecraft.client.entity.EntityPlayerSP;
- import net.minecraft.util.math.BlockPos;
- import net.minecraft.world.World;
- import org.spongepowered.asm.mixin.Mixin;
- import org.spongepowered.asm.mixin.Overwrite;
- import org.spongepowered.asm.mixin.Shadow;
- import org.spongepowered.asm.mixin.injection.At;
- import org.spongepowered.asm.mixin.injection.Inject;
- import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
- @Mixin(EntityPlayerSP.class)
- public abstract class MixinEntityPlayerSP extends AbstractClientPlayer {
- @Shadow
- protected abstract boolean isOpenBlockSpace(BlockPos pos);
- public MixinEntityPlayerSP(World worldIn, GameProfile playerProfile) {
- super(worldIn, playerProfile);
- }
- @Inject(method = "isOpenBlockSpace", at = @At("HEAD"), cancellable = true)
- private void adjustIsOpenBlockSpace(BlockPos pos, CallbackInfoReturnable<Boolean> cir) {
- cir.setReturnValue(!this.world.getBlockState(pos).isNormalCube());
- }
- private boolean isHeadspaceFree(BlockPos pos, int height) {
- for (int y = 0; y < height; ++y) {
- if (!this.isOpenBlockSpace(pos.add(0, y, 0))) {
- return false;
- }
- }
- return true;
- }
- @SuppressWarnings("OverwriteAuthorRequired")
- @Overwrite
- protected boolean pushOutOfBlocks(double x, double y, double z) {
- if (this.noClip) {
- return false;
- } else {
- BlockPos blockpos = new BlockPos(x, y, z);
- double d0 = x - (double) blockpos.getX();
- double d1 = z - (double) blockpos.getZ();
- int entHeight = Math.max((int) Math.ceil(this.height), 1);
- boolean inTranslucentBlock = !this.isHeadspaceFree(blockpos, entHeight);
- if (inTranslucentBlock) {
- int i = -1;
- double d2 = 9999.0D;
- if (this.isHeadspaceFree(blockpos.west(), entHeight) && d0 < d2) {
- d2 = d0;
- i = 0;
- }
- if (this.isHeadspaceFree(blockpos.east(), entHeight) && 1.0D - d0 < d2) {
- d2 = 1.0D - d0;
- i = 1;
- }
- if (this.isHeadspaceFree(blockpos.north(), entHeight) && d1 < d2) {
- d2 = d1;
- i = 4;
- }
- if (this.isHeadspaceFree(blockpos.south(), entHeight) && 1.0D - d1 < d2) {
- i = 5;
- }
- float f = 0.1F;
- if (i == 0) {
- this.motionX = -f;
- }
- if (i == 1) {
- this.motionX = f;
- }
- if (i == 4) {
- this.motionZ = -f;
- }
- if (i == 5) {
- this.motionZ = f;
- }
- }
- return false;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment