Mirror von
https://github.com/GeyserMC/Geyser.git
synchronisiert 2024-12-27 08:30:12 +01:00
Consolidate NoteblockBlockEntityTranslator behavior
It was only used in one place that could better use existing code.
Dieser Commit ist enthalten in:
Ursprung
10383d31ab
Commit
780218d39d
@ -1,48 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2019-2022 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.translator.level.block.entity;
|
|
||||||
|
|
||||||
import com.github.steveice10.mc.protocol.data.game.entity.metadata.Position;
|
|
||||||
import com.nukkitx.math.vector.Vector3i;
|
|
||||||
import com.nukkitx.protocol.bedrock.packet.BlockEventPacket;
|
|
||||||
import org.geysermc.geyser.session.GeyserSession;
|
|
||||||
import org.geysermc.geyser.level.block.BlockStateValues;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Does not implement BlockEntityTranslator because it's only a block entity in Bedrock
|
|
||||||
*/
|
|
||||||
public class NoteblockBlockEntityTranslator {
|
|
||||||
|
|
||||||
public static void translate(GeyserSession session, Position position) {
|
|
||||||
int blockState = session.getGeyser().getWorldManager().getBlockAt(session, position);
|
|
||||||
BlockEventPacket blockEventPacket = new BlockEventPacket();
|
|
||||||
blockEventPacket.setBlockPosition(Vector3i.from(position.getX(), position.getY(), position.getZ()));
|
|
||||||
blockEventPacket.setEventType(0);
|
|
||||||
blockEventPacket.setEventData(BlockStateValues.getNoteblockPitch(blockState));
|
|
||||||
session.sendUpstreamPacket(blockEventPacket);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -35,14 +35,13 @@ import com.nukkitx.protocol.bedrock.packet.BlockEntityDataPacket;
|
|||||||
import com.nukkitx.protocol.bedrock.packet.BlockEventPacket;
|
import com.nukkitx.protocol.bedrock.packet.BlockEventPacket;
|
||||||
import it.unimi.dsi.fastutil.objects.Object2IntMaps;
|
import it.unimi.dsi.fastutil.objects.Object2IntMaps;
|
||||||
import org.geysermc.common.PlatformType;
|
import org.geysermc.common.PlatformType;
|
||||||
|
import org.geysermc.geyser.level.block.BlockStateValues;
|
||||||
|
import org.geysermc.geyser.level.physics.Direction;
|
||||||
import org.geysermc.geyser.session.GeyserSession;
|
import org.geysermc.geyser.session.GeyserSession;
|
||||||
import org.geysermc.geyser.session.cache.PistonCache;
|
import org.geysermc.geyser.session.cache.PistonCache;
|
||||||
|
import org.geysermc.geyser.translator.level.block.entity.PistonBlockEntity;
|
||||||
import org.geysermc.geyser.translator.protocol.PacketTranslator;
|
import org.geysermc.geyser.translator.protocol.PacketTranslator;
|
||||||
import org.geysermc.geyser.translator.protocol.Translator;
|
import org.geysermc.geyser.translator.protocol.Translator;
|
||||||
import org.geysermc.geyser.level.block.BlockStateValues;
|
|
||||||
import org.geysermc.geyser.translator.level.block.entity.NoteblockBlockEntityTranslator;
|
|
||||||
import org.geysermc.geyser.translator.level.block.entity.PistonBlockEntity;
|
|
||||||
import org.geysermc.geyser.level.physics.Direction;
|
|
||||||
|
|
||||||
@Translator(packet = ClientboundBlockEventPacket.class)
|
@Translator(packet = ClientboundBlockEventPacket.class)
|
||||||
public class JavaBlockEventTranslator extends PacketTranslator<ClientboundBlockEventPacket> {
|
public class JavaBlockEventTranslator extends PacketTranslator<ClientboundBlockEventPacket> {
|
||||||
@ -50,8 +49,9 @@ public class JavaBlockEventTranslator extends PacketTranslator<ClientboundBlockE
|
|||||||
@Override
|
@Override
|
||||||
public void translate(GeyserSession session, ClientboundBlockEventPacket packet) {
|
public void translate(GeyserSession session, ClientboundBlockEventPacket packet) {
|
||||||
BlockEventPacket blockEventPacket = new BlockEventPacket();
|
BlockEventPacket blockEventPacket = new BlockEventPacket();
|
||||||
blockEventPacket.setBlockPosition(Vector3i.from(packet.getPosition().getX(),
|
Position position = packet.getPosition();
|
||||||
packet.getPosition().getY(), packet.getPosition().getZ()));
|
Vector3i vector = Vector3i.from(position.getX(), position.getY(), position.getZ());
|
||||||
|
blockEventPacket.setBlockPosition(vector);
|
||||||
if (packet.getValue() instanceof ChestValue value) {
|
if (packet.getValue() instanceof ChestValue value) {
|
||||||
blockEventPacket.setEventType(1);
|
blockEventPacket.setEventType(1);
|
||||||
blockEventPacket.setEventData(value.getViewers() > 0 ? 1 : 0);
|
blockEventPacket.setEventData(value.getViewers() > 0 ? 1 : 0);
|
||||||
@ -60,11 +60,12 @@ public class JavaBlockEventTranslator extends PacketTranslator<ClientboundBlockE
|
|||||||
blockEventPacket.setEventType(1);
|
blockEventPacket.setEventType(1);
|
||||||
session.sendUpstreamPacket(blockEventPacket);
|
session.sendUpstreamPacket(blockEventPacket);
|
||||||
} else if (packet.getValue() instanceof NoteBlockValue) {
|
} else if (packet.getValue() instanceof NoteBlockValue) {
|
||||||
NoteblockBlockEntityTranslator.translate(session, packet.getPosition());
|
int blockState = session.getGeyser().getWorldManager().getBlockAt(session, position);
|
||||||
|
blockEventPacket.setEventData(BlockStateValues.getNoteblockPitch(blockState));
|
||||||
|
session.sendUpstreamPacket(blockEventPacket);
|
||||||
} else if (packet.getValue() instanceof PistonValue pistonValue) {
|
} else if (packet.getValue() instanceof PistonValue pistonValue) {
|
||||||
PistonValueType action = (PistonValueType) packet.getType();
|
PistonValueType action = (PistonValueType) packet.getType();
|
||||||
Direction direction = Direction.fromPistonValue(pistonValue);
|
Direction direction = Direction.fromPistonValue(pistonValue);
|
||||||
Vector3i position = Vector3i.from(packet.getPosition().getX(), packet.getPosition().getY(), packet.getPosition().getZ());
|
|
||||||
PistonCache pistonCache = session.getPistonCache();
|
PistonCache pistonCache = session.getPistonCache();
|
||||||
|
|
||||||
if (session.getGeyser().getPlatformType() == PlatformType.SPIGOT) {
|
if (session.getGeyser().getPlatformType() == PlatformType.SPIGOT) {
|
||||||
@ -77,20 +78,20 @@ public class JavaBlockEventTranslator extends PacketTranslator<ClientboundBlockE
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (action != PistonValueType.CANCELLED_MID_PUSH) {
|
if (action != PistonValueType.CANCELLED_MID_PUSH) {
|
||||||
Vector3i blockInFrontPos = position.add(direction.getUnitVector());
|
Vector3i blockInFrontPos = vector.add(direction.getUnitVector());
|
||||||
int blockInFront = session.getGeyser().getWorldManager().getBlockAt(session, blockInFrontPos);
|
int blockInFront = session.getGeyser().getWorldManager().getBlockAt(session, blockInFrontPos);
|
||||||
if (blockInFront != BlockStateValues.JAVA_AIR_ID) {
|
if (blockInFront != BlockStateValues.JAVA_AIR_ID) {
|
||||||
// Piston pulled something
|
// Piston pulled something
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
PistonBlockEntity blockEntity = pistonCache.getPistons().computeIfAbsent(position, pos -> new PistonBlockEntity(session, pos, direction, true, true));
|
PistonBlockEntity blockEntity = pistonCache.getPistons().computeIfAbsent(vector, pos -> new PistonBlockEntity(session, pos, direction, true, true));
|
||||||
if (blockEntity.getAction() != action) {
|
if (blockEntity.getAction() != action) {
|
||||||
blockEntity.setAction(action, Object2IntMaps.emptyMap());
|
blockEntity.setAction(action, Object2IntMaps.emptyMap());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
PistonBlockEntity blockEntity = pistonCache.getPistons().computeIfAbsent(position, pos -> {
|
PistonBlockEntity blockEntity = pistonCache.getPistons().computeIfAbsent(vector, pos -> {
|
||||||
int blockId = session.getGeyser().getWorldManager().getBlockAt(session, position);
|
int blockId = session.getGeyser().getWorldManager().getBlockAt(session, position);
|
||||||
boolean sticky = BlockStateValues.isStickyPiston(blockId);
|
boolean sticky = BlockStateValues.isStickyPiston(blockId);
|
||||||
boolean extended = action != PistonValueType.PUSHING;
|
boolean extended = action != PistonValueType.PUSHING;
|
||||||
@ -106,10 +107,8 @@ public class JavaBlockEventTranslator extends PacketTranslator<ClientboundBlockE
|
|||||||
session.sendUpstreamPacket(blockEventPacket);
|
session.sendUpstreamPacket(blockEventPacket);
|
||||||
} else if (packet.getValue() instanceof GenericBlockValue bellValue && packet.getBlockId() == BlockStateValues.JAVA_BELL_ID) {
|
} else if (packet.getValue() instanceof GenericBlockValue bellValue && packet.getBlockId() == BlockStateValues.JAVA_BELL_ID) {
|
||||||
// Bells - needed to show ring from other players
|
// Bells - needed to show ring from other players
|
||||||
Position position = packet.getPosition();
|
|
||||||
|
|
||||||
BlockEntityDataPacket blockEntityPacket = new BlockEntityDataPacket();
|
BlockEntityDataPacket blockEntityPacket = new BlockEntityDataPacket();
|
||||||
blockEntityPacket.setBlockPosition(Vector3i.from(position.getX(), position.getY(), position.getZ()));
|
blockEntityPacket.setBlockPosition(vector);
|
||||||
|
|
||||||
NbtMapBuilder builder = NbtMap.builder();
|
NbtMapBuilder builder = NbtMap.builder();
|
||||||
builder.putInt("x", position.getX());
|
builder.putInt("x", position.getX());
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren