Skip to content

Commit f8060a0

Browse files
committed
Cleanup
1 parent ffa738c commit f8060a0

7 files changed

Lines changed: 25 additions & 74 deletions

File tree

core/src/main/java/org/geysermc/geyser/entity/type/FireworkEntity.java

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@
2727

2828
import org.cloudburstmc.math.vector.Vector3f;
2929
import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes;
30-
import org.cloudburstmc.protocol.bedrock.packet.SetEntityMotionPacket;
3130
import org.geysermc.geyser.entity.EntityDefinition;
32-
import org.geysermc.geyser.entity.type.player.PlayerEntity;
3331
import org.geysermc.geyser.item.Items;
3432
import org.geysermc.geyser.item.TooltipOptions;
3533
import org.geysermc.geyser.session.GeyserSession;
@@ -72,20 +70,22 @@ public void setPlayerGliding(EntityMetadata<OptionalInt, ?> entityMetadata) {
7270
// and checks to make sure the player that is gliding is the one getting sent the packet
7371
// or else every player near the gliding player will boost too.
7472
if (optional.isPresent() && optional.getAsInt() == session.getPlayerEntity().getEntityId()) {
75-
PlayerEntity entity = session.getPlayerEntity();
76-
float yaw = entity.getYaw();
77-
float pitch = entity.getPitch();
78-
// Uses math from NukkitX
79-
entity.setMotion(Vector3f.from(
80-
-Math.sin(Math.toRadians(yaw)) * Math.cos(Math.toRadians(pitch)) * 2,
81-
-Math.sin(Math.toRadians(pitch)) * 2,
82-
Math.cos(Math.toRadians(yaw)) * Math.cos(Math.toRadians(pitch)) * 2));
83-
// Need to update the EntityMotionPacket or else the player won't boost
84-
SetEntityMotionPacket entityMotionPacket = new SetEntityMotionPacket();
85-
entityMotionPacket.setRuntimeEntityId(entity.getGeyserId());
86-
entityMotionPacket.setMotion(entity.getMotion());
87-
88-
session.sendUpstreamPacket(entityMotionPacket);
73+
// TODO Firework rocket boosting is client side. Sending this boost is no longer needed
74+
// Good luck to whoever is going to try implementing cancelling firework rocket boosting :)
75+
// PlayerEntity entity = session.getPlayerEntity();
76+
// float yaw = entity.getYaw();
77+
// float pitch = entity.getPitch();
78+
// // Uses math from NukkitX
79+
// entity.setMotion(Vector3f.from(
80+
// -Math.sin(Math.toRadians(yaw)) * Math.cos(Math.toRadians(pitch)) * 2,
81+
// -Math.sin(Math.toRadians(pitch)) * 2,
82+
// Math.cos(Math.toRadians(yaw)) * Math.cos(Math.toRadians(pitch)) * 2));
83+
// // Need to update the EntityMotionPacket or else the player won't boost
84+
// SetEntityMotionPacket entityMotionPacket = new SetEntityMotionPacket();
85+
// entityMotionPacket.setRuntimeEntityId(entity.getGeyserId());
86+
// entityMotionPacket.setMotion(entity.getMotion());
87+
//
88+
// session.sendUpstreamPacket(entityMotionPacket);
8989
}
9090
}
9191
}

