Skip to content

Commit

Permalink
Merge branch '1.21.0' into 1.21.4
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/main/java/com/zenith/module/impl/PlayerSimulation.java
  • Loading branch information
rfresh2 committed Jan 3, 2025
2 parents 50c674e + 1b9b8bc commit b82d304
Show file tree
Hide file tree
Showing 20 changed files with 416 additions and 127 deletions.
4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ dependencies {
implementation("com.github.rfresh2.fastutil.maps:reference-object-maps:$fastutilVersion")
implementation("com.github.rfresh2.fastutil.queues:int-queues:$fastutilVersion")
implementation("net.raphimc:ViaLoader:3.0.4")
implementation("com.viaversion:viaversion:5.2.0")
implementation("com.viaversion:viabackwards:5.2.0")
implementation("com.viaversion:viaversion:5.2.1")
implementation("com.viaversion:viabackwards:5.2.1")
implementation("org.jline:jline:3.28.0")
implementation("org.jline:jline-terminal-jni:3.28.0")
implementation("ar.com.hjg:pngj:2.1.0")
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/com/zenith/cache/data/PlayerCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,10 @@ public static void sync() {
}
}

public boolean isAlive() {
return this.thePlayer.getHealth() > 0;
}

public void setInventory(final int containerId, final ItemStack[] inventory) {
this.inventoryCache.setInventory(containerId, inventory);
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/zenith/cache/data/chunk/ChunkCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ public boolean updateBlock(final @NonNull BlockChangeEntry record) {
// update any block entities implicitly affected by this block update
// server doesn't send us tile entity update packets and relies on logic in client
private void handleBlockUpdateBlockEntity(BlockChangeEntry record, int relativeX, int y, int relativeZ, Chunk chunk) {
if (record.getBlock() == BlockRegistry.AIR.id()) {
if (BLOCK_DATA.isAir(BlockRegistry.REGISTRY.get(record.getBlock()))) {
chunk.blockEntities.removeIf(tileEntity -> tileEntity.getX() == relativeX && tileEntity.getY() == y && tileEntity.getZ() == relativeZ);
} else {
final var block = BLOCK_DATA.getBlockDataFromBlockStateId(record.getBlock());
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/com/zenith/cache/data/entity/EntityLiving.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,9 @@ public void addPackets(final @NotNull Consumer<Packet> consumer) {
private boolean isSelfPlayer() {
return this instanceof EntityPlayer player && player.isSelfPlayer();
}

public boolean isAlive() {
var h = health;
return h != null && h > 0;
}
}
76 changes: 62 additions & 14 deletions src/main/java/com/zenith/command/impl/ClickCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public CommandUsage commandUsage() {
"left hold",
"right",
"right hold",
"right hold <mainHand/offHand/alternate>",
"stop"
)
);
Expand Down Expand Up @@ -93,19 +94,66 @@ public LiteralArgumentBuilder<CommandContext> register() {
.primaryColor();
return 1;
})
.then(literal("hold").executes(c -> {
if (!Proxy.getInstance().isConnected()) {
c.getSource().getEmbed()
.title("Not Connected")
.errorColor();
return OK;
}
MODULE.get(PlayerSimulation.class).holdLeftClickOverride = false;
MODULE.get(PlayerSimulation.class).holdRightClickOverride = true;
c.getSource().getEmbed()
.title("Right Click Hold")
.primaryColor();
return OK;
})));
.then(literal("hold")
.executes(c -> {
if (!Proxy.getInstance().isConnected()) {
c.getSource().getEmbed()
.title("Not Connected")
.errorColor();
return OK;
}
MODULE.get(PlayerSimulation.class).holdLeftClickOverride = false;
MODULE.get(PlayerSimulation.class).holdRightClickOverride = true;
MODULE.get(PlayerSimulation.class).holdRightClickMode = PlayerSimulation.HoldRightClickMode.MAIN_HAND;
c.getSource().getEmbed()
.title("Right Click Hold")
.primaryColor();
return OK;
})
.then(literal("mainHand").executes(c -> {
if (!Proxy.getInstance().isConnected()) {
c.getSource().getEmbed()
.title("Not Connected")
.errorColor();
return OK;
}
MODULE.get(PlayerSimulation.class).holdLeftClickOverride = false;
MODULE.get(PlayerSimulation.class).holdRightClickOverride = true;
MODULE.get(PlayerSimulation.class).holdRightClickMode = PlayerSimulation.HoldRightClickMode.MAIN_HAND;
c.getSource().getEmbed()
.title("Right Click Hold (Main Hand)")
.primaryColor();
return OK;
}))
.then(literal("offHand").executes(c -> {
if (!Proxy.getInstance().isConnected()) {
c.getSource().getEmbed()
.title("Not Connected")
.errorColor();
return OK;
}
MODULE.get(PlayerSimulation.class).holdLeftClickOverride = false;
MODULE.get(PlayerSimulation.class).holdRightClickOverride = true;
MODULE.get(PlayerSimulation.class).holdRightClickMode = PlayerSimulation.HoldRightClickMode.OFF_HAND;
c.getSource().getEmbed()
.title("Right Click Hold (Offhand)")
.primaryColor();
return OK;
}))
.then(literal("alternate").executes(c -> {
if (!Proxy.getInstance().isConnected()) {
c.getSource().getEmbed()
.title("Not Connected")
.errorColor();
return OK;
}
MODULE.get(PlayerSimulation.class).holdLeftClickOverride = false;
MODULE.get(PlayerSimulation.class).holdRightClickOverride = true;
MODULE.get(PlayerSimulation.class).holdRightClickMode = PlayerSimulation.HoldRightClickMode.ALTERNATE_HANDS;
c.getSource().getEmbed()
.title("Right Click Hold (Alternate)")
.primaryColor();
return OK;
}))));
}
}
12 changes: 11 additions & 1 deletion src/main/java/com/zenith/command/impl/RaycastCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
import com.zenith.command.CommandUsage;
import com.zenith.command.brigadier.CommandCategory;
import com.zenith.command.brigadier.CommandContext;
import com.zenith.feature.world.World;
import com.zenith.feature.world.raycast.RaycastHelper;
import com.zenith.module.impl.PlayerSimulation;

import static com.zenith.Shared.MODULE;

public class RaycastCommand extends Command {
@Override
Expand All @@ -29,6 +33,9 @@ public LiteralArgumentBuilder<CommandContext> register() {
embed.addField("Block", result.block().block().toString(), false)
.addField("Pos", result.block().x() + ", " + result.block().y() + ", " + result.block().z(), false)
.addField("Direction", result.block().direction().name(), false);
if (result.hit()) {
embed.addField("State", World.getBlockState(result.block().x(), result.block().y(), result.block().z()).toString(), false);
}
} else if (result.isEntity()) {
var type = result.entity().entityType();
embed.addField("Entity", type != null ? type : "N/A", false);
Expand All @@ -44,14 +51,17 @@ public LiteralArgumentBuilder<CommandContext> register() {
.primaryColor();
}))
.then(literal("b").executes(c -> {
var result = RaycastHelper.playerBlockRaycast(4.5, false);
var result = RaycastHelper.playerBlockRaycast(MODULE.get(PlayerSimulation.class).getBlockReachDistance(), false);
c.getSource().getEmbed()
.title("Raycast Result")
.addField("Hit", result.hit(), false)
.addField("Block", result.block().toString(), false)
.addField("Pos", result.x() + ", " + result.y() + ", " + result.z(), false)
.addField("Direction", result.direction().name(), false)
.primaryColor();
if (result.hit()) {
c.getSource().getEmbed().addField("State", World.getBlockState(result.x(), result.y(), result.z()).toString(), false);
}
}));
}
}
3 changes: 1 addition & 2 deletions src/main/java/com/zenith/feature/map/MapGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import com.zenith.cache.data.chunk.Chunk;
import com.zenith.feature.world.World;
import com.zenith.mc.block.Block;
import com.zenith.mc.block.BlockRegistry;
import com.zenith.util.math.MathHelper;
import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
Expand Down Expand Up @@ -206,7 +205,7 @@ private static BitStorage generateHeightMapData(final Chunk chunk) {
for (int y = maxBuildHeight; y > minBuildHeight; y--) {
final int blockStateId = chunk.getBlockStateId(x, y, z);
Block block = BLOCK_DATA.getBlockDataFromBlockStateId(blockStateId);
if (block != null && block != BlockRegistry.AIR) {
if (block != null && !BLOCK_DATA.isAir(block)) {
int index = x + z * 16;
storage.set(index, y - minBuildHeight);
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
import com.zenith.cache.data.inventory.Container;
import com.zenith.feature.world.raycast.BlockRaycastResult;
import com.zenith.feature.world.raycast.EntityRaycastResult;
import com.zenith.mc.block.Block;
import com.zenith.mc.block.BlockRegistry;
import com.zenith.mc.block.BlockState;
import com.zenith.mc.block.BlockTags;
import com.zenith.mc.block.*;
import com.zenith.mc.enchantment.EnchantmentData;
import com.zenith.mc.item.ItemData;
import com.zenith.mc.item.ItemRegistry;
Expand All @@ -18,7 +15,6 @@
import org.geysermc.mcprotocollib.protocol.data.game.entity.Effect;
import org.geysermc.mcprotocollib.protocol.data.game.entity.EquipmentSlot;
import org.geysermc.mcprotocollib.protocol.data.game.entity.attribute.AttributeType;
import org.geysermc.mcprotocollib.protocol.data.game.entity.object.Direction;
import org.geysermc.mcprotocollib.protocol.data.game.entity.player.GameMode;
import org.geysermc.mcprotocollib.protocol.data.game.entity.player.Hand;
import org.geysermc.mcprotocollib.protocol.data.game.entity.player.InteractAction;
Expand All @@ -32,6 +28,7 @@

import java.util.Objects;

import static com.zenith.Shared.BLOCK_DATA;
import static com.zenith.Shared.CACHE;

public class PlayerInteractionManager {
Expand Down Expand Up @@ -68,7 +65,7 @@ public boolean startDestroyBlock(final int x, final int y, final int z, Directio
new ServerboundPlayerActionPacket(
PlayerAction.START_DIGGING,
x, y, z,
face,
face.mcpl(),
CACHE.getPlayerCache().getSeqId().incrementAndGet()
)
);
Expand All @@ -81,14 +78,14 @@ public boolean startDestroyBlock(final int x, final int y, final int z, Directio
new ServerboundPlayerActionPacket(
PlayerAction.CANCEL_DIGGING,
this.destroyBlockPosX, this.destroyBlockPosY, this.destroyBlockPosZ,
face,
face.mcpl(),
CACHE.getPlayerCache().getSeqId().incrementAndGet()
)
);
}

BlockState blockState = World.getBlockState(x, y, z);
if (blockState.block() == BlockRegistry.AIR || blockBreakSpeed(blockState) < 1.0) {
if (BLOCK_DATA.isAir(blockState.block()) || blockBreakSpeed(blockState) < 1.0) {
this.isDestroying = true;
this.destroyBlockPosX = x;
this.destroyBlockPosY = y;
Expand All @@ -106,7 +103,7 @@ public boolean startDestroyBlock(final int x, final int y, final int z, Directio
new ServerboundPlayerActionPacket(
PlayerAction.START_DIGGING,
x, y, z,
face,
face.mcpl(),
CACHE.getPlayerCache().getSeqId().incrementAndGet()));
}

Expand All @@ -120,7 +117,7 @@ public void stopDestroyBlock() {
.send(new ServerboundPlayerActionPacket(
PlayerAction.CANCEL_DIGGING,
this.destroyBlockPosX, this.destroyBlockPosY, this.destroyBlockPosZ,
Direction.DOWN,
Direction.DOWN.mcpl(),
CACHE.getPlayerCache().getSeqId().incrementAndGet()
));
}
Expand All @@ -138,15 +135,15 @@ public boolean continueDestroyBlock(final int x, final int y, final int z, Direc
new ServerboundPlayerActionPacket(
PlayerAction.START_DIGGING,
x, y, z,
directionFacing,
directionFacing.mcpl(),
CACHE.getPlayerCache().getSeqId().incrementAndGet()
));
destroyBlock(x, y, z);
player.debug("[{}] [{}, {}, {}] ContinueDestroyBlock START: Creative Break", System.currentTimeMillis(), x, y, z);
return true;
} else if (this.sameDestroyTarget(x, y, z)) {
BlockState blockState = World.getBlockState(x, y, z);
if (blockState.block() == BlockRegistry.AIR) {
if (BLOCK_DATA.isAir(blockState.block())) {
this.isDestroying = false;
return false;
} else {
Expand All @@ -158,7 +155,7 @@ public boolean continueDestroyBlock(final int x, final int y, final int z, Direc
new ServerboundPlayerActionPacket(
PlayerAction.FINISH_DIGGING,
x, y, z,
directionFacing,
directionFacing.mcpl(),
CACHE.getPlayerCache().getSeqId().incrementAndGet()
));
destroyBlock(x, y, z);
Expand All @@ -180,14 +177,22 @@ public int getDestroyStage() {

public double blockBreakSpeed(BlockState state) {
double destroySpeed = state.block().destroySpeed();
double toolFactor = hasCorrectToolForDrops(state) ? 30.0 : 100.0;
double toolFactor = hasCorrectToolForDrops(state, CACHE.getPlayerCache().getEquipment(EquipmentSlot.MAIN_HAND))
? 30.0
: 100.0;
double playerDestroySpeed = getPlayerDestroySpeed(state);
return playerDestroySpeed / destroySpeed / toolFactor;
}

public boolean hasCorrectToolForDrops(BlockState state) {
public double blockBreakSpeed(BlockState state, ItemStack item) {
double destroySpeed = state.block().destroySpeed();
double toolFactor = hasCorrectToolForDrops(state, item) ? 30.0 : 100.0;
double playerDestroySpeed = getPlayerDestroySpeed(state);
return playerDestroySpeed / destroySpeed / toolFactor;
}

public boolean hasCorrectToolForDrops(BlockState state, ItemStack item) {
if (!state.block().requiresCorrectToolForDrops()) return true;
var item = CACHE.getPlayerCache().getEquipment(EquipmentSlot.MAIN_HAND);
if (item == Container.EMPTY_STACK) return false;
ItemData itemData = ItemRegistry.REGISTRY.get(item.getId());
if (itemData == null) return false;
Expand Down Expand Up @@ -320,7 +325,7 @@ public InteractionResult interactAt(Hand hand, EntityRaycastResult ray) {
public InteractionResult useItemOn(Hand hand, BlockRaycastResult ray) {
Proxy.getInstance().getClient().send(new ServerboundUseItemOnPacket(
ray.x(), ray.y(), ray.z(),
ray.direction(),
ray.direction().mcpl(),
hand,
// todo: cursor raytrace
0, 0, 0,
Expand Down
Loading

0 comments on commit b82d304

Please sign in to comment.