Skip to content

Commit

Permalink
Handle ClientboundTickingStatePacket correctly and fix Throwable Scal…
Browse files Browse the repository at this point in the history
…es (#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 <[email protected]>

* 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 <[email protected]>

* 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 <[email protected]>

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

Co-authored-by: chris <[email protected]>

* Fix missing import

---------

Co-authored-by: rtm516 <[email protected]>
Co-authored-by: chris <[email protected]>
  • Loading branch information
3 people authored Dec 9, 2024
1 parent 1fea22d commit 8b232d7
Show file tree
Hide file tree
Showing 13 changed files with 277 additions and 83 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.geysermc.geyser.entity.type.CommandBlockMinecartEntity;
import org.geysermc.geyser.entity.type.DisplayBaseEntity;
import org.geysermc.geyser.entity.type.EnderCrystalEntity;
import org.geysermc.geyser.entity.type.EnderEyeEntity;
import org.geysermc.geyser.entity.type.Entity;
import org.geysermc.geyser.entity.type.EvokerFangsEntity;
import org.geysermc.geyser.entity.type.ExpOrbEntity;
Expand Down Expand Up @@ -197,7 +198,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 @@ -345,7 +346,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 @@ -189,7 +189,7 @@ public void tick() {
session.sendDownstreamGamePacket(steerPacket);
return;
}
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 @@ -25,12 +25,14 @@

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.entity.EntityDefinitions;
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;

Expand All @@ -39,7 +41,7 @@
*/
public class ThrowableItemEntity extends ThrowableEntity {
/**
* Number of ticks since the entity was spawned by the Java server
* Number of draw ticks since the entity was spawned by the Java server
*/
private int age;
private boolean invisible;
Expand All @@ -48,29 +50,38 @@ public ThrowableItemEntity(GeyserSession session, int entityId, long geyserId, U
super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw);
setFlag(EntityFlag.INVISIBLE, true);
invisible = false;
age = 0;
}

@Override
protected void initializeMetadata() {
super.initializeMetadata();
// Correct sizing
dirtyMetadata.put(EntityDataTypes.SCALE, 0.5f);
}

private void checkVisibility() {
age++;

// Prevent projectiles from blocking the player's screen
if (session.isTickingFrozen()) {
// This may seem odd, but it matches java edition
Vector3f playerPos = session.getPlayerEntity().getPosition().down(EntityDefinitions.PLAYER.offset());
setInvisible(playerPos.distanceSquared(position.add(0, definition.offset(), 0)) < 12.25);
} else {
setInvisible(age < 2);
}

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();
}
Loading

0 comments on commit 8b232d7

Please sign in to comment.