mirror of
https://github.com/GeyserMC/Geyser.git
synced 2024-08-14 23:57:35 +00:00
fix some stuff
This commit is contained in:
parent
c5f1f8375c
commit
99e7385bdc
4 changed files with 28 additions and 16 deletions
|
|
@ -39,14 +39,17 @@ import java.util.UUID;
|
||||||
* Used as a class for any projectile entity that looks like an item
|
* Used as a class for any projectile entity that looks like an item
|
||||||
*/
|
*/
|
||||||
public class ThrowableItemEntity extends ThrowableEntity {
|
public class ThrowableItemEntity extends ThrowableEntity {
|
||||||
private boolean invisible;
|
/**
|
||||||
|
* Number of draw ticks since the entity was spawned by the Java server
|
||||||
|
*/
|
||||||
private int age;
|
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) {
|
public ThrowableItemEntity(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);
|
super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw);
|
||||||
setFlag(EntityFlag.INVISIBLE, true);
|
setFlag(EntityFlag.INVISIBLE, true);
|
||||||
invisible = false;
|
invisible = false;
|
||||||
age = 0;
|
age = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -58,10 +61,14 @@ public class ThrowableItemEntity extends ThrowableEntity {
|
||||||
|
|
||||||
private void checkVisibility() {
|
private void checkVisibility() {
|
||||||
age++;
|
age++;
|
||||||
Vector3f playerPos = session.getPlayerEntity().getPosition().sub(0, session.getPlayerEntity().getDefinition().offset(),0);
|
|
||||||
|
|
||||||
// Prevent projectiles from blocking the player's screen
|
// Prevent projectiles from blocking the player's screen
|
||||||
setInvisible((age <= 2 && !session.isTickingFrozen()) || (playerPos.distanceSquared(position.add(0, definition.offset(), 0)) < 12.25));
|
if (session.isTickingFrozen()) {
|
||||||
|
Vector3f playerPos = session.getPlayerEntity().getPosition().sub(0, session.getPlayerEntity().getDefinition().offset(), 0);
|
||||||
|
setInvisible(playerPos.distanceSquared(position.add(0, definition.offset(), 0)) < 12.25);
|
||||||
|
} else {
|
||||||
|
setInvisible(age <= 2);
|
||||||
|
}
|
||||||
|
|
||||||
if (invisible != getFlag(EntityFlag.INVISIBLE)) {
|
if (invisible != getFlag(EntityFlag.INVISIBLE)) {
|
||||||
setFlag(EntityFlag.INVISIBLE, invisible);
|
setFlag(EntityFlag.INVISIBLE, invisible);
|
||||||
|
|
|
||||||
|
|
@ -587,7 +587,7 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource {
|
||||||
private boolean advancedTooltips = false;
|
private boolean advancedTooltips = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The thread that will run every 50 milliseconds - one Minecraft tick.
|
* The thread that will run every game tick.
|
||||||
*/
|
*/
|
||||||
private ScheduledFuture<?> tickThread = null;
|
private ScheduledFuture<?> tickThread = null;
|
||||||
|
|
||||||
|
|
@ -628,14 +628,15 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource {
|
||||||
private MinecraftProtocol protocol;
|
private MinecraftProtocol protocol;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
private int millisecondsPerTick = 50;
|
private int nanosecondsPerTick = 50000000;
|
||||||
|
@Getter
|
||||||
|
private float millisecondsPerTick = 50.0f;
|
||||||
private boolean tickingFrozen = false;
|
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.
|
* The amount of ticks requested by the server that the game should proceed with, even if the game tick loop is frozen.
|
||||||
*/
|
*/
|
||||||
@Setter
|
@Setter
|
||||||
private int stepTicks = 0;
|
private int stepTicks = 0;
|
||||||
private boolean gameShouldUpdate = true;
|
|
||||||
|
|
||||||
public GeyserSession(GeyserImpl geyser, BedrockServerSession bedrockServerSession, EventLoop eventLoop) {
|
public GeyserSession(GeyserImpl geyser, BedrockServerSession bedrockServerSession, EventLoop eventLoop) {
|
||||||
this.geyser = geyser;
|
this.geyser = geyser;
|
||||||
|
|
@ -904,7 +905,7 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource {
|
||||||
boolean floodgate = this.remoteServer.authType() == AuthType.FLOODGATE;
|
boolean floodgate = this.remoteServer.authType() == AuthType.FLOODGATE;
|
||||||
|
|
||||||
// Start ticking
|
// Start ticking
|
||||||
tickThread = eventLoop.scheduleAtFixedRate(this::tick, millisecondsPerTick, millisecondsPerTick, TimeUnit.MILLISECONDS);
|
tickThread = eventLoop.scheduleAtFixedRate(this::tick, nanosecondsPerTick, nanosecondsPerTick, TimeUnit.NANOSECONDS);
|
||||||
|
|
||||||
this.protocol.setUseDefaultListeners(false);
|
this.protocol.setUseDefaultListeners(false);
|
||||||
|
|
||||||
|
|
@ -1224,12 +1225,14 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource {
|
||||||
public void updateTickingState(float tickRate, boolean frozen) {
|
public void updateTickingState(float tickRate, boolean frozen) {
|
||||||
tickThread.cancel(false);
|
tickThread.cancel(false);
|
||||||
this.tickingFrozen = frozen;
|
this.tickingFrozen = frozen;
|
||||||
millisecondsPerTick = Math.round(1000.0f / MathUtils.clamp(tickRate, 1.0f, 10000.0f));
|
millisecondsPerTick = 1000.0f / tickRate;
|
||||||
tickThread = eventLoop.scheduleAtFixedRate(this::tick, millisecondsPerTick, millisecondsPerTick, TimeUnit.MILLISECONDS);
|
|
||||||
|
nanosecondsPerTick = MathUtils.ceil(1000000000.0f / MathUtils.clamp(tickRate, 1.0f, 10000.0f));
|
||||||
|
tickThread = eventLoop.scheduleAtFixedRate(this::tick, nanosecondsPerTick, nanosecondsPerTick, TimeUnit.NANOSECONDS);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called every Minecraft tick - 1000/tickRate milliseconds.
|
* Called every Minecraft tick.
|
||||||
*/
|
*/
|
||||||
protected void tick() {
|
protected void tick() {
|
||||||
try {
|
try {
|
||||||
|
|
@ -1267,7 +1270,7 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource {
|
||||||
isInWorldBorderWarningArea = false;
|
isInWorldBorderWarningArea = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
gameShouldUpdate = !tickingFrozen || stepTicks > 0;
|
boolean gameShouldUpdate = !tickingFrozen || stepTicks > 0;
|
||||||
if (stepTicks > 0) {
|
if (stepTicks > 0) {
|
||||||
--stepTicks;
|
--stepTicks;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -66,7 +66,7 @@ public class BedrockMobEquipmentTranslator extends PacketTranslator<MobEquipment
|
||||||
// (No need to send a release item packet - Java doesn't do this when swapping items)
|
// (No need to send a release item packet - Java doesn't do this when swapping items)
|
||||||
// Required to do it a tick later or else it doesn't register
|
// Required to do it a tick later or else it doesn't register
|
||||||
session.scheduleInEventLoop(() -> session.useItem(Hand.MAIN_HAND),
|
session.scheduleInEventLoop(() -> session.useItem(Hand.MAIN_HAND),
|
||||||
session.getMillisecondsPerTick(), TimeUnit.MILLISECONDS);
|
session.getNanosecondsPerTick(), TimeUnit.NANOSECONDS);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (oldItem.getJavaId() != newItem.getJavaId()) {
|
if (oldItem.getJavaId() != newItem.getJavaId()) {
|
||||||
|
|
|
||||||
|
|
@ -58,7 +58,8 @@ public class CooldownUtils {
|
||||||
CooldownType sessionPreference = session.getPreferencesCache().getCooldownPreference();
|
CooldownType sessionPreference = session.getPreferencesCache().getCooldownPreference();
|
||||||
if (sessionPreference == CooldownType.DISABLED) return;
|
if (sessionPreference == CooldownType.DISABLED) return;
|
||||||
|
|
||||||
if (session.getAttackSpeed() == 0.0 || session.getAttackSpeed() > 20) return; // 0.0 usually happens on login and causes issues with visuals; anything above 20 means a plugin like OldCombatMechanics is being used
|
if (session.getAttackSpeed() == 0.0 || session.getAttackSpeed() > 20)
|
||||||
|
return; // 0.0 usually happens on login and causes issues with visuals; anything above 20 means a plugin like OldCombatMechanics is being used
|
||||||
// Set the times to stay a bit with no fade in nor out
|
// Set the times to stay a bit with no fade in nor out
|
||||||
SetTitlePacket titlePacket = new SetTitlePacket();
|
SetTitlePacket titlePacket = new SetTitlePacket();
|
||||||
titlePacket.setType(SetTitlePacket.Type.TIMES);
|
titlePacket.setType(SetTitlePacket.Type.TIMES);
|
||||||
|
|
@ -91,7 +92,8 @@ public class CooldownUtils {
|
||||||
*/
|
*/
|
||||||
private static void computeCooldown(GeyserSession session, CooldownType sessionPreference, long lastHitTime) {
|
private static void computeCooldown(GeyserSession session, CooldownType sessionPreference, long lastHitTime) {
|
||||||
if (session.isClosed()) return; // Don't run scheduled tasks if the client left
|
if (session.isClosed()) return; // Don't run scheduled tasks if the client left
|
||||||
if (lastHitTime != session.getLastHitTime()) return; // Means another cooldown has started so there's no need to continue this one
|
if (lastHitTime != session.getLastHitTime())
|
||||||
|
return; // Means another cooldown has started so there's no need to continue this one
|
||||||
SetTitlePacket titlePacket = new SetTitlePacket();
|
SetTitlePacket titlePacket = new SetTitlePacket();
|
||||||
if (sessionPreference == CooldownType.ACTIONBAR) {
|
if (sessionPreference == CooldownType.ACTIONBAR) {
|
||||||
titlePacket.setType(SetTitlePacket.Type.ACTIONBAR);
|
titlePacket.setType(SetTitlePacket.Type.ACTIONBAR);
|
||||||
|
|
@ -104,7 +106,7 @@ public class CooldownUtils {
|
||||||
session.sendUpstreamPacket(titlePacket);
|
session.sendUpstreamPacket(titlePacket);
|
||||||
if (hasCooldown(session)) {
|
if (hasCooldown(session)) {
|
||||||
session.scheduleInEventLoop(() ->
|
session.scheduleInEventLoop(() ->
|
||||||
computeCooldown(session, sessionPreference, lastHitTime), session.getMillisecondsPerTick(), TimeUnit.MILLISECONDS); // Updated per tick. 1000 divided by 20 ticks equals 50
|
computeCooldown(session, sessionPreference, lastHitTime), session.getNanosecondsPerTick(), TimeUnit.NANOSECONDS); // Updated per tick. 1000 divided by 20 ticks equals 50
|
||||||
} else {
|
} else {
|
||||||
SetTitlePacket removeTitlePacket = new SetTitlePacket();
|
SetTitlePacket removeTitlePacket = new SetTitlePacket();
|
||||||
removeTitlePacket.setType(SetTitlePacket.Type.CLEAR);
|
removeTitlePacket.setType(SetTitlePacket.Type.CLEAR);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue