diff --git a/src/main/java/bypass/event/events/MoveEntityEvent.java b/src/main/java/bypass/event/events/MoveEntityEvent.java index 8cc9d034..ba0edeee 100644 --- a/src/main/java/bypass/event/events/MoveEntityEvent.java +++ b/src/main/java/bypass/event/events/MoveEntityEvent.java @@ -25,9 +25,10 @@ @SuppressWarnings("unused") public final class MoveEntityEvent implements IEvent, ICancelable { - private final double x; - private final double y; - private final double z; + private double x; + private double y; + private double z; + private boolean safeWalk = false; private boolean canceled = false; public MoveEntityEvent(final double x, final double y, final double z) { @@ -40,14 +41,34 @@ public double getX() { return x; } + public void setX(final double x) { + this.x = x; + } + public double getY() { return y; } + public void setY(final double y) { + this.y = y; + } + public double getZ() { return z; } + public void setZ(final double z) { + this.z = z; + } + + public boolean isSafeWalk() { + return safeWalk; + } + + public void setSafeWalk(final boolean safeWalk) { + this.safeWalk = safeWalk; + } + public boolean isCanceled() { return canceled; } diff --git a/src/main/java/bypass/lua/api/LuaEventApi.java b/src/main/java/bypass/lua/api/LuaEventApi.java index 09b1fefa..72f1a3d7 100644 --- a/src/main/java/bypass/lua/api/LuaEventApi.java +++ b/src/main/java/bypass/lua/api/LuaEventApi.java @@ -319,6 +319,92 @@ public LuaValue call() { return LuaValue.valueOf(playerMoveEvent.isCanceled()); } }); + } else if(event instanceof final MoveEntityEvent moveEntityEvent) { + eventTable.set( + "getX", + new ZeroArgFunction() { + @Override + public LuaValue call() { + return LuaValue.valueOf(moveEntityEvent.getX()); + } + }); + eventTable.set( + "getY", + new ZeroArgFunction() { + @Override + public LuaValue call() { + return LuaValue.valueOf(moveEntityEvent.getY()); + } + }); + eventTable.set( + "getZ", + new ZeroArgFunction() { + @Override + public LuaValue call() { + return LuaValue.valueOf(moveEntityEvent.getZ()); + } + }); + eventTable.set( + "setX", + new OneArgFunction() { + @Override + public LuaValue call(LuaValue xValue) { + moveEntityEvent.setX(xValue.todouble()); + return LuaValue.NIL; + } + }); + eventTable.set( + "setY", + new OneArgFunction() { + @Override + public LuaValue call(LuaValue yValue) { + moveEntityEvent.setY(yValue.todouble()); + return LuaValue.NIL; + } + }); + eventTable.set( + "setZ", + new OneArgFunction() { + @Override + public LuaValue call(LuaValue zValue) { + moveEntityEvent.setZ(zValue.todouble()); + return LuaValue.NIL; + } + }); + eventTable.set( + "isSafeWalk", + new ZeroArgFunction() { + @Override + public LuaValue call() { + return LuaValue.valueOf(moveEntityEvent.isSafeWalk()); + } + }); + eventTable.set( + "setSafeWalk", + new OneArgFunction() { + @Override + public LuaValue call(LuaValue safeWalkValue) { + moveEntityEvent.setSafeWalk(safeWalkValue.toboolean()); + return LuaValue.NIL; + } + }); + eventTable.set( + "cancel", + new ZeroArgFunction() { + @Override + public LuaValue call() { + moveEntityEvent.cancel(); + return LuaValue.NIL; + } + }); + eventTable.set( + "isCanceled", + new ZeroArgFunction() { + @Override + public LuaValue call() { + return LuaValue.valueOf(moveEntityEvent.isCanceled()); + } + }); } else if(event instanceof final PlayerInputEvent playerInputEvent) { eventTable.set( "cancel", diff --git a/src/main/java/bypass/lua/api/LuaMinecraftApi.java b/src/main/java/bypass/lua/api/LuaMinecraftApi.java index a0f0d4eb..4c3ddd08 100644 --- a/src/main/java/bypass/lua/api/LuaMinecraftApi.java +++ b/src/main/java/bypass/lua/api/LuaMinecraftApi.java @@ -759,7 +759,7 @@ public LuaValue call() { new ZeroArgFunction() { @Override public LuaValue call() { - return LuaValue.valueOf(minecraft.thePlayer != null && minecraft.thePlayer.isInWater()); + return LuaValue.valueOf(isInLiquid()); } }); set( @@ -767,16 +767,7 @@ public LuaValue call() { new ZeroArgFunction() { @Override public LuaValue call() { - if(minecraft.thePlayer == null || minecraft.theWorld == null) { - return LuaValue.FALSE; - } - BlockPos pos = - new BlockPos( - minecraft.thePlayer.posX, - minecraft.thePlayer.getEntityBoundingBox().minY - 0.1, - minecraft.thePlayer.posZ); - return LuaValue.valueOf( - minecraft.theWorld.getBlockState(pos).getBlock() instanceof BlockLiquid); + return LuaValue.valueOf(isOnLiquid()); } }); set( @@ -1217,4 +1208,23 @@ public LuaValue call() { } ); } + + public static boolean isInLiquid() { + return isLiquidAtOffset(0.0D); + } + + public static boolean isOnLiquid() { + return isLiquidAtOffset(-0.01D); + } + + private static boolean isLiquidAtOffset(final double yOffset) { + if(minecraft.thePlayer == null || minecraft.theWorld == null) { + return false; + } + return minecraft.theWorld.isAnyLiquid( + minecraft.thePlayer + .getEntityBoundingBox() + .contract(0.001D, 0.001D, 0.001D) + .offset(0.0D, yOffset, 0.0D)); + } } diff --git a/src/main/java/net/minecraft/block/BlockLiquid.java b/src/main/java/net/minecraft/block/BlockLiquid.java index 7b42e8e6..895fac23 100644 --- a/src/main/java/net/minecraft/block/BlockLiquid.java +++ b/src/main/java/net/minecraft/block/BlockLiquid.java @@ -1,6 +1,5 @@ package net.minecraft.block; -import java.util.Random; import net.minecraft.block.material.Material; import net.minecraft.block.properties.IProperty; import net.minecraft.block.properties.PropertyInteger; @@ -9,98 +8,77 @@ import net.minecraft.entity.Entity; import net.minecraft.init.Blocks; import net.minecraft.item.Item; -import net.minecraft.util.AxisAlignedBB; -import net.minecraft.util.BlockPos; -import net.minecraft.util.EnumFacing; -import net.minecraft.util.EnumParticleTypes; -import net.minecraft.util.EnumWorldBlockLayer; -import net.minecraft.util.MathHelper; -import net.minecraft.util.Vec3; +import net.minecraft.util.*; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import net.minecraft.world.biome.BiomeColorHelper; -public abstract class BlockLiquid extends Block -{ +import java.util.Random; + +public abstract class BlockLiquid extends Block { public static final PropertyInteger LEVEL = PropertyInteger.create("level", 0, 15); - protected BlockLiquid(Material materialIn) - { + protected BlockLiquid(Material materialIn) { super(materialIn); this.setDefaultState(this.blockState.getBaseState().withProperty(LEVEL, Integer.valueOf(0))); this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F); this.setTickRandomly(true); } - public boolean isPassable(IBlockAccess worldIn, BlockPos pos) - { + public boolean isPassable(IBlockAccess worldIn, BlockPos pos) { return this.blockMaterial != Material.lava; } - public int colorMultiplier(IBlockAccess worldIn, BlockPos pos, int renderPass) - { + public int colorMultiplier(IBlockAccess worldIn, BlockPos pos, int renderPass) { return this.blockMaterial == Material.water ? BiomeColorHelper.getWaterColorAtPos(worldIn, pos) : 16777215; } - public static float getLiquidHeightPercent(int meta) - { - if (meta >= 8) - { + public static float getLiquidHeightPercent(int meta) { + if(meta >= 8) { meta = 0; } - return (float)(meta + 1) / 9.0F; + return (float) (meta + 1) / 9.0F; } - protected int getLevel(IBlockAccess worldIn, BlockPos pos) - { - return worldIn.getBlockState(pos).getBlock().getMaterial() == this.blockMaterial ? ((Integer)worldIn.getBlockState(pos).getValue(LEVEL)).intValue() : -1; + protected int getLevel(IBlockAccess worldIn, BlockPos pos) { + return worldIn.getBlockState(pos).getBlock().getMaterial() == this.blockMaterial ? ((Integer) worldIn.getBlockState(pos).getValue(LEVEL)).intValue() : -1; } - protected int getEffectiveFlowDecay(IBlockAccess worldIn, BlockPos pos) - { + protected int getEffectiveFlowDecay(IBlockAccess worldIn, BlockPos pos) { int i = this.getLevel(worldIn, pos); return i >= 8 ? 0 : i; } - public boolean isFullCube() - { + public boolean isFullCube() { return false; } - public boolean isOpaqueCube() - { + public boolean isOpaqueCube() { return false; } - public boolean canCollideCheck(IBlockState state, boolean hitIfLiquid) - { - return hitIfLiquid && ((Integer)state.getValue(LEVEL)).intValue() == 0; + public boolean canCollideCheck(IBlockState state, boolean hitIfLiquid) { + return hitIfLiquid && ((Integer) state.getValue(LEVEL)).intValue() == 0; } - public boolean isBlockSolid(IBlockAccess worldIn, BlockPos pos, EnumFacing side) - { + public boolean isBlockSolid(IBlockAccess worldIn, BlockPos pos, EnumFacing side) { Material material = worldIn.getBlockState(pos).getBlock().getMaterial(); return material == this.blockMaterial ? false : (side == EnumFacing.UP ? true : (material == Material.ice ? false : super.isBlockSolid(worldIn, pos, side))); } - public boolean shouldSideBeRendered(IBlockAccess worldIn, BlockPos pos, EnumFacing side) - { + public boolean shouldSideBeRendered(IBlockAccess worldIn, BlockPos pos, EnumFacing side) { return worldIn.getBlockState(pos).getBlock().getMaterial() == this.blockMaterial ? false : (side == EnumFacing.UP ? true : super.shouldSideBeRendered(worldIn, pos, side)); } - public boolean shouldRenderSides(IBlockAccess blockAccess, BlockPos pos) - { - for (int i = -1; i <= 1; ++i) - { - for (int j = -1; j <= 1; ++j) - { + public boolean shouldRenderSides(IBlockAccess blockAccess, BlockPos pos) { + for(int i = -1; i <= 1; ++i) { + for(int j = -1; j <= 1; ++j) { IBlockState iblockstate = blockAccess.getBlockState(pos.add(i, 0, j)); Block block = iblockstate.getBlock(); Material material = block.getMaterial(); - if (material != this.blockMaterial && !block.isFullBlock()) - { + if(material != this.blockMaterial && !block.isFullBlock()) { return true; } } @@ -109,64 +87,60 @@ public boolean shouldRenderSides(IBlockAccess blockAccess, BlockPos pos) return false; } - public AxisAlignedBB getCollisionBoundingBox(World worldIn, BlockPos pos, IBlockState state) - { + public AxisAlignedBB getCollisionBoundingBox(World worldIn, BlockPos pos, IBlockState state) { + if(bypass.lua.api.LuaMinecraftApi.jesusActive) { + net.minecraft.client.Minecraft mc = net.minecraft.client.Minecraft.getMinecraft(); + if(mc.thePlayer != null + && !bypass.lua.api.LuaMinecraftApi.isInLiquid() + && !mc.thePlayer.isSneaking() + && mc.thePlayer.fallDistance <= 3.0F + && pos.getY() + 1.0D <= mc.thePlayer.getEntityBoundingBox().minY) { + return new AxisAlignedBB(pos.getX(), pos.getY(), pos.getZ(), pos.getX() + 1.0D, pos.getY() + 1.0D, pos.getZ() + 1.0D); + } + } return null; } - public int getRenderType() - { + public int getRenderType() { return 1; } - public Item getItemDropped(IBlockState state, Random rand, int fortune) - { + public Item getItemDropped(IBlockState state, Random rand, int fortune) { return null; } - public int quantityDropped(Random random) - { + public int quantityDropped(Random random) { return 0; } - protected Vec3 getFlowVector(IBlockAccess worldIn, BlockPos pos) - { + protected Vec3 getFlowVector(IBlockAccess worldIn, BlockPos pos) { Vec3 vec3 = new Vec3(0.0D, 0.0D, 0.0D); int i = this.getEffectiveFlowDecay(worldIn, pos); - for (EnumFacing enumfacing : EnumFacing.Plane.HORIZONTAL) - { + for(EnumFacing enumfacing : EnumFacing.Plane.HORIZONTAL) { BlockPos blockpos = pos.offset(enumfacing); int j = this.getEffectiveFlowDecay(worldIn, blockpos); - if (j < 0) - { - if (!worldIn.getBlockState(blockpos).getBlock().getMaterial().blocksMovement()) - { + if(j < 0) { + if(!worldIn.getBlockState(blockpos).getBlock().getMaterial().blocksMovement()) { j = this.getEffectiveFlowDecay(worldIn, blockpos.down()); - if (j >= 0) - { + if(j >= 0) { int k = j - (i - 8); - vec3 = vec3.addVector((double)((blockpos.getX() - pos.getX()) * k), (double)((blockpos.getY() - pos.getY()) * k), (double)((blockpos.getZ() - pos.getZ()) * k)); + vec3 = vec3.addVector((double) ((blockpos.getX() - pos.getX()) * k), (double) ((blockpos.getY() - pos.getY()) * k), (double) ((blockpos.getZ() - pos.getZ()) * k)); } } - } - else if (j >= 0) - { + } else if(j >= 0) { int l = j - i; - vec3 = vec3.addVector((double)((blockpos.getX() - pos.getX()) * l), (double)((blockpos.getY() - pos.getY()) * l), (double)((blockpos.getZ() - pos.getZ()) * l)); + vec3 = vec3.addVector((double) ((blockpos.getX() - pos.getX()) * l), (double) ((blockpos.getY() - pos.getY()) * l), (double) ((blockpos.getZ() - pos.getZ()) * l)); } } - if (((Integer)worldIn.getBlockState(pos).getValue(LEVEL)).intValue() >= 8) - { - for (EnumFacing enumfacing1 : EnumFacing.Plane.HORIZONTAL) - { + if(((Integer) worldIn.getBlockState(pos).getValue(LEVEL)).intValue() >= 8) { + for(EnumFacing enumfacing1 : EnumFacing.Plane.HORIZONTAL) { BlockPos blockpos1 = pos.offset(enumfacing1); - if (this.isBlockSolid(worldIn, blockpos1, enumfacing1) || this.isBlockSolid(worldIn, blockpos1.up(), enumfacing1)) - { + if(this.isBlockSolid(worldIn, blockpos1, enumfacing1) || this.isBlockSolid(worldIn, blockpos1.up(), enumfacing1)) { vec3 = vec3.normalize().addVector(0.0D, -6.0D, 0.0D); break; } @@ -176,18 +150,15 @@ else if (j >= 0) return vec3.normalize(); } - public Vec3 modifyAcceleration(World worldIn, BlockPos pos, Entity entityIn, Vec3 motion) - { + public Vec3 modifyAcceleration(World worldIn, BlockPos pos, Entity entityIn, Vec3 motion) { return motion.add(this.getFlowVector(worldIn, pos)); } - public int tickRate(World worldIn) - { + public int tickRate(World worldIn) { return this.blockMaterial == Material.water ? 5 : (this.blockMaterial == Material.lava ? (worldIn.provider.getHasNoSky() ? 10 : 30) : 0); } - public int getMixedBrightnessForBlock(IBlockAccess worldIn, BlockPos pos) - { + public int getMixedBrightnessForBlock(IBlockAccess worldIn, BlockPos pos) { int i = worldIn.getCombinedLight(pos, 0); int j = worldIn.getCombinedLight(pos.up(), 0); int k = i & 255; @@ -197,117 +168,92 @@ public int getMixedBrightnessForBlock(IBlockAccess worldIn, BlockPos pos) return (k > l ? k : l) | (i1 > j1 ? i1 : j1) << 16; } - public EnumWorldBlockLayer getBlockLayer() - { + public EnumWorldBlockLayer getBlockLayer() { return this.blockMaterial == Material.water ? EnumWorldBlockLayer.TRANSLUCENT : EnumWorldBlockLayer.SOLID; } - public void randomDisplayTick(World worldIn, BlockPos pos, IBlockState state, Random rand) - { - double d0 = (double)pos.getX(); - double d1 = (double)pos.getY(); - double d2 = (double)pos.getZ(); + public void randomDisplayTick(World worldIn, BlockPos pos, IBlockState state, Random rand) { + double d0 = (double) pos.getX(); + double d1 = (double) pos.getY(); + double d2 = (double) pos.getZ(); - if (this.blockMaterial == Material.water) - { - int i = ((Integer)state.getValue(LEVEL)).intValue(); + if(this.blockMaterial == Material.water) { + int i = ((Integer) state.getValue(LEVEL)).intValue(); - if (i > 0 && i < 8) - { - if (rand.nextInt(64) == 0) - { + if(i > 0 && i < 8) { + if(rand.nextInt(64) == 0) { worldIn.playSound(d0 + 0.5D, d1 + 0.5D, d2 + 0.5D, "liquid.water", rand.nextFloat() * 0.25F + 0.75F, rand.nextFloat() * 1.0F + 0.5F, false); } - } - else if (rand.nextInt(10) == 0) - { - worldIn.spawnParticle(EnumParticleTypes.SUSPENDED, d0 + (double)rand.nextFloat(), d1 + (double)rand.nextFloat(), d2 + (double)rand.nextFloat(), 0.0D, 0.0D, 0.0D, new int[0]); + } else if(rand.nextInt(10) == 0) { + worldIn.spawnParticle(EnumParticleTypes.SUSPENDED, d0 + (double) rand.nextFloat(), d1 + (double) rand.nextFloat(), d2 + (double) rand.nextFloat(), 0.0D, 0.0D, 0.0D, new int[0]); } } - if (this.blockMaterial == Material.lava && worldIn.getBlockState(pos.up()).getBlock().getMaterial() == Material.air && !worldIn.getBlockState(pos.up()).getBlock().isOpaqueCube()) - { - if (rand.nextInt(100) == 0) - { - double d8 = d0 + (double)rand.nextFloat(); + if(this.blockMaterial == Material.lava && worldIn.getBlockState(pos.up()).getBlock().getMaterial() == Material.air && !worldIn.getBlockState(pos.up()).getBlock().isOpaqueCube()) { + if(rand.nextInt(100) == 0) { + double d8 = d0 + (double) rand.nextFloat(); double d4 = d1 + this.maxY; - double d6 = d2 + (double)rand.nextFloat(); + double d6 = d2 + (double) rand.nextFloat(); worldIn.spawnParticle(EnumParticleTypes.LAVA, d8, d4, d6, 0.0D, 0.0D, 0.0D, new int[0]); worldIn.playSound(d8, d4, d6, "liquid.lavapop", 0.2F + rand.nextFloat() * 0.2F, 0.9F + rand.nextFloat() * 0.15F, false); } - if (rand.nextInt(200) == 0) - { + if(rand.nextInt(200) == 0) { worldIn.playSound(d0, d1, d2, "liquid.lava", 0.2F + rand.nextFloat() * 0.2F, 0.9F + rand.nextFloat() * 0.15F, false); } } - if (rand.nextInt(10) == 0 && World.doesBlockHaveSolidTopSurface(worldIn, pos.down())) - { + if(rand.nextInt(10) == 0 && World.doesBlockHaveSolidTopSurface(worldIn, pos.down())) { Material material = worldIn.getBlockState(pos.down(2)).getBlock().getMaterial(); - if (!material.blocksMovement() && !material.isLiquid()) - { - double d3 = d0 + (double)rand.nextFloat(); + if(!material.blocksMovement() && !material.isLiquid()) { + double d3 = d0 + (double) rand.nextFloat(); double d5 = d1 - 1.05D; - double d7 = d2 + (double)rand.nextFloat(); + double d7 = d2 + (double) rand.nextFloat(); - if (this.blockMaterial == Material.water) - { + if(this.blockMaterial == Material.water) { worldIn.spawnParticle(EnumParticleTypes.DRIP_WATER, d3, d5, d7, 0.0D, 0.0D, 0.0D, new int[0]); - } - else - { + } else { worldIn.spawnParticle(EnumParticleTypes.DRIP_LAVA, d3, d5, d7, 0.0D, 0.0D, 0.0D, new int[0]); } } } } - public static double getFlowDirection(IBlockAccess worldIn, BlockPos pos, Material materialIn) - { + public static double getFlowDirection(IBlockAccess worldIn, BlockPos pos, Material materialIn) { Vec3 vec3 = getFlowingBlock(materialIn).getFlowVector(worldIn, pos); return vec3.xCoord == 0.0D && vec3.zCoord == 0.0D ? -1000.0D : MathHelper.atan2(vec3.zCoord, vec3.xCoord) - (Math.PI / 2D); } - public void onBlockAdded(World worldIn, BlockPos pos, IBlockState state) - { + public void onBlockAdded(World worldIn, BlockPos pos, IBlockState state) { this.checkForMixing(worldIn, pos, state); } - public void onNeighborBlockChange(World worldIn, BlockPos pos, IBlockState state, Block neighborBlock) - { + public void onNeighborBlockChange(World worldIn, BlockPos pos, IBlockState state, Block neighborBlock) { this.checkForMixing(worldIn, pos, state); } - public boolean checkForMixing(World worldIn, BlockPos pos, IBlockState state) - { - if (this.blockMaterial == Material.lava) - { + public boolean checkForMixing(World worldIn, BlockPos pos, IBlockState state) { + if(this.blockMaterial == Material.lava) { boolean flag = false; - for (EnumFacing enumfacing : EnumFacing.values()) - { - if (enumfacing != EnumFacing.DOWN && worldIn.getBlockState(pos.offset(enumfacing)).getBlock().getMaterial() == Material.water) - { + for(EnumFacing enumfacing : EnumFacing.values()) { + if(enumfacing != EnumFacing.DOWN && worldIn.getBlockState(pos.offset(enumfacing)).getBlock().getMaterial() == Material.water) { flag = true; break; } } - if (flag) - { - Integer integer = (Integer)state.getValue(LEVEL); + if(flag) { + Integer integer = (Integer) state.getValue(LEVEL); - if (integer.intValue() == 0) - { + if(integer.intValue() == 0) { worldIn.setBlockState(pos, Blocks.obsidian.getDefaultState()); this.triggerMixEffects(worldIn, pos); return true; } - if (integer.intValue() <= 4) - { + if(integer.intValue() <= 4) { worldIn.setBlockState(pos, Blocks.cobblestone.getDefaultState()); this.triggerMixEffects(worldIn, pos); return true; @@ -318,62 +264,45 @@ public boolean checkForMixing(World worldIn, BlockPos pos, IBlockState state) return false; } - protected void triggerMixEffects(World worldIn, BlockPos pos) - { - double d0 = (double)pos.getX(); - double d1 = (double)pos.getY(); - double d2 = (double)pos.getZ(); + protected void triggerMixEffects(World worldIn, BlockPos pos) { + double d0 = (double) pos.getX(); + double d1 = (double) pos.getY(); + double d2 = (double) pos.getZ(); worldIn.playSoundEffect(d0 + 0.5D, d1 + 0.5D, d2 + 0.5D, "random.fizz", 0.5F, 2.6F + (worldIn.rand.nextFloat() - worldIn.rand.nextFloat()) * 0.8F); - for (int i = 0; i < 8; ++i) - { + for(int i = 0; i < 8; ++i) { worldIn.spawnParticle(EnumParticleTypes.SMOKE_LARGE, d0 + Math.random(), d1 + 1.2D, d2 + Math.random(), 0.0D, 0.0D, 0.0D, new int[0]); } } - public IBlockState getStateFromMeta(int meta) - { + public IBlockState getStateFromMeta(int meta) { return this.getDefaultState().withProperty(LEVEL, Integer.valueOf(meta)); } - public int getMetaFromState(IBlockState state) - { - return ((Integer)state.getValue(LEVEL)).intValue(); + public int getMetaFromState(IBlockState state) { + return ((Integer) state.getValue(LEVEL)).intValue(); } - protected BlockState createBlockState() - { - return new BlockState(this, new IProperty[] {LEVEL}); + protected BlockState createBlockState() { + return new BlockState(this, new IProperty[]{LEVEL}); } - public static BlockDynamicLiquid getFlowingBlock(Material materialIn) - { - if (materialIn == Material.water) - { + public static BlockDynamicLiquid getFlowingBlock(Material materialIn) { + if(materialIn == Material.water) { return Blocks.flowing_water; - } - else if (materialIn == Material.lava) - { + } else if(materialIn == Material.lava) { return Blocks.flowing_lava; - } - else - { + } else { throw new IllegalArgumentException("Invalid material"); } } - public static BlockStaticLiquid getStaticBlock(Material materialIn) - { - if (materialIn == Material.water) - { + public static BlockStaticLiquid getStaticBlock(Material materialIn) { + if(materialIn == Material.water) { return Blocks.water; - } - else if (materialIn == Material.lava) - { + } else if(materialIn == Material.lava) { return Blocks.lava; - } - else - { + } else { throw new IllegalArgumentException("Invalid material"); } } diff --git a/src/main/java/net/minecraft/client/entity/EntityPlayerSP.java b/src/main/java/net/minecraft/client/entity/EntityPlayerSP.java index a98b519c..add699e3 100644 --- a/src/main/java/net/minecraft/client/entity/EntityPlayerSP.java +++ b/src/main/java/net/minecraft/client/entity/EntityPlayerSP.java @@ -492,7 +492,9 @@ public void moveEntity(double x, double y, double z) { x = event.getX(); y = event.getY(); z = event.getZ(); + this.safeWalk = event.isSafeWalk(); super.moveEntity(x, y, z); + this.safeWalk = false; } } diff --git a/src/main/java/net/minecraft/entity/Entity.java b/src/main/java/net/minecraft/entity/Entity.java index 4375fd1f..978f3033 100644 --- a/src/main/java/net/minecraft/entity/Entity.java +++ b/src/main/java/net/minecraft/entity/Entity.java @@ -75,6 +75,7 @@ public abstract class Entity implements ICommandSender public float prevRotationPitch; private AxisAlignedBB boundingBox; public boolean onGround; + public boolean safeWalk = false; public boolean isCollidedHorizontally; public boolean isCollidedVertically; public boolean isCollided; @@ -453,7 +454,7 @@ public void moveEntity(double x, double y, double z) double d3 = x; double d4 = y; double d5 = z; - boolean flag = this.onGround && this.isSneaking() && this instanceof EntityPlayer; + boolean flag = this.onGround && (this.isSneaking() || this.safeWalk) && this instanceof EntityPlayer; if (flag) { diff --git a/src/main/resources/lua/alya.d.lua b/src/main/resources/lua/alya.d.lua index 07cd1067..bd08c361 100644 --- a/src/main/resources/lua/alya.d.lua +++ b/src/main/resources/lua/alya.d.lua @@ -104,6 +104,16 @@ ---@field getMessage fun(): string ---@field setMessage fun(message: string) +---@class AlyaMoveEntityEvent : AlyaCancelableEvent +---@field getX fun(): number +---@field getY fun(): number +---@field getZ fun(): number +---@field setX fun(x: number) +---@field setY fun(y: number) +---@field setZ fun(z: number) +---@field isSafeWalk fun(): boolean +---@field setSafeWalk fun(safeWalk: boolean) + ---@class AlyaSlowDownEvent : AlyaCancelableEvent ---@field getReason fun(): "eat"|"drink"|"block"|"bow"|"unknown" diff --git a/src/main/resources/lua/modules/movement/flight.lua b/src/main/resources/lua/modules/movement/flight.lua index df93fbd8..27c3dcc0 100644 --- a/src/main/resources/lua/modules/movement/flight.lua +++ b/src/main/resources/lua/modules/movement/flight.lua @@ -21,12 +21,14 @@ local moduleTable = alya.modules.register("Flight", "Airplane", "MOVEMENT") local mode = moduleTable.addModeSetting("Mode", "Flight mode", "Motion", "Motion", "Static", "Air Jump") local speed = moduleTable.addNumberSetting("Speed", "How fast", 1.0, 0.1, 10.0) +local antiKick = moduleTable.addBooleanSetting("AntiKick", "Prevent vanilla kick", false) +antiKick.setVisibility(function() return mode.is("Motion") end) speed.setVisibility(function() return mode.is("Motion") end) local createMotionFlightMode = loadScript("/lua/modules/movement/flight/motion.lua") local createStaticFlightMode = loadScript("/lua/modules/movement/flight/static.lua") local createAirJumpFlightMode = loadScript("/lua/modules/movement/flight/airjump.lua") -createMotionFlightMode(moduleTable, mode, speed) +createMotionFlightMode(moduleTable, mode, speed, antiKick) createStaticFlightMode(moduleTable, mode) createAirJumpFlightMode(moduleTable, mode) diff --git a/src/main/resources/lua/modules/movement/flight/motion.lua b/src/main/resources/lua/modules/movement/flight/motion.lua index 51208022..a8aedfc0 100644 --- a/src/main/resources/lua/modules/movement/flight/motion.lua +++ b/src/main/resources/lua/modules/movement/flight/motion.lua @@ -18,24 +18,29 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. --]] -local function createMotionFlightMode(moduleTable, modeSettings, speedSetting) - local glide = moduleTable.addBooleanSetting("Glide", "Slowly fall", false) +local function createMotionFlightMode(moduleTable, modeSettings, speedSetting, antiKick) local smooth = moduleTable.addBooleanSetting("Smooth", "Smooth movement", true) - glide.setVisibility(function() return modeSettings.is("Motion") end) smooth.setVisibility(function() return modeSettings.is("Motion") end) - alya.events.on("playermove", function(event) + + alya.events.on("motion", function(event) if not moduleTable.isEnabled() then return end if not modeSettings.is("Motion") then return end + if not event.isPre() then return end + if not smooth.isEnabled() then alya.mc.setCameraYaw(0.1) end + + local verticalMotion = 0.0 if alya.mc.isJumpPressed() then - alya.mc.setMotionY(alya.mc.getMotionY() + speedSetting.getValue() / 4.0) + verticalMotion = speedSetting.getValue() / 4.0 elseif alya.mc.isSneakPressed() then - alya.mc.setMotionY(alya.mc.getMotionY() - speedSetting.getValue() / 4.0) - else - alya.mc.setMotionY(glide.isEnabled() and -0.05 or 0) + verticalMotion = -speedSetting.getValue() / 4.0 + elseif antiKick.isEnabled() then + verticalMotion = -0.05 end + + alya.mc.setMotionY(verticalMotion) alya.movement.setSpeed(speedSetting.getValue()) end) end diff --git a/src/main/resources/lua/modules/movement/jesus.lua b/src/main/resources/lua/modules/movement/jesus.lua index 255886ae..77980e07 100644 --- a/src/main/resources/lua/modules/movement/jesus.lua +++ b/src/main/resources/lua/modules/movement/jesus.lua @@ -27,8 +27,22 @@ end) alya.events.on("motion", function(event) if not moduleTable.isEnabled() then return end if not event.isPre() then return end - if not alya.mc.isInWater() and not alya.mc.isOnLiquid() then return end - event.setOnGround(true) + if alya.mc.isSneakPressed() then return end + + if alya.mc.isInWater() then + if alya.mc.getFallDistance() <= 3.0 then + alya.mc.setMotionY(0.11) + end + return + end + + if alya.mc.isOnLiquid() then + event.setOnGround(true) + end +end) + +moduleTable.onEnable(function() + alya.mc.setJesusActive(true) end) moduleTable.onDisable(function() diff --git a/src/main/resources/lua/modules/movement/safewalk.lua b/src/main/resources/lua/modules/movement/safewalk.lua index f161a5c7..621d9ac7 100644 --- a/src/main/resources/lua/modules/movement/safewalk.lua +++ b/src/main/resources/lua/modules/movement/safewalk.lua @@ -19,88 +19,9 @@ --]] local moduleTable = alya.modules.register("Safewalk", "Prevents walking off edges", "MOVEMENT") -local airSetting = moduleTable.addBooleanSetting("Air", "Hug walls when in air after jumping off a block", false) -alya.events.on("update", function(event) +alya.events.on("moveentity", function(event) if not moduleTable.isEnabled() then return end if not alya.mc.isOnGround() then return end - - local playerX = alya.mc.getPlayerX() - local playerY = alya.mc.getPlayerY() - local playerZ = alya.mc.getPlayerZ() - local motionX = alya.mc.getMotionX() - local motionZ = alya.mc.getMotionZ() - local floorY = math.floor(playerY) - - if math.abs(motionX) > 0.001 then - if not alya.mc.isBlockSolid(math.floor(playerX + motionX), floorY - 1, math.floor(playerZ)) then - alya.mc.setMotionX(0) - end - end - - if math.abs(motionZ) > 0.001 then - if not alya.mc.isBlockSolid(math.floor(playerX), floorY - 1, math.floor(playerZ + motionZ)) then - alya.mc.setMotionZ(0) - end - end -end) - -alya.events.on("playerinput", function(event) - if not moduleTable.isEnabled() then return end - if not alya.mc.isOnGround() then return end - - local moveForward = alya.mc.getInputMoveForward() - local moveStrafe = alya.mc.getInputMoveStrafe() - if math.abs(moveForward) < 0.001 and math.abs(moveStrafe) < 0.001 then return end - - local playerX = alya.mc.getPlayerX() - local playerY = alya.mc.getPlayerY() - local playerZ = alya.mc.getPlayerZ() - local yaw = math.rad(alya.mc.getYaw()) - local floorY = math.floor(playerY) - - local worldX = -math.sin(yaw) * moveForward + math.cos(yaw) * moveStrafe - local worldZ = math.cos(yaw) * moveForward + math.sin(yaw) * moveStrafe - - local solidUnderX = alya.mc.isBlockSolid(math.floor(playerX + worldX * 0.4), floorY - 1, math.floor(playerZ)) - local solidUnderZ = alya.mc.isBlockSolid(math.floor(playerX), floorY - 1, math.floor(playerZ + worldZ * 0.4)) - - if not solidUnderX or not solidUnderZ then - alya.mc.setInputMoveForward(0) - alya.mc.setInputMoveStrafe(0) - end -end) - -alya.events.on("motion", function(event) - if not moduleTable.isEnabled() then return end - if not event.isPre() then return end - if alya.mc.isOnGround() then return end - if not airSetting.isEnabled() then return end - - local motionX = alya.mc.getMotionX() - local motionZ = alya.mc.getMotionZ() - local playerX = alya.mc.getPlayerX() - local playerY = alya.mc.getPlayerY() - local playerZ = alya.mc.getPlayerZ() - local floorY = math.floor(playerY) - - if math.abs(motionX) > 0.001 then - local checkX = math.floor(playerX + motionX + (motionX > 0 and 0.3 or -0.3)) - if alya.mc.isBlockSolid(checkX, floorY, math.floor(playerZ)) or - alya.mc.isBlockSolid(checkX, floorY + 1, math.floor(playerZ)) then - alya.mc.setMotionX(0) - end - end - - if math.abs(motionZ) > 0.001 then - local checkZ = math.floor(playerZ + motionZ + (motionZ > 0 and 0.3 or -0.3)) - if alya.mc.isBlockSolid(math.floor(playerX), floorY, checkZ) or - alya.mc.isBlockSolid(math.floor(playerX), floorY + 1, checkZ) then - alya.mc.setMotionZ(0) - end - end -end) - -moduleTable.onDisable(function() - alya.mc.setSneakPressed(false) + event.setSafeWalk(true) end)