Jump to content

[1.12 MCP] Can't noClip through blocks


Hyblocker

Recommended Posts

Firstly, I'm not sure where to post this as there's no dedicated MCP forum, and I know that MCP is developed and maintained by LexManos, the person who also maintains Minecraft Forge.

 

The actual problem:

I'm working on a hacked client for Minecraft 1.12, and I've been stuck with freecam now. How do I make the player noclip through blocks? I'm able to fly, I'm not sending movement packets to the server and the only problem now is that I'm unable to noclip through blocks. I've tried Minecraft.getMinecraft().player.noClip=true;, but nothing happens.

 

Here is my freecam class:

 

import org.lwjgl.input.Keyboard;

import com.hyblocker.client.module.Category;
import com.hyblocker.client.module.Module;

import net.minecraft.client.entity.EntityOtherPlayerMP;
import net.minecraft.entity.player.EntityPlayer;

public class Freecam extends Module {
	
	double oldX;
	double oldY;
	double oldZ;
	EntityOtherPlayerMP fakePlayer;
	
	public Freecam() {
		super("Freecam",Keyboard.KEY_U, Category.RENDER);
	}
	
	public void onEnable() {
		fakePlayer = new EntityOtherPlayerMP(mc.world, mc.player.getGameProfile());
		if(mc.inGameHasFocus){
			oldX = mc.player.posX;
			oldY = mc.player.posY;
			oldZ = mc.player.posZ;
			fakePlayer.setEntityId(-1881);
			fakePlayer.inventory.copyInventory(mc.player.inventory);
			fakePlayer.getDataManager().set(EntityPlayer.PLAYER_MODEL_FLAG, mc.player.getDataManager().get(EntityPlayer.PLAYER_MODEL_FLAG));
			fakePlayer.copyLocationAndAnglesFrom(mc.player);
			fakePlayer.rotationYawHead = mc.player.rotationYawHead;
			mc.world.addEntityToWorld(fakePlayer.getEntityId(), fakePlayer);
			fakePlayer.noClip=true;
		}
	}
	
	public void onDisable() {
		if(mc.inGameHasFocus){
			mc.player.setLocationAndAngles(oldX, oldY, oldZ, mc.player.rotationYaw, mc.player.rotationPitch);
			fakePlayer.noClip=false;
			mc.player.noClip=false;
			mc.world.removeEntityFromWorld(fakePlayer.getEntityId());
		}
	}
	
	public void onUpdate() {
		if(getState()) {
			mc.player.motionX = 0;
			mc.player.motionY = 0;
			mc.player.motionZ = 0;
			mc.player.jumpMovementFactor = (float) Flight.flightSpeed.getValue();
			
			if(mc.gameSettings.keyBindJump.isKeyDown()){
				mc.player.motionY += Flight.flightSpeed.getValue();
			}
			if(mc.gameSettings.keyBindSneak.isKeyDown()){
				mc.player.motionY -= Flight.flightSpeed.getValue();
			}
			mc.player.noClip=true;
			fakePlayer.noClip=true;
		}
	}
}

 

Here is my modified onUpdateWalkingPlayer() method (net.minecraft.client.entity.EntityPlayerSP):

 

private void onUpdateWalkingPlayer()
    {
        boolean flag = this.isSprinting();

        if (flag != this.serverSprintState)
        {
            if (flag||Client.moduleManager.getModule(Sprint.class).getState())
            {
                this.connection.sendPacket(new CPacketEntityAction(this, CPacketEntityAction.Action.START_SPRINTING));
            }
            else if(!Client.moduleManager.getModule(Sprint.class).getState())
            {
                this.connection.sendPacket(new CPacketEntityAction(this, CPacketEntityAction.Action.STOP_SPRINTING));
            }

            this.serverSprintState = flag;
        }

        boolean flag1 = this.isSneaking();

        if (flag1 != this.serverSneakState)
        {
            if (flag1||Client.moduleManager.getModule(Sneak.class).getState())
            {
                this.connection.sendPacket(new CPacketEntityAction(this, CPacketEntityAction.Action.START_SNEAKING));
            }
            else if(!Client.moduleManager.getModule(Sneak.class).getState())
            {
                this.connection.sendPacket(new CPacketEntityAction(this, CPacketEntityAction.Action.STOP_SNEAKING));
            }

            this.serverSneakState = flag1;
        }

        if (this.isCurrentViewEntity())
        {
            AxisAlignedBB axisalignedbb = this.getEntityBoundingBox();
            double d0 = this.posX - this.lastReportedPosX;
            double d1 = axisalignedbb.minY - this.lastReportedPosY;
            double d2 = this.posZ - this.lastReportedPosZ;
            double d3 = (double)(this.rotationYaw - this.lastReportedYaw);
            double d4 = (double)(this.rotationPitch - this.lastReportedPitch);
            ++this.positionUpdateTicks;
            boolean flag2 = d0 * d0 + d1 * d1 + d2 * d2 > 9.0E-4D || this.positionUpdateTicks >= 20;
            boolean flag3 = d3 != 0.0D || d4 != 0.0D;

	        if (this.isRiding())
	        {
	            this.connection.sendPacket(new CPacketPlayer.PositionRotation(this.motionX, -999.0D, this.motionZ, this.rotationYaw, this.rotationPitch, this.onGround));
	            flag2 = false;
	        }
	        else if(!Client.moduleManager.getModule(Freecam.class).getState()){
		        if (flag2 && flag3)
		        {
		            this.connection.sendPacket(new CPacketPlayer.PositionRotation(this.posX, axisalignedbb.minY, this.posZ, this.rotationYaw, this.rotationPitch, this.onGround));
		        }
		        else if (flag2)
		        {
		        	this.connection.sendPacket(new CPacketPlayer.Position(this.posX, axisalignedbb.minY, this.posZ, this.onGround));
		        }
		        else if (flag3)
		        {
		            this.connection.sendPacket(new CPacketPlayer.Rotation(this.rotationYaw, this.rotationPitch, this.onGround));
		        }
	        }
	        else if(Client.moduleManager.getModule(Freecam.class).getState()) {
				mc.player.noClip=true;
	        }
	        else if (this.prevOnGround != this.onGround||Client.moduleManager.getModule(NoFall.class).getState())
	        {
	        	this.connection.sendPacket(new CPacketPlayer(this.onGround));
	        }

            if (flag2)
            {
                this.lastReportedPosX = this.posX;
                this.lastReportedPosY = axisalignedbb.minY;
                this.lastReportedPosZ = this.posZ;
                this.positionUpdateTicks = 0;
            }

            if (flag3)
            {
                this.lastReportedYaw = this.rotationYaw;
                this.lastReportedPitch = this.rotationPitch;
            }

            this.prevOnGround = this.onGround;
            this.autoJumpEnabled = this.mc.gameSettings.autoJump;
        }
    }

 

The getState() method returns a boolean indicating whether the module is active or not. 

The ModuleManager class returns a loaded module.

 

Also ignore the bad coding practices (package names, etc.). They're like that because I don't want to share the name of my client and my full code.

Link to comment
Share on other sites

  • Guest locked this topic
Guest
This topic is now closed to further replies.


×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.