mirror of
https://github.com/GeyserMC/Geyser.git
synced 2024-12-29 15:49:09 +01:00
Camera shake and fog effect api (#3931)
This commit is contained in:
parent
b344e21f7f
commit
ff05c98690
8 changed files with 142 additions and 52 deletions
|
@ -0,0 +1,31 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2019-2023 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.api.bedrock.camera;
|
||||||
|
|
||||||
|
public enum CameraShake {
|
||||||
|
POSITIONAL,
|
||||||
|
ROTATIONAL;
|
||||||
|
}
|
|
@ -29,10 +29,12 @@ import org.checkerframework.checker.index.qual.NonNegative;
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
import org.geysermc.api.connection.Connection;
|
import org.geysermc.api.connection.Connection;
|
||||||
|
import org.geysermc.geyser.api.bedrock.camera.CameraShake;
|
||||||
import org.geysermc.geyser.api.command.CommandSource;
|
import org.geysermc.geyser.api.command.CommandSource;
|
||||||
import org.geysermc.geyser.api.entity.type.GeyserEntity;
|
import org.geysermc.geyser.api.entity.type.GeyserEntity;
|
||||||
import org.geysermc.geyser.api.entity.type.player.GeyserPlayerEntity;
|
import org.geysermc.geyser.api.entity.type.player.GeyserPlayerEntity;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -47,9 +49,50 @@ public interface GeyserConnection extends Connection, CommandSource {
|
||||||
CompletableFuture<@Nullable GeyserEntity> entityByJavaId(@NonNegative int javaId);
|
CompletableFuture<@Nullable GeyserEntity> entityByJavaId(@NonNegative int javaId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Displays a player entity as emoting to this client.
|
||||||
*
|
*
|
||||||
* @param emoter the player entity emoting.
|
* @param emoter the player entity emoting.
|
||||||
* @param emoteId the emote ID to send to the client.
|
* @param emoteId the emote ID to send to this client.
|
||||||
*/
|
*/
|
||||||
void showEmote(@NonNull GeyserPlayerEntity emoter, @NonNull String emoteId);
|
void showEmote(@NonNull GeyserPlayerEntity emoter, @NonNull String emoteId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shakes the client's camera.<br><br>
|
||||||
|
* If the camera is already shaking with the same {@link CameraShake} type, then the additional intensity
|
||||||
|
* will be layered on top of the existing intensity, with their own distinct durations.<br>
|
||||||
|
* If the existing shake type is different and the new intensity/duration are not positive, the existing shake only
|
||||||
|
* switches to the new type. Otherwise, the existing shake is completely overridden.
|
||||||
|
*
|
||||||
|
* @param intensity the intensity of the shake. The client has a maximum total intensity of 4.
|
||||||
|
* @param duration the time in seconds that the shake will occur for
|
||||||
|
* @param type the type of shake
|
||||||
|
*/
|
||||||
|
void shakeCamera(float intensity, float duration, @NonNull CameraShake type);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stops all camera shake of any type.
|
||||||
|
*/
|
||||||
|
void stopCameraShake();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds the given fog IDs to the fog cache, then sends all fog IDs in the cache to the client.
|
||||||
|
* <p>
|
||||||
|
* Fog IDs can be found <a href="https://wiki.bedrock.dev/documentation/fog-ids.html">here</a>
|
||||||
|
*
|
||||||
|
* @param fogNameSpaces the fog IDs to add. If empty, the existing cached IDs will still be sent.
|
||||||
|
*/
|
||||||
|
void sendFog(String... fogNameSpaces);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes the given fog IDs from the fog cache, then sends all fog IDs in the cache to the client.
|
||||||
|
*
|
||||||
|
* @param fogNameSpaces the fog IDs to remove. If empty, all fog IDs will be removed.
|
||||||
|
*/
|
||||||
|
void removeFog(String... fogNameSpaces);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns an immutable copy of all fog affects currently applied to this client.
|
||||||
|
*/
|
||||||
|
@NonNull
|
||||||
|
Set<String> fogEffects();
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@ plugins {
|
||||||
|
|
||||||
allprojects {
|
allprojects {
|
||||||
group = "org.geysermc.geyser"
|
group = "org.geysermc.geyser"
|
||||||
version = "2.1.1-SNAPSHOT"
|
version = "2.1.2-SNAPSHOT"
|
||||||
description = "Allows for players from Minecraft: Bedrock Edition to join Minecraft: Java Edition servers."
|
description = "Allows for players from Minecraft: Bedrock Edition to join Minecraft: Java Edition servers."
|
||||||
|
|
||||||
tasks.withType<JavaCompile> {
|
tasks.withType<JavaCompile> {
|
||||||
|
|
|
@ -35,7 +35,7 @@ package org.geysermc.geyser.level;
|
||||||
* @param doUpperHeightWarn whether to warn in the console if the Java dimension height exceeds Bedrock's.
|
* @param doUpperHeightWarn whether to warn in the console if the Java dimension height exceeds Bedrock's.
|
||||||
*/
|
*/
|
||||||
public record BedrockDimension(int minY, int height, boolean doUpperHeightWarn) {
|
public record BedrockDimension(int minY, int height, boolean doUpperHeightWarn) {
|
||||||
public static BedrockDimension OVERWORLD = new BedrockDimension(-64, 384, true);
|
public static final BedrockDimension OVERWORLD = new BedrockDimension(-64, 384, true);
|
||||||
public static BedrockDimension THE_NETHER = new BedrockDimension(0, 128, false);
|
public static final BedrockDimension THE_NETHER = new BedrockDimension(0, 128, false);
|
||||||
public static BedrockDimension THE_END = new BedrockDimension(0, 256, true);
|
public static final BedrockDimension THE_END = new BedrockDimension(0, 256, true);
|
||||||
}
|
}
|
||||||
|
|
|
@ -98,6 +98,7 @@ import org.cloudburstmc.protocol.common.util.OptionalBoolean;
|
||||||
import org.geysermc.api.util.BedrockPlatform;
|
import org.geysermc.api.util.BedrockPlatform;
|
||||||
import org.geysermc.api.util.InputMode;
|
import org.geysermc.api.util.InputMode;
|
||||||
import org.geysermc.api.util.UiProfile;
|
import org.geysermc.api.util.UiProfile;
|
||||||
|
import org.geysermc.geyser.api.bedrock.camera.CameraShake;
|
||||||
import org.geysermc.geyser.api.util.PlatformType;
|
import org.geysermc.geyser.api.util.PlatformType;
|
||||||
import org.geysermc.cumulus.form.Form;
|
import org.geysermc.cumulus.form.Form;
|
||||||
import org.geysermc.cumulus.form.util.FormBuilder;
|
import org.geysermc.cumulus.form.util.FormBuilder;
|
||||||
|
@ -533,7 +534,10 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource {
|
||||||
@Setter
|
@Setter
|
||||||
private boolean waitingForStatistics = false;
|
private boolean waitingForStatistics = false;
|
||||||
|
|
||||||
private final Set<String> fogNameSpaces = new HashSet<>();
|
/**
|
||||||
|
* All fog effects that are currently applied to the client.
|
||||||
|
*/
|
||||||
|
private final Set<String> appliedFog = new HashSet<>();
|
||||||
|
|
||||||
private final Set<UUID> emotes;
|
private final Set<UUID> emotes;
|
||||||
|
|
||||||
|
@ -1828,38 +1832,6 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Send the following fog IDs, as well as the cached ones, to the client.
|
|
||||||
*
|
|
||||||
* Fog IDs can be found here:
|
|
||||||
* https://wiki.bedrock.dev/documentation/fog-ids.html
|
|
||||||
*
|
|
||||||
* @param fogNameSpaces the fog ids to add
|
|
||||||
*/
|
|
||||||
public void sendFog(String... fogNameSpaces) {
|
|
||||||
this.fogNameSpaces.addAll(Arrays.asList(fogNameSpaces));
|
|
||||||
|
|
||||||
PlayerFogPacket packet = new PlayerFogPacket();
|
|
||||||
packet.getFogStack().addAll(this.fogNameSpaces);
|
|
||||||
sendUpstreamPacket(packet);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Removes the following fog IDs from the client and the cache.
|
|
||||||
*
|
|
||||||
* @param fogNameSpaces the fog ids to remove
|
|
||||||
*/
|
|
||||||
public void removeFog(String... fogNameSpaces) {
|
|
||||||
if (fogNameSpaces.length == 0) {
|
|
||||||
this.fogNameSpaces.clear();
|
|
||||||
} else {
|
|
||||||
this.fogNameSpaces.removeAll(Arrays.asList(fogNameSpaces));
|
|
||||||
}
|
|
||||||
PlayerFogPacket packet = new PlayerFogPacket();
|
|
||||||
packet.getFogStack().addAll(this.fogNameSpaces);
|
|
||||||
sendUpstreamPacket(packet);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean canUseCommandBlocks() {
|
public boolean canUseCommandBlocks() {
|
||||||
return instabuild && opPermissionLevel >= 2;
|
return instabuild && opPermissionLevel >= 2;
|
||||||
}
|
}
|
||||||
|
@ -1971,6 +1943,54 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource {
|
||||||
sendUpstreamPacket(packet);
|
sendUpstreamPacket(packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void shakeCamera(float intensity, float duration, @NonNull CameraShake type) {
|
||||||
|
CameraShakePacket packet = new CameraShakePacket();
|
||||||
|
packet.setIntensity(intensity);
|
||||||
|
packet.setDuration(duration);
|
||||||
|
packet.setShakeType(type == CameraShake.POSITIONAL ? CameraShakeType.POSITIONAL : CameraShakeType.ROTATIONAL);
|
||||||
|
packet.setShakeAction(CameraShakeAction.ADD);
|
||||||
|
sendUpstreamPacket(packet);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void stopCameraShake() {
|
||||||
|
CameraShakePacket packet = new CameraShakePacket();
|
||||||
|
// CameraShakeAction.STOP removes all types regardless of the given type, but regardless it can't be null
|
||||||
|
packet.setShakeType(CameraShakeType.POSITIONAL);
|
||||||
|
packet.setShakeAction(CameraShakeAction.STOP);
|
||||||
|
sendUpstreamPacket(packet);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void sendFog(String... fogNameSpaces) {
|
||||||
|
Collections.addAll(this.appliedFog, fogNameSpaces);
|
||||||
|
|
||||||
|
PlayerFogPacket packet = new PlayerFogPacket();
|
||||||
|
packet.getFogStack().addAll(this.appliedFog);
|
||||||
|
sendUpstreamPacket(packet);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void removeFog(String... fogNameSpaces) {
|
||||||
|
if (fogNameSpaces.length == 0) {
|
||||||
|
this.appliedFog.clear();
|
||||||
|
} else {
|
||||||
|
for (String id : fogNameSpaces) {
|
||||||
|
this.appliedFog.remove(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
PlayerFogPacket packet = new PlayerFogPacket();
|
||||||
|
packet.getFogStack().addAll(this.appliedFog);
|
||||||
|
sendUpstreamPacket(packet);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NonNull Set<String> fogEffects() {
|
||||||
|
// Use a copy so that sendFog/removeFog can be called while iterating the returned set (avoid CME)
|
||||||
|
return Set.copyOf(this.appliedFog);
|
||||||
|
}
|
||||||
|
|
||||||
public void addCommandEnum(String name, String enums) {
|
public void addCommandEnum(String name, String enums) {
|
||||||
softEnumPacket(name, SoftEnumUpdateType.ADD, enums);
|
softEnumPacket(name, SoftEnumUpdateType.ADD, enums);
|
||||||
}
|
}
|
||||||
|
|
|
@ -148,7 +148,7 @@ public class JavaLoginTranslator extends PacketTranslator<ClientboundLoginPacket
|
||||||
DimensionUtils.switchDimension(session, newDimension);
|
DimensionUtils.switchDimension(session, newDimension);
|
||||||
} else if (DimensionUtils.isCustomBedrockNetherId() && newDimension.equalsIgnoreCase(DimensionUtils.NETHER)) {
|
} else if (DimensionUtils.isCustomBedrockNetherId() && newDimension.equalsIgnoreCase(DimensionUtils.NETHER)) {
|
||||||
// If the player is spawning into the "fake" nether, send them some fog
|
// If the player is spawning into the "fake" nether, send them some fog
|
||||||
session.sendFog("minecraft:fog_hell");
|
session.sendFog(DimensionUtils.BEDROCK_FOG_HELL);
|
||||||
}
|
}
|
||||||
|
|
||||||
ChunkUtils.loadDimension(session);
|
ChunkUtils.loadDimension(session);
|
||||||
|
|
|
@ -45,6 +45,8 @@ public class DimensionUtils {
|
||||||
// Changes if the above-bedrock Nether building workaround is applied
|
// Changes if the above-bedrock Nether building workaround is applied
|
||||||
private static int BEDROCK_NETHER_ID = 1;
|
private static int BEDROCK_NETHER_ID = 1;
|
||||||
|
|
||||||
|
public static final String BEDROCK_FOG_HELL = "minecraft:fog_hell";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* String reference to vanilla Java overworld dimension identifier
|
* String reference to vanilla Java overworld dimension identifier
|
||||||
*/
|
*/
|
||||||
|
@ -59,8 +61,8 @@ public class DimensionUtils {
|
||||||
public static final String THE_END = "minecraft:the_end";
|
public static final String THE_END = "minecraft:the_end";
|
||||||
|
|
||||||
public static void switchDimension(GeyserSession session, String javaDimension) {
|
public static void switchDimension(GeyserSession session, String javaDimension) {
|
||||||
int bedrockDimension = javaToBedrock(javaDimension);
|
int bedrockDimension = javaToBedrock(javaDimension); // new bedrock dimension
|
||||||
int previousDimension = javaToBedrock(session.getDimension());
|
String previousDimension = session.getDimension(); // previous java dimension
|
||||||
|
|
||||||
Entity player = session.getPlayerEntity();
|
Entity player = session.getPlayerEntity();
|
||||||
|
|
||||||
|
@ -139,11 +141,11 @@ public class DimensionUtils {
|
||||||
// If the bedrock nether height workaround is enabled, meaning the client is told it's in the end dimension,
|
// If the bedrock nether height workaround is enabled, meaning the client is told it's in the end dimension,
|
||||||
// we check if the player is entering the nether and apply the nether fog to fake the fact that the client
|
// we check if the player is entering the nether and apply the nether fog to fake the fact that the client
|
||||||
// thinks they are in the end dimension.
|
// thinks they are in the end dimension.
|
||||||
if (BEDROCK_NETHER_ID == 2) {
|
if (isCustomBedrockNetherId()) {
|
||||||
if (NETHER.equals(javaDimension)) {
|
if (NETHER.equals(javaDimension)) {
|
||||||
session.sendFog("minecraft:fog_hell");
|
session.sendFog(BEDROCK_FOG_HELL);
|
||||||
} else if (previousDimension == BEDROCK_NETHER_ID) {
|
} else if (NETHER.equals(previousDimension)) {
|
||||||
session.removeFog("minecraft:fog_hell");
|
session.removeFog(BEDROCK_FOG_HELL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -200,7 +202,7 @@ public class DimensionUtils {
|
||||||
* @return the fake dimension to transfer to
|
* @return the fake dimension to transfer to
|
||||||
*/
|
*/
|
||||||
public static String getTemporaryDimension(String currentDimension, String newDimension) {
|
public static String getTemporaryDimension(String currentDimension, String newDimension) {
|
||||||
if (BEDROCK_NETHER_ID == 2) {
|
if (isCustomBedrockNetherId()) {
|
||||||
// Prevents rare instances of Bedrock locking up
|
// Prevents rare instances of Bedrock locking up
|
||||||
return javaToBedrock(newDimension) == 2 ? OVERWORLD : NETHER;
|
return javaToBedrock(newDimension) == 2 ? OVERWORLD : NETHER;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,6 @@
|
||||||
# Gradle settings
|
# Gradle settings
|
||||||
org.gradle.jvmargs=-Xmx4G
|
org.gradle.jvmargs=-Xmx4G
|
||||||
org.gradle.configureondemand=true
|
org.gradle.configureondemand=true
|
||||||
org.gradle.caching=true
|
|
||||||
org.gradle.parallel=true
|
|
||||||
|
|
||||||
group=org.geysermc
|
|
||||||
version=2.1.1-SNAPSHOT
|
|
||||||
|
|
||||||
org.gradle.caching=true
|
org.gradle.caching=true
|
||||||
org.gradle.parallel=true
|
org.gradle.parallel=true
|
||||||
org.gradle.vfs.watch=false
|
org.gradle.vfs.watch=false
|
Loading…
Reference in a new issue