core/src/main/java/org/geysermc/geyser/entity/type/LivingEntity.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ public void setLivingEntityFlags(ByteEntityMetadata entityMetadata) {
201201

202202
boolean isUsingShield = hasShield(isUsingOffhand);
203203

204-
setUsingItem(isUsingItem && !isUsingShield);
204+
setFlag(EntityFlag.USING_ITEM, isUsingItem && !isUsingShield);
205205
// Override the blocking
206206
setFlag(EntityFlag.BLOCKING, isUsingItem && isUsingShield);
207207

@@ -216,10 +216,6 @@ public void setSpinAttack(boolean value) {
216216
setFlag(EntityFlag.DAMAGE_NEARBY_MOBS, value);
217217
}
218218

219-
public void setUsingItem(boolean value) {
220-
setFlag(EntityFlag.USING_ITEM, value);
221-
}
222-
223219
public void setHealth(FloatEntityMetadata entityMetadata) {
224220
this.health = entityMetadata.getPrimitiveValue();
225221

core/src/main/java/org/geysermc/geyser/entity/type/player/SessionPlayerEntity.java

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag;
3838
import org.cloudburstmc.protocol.bedrock.packet.MovePlayerPacket;
3939
import org.cloudburstmc.protocol.bedrock.packet.UpdateAttributesPacket;
40-
import org.geysermc.geyser.GeyserImpl;
4140
import org.geysermc.geyser.entity.EntityDefinitions;
4241
import org.geysermc.geyser.entity.attribute.GeyserAttributeType;
4342
import org.geysermc.geyser.inventory.GeyserItemStack;
@@ -217,12 +216,6 @@ public void setSpinAttack(boolean value) {
217216
session.setSpinAttack(value);
218217
}
219218

220-
@Override
221-
public void setUsingItem(boolean value) {
222-
GeyserImpl.getInstance().getLogger().error("Server is stopping item use! " + value);
223-
setFlagForce(EntityFlag.USING_ITEM, value);
224-
}
225-
226219
/**
227220
* Since 1.19.40, the client must be re-informed of its bounding box on respawn
228221
* See <a href="https://github.com/GeyserMC/Geyser/issues/3370">issue 3370</a>
@@ -511,12 +504,8 @@ public boolean canStartGliding() {
511504
return false;
512505
}
513506

514-
// A method that is guaranteed to send updated flags, even if "nothing changed".
515-
// This is useful to prevent e.g. Elytra gliding stopping
516-
public void setFlagForce(EntityFlag flag, boolean value) {
517-
setFlag(flag, value);
507+
public void forceFlagUpdate() {
518508
setFlagsDirty(true);
519-
updateBedrockMetadata();
520509
}
521510

522511
public boolean isGliding() {

core/src/main/java/org/geysermc/geyser/inventory/item/StoredItemMappings.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ public class StoredItemMappings {
4747
private final ItemMapping compass;
4848
private final ItemMapping crossbow;
4949
private final ItemMapping egg;
50-
private final ItemMapping fireworkRocket;
5150
private final ItemMapping glassBottle;
5251
private final ItemMapping milkBucket;
5352
private final ItemMapping powderSnowBucket;
@@ -67,7 +66,6 @@ public StoredItemMappings(Map<Item, ItemMapping> itemMappings) {
6766
this.compass = load(itemMappings, Items.COMPASS);
6867
this.crossbow = load(itemMappings, Items.CROSSBOW);
6968
this.egg = load(itemMappings, Items.EGG);
70-
this.fireworkRocket = load(itemMappings, Items.FIREWORK_ROCKET);
7169
this.glassBottle = load(itemMappings, Items.GLASS_BOTTLE);
7270
this.milkBucket = load(itemMappings, Items.MILK_BUCKET);
7371
this.powderSnowBucket = load(itemMappings, Items.POWDER_SNOW_BUCKET);

core/src/main/java/org/geysermc/geyser/session/GeyserSession.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1268,9 +1268,7 @@ public void setSpinAttack(boolean spinAttack) {
12681268
}
12691269

12701270
public void setGliding(boolean gliding) {
1271-
this.pose = gliding ? Pose.FALL_FLYING : Pose.STANDING;
1272-
playerEntity.setDimensions(this.pose);
1273-
playerEntity.setFlagForce(EntityFlag.GLIDING, gliding);
1271+
switchPose(gliding, EntityFlag.GLIDING, Pose.FALL_FLYING);
12741272
}
12751273

12761274
private void setSneaking(boolean sneaking) {

core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockInventoryTransactionTranslator.java

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,9 @@
3030
import org.cloudburstmc.math.vector.Vector3d;
3131
import org.cloudburstmc.math.vector.Vector3f;
3232
import org.cloudburstmc.math.vector.Vector3i;
33-
import org.cloudburstmc.protocol.bedrock.data.MovementEffectType;
3433
import org.cloudburstmc.protocol.bedrock.data.SoundEvent;
3534
import org.cloudburstmc.protocol.bedrock.data.definitions.BlockDefinition;
3635
import org.cloudburstmc.protocol.bedrock.data.definitions.ItemDefinition;
37-
import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag;
3836
import org.cloudburstmc.protocol.bedrock.data.inventory.ContainerType;
3937
import org.cloudburstmc.protocol.bedrock.data.inventory.ItemData;
4038
import org.cloudburstmc.protocol.bedrock.data.inventory.transaction.InventoryActionData;
@@ -44,9 +42,7 @@
4442
import org.cloudburstmc.protocol.bedrock.packet.ContainerOpenPacket;
4543
import org.cloudburstmc.protocol.bedrock.packet.InventoryTransactionPacket;
4644
import org.cloudburstmc.protocol.bedrock.packet.LevelSoundEventPacket;
47-
import org.cloudburstmc.protocol.bedrock.packet.MovementEffectPacket;
4845
import org.cloudburstmc.protocol.bedrock.packet.PlaySoundPacket;
49-
import org.cloudburstmc.protocol.bedrock.packet.SetEntityMotionPacket;
5046
import org.cloudburstmc.protocol.bedrock.packet.UpdateBlockPacket;
5147
import org.geysermc.geyser.GeyserImpl;
5248
import org.geysermc.geyser.entity.EntityDefinitions;
@@ -368,7 +364,6 @@ public void translate(GeyserSession session, InventoryTransactionPacket packet)
368364
}
369365
case 1 -> {
370366
if (isIncorrectHeldItem(session, packet)) {
371-
session.getPlayerEntity().setFlag(EntityFlag.USING_ITEM, false);
372367
session.getPlayerInventoryHolder().updateSlot(session.getPlayerInventory().getOffsetForHotbar(packet.getHotbarSlot()));
373368
break;
374369
}
@@ -378,9 +373,6 @@ public void translate(GeyserSession session, InventoryTransactionPacket packet)
378373
break;
379374
}
380375

381-
// NOT updating here on purpose; will do that in auth input OR when the java server replies
382-
//session.getPlayerEntity().setFlag(EntityFlag.USING_ITEM, true);
383-
384376
// Handled in ITEM_USE if the item is not milk
385377
if (packet.getItemInHand() != null) {
386378
if (session.getItemMappings().getBuckets().contains(packet.getItemInHand().getDefinition()) &&
@@ -421,25 +413,6 @@ public void translate(GeyserSession session, InventoryTransactionPacket packet)
421413
}
422414
}
423415
}
424-
} else if (packet.getItemInHand().getDefinition() == session.getItemMappings().getStoredItems().fireworkRocket().getBedrockDefinition()) {
425-
GeyserImpl.getInstance().getLogger().error("firework! " + session.getPlayerEntity().isGliding() + " " + session.getPlayerEntity().getMotion() + " " + packet);
426-
// TODO prevent elytra boosting when not gliding
427-
if (!session.getPlayerEntity().isGliding()) {
428-
// Need to wait until we can "confirm" the session wants to use this rocket to fly
429-
session.setFireworkBoostTick(session.getTicks());
430-
} else {
431-
// Prevent boost from applying, we're gonna do that instead of the server
432-
MovementEffectPacket effectPacket = new MovementEffectPacket();
433-
effectPacket.setEffectType(MovementEffectType.GLIDE_BOOST);
434-
effectPacket.setDuration(0);
435-
effectPacket.setEntityRuntimeId(session.getPlayerEntity().getEntityId());
436-
session.sendUpstreamPacket(effectPacket);
437-
438-
SetEntityMotionPacket motionPacket = new SetEntityMotionPacket();
439-
motionPacket.setMotion(session.getPlayerEntity().getMotion());
440-
motionPacket.setRuntimeEntityId(session.getPlayerEntity().getGeyserId());
441-
session.sendUpstreamPacket(motionPacket);
442-
}
443416
}
444417
}
445418

core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/entity/player/input/BedrockPlayerAuthInputTranslator.java

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
import org.cloudburstmc.protocol.bedrock.packet.AnimatePacket;
3737
import org.cloudburstmc.protocol.bedrock.packet.LevelEventPacket;
3838
import org.cloudburstmc.protocol.bedrock.packet.PlayerAuthInputPacket;
39-
import org.geysermc.geyser.GeyserImpl;
4039
import org.geysermc.geyser.entity.EntityDefinitions;
4140
import org.geysermc.geyser.entity.type.BoatEntity;
4241
import org.geysermc.geyser.entity.type.Entity;
@@ -89,7 +88,6 @@ public void translate(GeyserSession session, PlayerAuthInputPacket packet) {
8988
leftOverInputData.remove(input);
9089
switch (input) {
9190
case PERFORM_ITEM_INTERACTION -> {
92-
GeyserImpl.getInstance().getLogger().info(packet.toString());
9391
processItemUseTransaction(session, packet.getItemUseTransaction());
9492
}
9593
case PERFORM_BLOCK_ACTIONS -> BedrockBlockActions.translate(session, packet.getPlayerActions());
@@ -128,7 +126,7 @@ public void translate(GeyserSession session, PlayerAuthInputPacket packet) {
128126
// Bedrock can send both start_glide and stop_glide in the same packet.
129127
// We only want to start gliding if the client has not stopped gliding in the same tick.
130128
// last replicated on 1.21.70 by "walking" and jumping while in water
131-
if (!entity.isGliding() && !leftOverInputData.contains(PlayerAuthInputData.STOP_GLIDING)) {
129+
if (!leftOverInputData.contains(PlayerAuthInputData.STOP_GLIDING)) {
132130
if (entity.canStartGliding()) {
133131
// On Java you can't start gliding while flying
134132
if (session.isFlying()) {
@@ -138,6 +136,7 @@ public void translate(GeyserSession session, PlayerAuthInputPacket packet) {
138136
session.setGliding(true);
139137
session.sendDownstreamGamePacket(new ServerboundPlayerCommandPacket(entity.getEntityId(), PlayerState.START_ELYTRA_FLYING));
140138
} else {
139+
entity.forceFlagUpdate();
141140
session.setGliding(false);
142141
// return to flying if we can't start gliding
143142
if (session.isFlying()) {
@@ -150,7 +149,10 @@ public void translate(GeyserSession session, PlayerAuthInputPacket packet) {
150149
case STOP_SPIN_ATTACK -> session.setSpinAttack(false);
151150
case STOP_GLIDING -> {
152151
// Java doesn't allow elytra gliding to stop mid-air.
153-
session.setGliding(entity.isGliding() && entity.canStartGliding());
152+
boolean shouldBeGliding = entity.isGliding() && entity.canStartGliding();
153+
// Always update; Bedrock can get real weird if the gliding state is mismatching
154+
entity.forceFlagUpdate();
155+
session.setGliding(shouldBeGliding);
154156
}
155157
case MISSED_SWING -> {
156158
session.setLastAirHitTick(session.getTicks());
@@ -171,10 +173,6 @@ public void translate(GeyserSession session, PlayerAuthInputPacket packet) {
171173
// Java edition sends a cooldown when hitting air.
172174
CooldownUtils.sendCooldown(session);
173175
}
174-
case START_USING_ITEM -> {
175-
GeyserImpl.getInstance().getLogger().info("Using item! " + packet);
176-
//entity.setFlag(EntityFlag.USING_ITEM, true);
177-
}
178176
}
179177
}
180178

@@ -189,7 +187,6 @@ public void translate(GeyserSession session, PlayerAuthInputPacket packet) {
189187
}
190188

191189
private static void processItemUseTransaction(GeyserSession session, ItemUseTransaction transaction) {
192-
GeyserImpl.getInstance().getLogger().info("item transaction: " + transaction);
193190
if (transaction.getActionType() == 2) {
194191
int blockState = session.getGameMode() == GameMode.CREATIVE ?
195192
session.getGeyser().getWorldManager().getBlockAt(session, transaction.getBlockPosition()) : session.getBreakingBlock();

0 commit comments

Comments
 (0)