Skip to content

Commit

Permalink
Initial work on more exact abilities and new movement
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexProgrammerDE committed Nov 6, 2024
1 parent cb36950 commit 685af97
Show file tree
Hide file tree
Showing 14 changed files with 187 additions and 1,173 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public static TickResult getRequiredMiningTicks(
// If this value adds up over all ticks to 1, the block is fully mined
var damage = getBlockDamagePerTick(tagsState, entity, onGround, itemStack, blockType);

var creativeMode = entity != null && entity.abilities().creativeModeBreak();
var creativeMode = entity != null && entity.abilities().instabuild();
var willDropUsableBlockItem = correctToolUsed && !creativeMode && BlockTypeHelper.isUsableBlockItem(blockType);

// Insta mine
Expand All @@ -159,7 +159,7 @@ private static float getBlockDamagePerTick(TagsState tagsState,
boolean onGround,
@Nullable SFItemStack itemStack,
BlockType blockType) {
if (entity != null && entity.abilities().creativeModeBreak()) {
if (entity != null && entity.abilities().instabuild()) {
// We instantly break any block in creative mode
return 1.0F;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public PathConstraint(BotConnection botConnection) {
}

public boolean doUsableBlocksDecreaseWhenPlaced() {
return entity == null || !entity.abilities().creativeModeBreak();
return entity == null || !entity.abilities().instabuild();
}

public boolean isPlaceable(SFItemStack item) {
Expand Down
70 changes: 37 additions & 33 deletions server/src/main/java/com/soulfiremc/server/plugins/POVServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -633,46 +633,48 @@ private void syncBotAndUser() {
dataManager.loginData().enforcesSecureChat()));
session.send(new ClientboundRespawnPacket(spawnInfo, false, false));

if (dataManager.difficultyData() != null) {
var difficultyData = dataManager.difficultyData();
if (difficultyData != null) {
session.send(
new ClientboundChangeDifficultyPacket(
dataManager.difficultyData().difficulty(),
dataManager.difficultyData().locked()));
difficultyData.difficulty(),
difficultyData.locked()));
}

if (dataManager.abilitiesData() != null) {
session.send(
new ClientboundPlayerAbilitiesPacket(
dataManager.abilitiesData().invulnerable(),
dataManager.abilitiesData().flying(),
dataManager.abilitiesData().allowFlying(),
dataManager.abilitiesData().creativeModeBreak(),
dataManager.abilitiesData().flySpeed(),
dataManager.abilitiesData().walkSpeed()));
}
var abilitiesData = dataManager.clientEntity().abilitiesData();
session.send(
new ClientboundPlayerAbilitiesPacket(
abilitiesData.invulnerable(),
abilitiesData.flying(),
abilitiesData.mayfly(),
abilitiesData.instabuild(),
abilitiesData.flySpeed(),
abilitiesData.walkSpeed()));

session.send(
new ClientboundGameEventPacket(
GameEvent.CHANGE_GAMEMODE, dataManager.gameMode()));

if (dataManager.borderState() != null) {
var borderState = dataManager.borderState();
if (borderState != null) {
session.send(
new ClientboundInitializeBorderPacket(
dataManager.borderState().centerX(),
dataManager.borderState().centerZ(),
dataManager.borderState().oldSize(),
dataManager.borderState().newSize(),
dataManager.borderState().lerpTime(),
dataManager.borderState().newAbsoluteMaxSize(),
dataManager.borderState().warningBlocks(),
dataManager.borderState().warningTime()));
borderState.centerX(),
borderState.centerZ(),
borderState.oldSize(),
borderState.newSize(),
borderState.lerpTime(),
borderState.newAbsoluteMaxSize(),
borderState.warningBlocks(),
borderState.warningTime()));
}

if (dataManager.defaultSpawnData() != null) {
var defaultSpawnData = dataManager.defaultSpawnData();
if (defaultSpawnData != null) {
session.send(
new ClientboundSetDefaultSpawnPositionPacket(
dataManager.defaultSpawnData().position(),
dataManager.defaultSpawnData().angle()));
defaultSpawnData.position(),
defaultSpawnData.angle()));
}

if (dataManager.weatherState() != null) {
Expand All @@ -694,20 +696,22 @@ private void syncBotAndUser() {
dataManager.weatherState().thunderStrength())));
}

