mirror of
https://github.com/GeyserMC/Geyser.git
synced 2024-08-14 23:57:35 +00:00
address review
This commit is contained in:
parent
79eb277523
commit
3a3f5e849b
6 changed files with 47 additions and 56 deletions
|
|
@ -122,7 +122,7 @@ public abstract class GeyserModBootstrap implements GeyserBootstrap {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.geyserWorldManager = new GeyserModWorldManager(geyser, server);
|
this.geyserWorldManager = new GeyserModWorldManager(server);
|
||||||
|
|
||||||
// We want to do this late in the server startup process to allow other mods
|
// We want to do this late in the server startup process to allow other mods
|
||||||
// To do their job injecting, then connect into *that*
|
// To do their job injecting, then connect into *that*
|
||||||
|
|
|
||||||
|
|
@ -40,6 +40,7 @@ import org.spongepowered.asm.mixin.Shadow;
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
import org.spongepowered.asm.mixin.injection.Inject;
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||||
|
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
|
||||||
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
|
|
@ -50,7 +51,7 @@ public class IntegratedServerMixin implements GeyserServerPortGetter {
|
||||||
|
|
||||||
@Shadow @Final private Minecraft minecraft;
|
@Shadow @Final private Minecraft minecraft;
|
||||||
|
|
||||||
@Inject(method = "publishServer", at = @At("RETURN"))
|
@Inject(method = "publishServer", at = @At("RETURN"), locals = LocalCapture.NO_CAPTURE)
|
||||||
private void onOpenToLan(GameType gameType, boolean cheatsAllowed, int port, CallbackInfoReturnable<Boolean> cir) {
|
private void onOpenToLan(GameType gameType, boolean cheatsAllowed, int port, CallbackInfoReturnable<Boolean> cir) {
|
||||||
if (cir.getReturnValueZ()) {
|
if (cir.getReturnValueZ()) {
|
||||||
// If the LAN is opened, starts Geyser.
|
// If the LAN is opened, starts Geyser.
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,10 @@ import net.minecraft.world.level.block.Block;
|
||||||
import net.minecraft.world.level.block.SoundType;
|
import net.minecraft.world.level.block.SoundType;
|
||||||
import net.minecraft.world.level.block.state.BlockState;
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
import org.cloudburstmc.math.vector.Vector3f;
|
import org.cloudburstmc.math.vector.Vector3f;
|
||||||
import org.geysermc.geyser.platform.mod.world.GeyserModWorldManager;
|
import org.cloudburstmc.protocol.bedrock.data.SoundEvent;
|
||||||
|
import org.cloudburstmc.protocol.bedrock.packet.LevelSoundEventPacket;
|
||||||
|
import org.geysermc.geyser.GeyserImpl;
|
||||||
|
import org.geysermc.geyser.session.GeyserSession;
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
import org.spongepowered.asm.mixin.injection.Inject;
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
|
|
@ -44,7 +47,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||||
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
|
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
|
||||||
|
|
||||||
@Mixin(BlockItem.class)
|
@Mixin(BlockItem.class)
|
||||||
public class ModBlockPlaceListener {
|
public class BlockPlaceMixin {
|
||||||
|
|
||||||
@Inject(method = "place", locals = LocalCapture.CAPTURE_FAILSOFT, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;playSound(Lnet/minecraft/world/entity/player/Player;Lnet/minecraft/core/BlockPos;Lnet/minecraft/sounds/SoundEvent;Lnet/minecraft/sounds/SoundSource;FF)V"))
|
@Inject(method = "place", locals = LocalCapture.CAPTURE_FAILSOFT, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;playSound(Lnet/minecraft/world/entity/player/Player;Lnet/minecraft/core/BlockPos;Lnet/minecraft/sounds/SoundEvent;Lnet/minecraft/sounds/SoundSource;FF)V"))
|
||||||
private void geyser$hijackPlaySound(BlockPlaceContext blockPlaceContext, CallbackInfoReturnable<InteractionResult> cir, BlockPlaceContext blockPlaceContext2, BlockState blockState, BlockPos blockPos, Level level, Player player, ItemStack itemStack, BlockState blockState2, SoundType soundType) {
|
private void geyser$hijackPlaySound(BlockPlaceContext blockPlaceContext, CallbackInfoReturnable<InteractionResult> cir, BlockPlaceContext blockPlaceContext2, BlockState blockState, BlockPos blockPos, Level level, Player player, ItemStack itemStack, BlockState blockState2, SoundType soundType) {
|
||||||
|
|
@ -52,12 +55,25 @@ public class ModBlockPlaceListener {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GeyserSession session = GeyserImpl.getInstance().connectionByUuid(player.getUUID());
|
||||||
|
if (session == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Vector3f position = Vector3f.from(
|
Vector3f position = Vector3f.from(
|
||||||
blockPos.getX(),
|
blockPos.getX(),
|
||||||
blockPos.getY(),
|
blockPos.getY(),
|
||||||
blockPos.getZ()
|
blockPos.getZ()
|
||||||
);
|
);
|
||||||
|
|
||||||
GeyserModWorldManager.handleBlockPlace(player.getUUID(), position, Block.BLOCK_STATE_REGISTRY.getId(blockState2));
|
LevelSoundEventPacket placeBlockSoundPacket = new LevelSoundEventPacket();
|
||||||
|
placeBlockSoundPacket.setSound(SoundEvent.PLACE);
|
||||||
|
placeBlockSoundPacket.setPosition(position);
|
||||||
|
placeBlockSoundPacket.setBabySound(false);
|
||||||
|
placeBlockSoundPacket.setExtraData(session.getBlockMappings().getBedrockBlockId(Block.BLOCK_STATE_REGISTRY.getId(blockState2)));
|
||||||
|
placeBlockSoundPacket.setIdentifier(":");
|
||||||
|
session.sendUpstreamPacket(placeBlockSoundPacket);
|
||||||
|
session.setLastBlockPlacePosition(null);
|
||||||
|
session.setLastBlockPlaced(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -45,11 +45,7 @@ import net.minecraft.world.level.chunk.ChunkAccess;
|
||||||
import net.minecraft.world.level.chunk.LevelChunkSection;
|
import net.minecraft.world.level.chunk.LevelChunkSection;
|
||||||
import net.minecraft.world.level.chunk.status.ChunkStatus;
|
import net.minecraft.world.level.chunk.status.ChunkStatus;
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
import org.cloudburstmc.math.vector.Vector3f;
|
|
||||||
import org.cloudburstmc.math.vector.Vector3i;
|
import org.cloudburstmc.math.vector.Vector3i;
|
||||||
import org.cloudburstmc.protocol.bedrock.data.SoundEvent;
|
|
||||||
import org.cloudburstmc.protocol.bedrock.packet.LevelSoundEventPacket;
|
|
||||||
import org.geysermc.geyser.GeyserImpl;
|
|
||||||
import org.geysermc.geyser.level.GeyserWorldManager;
|
import org.geysermc.geyser.level.GeyserWorldManager;
|
||||||
import org.geysermc.geyser.network.GameProtocol;
|
import org.geysermc.geyser.network.GameProtocol;
|
||||||
import org.geysermc.geyser.platform.mod.GeyserModBootstrap;
|
import org.geysermc.geyser.platform.mod.GeyserModBootstrap;
|
||||||
|
|
@ -62,7 +58,6 @@ import org.geysermc.mcprotocollib.protocol.data.game.item.component.DataComponen
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
|
|
@ -70,11 +65,9 @@ public class GeyserModWorldManager extends GeyserWorldManager {
|
||||||
|
|
||||||
private static final GsonComponentSerializer GSON_SERIALIZER = GsonComponentSerializer.gson();
|
private static final GsonComponentSerializer GSON_SERIALIZER = GsonComponentSerializer.gson();
|
||||||
private final MinecraftServer server;
|
private final MinecraftServer server;
|
||||||
private static GeyserImpl geyser;
|
|
||||||
|
|
||||||
public GeyserModWorldManager(GeyserImpl geyser, MinecraftServer server) {
|
public GeyserModWorldManager(MinecraftServer server) {
|
||||||
this.server = server;
|
this.server = server;
|
||||||
GeyserModWorldManager.geyser = geyser;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -193,23 +186,6 @@ public class GeyserModWorldManager extends GeyserWorldManager {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void handleBlockPlace(UUID uuid, Vector3f position, int blockId) {
|
|
||||||
GeyserSession session = geyser.connectionByUuid(uuid);
|
|
||||||
if (session == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
LevelSoundEventPacket placeBlockSoundPacket = new LevelSoundEventPacket();
|
|
||||||
placeBlockSoundPacket.setSound(SoundEvent.PLACE);
|
|
||||||
placeBlockSoundPacket.setPosition(position);
|
|
||||||
placeBlockSoundPacket.setBabySound(false);
|
|
||||||
placeBlockSoundPacket.setExtraData(session.getBlockMappings().getBedrockBlockId(blockId));
|
|
||||||
placeBlockSoundPacket.setIdentifier(":");
|
|
||||||
session.sendUpstreamPacket(placeBlockSoundPacket);
|
|
||||||
session.setLastBlockPlacePosition(null);
|
|
||||||
session.setLastBlockPlaced(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
private ServerPlayer getPlayer(GeyserSession session) {
|
private ServerPlayer getPlayer(GeyserSession session) {
|
||||||
return server.getPlayerList().getPlayer(session.getPlayerEntity().getUuid());
|
return server.getPlayerList().getPlayer(session.getPlayerEntity().getUuid());
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
"package": "org.geysermc.geyser.platform.mod.mixin",
|
"package": "org.geysermc.geyser.platform.mod.mixin",
|
||||||
"compatibilityLevel": "JAVA_17",
|
"compatibilityLevel": "JAVA_17",
|
||||||
"mixins": [
|
"mixins": [
|
||||||
"server.ModBlockPlaceListener",
|
"server.BlockPlaceMixin",
|
||||||
"server.ServerConnectionListenerMixin"
|
"server.ServerConnectionListenerMixin"
|
||||||
],
|
],
|
||||||
"server": [
|
"server": [
|
||||||
|
|
|
||||||
|
|
@ -28,8 +28,8 @@ package org.geysermc.geyser.translator.protocol.java.level;
|
||||||
import org.cloudburstmc.math.vector.Vector3i;
|
import org.cloudburstmc.math.vector.Vector3i;
|
||||||
import org.cloudburstmc.protocol.bedrock.data.SoundEvent;
|
import org.cloudburstmc.protocol.bedrock.data.SoundEvent;
|
||||||
import org.cloudburstmc.protocol.bedrock.packet.LevelSoundEventPacket;
|
import org.cloudburstmc.protocol.bedrock.packet.LevelSoundEventPacket;
|
||||||
import org.geysermc.geyser.api.util.PlatformType;
|
|
||||||
import org.geysermc.geyser.item.type.Item;
|
import org.geysermc.geyser.item.type.Item;
|
||||||
|
import org.geysermc.geyser.level.WorldManager;
|
||||||
import org.geysermc.geyser.level.block.type.BlockState;
|
import org.geysermc.geyser.level.block.type.BlockState;
|
||||||
import org.geysermc.geyser.session.GeyserSession;
|
import org.geysermc.geyser.session.GeyserSession;
|
||||||
import org.geysermc.geyser.translator.protocol.PacketTranslator;
|
import org.geysermc.geyser.translator.protocol.PacketTranslator;
|
||||||
|
|
@ -43,16 +43,19 @@ public class JavaBlockUpdateTranslator extends PacketTranslator<ClientboundBlock
|
||||||
@Override
|
@Override
|
||||||
public void translate(GeyserSession session, ClientboundBlockUpdatePacket packet) {
|
public void translate(GeyserSession session, ClientboundBlockUpdatePacket packet) {
|
||||||
Vector3i pos = packet.getEntry().getPosition();
|
Vector3i pos = packet.getEntry().getPosition();
|
||||||
boolean updatePlacement = !handledByPlatform(session.getGeyser().getPlatformType()) &&
|
WorldManager worldManager = session.getGeyser().getWorldManager();
|
||||||
!session.getErosionHandler().isActive() && session.getGeyser().getWorldManager().getBlockAt(session, pos) != packet.getEntry().getBlock();
|
// Platforms where Geyser has direct server access don't allow us to detect actual block changes,
|
||||||
|
// hence why those platforms deal with sounds for block placements differently
|
||||||
|
boolean updatePlacement = !worldManager.hasOwnChunkCache() &&
|
||||||
|
!session.getErosionHandler().isActive() && worldManager.getBlockAt(session, pos) != packet.getEntry().getBlock();
|
||||||
session.getWorldCache().updateServerCorrectBlockState(pos, packet.getEntry().getBlock());
|
session.getWorldCache().updateServerCorrectBlockState(pos, packet.getEntry().getBlock());
|
||||||
if (updatePlacement) {
|
if (updatePlacement) {
|
||||||
this.checkPlace(session, packet);
|
this.checkPlaceSound(session, packet);
|
||||||
}
|
}
|
||||||
this.checkInteract(session, packet);
|
this.checkInteract(session, packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkPlace(GeyserSession session, ClientboundBlockUpdatePacket packet) {
|
private void checkPlaceSound(GeyserSession session, ClientboundBlockUpdatePacket packet) {
|
||||||
Vector3i lastPlacePos = session.getLastBlockPlacePosition();
|
Vector3i lastPlacePos = session.getLastBlockPlacePosition();
|
||||||
if (lastPlacePos == null) {
|
if (lastPlacePos == null) {
|
||||||
return;
|
return;
|
||||||
|
|
@ -103,9 +106,4 @@ public class JavaBlockUpdateTranslator extends PacketTranslator<ClientboundBlock
|
||||||
session.setInteracting(false);
|
session.setInteracting(false);
|
||||||
BlockSoundInteractionTranslator.handleBlockInteraction(session, lastInteractPos.toFloat(), state);
|
BlockSoundInteractionTranslator.handleBlockInteraction(session, lastInteractPos.toFloat(), state);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Spigot simply listens for the block place event, and then there's mixins
|
|
||||||
private boolean handledByPlatform(PlatformType type) {
|
|
||||||
return type == PlatformType.SPIGOT || type == PlatformType.NEOFORGE || type == PlatformType.FABRIC;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue