mirror of
https://github.com/GeyserMC/Geyser.git
synced 2024-08-14 23:57:35 +00: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
|
@ -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.
|
||||
*/
|
||||
public record BedrockDimension(int minY, int height, boolean doUpperHeightWarn) {
|
||||
public static BedrockDimension OVERWORLD = new BedrockDimension(-64, 384, true);
|
||||
public static BedrockDimension THE_NETHER = new BedrockDimension(0, 128, false);
|
||||
public static BedrockDimension THE_END = new BedrockDimension(0, 256, true);
|
||||
public static final BedrockDimension OVERWORLD = new BedrockDimension(-64, 384, true);
|
||||
public static final BedrockDimension THE_NETHER = new BedrockDimension(0, 128, false);
|
||||
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.InputMode;
|
||||
import org.geysermc.api.util.UiProfile;
|
||||
import org.geysermc.geyser.api.bedrock.camera.CameraShake;
|
||||
import org.geysermc.geyser.api.util.PlatformType;
|
||||
import org.geysermc.cumulus.form.Form;
|
||||
import org.geysermc.cumulus.form.util.FormBuilder;
|
||||
|
@ -533,7 +534,10 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource {
|
|||
@Setter
|
||||
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;
|
||||
|
||||
|
@ -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() {
|
||||
return instabuild && opPermissionLevel >= 2;
|
||||
}
|
||||
|
@ -1971,6 +1943,54 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource {
|
|||
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) {
|
||||
softEnumPacket(name, SoftEnumUpdateType.ADD, enums);
|
||||
}
|
||||
|
|
|
@ -148,7 +148,7 @@ public class JavaLoginTranslator extends PacketTranslator<ClientboundLoginPacket
|
|||
DimensionUtils.switchDimension(session, newDimension);
|
||||
} else if (DimensionUtils.isCustomBedrockNetherId() && newDimension.equalsIgnoreCase(DimensionUtils.NETHER)) {
|
||||
// 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);
|
||||
|
|
|
@ -45,6 +45,8 @@ public class DimensionUtils {
|
|||
// Changes if the above-bedrock Nether building workaround is applied
|
||||
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
|
||||
*/
|
||||
|
@ -59,8 +61,8 @@ public class DimensionUtils {
|
|||
public static final String THE_END = "minecraft:the_end";
|
||||
|
||||
public static void switchDimension(GeyserSession session, String javaDimension) {
|
||||
int bedrockDimension = javaToBedrock(javaDimension);
|
||||
int previousDimension = javaToBedrock(session.getDimension());
|
||||
int bedrockDimension = javaToBedrock(javaDimension); // new bedrock dimension
|
||||
String previousDimension = session.getDimension(); // previous java dimension
|
||||
|
||||
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,
|
||||
// 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.
|
||||
if (BEDROCK_NETHER_ID == 2) {
|
||||
if (isCustomBedrockNetherId()) {
|
||||
if (NETHER.equals(javaDimension)) {
|
||||
session.sendFog("minecraft:fog_hell");
|
||||
} else if (previousDimension == BEDROCK_NETHER_ID) {
|
||||
session.removeFog("minecraft:fog_hell");
|
||||
session.sendFog(BEDROCK_FOG_HELL);
|
||||
} else if (NETHER.equals(previousDimension)) {
|
||||
session.removeFog(BEDROCK_FOG_HELL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -200,7 +202,7 @@ public class DimensionUtils {
|
|||
* @return the fake dimension to transfer to
|
||||
*/
|
||||
public static String getTemporaryDimension(String currentDimension, String newDimension) {
|
||||
if (BEDROCK_NETHER_ID == 2) {
|
||||
if (isCustomBedrockNetherId()) {
|
||||
// Prevents rare instances of Bedrock locking up
|
||||
return javaToBedrock(newDimension) == 2 ? OVERWORLD : NETHER;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue