Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle ClientboundTickingStatePacket correctly and fix Throwable Scales #4850

Open
wants to merge 40 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
3d957e3
Proper tick rate handling
letsgoawaydev Jul 12, 2024
91a1a12
Fix frozen variable getter
letsgoawaydev Jul 13, 2024
83fab59
Merge branch 'master' into tick-rate-handling
letsgoawaydev Jul 13, 2024
8418691
Fix formatting i think third attempt
letsgoawaydev Jul 13, 2024
fc04909
Formatting fix attempt 5 fsdiofhsdioufhvuisdhviuo9ds
letsgoawaydev Jul 13, 2024
f83e2fb
Fix stuff, also fixed the sizing of throwables as they were to big
letsgoawaydev Jul 13, 2024
4fd9cbe
Move update ticking state
letsgoawaydev Jul 13, 2024
dc130eb
Merge branch 'master' into tick-rate-handling
letsgoawaydev Jul 14, 2024
d20b18a
Merge branch 'master' into tick-rate-handling
letsgoawaydev Jul 15, 2024
0eb9134
Update core/src/main/java/org/geysermc/geyser/session/GeyserSession.java
letsgoawaydev Jul 18, 2024
b2a5cd5
Merge branch 'master' into tick-rate-handling
letsgoawaydev Jul 23, 2024
b8b0517
Fixes for spaces and documentation
letsgoawaydev Jul 24, 2024
02c0469
Missed a space
letsgoawaydev Jul 24, 2024
611b010
wait now ive fixed it
letsgoawaydev Jul 24, 2024
4f345c0
Fix languages
letsgoawaydev Jul 24, 2024
046d287
try again to fix languages
letsgoawaydev Jul 24, 2024
2da5599
Fix Java doc comments for tickable interface
letsgoawaydev Jul 25, 2024
09bfe4b
Fix javadoc comment in Geyser Session
letsgoawaydev Jul 25, 2024
dadd5ba
Merge branch 'master' into tick-rate-handling
letsgoawaydev Jul 26, 2024
e86d11c
fix comment
letsgoawaydev Jul 26, 2024
8d4f259
Merge branch 'master' into tick-rate-handling
letsgoawaydev Jul 28, 2024
0ce7240
Merge branch 'master' into tick-rate-handling
letsgoawaydev Jul 29, 2024
e348d3e
fix some tick rate stuffs
letsgoawaydev Jul 29, 2024
7af831f
Fix build fail
letsgoawaydev Jul 30, 2024
c5f1f83
Merge branch 'master' into tick-rate-handling
letsgoawaydev Jul 31, 2024
e78568d
Merge branch 'master' into tick-rate-handling
letsgoawaydev Aug 6, 2024
ad3990b
Merge branch 'master' into tick-rate-handling
letsgoawaydev Aug 9, 2024
99e7385
fix some stuff
letsgoawaydev Aug 10, 2024
089d96c
Merge branch 'tick-rate-handling' of https://github.com/letsgoawaydev…
letsgoawaydev Aug 10, 2024
bd27743
Merge remote-tracking branch 'upstream/master' into tick-rate-handling
letsgoawaydev Aug 16, 2024
27de994
Merge remote-tracking branch 'upstream/master' into tick-rate-handling
letsgoawaydev Aug 16, 2024
e5a2ae4
merge
letsgoawaydev Aug 16, 2024
807881f
test
letsgoawaydev Aug 16, 2024
3602fc2
Update languages
letsgoawaydev Aug 16, 2024
21b87c8
Update mappings
letsgoawaydev Aug 16, 2024
dd40bb1
Merge branch 'master' into tick-rate-handling
letsgoawaydev Aug 31, 2024
079c4e6
delete broken stuff
letsgoawaydev Aug 31, 2024
90a0119
Fix cooldown
letsgoawaydev Aug 31, 2024
dcc3dce
fix cooldowns
letsgoawaydev Aug 31, 2024
4fc1d66
Update core/src/main/java/org/geysermc/geyser/util/CooldownUtils.java
letsgoawaydev Aug 31, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public final class EntityDefinitions {
public static final EntityDefinition<EvokerFangsEntity> EVOKER_FANGS;
public static final EntityDefinition<ThrowableItemEntity> EXPERIENCE_BOTTLE;
public static final EntityDefinition<ExpOrbEntity> EXPERIENCE_ORB;
public static final EntityDefinition<Entity> EYE_OF_ENDER;
public static final EntityDefinition<EnderEyeEntity> EYE_OF_ENDER;
public static final EntityDefinition<FallingBlockEntity> FALLING_BLOCK;
public static final EntityDefinition<FireballEntity> FIREBALL;
public static final EntityDefinition<FireworkEntity> FIREWORK_ROCKET;
Expand Down Expand Up @@ -250,7 +250,7 @@ public final class EntityDefinitions {
.height(0.8f).width(0.5f)
.identifier("minecraft:evocation_fang")
.build();
EYE_OF_ENDER = EntityDefinition.inherited(Entity::new, entityBase)
EYE_OF_ENDER = EntityDefinition.inherited(EnderEyeEntity::new, entityBase)
.type(EntityType.EYE_OF_ENDER)
.heightAndWidth(0.25f)
.identifier("minecraft:eye_of_ender_signal")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ public InteractionResult interact(Hand hand) {
@Override
public void tick() {
// Java sends simply "true" and "false" (is_paddling_left), Bedrock keeps sending packets as you're rowing
doTick = !doTick; // Run every 100 ms
doTick = !doTick; // Run every other tick
if (!doTick || passengers.isEmpty()) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright (c) 2024 GeyserMC. http://geysermc.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @author GeyserMC
* @link https://github.com/GeyserMC/Geyser
*/

package org.geysermc.geyser.entity.type;


import org.cloudburstmc.math.vector.Vector3f;
import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes;
import org.geysermc.geyser.entity.EntityDefinition;
import org.geysermc.geyser.entity.EntityDefinitions;
import org.geysermc.geyser.session.GeyserSession;

import java.util.UUID;

public class EnderEyeEntity extends Entity {
public EnderEyeEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition<?> definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) {
super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw);
}

@Override
protected void initializeMetadata() {
super.initializeMetadata();
// Correct sizing
dirtyMetadata.put(EntityDataTypes.SCALE, 0.5f);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -423,3 +423,4 @@ protected AttributeData calculateAttribute(Attribute javaAttribute, GeyserAttrib
return type.getAttribute((float) AttributeUtils.calculateValue(javaAttribute));
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ protected float getGravity() {
case SNOWBALL:
case EGG:
case ENDER_PEARL:
return 0.03f;
return 0.0325f;
case LLAMA_SPIT:
return 0.06f;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,20 @@

package org.geysermc.geyser.entity.type;

import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.EntityMetadata;
import org.geysermc.mcprotocollib.protocol.data.game.item.ItemStack;
import org.cloudburstmc.math.vector.Vector3f;
import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes;
import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag;
import org.geysermc.geyser.entity.EntityDefinition;
import org.geysermc.geyser.session.GeyserSession;
import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.EntityMetadata;
import org.geysermc.mcprotocollib.protocol.data.game.item.ItemStack;

import java.util.UUID;

/**
* Used as a class for any projectile entity that looks like an item
*/
public class ThrowableItemEntity extends ThrowableEntity {
/**
* Number of ticks since the entity was spawned by the Java server
*/
private int age;
private boolean invisible;

public ThrowableItemEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition<?> definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) {
Expand All @@ -50,27 +47,28 @@ public ThrowableItemEntity(GeyserSession session, int entityId, long geyserId, U
invisible = false;
}

@Override
protected void initializeMetadata() {
super.initializeMetadata();
// Correct sizing
dirtyMetadata.put(EntityDataTypes.SCALE, 0.5f);
}
letsgoawaydev marked this conversation as resolved.
Show resolved Hide resolved
letsgoawaydev marked this conversation as resolved.
Show resolved Hide resolved

private void checkVisibility() {
Vector3f playerPos = session.getPlayerEntity().getPosition();
// Prevent projectiles from blocking the player's screen
setInvisible(position.distanceSquared(playerPos) < 9);

if (invisible != getFlag(EntityFlag.INVISIBLE)) {
if (!invisible) {
Vector3f playerPos = session.getPlayerEntity().getPosition();
// Prevent projectiles from blocking the player's screen
if (age >= 4 || position.distanceSquared(playerPos) > 16) {
setFlag(EntityFlag.INVISIBLE, false);
updateBedrockMetadata();
}
} else {
setFlag(EntityFlag.INVISIBLE, true);
updateBedrockMetadata();
}
setFlag(EntityFlag.INVISIBLE, invisible);
updateBedrockMetadata();
}
age++;
}

@Override
public void tick() {
public void drawTick() {
checkVisibility();
super.tick();
super.drawTick();
}

@Override
Expand Down
17 changes: 15 additions & 2 deletions core/src/main/java/org/geysermc/geyser/entity/type/Tickable.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019-2022 GeyserMC. http://geysermc.org
* Copyright (c) 2019-2024 GeyserMC. http://geysermc.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand All @@ -26,8 +26,21 @@
package org.geysermc.geyser.entity.type;

/**
* Implemented onto anything that should have code ran every Minecraft tick - 50 milliseconds.
* Implemented onto anything that should have code ran every Minecraft tick.
* By default, the Java server runs at 20 TPS, 50 milliseconds for each tick.
*/
public interface Tickable {
/**
* This function gets called every tick at all times, even when the server requests that
* the game should be frozen. This should be used for updating things that are always
* client side updated on Java, regardless of if the server is frozen or not.
*/
default void drawTick() {
}

/**
* This function gets called every game tick as long as the
* game tick loop isn't frozen.
*/
void tick();
}
35 changes: 28 additions & 7 deletions core/src/main/java/org/geysermc/geyser/session/GeyserSession.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019-2022 GeyserMC. http://geysermc.org
* Copyright (c) 2019-2024 GeyserMC. http://geysermc.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -619,7 +619,8 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource {
/**
* Stores cookies sent by the Java server.
*/
@Setter @Getter
@Setter
@Getter
private Map<String, byte[]> cookies = new Object2ObjectOpenHashMap<>();
letsgoawaydev marked this conversation as resolved.
Show resolved Hide resolved

private final GeyserCameraData cameraData;
Expand All @@ -628,6 +629,14 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource {

private MinecraftProtocol protocol;

private boolean tickingFrozen = false;
/**
* The amount of ticks requested by the server that the game should proceed with, even if the game tick loop is frozen.
*/
@Setter
private int stepTicks = 0;
letsgoawaydev marked this conversation as resolved.
Show resolved Hide resolved
private boolean gameShouldUpdate = true;
Konicai marked this conversation as resolved.
Show resolved Hide resolved

public GeyserSession(GeyserImpl geyser, BedrockServerSession bedrockServerSession, EventLoop eventLoop) {
this.geyser = geyser;
this.upstream = new UpstreamSession(bedrockServerSession);
Expand Down Expand Up @@ -1212,8 +1221,14 @@ public ScheduledFuture<?> scheduleInEventLoop(Runnable runnable, long duration,
}, duration, timeUnit);
}

public void updateTickingState(float tickRate, boolean frozen) {
tickThread.cancel(true);
this.tickingFrozen = frozen;
tickThread = eventLoop.scheduleAtFixedRate(this::tick, Math.round(1000 / tickRate), Math.round(1000 / tickRate), TimeUnit.MILLISECONDS);
}
letsgoawaydev marked this conversation as resolved.
Show resolved Hide resolved

/**
* Called every 50 milliseconds - one Minecraft tick.
* Called every Minecraft tick - 1000/tickRate milliseconds.
*/
protected void tick() {
try {
Expand Down Expand Up @@ -1251,9 +1266,15 @@ protected void tick() {
isInWorldBorderWarningArea = false;
}


gameShouldUpdate = !tickingFrozen || stepTicks > 0;
letsgoawaydev marked this conversation as resolved.
Show resolved Hide resolved
if (stepTicks > 0) {
--stepTicks;
}
for (Tickable entity : entityCache.getTickableEntities()) {
entity.tick();
entity.drawTick();
if (gameShouldUpdate) {
entity.tick();
}
}

letsgoawaydev marked this conversation as resolved.
Show resolved Hide resolved
if (armAnimationTicks >= 0) {
Expand Down Expand Up @@ -1681,7 +1702,7 @@ public void sendDownstreamLoginPacket(Packet packet) {
/**
* Send a packet to the remote server if in the specified state.
*
* @param packet the java edition packet from MCProtocolLib
* @param packet the java edition packet from MCProtocolLib
letsgoawaydev marked this conversation as resolved.
Show resolved Hide resolved
* @param intendedState the state the client should be in
*/
public void sendDownstreamPacket(Packet packet, ProtocolState intendedState) {
Expand Down Expand Up @@ -1977,7 +1998,7 @@ public float getEyeHeight() {

@Override
public UUID javaUuid() {
return playerEntity != null ? playerEntity.getUuid() : null ;
return playerEntity != null ? playerEntity.getUuid() : null;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright (c) 2024 GeyserMC. http://geysermc.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @author GeyserMC
* @link https://github.com/GeyserMC/Geyser
*/

package org.geysermc.geyser.translator.protocol.java;

import org.geysermc.geyser.session.GeyserSession;
import org.geysermc.geyser.translator.protocol.PacketTranslator;
import org.geysermc.geyser.translator.protocol.Translator;
import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.ClientboundTickingStatePacket;

@Translator(packet = ClientboundTickingStatePacket.class)
public class JavaTickingStateTranslator extends PacketTranslator<ClientboundTickingStatePacket> {

@Override
public void translate(GeyserSession session, ClientboundTickingStatePacket packet) {
session.updateTickingState(packet.getTickRate(), packet.isFrozen());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright (c) 2024 GeyserMC. http://geysermc.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @author GeyserMC
* @link https://github.com/GeyserMC/Geyser
*/

package org.geysermc.geyser.translator.protocol.java;

import org.geysermc.geyser.session.GeyserSession;
import org.geysermc.geyser.translator.protocol.PacketTranslator;
import org.geysermc.geyser.translator.protocol.Translator;
import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.ClientboundTickingStepPacket;

@Translator(packet = ClientboundTickingStepPacket.class)
public class JavaTickingStepTranslator extends PacketTranslator<ClientboundTickingStepPacket> {

@Override
public void translate(GeyserSession session, ClientboundTickingStepPacket packet) {
session.setStepTicks(packet.getTickSteps());
}
}