Fix signs (#439)

* Fix signs on everything except Paper

* Fix sign line placement

* Update shulker box block entity

Co-authored-by: James Harrison <james@fasttortoise.co.uk>
This commit is contained in:
Camotoy 2020-05-06 17:52:57 -04:00 committed by GitHub
parent 5ae95433e5
commit f11bae0bf0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 95 additions and 115 deletions

View file

@ -30,19 +30,13 @@ import com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerUpdate
import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.PacketTranslator; import org.geysermc.connector.network.translators.PacketTranslator;
import org.geysermc.connector.network.translators.Translator; import org.geysermc.connector.network.translators.Translator;
import org.geysermc.connector.network.translators.world.block.entity.BlockEntity;
import org.geysermc.connector.network.translators.world.block.entity.BlockEntityTranslator; import org.geysermc.connector.network.translators.world.block.entity.BlockEntityTranslator;
import org.geysermc.connector.utils.BlockEntityUtils; import org.geysermc.connector.utils.BlockEntityUtils;
import org.geysermc.connector.utils.ChunkUtils; import org.geysermc.connector.utils.ChunkUtils;
import java.util.concurrent.TimeUnit;
@Translator(packet = ServerUpdateTileEntityPacket.class) @Translator(packet = ServerUpdateTileEntityPacket.class)
public class JavaUpdateTileEntityTranslator extends PacketTranslator<ServerUpdateTileEntityPacket> { public class JavaUpdateTileEntityTranslator extends PacketTranslator<ServerUpdateTileEntityPacket> {
// This should be modified if sign text is not showing up
private static final int DELAY = 500;
@Override @Override
public void translate(ServerUpdateTileEntityPacket packet, GeyserSession session) { public void translate(ServerUpdateTileEntityPacket packet, GeyserSession session) {
String id = BlockEntityUtils.getBedrockBlockEntityId(packet.getType().name()); String id = BlockEntityUtils.getBedrockBlockEntityId(packet.getType().name());
@ -52,11 +46,6 @@ public class JavaUpdateTileEntityTranslator extends PacketTranslator<ServerUpdat
BlockEntityUtils.updateBlockEntity(session, translator.getBlockEntityTag(id, packet.getNbt(), BlockEntityUtils.updateBlockEntity(session, translator.getBlockEntityTag(id, packet.getNbt(),
ChunkUtils.CACHED_BLOCK_ENTITIES.get(packet.getPosition())), packet.getPosition()); ChunkUtils.CACHED_BLOCK_ENTITIES.get(packet.getPosition())), packet.getPosition());
ChunkUtils.CACHED_BLOCK_ENTITIES.remove(packet.getPosition()); ChunkUtils.CACHED_BLOCK_ENTITIES.remove(packet.getPosition());
} else if (translator.getClass().getAnnotation(BlockEntity.class).delay()) {
// Delay so chunks can finish sending
session.getConnector().getGeneralThreadPool().schedule(() ->
BlockEntityUtils.updateBlockEntity(session, translator.getBlockEntityTag(id, packet.getNbt(), null), packet.getPosition()),
DELAY, TimeUnit.MILLISECONDS);
} else { } else {
BlockEntityUtils.updateBlockEntity(session, translator.getBlockEntityTag(id, packet.getNbt(), null), packet.getPosition()); BlockEntityUtils.updateBlockEntity(session, translator.getBlockEntityTag(id, packet.getNbt(), null), packet.getPosition());
} }

View file

@ -37,7 +37,7 @@ import org.geysermc.connector.network.translators.world.block.BlockStateValues;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@BlockEntity(name = "Banner", delay = false, regex = "banner") @BlockEntity(name = "Banner", regex = "banner")
public class BannerBlockEntityTranslator extends BlockEntityTranslator implements RequiresBlockState { public class BannerBlockEntityTranslator extends BlockEntityTranslator implements RequiresBlockState {
@Override @Override

View file

@ -35,7 +35,7 @@ import org.geysermc.connector.network.translators.world.block.BlockStateValues;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@BlockEntity(name = "Bed", delay = false, regex = "bed") @BlockEntity(name = "Bed", regex = "bed")
public class BedBlockEntityTranslator extends BlockEntityTranslator implements RequiresBlockState { public class BedBlockEntityTranslator extends BlockEntityTranslator implements RequiresBlockState {
@Override @Override

View file

@ -31,12 +31,6 @@ import java.lang.annotation.RetentionPolicy;
@Retention(value = RetentionPolicy.RUNTIME) @Retention(value = RetentionPolicy.RUNTIME)
public @interface BlockEntity { public @interface BlockEntity {
/**
* Whether to delay the sending of the block entity
* @return the delay for when sending the block entity
*/
boolean delay();
/** /**
* The block entity name * The block entity name
* @return the name of the block entity * @return the name of the block entity

View file

@ -38,7 +38,7 @@ import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
@BlockEntity(name = "Campfire", delay = false, regex = "campfire") @BlockEntity(name = "Campfire", regex = "campfire")
public class CampfireBlockEntityTranslator extends BlockEntityTranslator { public class CampfireBlockEntityTranslator extends BlockEntityTranslator {
@Override @Override

View file

@ -32,7 +32,7 @@ import com.nukkitx.nbt.tag.Tag;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@BlockEntity(name = "Empty", delay = false, regex = "") @BlockEntity(name = "Empty", regex = "")
public class EmptyBlockEntityTranslator extends BlockEntityTranslator { public class EmptyBlockEntityTranslator extends BlockEntityTranslator {
@Override @Override

View file

@ -36,7 +36,7 @@ import java.util.ArrayList;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
@BlockEntity(name = "EndGateway", delay = true, regex = "end_gateway") @BlockEntity(name = "EndGateway", regex = "end_gateway")
public class EndGatewayBlockEntityTranslator extends BlockEntityTranslator { public class EndGatewayBlockEntityTranslator extends BlockEntityTranslator {
@Override @Override

View file

@ -36,7 +36,7 @@ import org.geysermc.connector.network.translators.world.block.BlockStateValues;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@BlockEntity(name = "ShulkerBox", delay = false, regex = "shulker_box") @BlockEntity(name = "ShulkerBox", regex = "shulker_box")
public class ShulkerBoxBlockEntityTranslator extends BlockEntityTranslator { public class ShulkerBoxBlockEntityTranslator extends BlockEntityTranslator {
@Override @Override

View file

@ -31,29 +31,35 @@ import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import com.nukkitx.nbt.CompoundTagBuilder; import com.nukkitx.nbt.CompoundTagBuilder;
import com.nukkitx.nbt.tag.StringTag; import com.nukkitx.nbt.tag.StringTag;
import com.nukkitx.nbt.tag.Tag; import com.nukkitx.nbt.tag.Tag;
import io.netty.util.internal.StringUtil;
import org.geysermc.connector.utils.MessageUtils; import org.geysermc.connector.utils.MessageUtils;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@BlockEntity(name = "Sign", delay = true, regex = "sign") @BlockEntity(name = "Sign", regex = "sign")
public class SignBlockEntityTranslator extends BlockEntityTranslator { public class SignBlockEntityTranslator extends BlockEntityTranslator {
@Override @Override
public List<Tag<?>> translateTag(CompoundTag tag, BlockState blockState) { public List<Tag<?>> translateTag(CompoundTag tag, BlockState blockState) {
List<Tag<?>> tags = new ArrayList<>(); List<Tag<?>> tags = new ArrayList<>();
String line1 = getOrDefault(tag.getValue().get("Text1"), ""); StringBuilder signText = new StringBuilder();
String line2 = getOrDefault(tag.getValue().get("Text2"), ""); for(int i = 0; i < 4; i++) {
String line3 = getOrDefault(tag.getValue().get("Text3"), ""); int currentLine = i+1;
String line4 = getOrDefault(tag.getValue().get("Text4"), ""); String signLine = getOrDefault(tag.getValue().get("Text" + currentLine), "");
signLine = MessageUtils.getBedrockMessage(Message.fromString(signLine));
tags.add(new StringTag("Text", MessageUtils.getBedrockMessage(Message.fromString(line1)) //Java allows up to 16+ characters on certain symbols.
+ "\n" + MessageUtils.getBedrockMessage(Message.fromString(line2)) if(signLine.length() >= 15 && (signLine.contains("-") || signLine.contains("="))) {
+ "\n" + MessageUtils.getBedrockMessage(Message.fromString(line3)) signLine = signLine.substring(0, 14);
+ "\n" + MessageUtils.getBedrockMessage(Message.fromString(line4)) }
));
signText.append(signLine);
signText.append("\n");
}
tags.add(new StringTag("Text", MessageUtils.getBedrockMessage(Message.fromString(signText.toString()))));
return tags; return tags;
} }

View file

@ -36,7 +36,7 @@ import org.geysermc.connector.network.translators.world.block.BlockStateValues;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@BlockEntity(name = "Skull", delay = false, regex = "skull") @BlockEntity(name = "Skull", regex = "skull")
public class SkullBlockEntityTranslator extends BlockEntityTranslator implements RequiresBlockState { public class SkullBlockEntityTranslator extends BlockEntityTranslator implements RequiresBlockState {
@Override @Override

View file

@ -89,21 +89,12 @@ public class ChunkUtils {
// Check to see if the name is in BlockTranslator.getBlockEntityString, and therefore must be handled differently // Check to see if the name is in BlockTranslator.getBlockEntityString, and therefore must be handled differently
if (BlockTranslator.getBlockEntityString(blockState) != null) { if (BlockTranslator.getBlockEntityString(blockState) != null) {
// Get the block entity translator
BlockEntityTranslator blockEntityTranslator = BlockEntityUtils.getBlockEntityTranslator(BlockTranslator.getBlockEntityString(blockState));
Position pos = new ChunkPosition(column.getX(), column.getZ()).getBlock(x, (chunkY << 4) + y, z); Position pos = new ChunkPosition(column.getX(), column.getZ()).getBlock(x, (chunkY << 4) + y, z);
blockEntityPositions.put(pos, blockState); blockEntityPositions.put(pos, blockState);
// If there is a delay required for the block, allow it.
if (blockEntityTranslator.getClass().getAnnotation(BlockEntity.class).delay()) {
chunkData.loadBlockEntitiesLater.put(blockEntityTranslator.getDefaultBedrockTag(BlockEntityUtils.getBedrockBlockEntityId(BlockTranslator.getBlockEntityString(blockState)),
pos.getX(), pos.getY(), pos.getZ()), blockState.getId());
} else {
section.getBlockStorageArray()[0].setFullBlock(ChunkSection.blockPosition(x, y, z), id);
}
} else {
section.getBlockStorageArray()[0].setFullBlock(ChunkSection.blockPosition(x, y, z), id);
} }
section.getBlockStorageArray()[0].setFullBlock(ChunkSection.blockPosition(x, y, z), id);
// Check if block is piston or flower - only block entities in Bedrock // Check if block is piston or flower - only block entities in Bedrock
if (BlockStateValues.getFlowerPotValues().containsKey(blockState.getId()) || if (BlockStateValues.getFlowerPotValues().containsKey(blockState.getId()) ||
BlockStateValues.getPistonValues().containsKey(blockState.getId())) { BlockStateValues.getPistonValues().containsKey(blockState.getId())) {