if (dataManager.healthData() != null) {
var healthData = dataManager.healthData();
if (healthData != null) {
session.send(
new ClientboundSetHealthPacket(
dataManager.healthData().health(),
dataManager.healthData().food(),
dataManager.healthData().saturation()));
healthData.health(),
healthData.food(),
healthData.saturation()));
}

if (dataManager.experienceData() != null) {
var experienceData = dataManager.experienceData();
if (experienceData != null) {
session.send(
new ClientboundSetExperiencePacket(
dataManager.experienceData().experience(),
dataManager.experienceData().level(),
dataManager.experienceData().totalExperience()));
experienceData.experience(),
experienceData.level(),
experienceData.totalExperience()));
}

// Give initial coordinates to the client
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,13 @@ public void tick() {
}

public boolean toggleFlight() {
var abilitiesData = dataManager.abilitiesData();
if (abilitiesData != null && !abilitiesData.allowFlying()) {
var abilitiesData = dataManager.clientEntity().abilitiesData();
if (abilitiesData != null && !abilitiesData.mayfly()) {
throw new IllegalStateException("You can't fly! (Server said so)");
}

var newFly = !dataManager.controlState().flying();
dataManager.controlState().flying(newFly);
var newFly = !dataManager.clientEntity().abilitiesData().flying();
dataManager.clientEntity().abilitiesData().flying(newFly);

// Let the server know we are flying
connection.sendPacket(new ServerboundPlayerAbilitiesPacket(newFly));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import com.soulfiremc.server.protocol.bot.container.SFItemStack;
import com.soulfiremc.server.protocol.bot.container.WindowContainer;
import com.soulfiremc.server.protocol.bot.model.*;
import com.soulfiremc.server.protocol.bot.movement.ControlState;
import com.soulfiremc.server.protocol.bot.state.*;
import com.soulfiremc.server.protocol.bot.state.entity.ClientEntity;
import com.soulfiremc.server.protocol.bot.state.entity.ExperienceOrbEntity;
Expand Down Expand Up @@ -146,7 +145,6 @@ public final class SessionDataManager {
private @Nullable GlobalPos lastDeathPos;
private int portalCooldown = -1;
private @Nullable DifficultyData difficultyData;
private @Nullable AbilitiesData abilitiesData;
private @Nullable DefaultSpawnData defaultSpawnData;
private @Nullable ExperienceData experienceData;
private @Nullable ChunkKey centerChunk;
Expand Down Expand Up @@ -502,24 +500,13 @@ public void onSetDifficulty(ClientboundChangeDifficultyPacket packet) {

@EventHandler
public void onAbilities(ClientboundPlayerAbilitiesPacket packet) {
abilitiesData =
new AbilitiesData(
packet.isInvincible(),
packet.isFlying(),
packet.isCanFly(),
packet.isCreative(),
packet.getFlySpeed(),
packet.getWalkSpeed());

var attributeState = clientEntity.attributeState();
attributeState
.getOrCreateAttribute(AttributeType.MOVEMENT_SPEED)
.baseValue(abilitiesData.walkSpeed());
attributeState
.getOrCreateAttribute(AttributeType.FLYING_SPEED)
.baseValue(abilitiesData.flySpeed());

controlState.flying(abilitiesData.flying());
var abilitiesData = clientEntity.abilitiesData();
abilitiesData.flying = packet.isFlying();
abilitiesData.instabuild = packet.isCreative();
abilitiesData.invulnerable = packet.isInvincible();
abilitiesData.mayfly = packet.isCanFly();
abilitiesData.flySpeed(packet.getFlySpeed());
abilitiesData.walkSpeed(packet.getWalkSpeed());
}

@EventHandler
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,23 @@
*/
package com.soulfiremc.server.protocol.bot.model;

public record AbilitiesData(
boolean invulnerable,
boolean flying,
boolean allowFlying,
boolean creativeModeBreak,
float flySpeed,
float walkSpeed) {}
import lombok.*;

@Setter
@Getter
@ToString
@EqualsAndHashCode
@AllArgsConstructor
public final class AbilitiesData {
public boolean invulnerable;
public boolean flying;
public boolean mayfly;
public boolean instabuild;
public boolean mayBuild;
private float flySpeed;
private float walkSpeed;

public AbilitiesData() {
this(false, false, false, false, true, 0.05F, 0.1F);
}
}
Loading

0 comments on commit 685af97

Please sign in to comment.