Skip to content
Merged

Dev #74

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 24 additions & 3 deletions src/main/java/bypass/event/events/MoveEntityEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
}
Expand Down
86 changes: 86 additions & 0 deletions src/main/java/bypass/lua/api/LuaEventApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
32 changes: 21 additions & 11 deletions src/main/java/bypass/lua/api/LuaMinecraftApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -759,24 +759,15 @@ public LuaValue call() {
new ZeroArgFunction() {
@Override
public LuaValue call() {
return LuaValue.valueOf(minecraft.thePlayer != null && minecraft.thePlayer.isInWater());
return LuaValue.valueOf(isInLiquid());
}
});
set(
"isOnLiquid",
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(
Expand Down Expand Up @@ -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));
}
}
Loading
Loading