Mirror von
https://github.com/GeyserMC/Geyser.git
synchronisiert 2024-11-20 06:50:09 +01:00
Prevent projectiles from blocking the player's vision (#2472)
Prevent Snowballs, Eggs, and other throwable projectiles from blocking the player's screen
Dieser Commit ist enthalten in:
Ursprung
3d04a957d0
Commit
57c0185b45
@ -43,17 +43,17 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.jline</groupId>
|
<groupId>org.jline</groupId>
|
||||||
<artifactId>jline-terminal</artifactId>
|
<artifactId>jline-terminal</artifactId>
|
||||||
<version>3.9.0</version>
|
<version>3.20.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.jline</groupId>
|
<groupId>org.jline</groupId>
|
||||||
<artifactId>jline-terminal-jna</artifactId>
|
<artifactId>jline-terminal-jna</artifactId>
|
||||||
<version>3.9.0</version>
|
<version>3.20.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.jline</groupId>
|
<groupId>org.jline</groupId>
|
||||||
<artifactId>jline-reader</artifactId>
|
<artifactId>jline-reader</artifactId>
|
||||||
<version>3.9.0</version>
|
<version>3.20.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.logging.log4j</groupId>
|
<groupId>org.apache.logging.log4j</groupId>
|
||||||
|
@ -249,10 +249,7 @@ public class Entity {
|
|||||||
// Swimming is ignored here and instead we rely on the pose
|
// Swimming is ignored here and instead we rely on the pose
|
||||||
metadata.getFlags().setFlag(EntityFlag.GLIDING, (xd & 0x80) == 0x80);
|
metadata.getFlags().setFlag(EntityFlag.GLIDING, (xd & 0x80) == 0x80);
|
||||||
|
|
||||||
// Armour stands are handled in their own class
|
setInvisible(session, (xd & 0x20) == 0x20);
|
||||||
if (!this.is(ArmorStandEntity.class)) {
|
|
||||||
metadata.getFlags().setFlag(EntityFlag.INVISIBLE, (xd & 0x20) == 0x20);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 1: // Air/bubbles
|
case 1: // Air/bubbles
|
||||||
@ -343,6 +340,16 @@ public class Entity {
|
|||||||
return 300;
|
return 300;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set a boolean - whether the entity is invisible or visible
|
||||||
|
*
|
||||||
|
* @param session the Geyser session
|
||||||
|
* @param value true if the entity is invisible
|
||||||
|
*/
|
||||||
|
protected void setInvisible(GeyserSession session, boolean value) {
|
||||||
|
metadata.getFlags().setFlag(EntityFlag.INVISIBLE, value);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* x = Pitch, y = HeadYaw, z = Yaw
|
* x = Pitch, y = HeadYaw, z = Yaw
|
||||||
*
|
*
|
||||||
|
@ -0,0 +1,76 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2019-2021 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.connector.entity;
|
||||||
|
|
||||||
|
import com.nukkitx.math.vector.Vector3f;
|
||||||
|
import com.nukkitx.protocol.bedrock.data.entity.EntityFlag;
|
||||||
|
import org.geysermc.connector.entity.type.EntityType;
|
||||||
|
import org.geysermc.connector.network.session.GeyserSession;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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(long entityId, long geyserId, EntityType entityType, Vector3f position, Vector3f motion, Vector3f rotation) {
|
||||||
|
super(entityId, geyserId, entityType, position, motion, rotation);
|
||||||
|
metadata.getFlags().setFlag(EntityFlag.INVISIBLE, true);
|
||||||
|
invisible = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void checkVisibility(GeyserSession session) {
|
||||||
|
if (invisible != metadata.getFlags().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) {
|
||||||
|
metadata.getFlags().setFlag(EntityFlag.INVISIBLE, false);
|
||||||
|
updateBedrockMetadata(session);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
metadata.getFlags().setFlag(EntityFlag.INVISIBLE, true);
|
||||||
|
updateBedrockMetadata(session);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
age++;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void tick(GeyserSession session) {
|
||||||
|
checkVisibility(session);
|
||||||
|
super.tick(session);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void setInvisible(GeyserSession session, boolean value) {
|
||||||
|
invisible = value;
|
||||||
|
}
|
||||||
|
}
|
@ -41,7 +41,7 @@ import org.geysermc.connector.registry.type.ItemMapping;
|
|||||||
|
|
||||||
import java.util.EnumSet;
|
import java.util.EnumSet;
|
||||||
|
|
||||||
public class ThrownPotionEntity extends ThrowableEntity {
|
public class ThrownPotionEntity extends ThrowableItemEntity {
|
||||||
private static final EnumSet<Potion> NON_ENCHANTED_POTIONS = EnumSet.of(Potion.WATER, Potion.MUNDANE, Potion.THICK, Potion.AWKWARD);
|
private static final EnumSet<Potion> NON_ENCHANTED_POTIONS = EnumSet.of(Potion.WATER, Potion.MUNDANE, Potion.THICK, Potion.AWKWARD);
|
||||||
|
|
||||||
public ThrownPotionEntity(long entityId, long geyserId, EntityType entityType, Vector3f position, Vector3f motion, Vector3f rotation) {
|
public ThrownPotionEntity(long entityId, long geyserId, EntityType entityType, Vector3f position, Vector3f motion, Vector3f rotation) {
|
||||||
|
@ -116,15 +116,7 @@ public class ArmorStandEntity extends LivingEntity {
|
|||||||
@Override
|
@Override
|
||||||
public void updateBedrockMetadata(EntityMetadata entityMetadata, GeyserSession session) {
|
public void updateBedrockMetadata(EntityMetadata entityMetadata, GeyserSession session) {
|
||||||
super.updateBedrockMetadata(entityMetadata, session);
|
super.updateBedrockMetadata(entityMetadata, session);
|
||||||
if (entityMetadata.getId() == 0 && entityMetadata.getType() == MetadataType.BYTE) {
|
if (entityMetadata.getId() == 2) {
|
||||||
byte xd = (byte) entityMetadata.getValue();
|
|
||||||
|
|
||||||
// Check if the armour stand is invisible and store accordingly
|
|
||||||
if (primaryEntity) {
|
|
||||||
isInvisible = (xd & 0x20) == 0x20;
|
|
||||||
updateSecondEntityStatus(false);
|
|
||||||
}
|
|
||||||
} else if (entityMetadata.getId() == 2) {
|
|
||||||
updateSecondEntityStatus(false);
|
updateSecondEntityStatus(false);
|
||||||
} else if (entityMetadata.getId() == 15 && entityMetadata.getType() == MetadataType.BYTE) {
|
} else if (entityMetadata.getId() == 15 && entityMetadata.getType() == MetadataType.BYTE) {
|
||||||
byte xd = (byte) entityMetadata.getValue();
|
byte xd = (byte) entityMetadata.getValue();
|
||||||
@ -242,6 +234,15 @@ public class ArmorStandEntity extends LivingEntity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void setInvisible(GeyserSession session, boolean value) {
|
||||||
|
// Check if the armour stand is invisible and store accordingly
|
||||||
|
if (primaryEntity) {
|
||||||
|
isInvisible = value;
|
||||||
|
updateSecondEntityStatus(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setHelmet(ItemData helmet) {
|
public void setHelmet(ItemData helmet) {
|
||||||
super.setHelmet(helmet);
|
super.setHelmet(helmet);
|
||||||
|
@ -107,7 +107,7 @@ public enum EntityType {
|
|||||||
PRIMED_TNT(TNTEntity.class, 65, 0.98f, 0.98f, 0.98f, 0f, "minecraft:tnt"),
|
PRIMED_TNT(TNTEntity.class, 65, 0.98f, 0.98f, 0.98f, 0f, "minecraft:tnt"),
|
||||||
FALLING_BLOCK(FallingBlockEntity.class, 66, 0.98f, 0.98f),
|
FALLING_BLOCK(FallingBlockEntity.class, 66, 0.98f, 0.98f),
|
||||||
MOVING_BLOCK(Entity.class, 67, 0f),
|
MOVING_BLOCK(Entity.class, 67, 0f),
|
||||||
THROWN_EXP_BOTTLE(ThrowableEntity.class, 68, 0.25f, 0.25f, 0f, 0f, "minecraft:xp_bottle"),
|
THROWN_EXP_BOTTLE(ThrowableItemEntity.class, 68, 0.25f, 0.25f, 0f, 0f, "minecraft:xp_bottle"),
|
||||||
EXPERIENCE_ORB(ExpOrbEntity.class, 69, 0f, 0f, 0f, 0f, "minecraft:xp_orb"),
|
EXPERIENCE_ORB(ExpOrbEntity.class, 69, 0f, 0f, 0f, 0f, "minecraft:xp_orb"),
|
||||||
EYE_OF_ENDER(Entity.class, 70, 0.25f, 0.25f, 0f, 0f, "minecraft:eye_of_ender_signal"),
|
EYE_OF_ENDER(Entity.class, 70, 0.25f, 0.25f, 0f, 0f, "minecraft:eye_of_ender_signal"),
|
||||||
END_CRYSTAL(EnderCrystalEntity.class, 71, 2.0f, 2.0f, 2.0f, 0f, "minecraft:ender_crystal"),
|
END_CRYSTAL(EnderCrystalEntity.class, 71, 2.0f, 2.0f, 2.0f, 0f, "minecraft:ender_crystal"),
|
||||||
@ -121,13 +121,13 @@ public enum EntityType {
|
|||||||
DRAGON_FIREBALL(ItemedFireballEntity.class, 79, 1.0f),
|
DRAGON_FIREBALL(ItemedFireballEntity.class, 79, 1.0f),
|
||||||
ARROW(TippedArrowEntity.class, 80, 0.25f, 0.25f),
|
ARROW(TippedArrowEntity.class, 80, 0.25f, 0.25f),
|
||||||
SPECTRAL_ARROW(AbstractArrowEntity.class, 80, 0.25f, 0.25f, 0.25f, 0f, "minecraft:arrow"),
|
SPECTRAL_ARROW(AbstractArrowEntity.class, 80, 0.25f, 0.25f, 0.25f, 0f, "minecraft:arrow"),
|
||||||
SNOWBALL(ThrowableEntity.class, 81, 0.25f),
|
SNOWBALL(ThrowableItemEntity.class, 81, 0.25f),
|
||||||
THROWN_EGG(ThrowableEntity.class, 82, 0.25f, 0.25f, 0.25f, 0f, "minecraft:egg"),
|
THROWN_EGG(ThrowableItemEntity.class, 82, 0.25f, 0.25f, 0.25f, 0f, "minecraft:egg"),
|
||||||
PAINTING(PaintingEntity.class, 83, 0f),
|
PAINTING(PaintingEntity.class, 83, 0f),
|
||||||
MINECART(MinecartEntity.class, 84, 0.7f, 0.98f, 0.98f, 0.35f),
|
MINECART(MinecartEntity.class, 84, 0.7f, 0.98f, 0.98f, 0.35f),
|
||||||
FIREBALL(ItemedFireballEntity.class, 85, 1.0f),
|
FIREBALL(ItemedFireballEntity.class, 85, 1.0f),
|
||||||
THROWN_POTION(ThrownPotionEntity.class, 86, 0.25f, 0.25f, 0.25f, 0f, "minecraft:splash_potion"),
|
THROWN_POTION(ThrownPotionEntity.class, 86, 0.25f, 0.25f, 0.25f, 0f, "minecraft:splash_potion"),
|
||||||
THROWN_ENDERPEARL(ThrowableEntity.class, 87, 0.25f, 0.25f, 0.25f, 0f, "minecraft:ender_pearl"),
|
THROWN_ENDERPEARL(ThrowableItemEntity.class, 87, 0.25f, 0.25f, 0.25f, 0f, "minecraft:ender_pearl"),
|
||||||
LEASH_KNOT(LeashKnotEntity.class, 88, 0.5f, 0.375f),
|
LEASH_KNOT(LeashKnotEntity.class, 88, 0.5f, 0.375f),
|
||||||
WITHER_SKULL(WitherSkullEntity.class, 89, 0.3125f),
|
WITHER_SKULL(WitherSkullEntity.class, 89, 0.3125f),
|
||||||
BOAT(BoatEntity.class, 90, 0.6f, 1.6f, 1.6f, 0.35f),
|
BOAT(BoatEntity.class, 90, 0.6f, 1.6f, 1.6f, 0.35f),
|
||||||
|
@ -75,6 +75,7 @@ import org.geysermc.connector.common.AuthType;
|
|||||||
import org.geysermc.connector.configuration.EmoteOffhandWorkaroundOption;
|
import org.geysermc.connector.configuration.EmoteOffhandWorkaroundOption;
|
||||||
import org.geysermc.connector.entity.Entity;
|
import org.geysermc.connector.entity.Entity;
|
||||||
import org.geysermc.connector.entity.ItemFrameEntity;
|
import org.geysermc.connector.entity.ItemFrameEntity;
|
||||||
|
import org.geysermc.connector.entity.ThrowableEntity;
|
||||||
import org.geysermc.connector.entity.Tickable;
|
import org.geysermc.connector.entity.Tickable;
|
||||||
import org.geysermc.connector.entity.attribute.GeyserAttributeType;
|
import org.geysermc.connector.entity.attribute.GeyserAttributeType;
|
||||||
import org.geysermc.connector.entity.player.SessionPlayerEntity;
|
import org.geysermc.connector.entity.player.SessionPlayerEntity;
|
||||||
@ -904,6 +905,7 @@ public class GeyserSession implements CommandSender {
|
|||||||
* Called every 50 milliseconds - one Minecraft tick.
|
* Called every 50 milliseconds - one Minecraft tick.
|
||||||
*/
|
*/
|
||||||
protected void tick() {
|
protected void tick() {
|
||||||
|
try {
|
||||||
// Check to see if the player's position needs updating - a position update should be sent once every 3 seconds
|
// Check to see if the player's position needs updating - a position update should be sent once every 3 seconds
|
||||||
if (spawned && (System.currentTimeMillis() - lastMovementTimestamp) > 3000) {
|
if (spawned && (System.currentTimeMillis() - lastMovementTimestamp) > 3000) {
|
||||||
// Recalculate in case something else changed position
|
// Recalculate in case something else changed position
|
||||||
@ -920,6 +922,9 @@ public class GeyserSession implements CommandSender {
|
|||||||
for (Tickable entity : entityCache.getTickableEntities()) {
|
for (Tickable entity : entityCache.getTickableEntities()) {
|
||||||
entity.tick(this);
|
entity.tick(this);
|
||||||
}
|
}
|
||||||
|
} catch (Throwable throwable) {
|
||||||
|
throwable.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setAuthenticationData(AuthData authData) {
|
public void setAuthenticationData(AuthData authData) {
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren