Skip to content

Commit 8b232d7

Browse files
letsgoawaydevrtm516onebeastchris
authored
Handle ClientboundTickingStatePacket correctly and fix Throwable Scales (#4850)
* Proper tick rate handling * Fix frozen variable getter * Fix formatting i think third attempt * Formatting fix attempt 5 fsdiofhsdioufhvuisdhviuo9ds * Fix stuff, also fixed the sizing of throwables as they were to big * Move update ticking state * Update core/src/main/java/org/geysermc/geyser/session/GeyserSession.java Co-authored-by: rtm516 <rtm516@users.noreply.github.com> * Fixes for spaces and documentation * Missed a space * wait now ive fixed it * Fix languages * try again to fix languages * Fix Java doc comments for tickable interface * Fix javadoc comment in Geyser Session * fix comment * fix some tick rate stuffs * Fix build fail * fix some stuff * merge * test * Update languages * Update mappings * delete broken stuff * Fix cooldown * fix cooldowns * Update core/src/main/java/org/geysermc/geyser/util/CooldownUtils.java Co-authored-by: chris <github@onechris.mozmail.com> * Update BoatEntity.java * Update GeyserSession.java * fix some stuff * Update CooldownUtils.java * fix some accidental formatting issues * Fix missing inport * Update GeyserSession.java * Update core/src/main/java/org/geysermc/geyser/entity/type/LivingEntity.java Co-authored-by: chris <github@onechris.mozmail.com> * Update core/src/main/java/org/geysermc/geyser/entity/type/ThrowableItemEntity.java Co-authored-by: chris <github@onechris.mozmail.com> * Fix missing import --------- Co-authored-by: rtm516 <rtm516@users.noreply.github.com> Co-authored-by: chris <github@onechris.mozmail.com>
1 parent 1fea22d commit 8b232d7

File tree

13 files changed

+277
-83
lines changed

13 files changed

+277
-83
lines changed

core/src/main/java/org/geysermc/geyser/entity/EntityDefinitions.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import org.geysermc.geyser.entity.type.CommandBlockMinecartEntity;
3939
import org.geysermc.geyser.entity.type.DisplayBaseEntity;
4040
import org.geysermc.geyser.entity.type.EnderCrystalEntity;
41+
import org.geysermc.geyser.entity.type.EnderEyeEntity;
4142
import org.geysermc.geyser.entity.type.Entity;
4243
import org.geysermc.geyser.entity.type.EvokerFangsEntity;
4344
import org.geysermc.geyser.entity.type.ExpOrbEntity;
@@ -197,7 +198,7 @@ public final class EntityDefinitions {
197198
public static final EntityDefinition<EvokerFangsEntity> EVOKER_FANGS;
198199
public static final EntityDefinition<ThrowableItemEntity> EXPERIENCE_BOTTLE;
199200
public static final EntityDefinition<ExpOrbEntity> EXPERIENCE_ORB;
200-
public static final EntityDefinition<Entity> EYE_OF_ENDER;
201+
public static final EntityDefinition<EnderEyeEntity> EYE_OF_ENDER;
201202
public static final EntityDefinition<FallingBlockEntity> FALLING_BLOCK;
202203
public static final EntityDefinition<FireballEntity> FIREBALL;
203204
public static final EntityDefinition<FireworkEntity> FIREWORK_ROCKET;
@@ -345,7 +346,7 @@ public final class EntityDefinitions {
345346
.height(0.8f).width(0.5f)
346347
.identifier("minecraft:evocation_fang")
347348
.build();
348-
EYE_OF_ENDER = EntityDefinition.inherited(Entity::new, entityBase)
349+
EYE_OF_ENDER = EntityDefinition.inherited(EnderEyeEntity::new, entityBase)
349350
.type(EntityType.EYE_OF_ENDER)
350351
.heightAndWidth(0.25f)
351352
.identifier("minecraft:eye_of_ender_signal")

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ public void tick() {
189189
session.sendDownstreamGamePacket(steerPacket);
190190
return;
191191
}
192-
doTick = !doTick; // Run every 100 ms
192+
doTick = !doTick; // Run every other tick
193193
if (!doTick || passengers.isEmpty()) {
194194
return;
195195
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Copyright (c) 2024 GeyserMC. http://geysermc.org
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy
5+
* of this software and associated documentation files (the "Software"), to deal
6+
* in the Software without restriction, including without limitation the rights
7+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
* copies of the Software, and to permit persons to whom the Software is
9+
* furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in
12+
* all copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20+
* THE SOFTWARE.
21+
*
22+
* @author GeyserMC
23+
* @link https://github.com/GeyserMC/Geyser
24+
*/
25+
26+
package org.geysermc.geyser.entity.type;
27+
28+
29+
import org.cloudburstmc.math.vector.Vector3f;
30+
import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes;
31+
import org.geysermc.geyser.entity.EntityDefinition;
32+
import org.geysermc.geyser.entity.EntityDefinitions;
33+
import org.geysermc.geyser.session.GeyserSession;
34+
35+
import java.util.UUID;
36+
37+
public class EnderEyeEntity extends Entity {
38+
public EnderEyeEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition<?> definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) {
39+
super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw);
40+
}
41+
42+
@Override
43+
protected void initializeMetadata() {
44+
super.initializeMetadata();
45+
// Correct sizing
46+
dirtyMetadata.put(EntityDataTypes.SCALE, 0.5f);
47+
}
48+
}

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

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,14 @@
2525

2626
package org.geysermc.geyser.entity.type;
2727

28-
import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.EntityMetadata;
29-
import org.geysermc.mcprotocollib.protocol.data.game.item.ItemStack;
3028
import org.cloudburstmc.math.vector.Vector3f;
29+
import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes;
3130
import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag;
3231
import org.geysermc.geyser.entity.EntityDefinition;
32+
import org.geysermc.geyser.entity.EntityDefinitions;
3333
import org.geysermc.geyser.session.GeyserSession;
34+
import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.EntityMetadata;
35+
import org.geysermc.mcprotocollib.protocol.data.game.item.ItemStack;
3436

3537
import java.util.UUID;
3638

@@ -39,7 +41,7 @@
3941
*/
4042
public class ThrowableItemEntity extends ThrowableEntity {
4143
/**
42-
* Number of ticks since the entity was spawned by the Java server
44+
* Number of draw ticks since the entity was spawned by the Java server
4345
*/
4446
private int age;
4547
private boolean invisible;
@@ -48,29 +50,38 @@ public ThrowableItemEntity(GeyserSession session, int entityId, long geyserId, U
4850
super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw);
4951
setFlag(EntityFlag.INVISIBLE, true);
5052
invisible = false;
53+
age = 0;
54+
}
55+
56+
@Override
57+
protected void initializeMetadata() {
58+
super.initializeMetadata();
59+
// Correct sizing
60+
dirtyMetadata.put(EntityDataTypes.SCALE, 0.5f);
5161
}
5262

5363
private void checkVisibility() {
64+
age++;
65+
66+
// Prevent projectiles from blocking the player's screen
67+
if (session.isTickingFrozen()) {
68+
// This may seem odd, but it matches java edition
69+
Vector3f playerPos = session.getPlayerEntity().getPosition().down(EntityDefinitions.PLAYER.offset());
70+
setInvisible(playerPos.distanceSquared(position.add(0, definition.offset(), 0)) < 12.25);
71+
} else {
72+
setInvisible(age < 2);
73+
}
74+
5475
if (invisible != getFlag(EntityFlag.INVISIBLE)) {
55-
if (!invisible) {
56-
Vector3f playerPos = session.getPlayerEntity().getPosition();
57-
// Prevent projectiles from blocking the player's screen
58-
if (age >= 4 || position.distanceSquared(playerPos) > 16) {
59-
setFlag(EntityFlag.INVISIBLE, false);
60-
updateBedrockMetadata();
61-
}
62-
} else {
63-
setFlag(EntityFlag.INVISIBLE, true);
64-
updateBedrockMetadata();
65-
}
76+
setFlag(EntityFlag.INVISIBLE, invisible);
77+
updateBedrockMetadata();
6678
}
67-
age++;
6879
}
6980

7081
@Override
71-
public void tick() {
82+
public void drawTick() {
7283
checkVisibility();
73-
super.tick();
84+
super.drawTick();
7485
}
7586

7687
@Override

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

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019-2022 GeyserMC. http://geysermc.org
2+
* Copyright (c) 2019-2024 GeyserMC. http://geysermc.org
33
*
44
* Permission is hereby granted, free of charge, to any person obtaining a copy
55
* of this software and associated documentation files (the "Software"), to deal
@@ -26,8 +26,21 @@
2626
package org.geysermc.geyser.entity.type;
2727

2828
/**
29-
* Implemented onto anything that should have code ran every Minecraft tick - 50 milliseconds.
29+
* Implemented onto anything that should have code ran every Minecraft tick.
30+
* By default, the Java server runs at 20 TPS, 50 milliseconds for each tick.
3031
*/
3132
public interface Tickable {
33+
/**
34+
* This function gets called every tick at all times, even when the server requests that
35+
* the game should be frozen. This should be used for updating things that are always
36+
* client side updated on Java, regardless of if the server is frozen or not.
37+
*/
38+
default void drawTick() {
39+
}
40+
41+
/**
42+
* This function gets called every game tick as long as the
43+
* game tick loop isn't frozen.
44+
*/
3245
void tick();
3346
}

0 commit comments

Comments
 (0)