mirror of
https://github.com/GeyserMC/Geyser.git
synced 2025-04-17 19:12:14 +02:00
Fix text on signs, remove unused Minecart entity property
This commit is contained in:
parent
d7f77e8caa
commit
8128fb9df2
5 changed files with 29 additions and 36 deletions
core/src/main/java/org/geysermc/geyser
entity
translator
|
@ -544,9 +544,8 @@ public final class EntityDefinitions {
|
|||
.addTranslator(MetadataTypes.FLOAT, (minecartEntity, entityMetadata) ->
|
||||
// Power in Java, hurt ticks in Bedrock
|
||||
minecartEntity.getDirtyMetadata().put(EntityDataTypes.HURT_TICKS, Math.min((int) ((FloatEntityMetadata) entityMetadata).getPrimitiveValue(), 15)))
|
||||
.addTranslator(MetadataTypes.INT, MinecartEntity::setCustomBlock)
|
||||
.addTranslator(MetadataTypes.OPTIONAL_BLOCK_STATE, MinecartEntity::setCustomBlock)
|
||||
.addTranslator(MetadataTypes.INT, MinecartEntity::setCustomBlockOffset)
|
||||
.addTranslator(MetadataTypes.BOOLEAN, MinecartEntity::setShowCustomBlock)
|
||||
.build();
|
||||
CHEST_MINECART = EntityDefinition.inherited(MINECART.factory(), MINECART)
|
||||
.type(EntityType.CHEST_MINECART)
|
||||
|
|
|
@ -25,12 +25,11 @@
|
|||
|
||||
package org.geysermc.geyser.entity.type;
|
||||
|
||||
import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.BooleanEntityMetadata;
|
||||
import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.IntEntityMetadata;
|
||||
import org.cloudburstmc.math.vector.Vector3f;
|
||||
import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes;
|
||||
import org.geysermc.geyser.entity.EntityDefinition;
|
||||
import org.geysermc.geyser.session.GeyserSession;
|
||||
import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.IntEntityMetadata;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
|
@ -58,9 +57,13 @@ public class DefaultBlockMinecartEntity extends MinecartEntity {
|
|||
@Override
|
||||
public void setCustomBlock(IntEntityMetadata entityMetadata) {
|
||||
customBlock = entityMetadata.getPrimitiveValue();
|
||||
showCustomBlock = entityMetadata.getPrimitiveValue() != 0;
|
||||
|
||||
if (showCustomBlock) {
|
||||
dirtyMetadata.put(EntityDataTypes.DISPLAY_BLOCK_STATE, session.getBlockMappings().getBedrockBlock(customBlock));
|
||||
dirtyMetadata.put(EntityDataTypes.DISPLAY_OFFSET, customBlockOffset);
|
||||
} else {
|
||||
updateDefaultBlockMetadata();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -73,18 +76,6 @@ public class DefaultBlockMinecartEntity extends MinecartEntity {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setShowCustomBlock(BooleanEntityMetadata entityMetadata) {
|
||||
if (entityMetadata.getPrimitiveValue()) {
|
||||
showCustomBlock = true;
|
||||
dirtyMetadata.put(EntityDataTypes.DISPLAY_BLOCK_STATE, session.getBlockMappings().getBedrockBlock(customBlock));
|
||||
dirtyMetadata.put(EntityDataTypes.DISPLAY_OFFSET, customBlockOffset);
|
||||
} else {
|
||||
showCustomBlock = false;
|
||||
updateDefaultBlockMetadata();
|
||||
}
|
||||
}
|
||||
|
||||
public void updateDefaultBlockMetadata() {
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,7 +37,6 @@ import org.geysermc.geyser.util.InteractionResult;
|
|||
import org.geysermc.geyser.util.InteractiveTag;
|
||||
import org.geysermc.geyser.util.MathUtils;
|
||||
import org.geysermc.mcprotocollib.protocol.data.game.entity.MinecartStep;
|
||||
import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.BooleanEntityMetadata;
|
||||
import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.IntEntityMetadata;
|
||||
import org.geysermc.mcprotocollib.protocol.data.game.entity.player.Hand;
|
||||
import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.entity.ClientboundMoveMinecartPacket;
|
||||
|
@ -65,6 +64,9 @@ public class MinecartEntity extends Entity implements Tickable {
|
|||
}
|
||||
|
||||
public void setCustomBlock(IntEntityMetadata entityMetadata) {
|
||||
// Optional block state -> "0" is air, aka none
|
||||
// Sets whether the custom block should be enabled
|
||||
dirtyMetadata.put(EntityDataTypes.CUSTOM_DISPLAY, (byte) (entityMetadata.getPrimitiveValue() != 0 ? 1 : 0));
|
||||
dirtyMetadata.put(EntityDataTypes.DISPLAY_BLOCK_STATE, session.getBlockMappings().getBedrockBlock(entityMetadata.getPrimitiveValue()));
|
||||
}
|
||||
|
||||
|
@ -72,12 +74,6 @@ public class MinecartEntity extends Entity implements Tickable {
|
|||
dirtyMetadata.put(EntityDataTypes.DISPLAY_OFFSET, entityMetadata.getPrimitiveValue());
|
||||
}
|
||||
|
||||
public void setShowCustomBlock(BooleanEntityMetadata entityMetadata) {
|
||||
// If the custom block should be enabled
|
||||
// Needs a byte based off of Java's boolean
|
||||
dirtyMetadata.put(EntityDataTypes.CUSTOM_DISPLAY, (byte) (entityMetadata.getPrimitiveValue() ? 1 : 0));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
if (!session.isUsingExperimentalMinecartLogic()) {
|
||||
|
|
|
@ -75,16 +75,20 @@ public class SignBlockEntityTranslator extends BlockEntityTranslator {
|
|||
|
||||
@Override
|
||||
public void translateTag(GeyserSession session, NbtMapBuilder bedrockNbt, NbtMap javaNbt, BlockState blockState) {
|
||||
bedrockNbt.putCompound("FrontText", translateSide(javaNbt.getCompound("front_text")));
|
||||
bedrockNbt.putCompound("BackText", translateSide(javaNbt.getCompound("back_text")));
|
||||
bedrockNbt.putCompound("FrontText", translateSide(session, javaNbt.getCompound("front_text")));
|
||||
bedrockNbt.putCompound("BackText", translateSide(session, javaNbt.getCompound("back_text")));
|
||||
bedrockNbt.putBoolean("IsWaxed", javaNbt.getBoolean("is_waxed"));
|
||||
}
|
||||
|
||||
private NbtMap translateSide(NbtMap javaNbt) {
|
||||
private NbtMap translateSide(GeyserSession session, NbtMap javaNbt) {
|
||||
NbtMapBuilder builder = NbtMap.builder();
|
||||
|
||||
StringBuilder signText = new StringBuilder();
|
||||
List<String> messages = javaNbt.getList("messages", NbtType.STRING);
|
||||
List<?> rawMessages = javaNbt.getList("messages", NbtType.COMPOUND);
|
||||
if (rawMessages.isEmpty()) {
|
||||
rawMessages = javaNbt.getList("messages", NbtType.STRING);
|
||||
}
|
||||
List<String> messages = MessageTranslator.signTextFromNbtTag(session, rawMessages);
|
||||
if (!messages.isEmpty()) {
|
||||
var it = messages.iterator();
|
||||
while (it.hasNext()) {
|
||||
|
|
|
@ -25,8 +25,6 @@
|
|||
|
||||
package org.geysermc.geyser.translator.text;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.JoinConfiguration;
|
||||
import net.kyori.adventure.text.ScoreComponent;
|
||||
|
@ -57,6 +55,9 @@ import org.geysermc.mcprotocollib.protocol.data.game.Holder;
|
|||
import org.geysermc.mcprotocollib.protocol.data.game.chat.ChatType;
|
||||
import org.geysermc.mcprotocollib.protocol.data.game.chat.ChatTypeDecoration;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class MessageTranslator {
|
||||
// These are used for handling the translations of the messages
|
||||
// Custom instead of TranslatableComponentRenderer#usingTranslationSource so we don't need to worry about finding a Locale class
|
||||
|
@ -202,13 +203,6 @@ public class MessageTranslator {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method for locale getting.
|
||||
*/
|
||||
public static String convertJsonMessage(GeyserSession session, String message) {
|
||||
return convertJsonMessage(message, session.locale());
|
||||
}
|
||||
|
||||
public static String convertJsonMessage(String message, String locale) {
|
||||
return convertMessage(GSON_SERIALIZER.deserialize(message), locale);
|
||||
}
|
||||
|
@ -448,6 +442,15 @@ public class MessageTranslator {
|
|||
return componentFromNbtTag(nbtTag, Style.empty());
|
||||
}
|
||||
|
||||
public static List<String> signTextFromNbtTag(GeyserSession session, List<?> nbtTag) {
|
||||
var components = componentsFromNbtList(nbtTag, Style.empty());
|
||||
List<String> messages = new ArrayList<>();
|
||||
for (Component component : components) {
|
||||
messages.add(convertMessageRaw(component, session.locale()));
|
||||
}
|
||||
return messages;
|
||||
}
|
||||
|
||||
private static Component componentFromNbtTag(Object nbtTag, Style style) {
|
||||
if (nbtTag instanceof String literal) {
|
||||
return Component.text(literal).style(style);
|
||||
|
|
Loading…
Add table
Reference in a new issue