mirror of
https://github.com/GeyserMC/Geyser.git
synced 2024-08-14 23:57:35 +00:00
Tiny fixes
This commit is contained in:
parent
ab8832b771
commit
687ddbb520
3 changed files with 24 additions and 46 deletions
|
@ -28,9 +28,14 @@ package org.geysermc.geyser.item.type;
|
|||
import com.github.steveice10.mc.protocol.data.game.item.component.DataComponentType;
|
||||
import com.github.steveice10.mc.protocol.data.game.item.component.DataComponents;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.cloudburstmc.nbt.NbtType;
|
||||
import org.geysermc.geyser.registry.type.ItemMapping;
|
||||
import org.geysermc.geyser.session.GeyserSession;
|
||||
import org.geysermc.geyser.translator.item.BedrockItemBuilder;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class DecoratedPotItem extends BlockItem {
|
||||
|
||||
public DecoratedPotItem(String javaIdentifier, Builder builder) {
|
||||
|
@ -41,12 +46,14 @@ public class DecoratedPotItem extends BlockItem {
|
|||
public void translateComponentsToBedrock(@NonNull GeyserSession session, @NonNull DataComponents components, @NonNull BedrockItemBuilder builder) {
|
||||
super.translateComponentsToBedrock(session, components, builder);
|
||||
|
||||
components.get(DataComponentType.POT_DECORATIONS); // TODO what does this look like on Bedrock?
|
||||
// if (tag.remove("BlockEntityTag") instanceof CompoundTag blockEntityTag) {
|
||||
// if (blockEntityTag.remove("sherds") instanceof ListTag sherds) {
|
||||
// // bedrock wants it on the root level
|
||||
// tag.put(sherds);
|
||||
// }
|
||||
// }
|
||||
List<Integer> decorations = components.get(DataComponentType.POT_DECORATIONS); // TODO maybe unbox in MCProtocolLib
|
||||
if (decorations != null) {
|
||||
List<String> sherds = new ArrayList<>(decorations.size());
|
||||
for (Integer decoration : decorations) {
|
||||
ItemMapping mapping = session.getItemMappings().getMapping(decoration);
|
||||
sherds.add(mapping.getBedrockIdentifier());
|
||||
}
|
||||
builder.putList("sherds", NbtType.STRING, sherds);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,10 +29,6 @@ import com.github.steveice10.mc.protocol.data.game.item.component.DataComponentT
|
|||
import com.github.steveice10.mc.protocol.data.game.item.component.DataComponents;
|
||||
import com.github.steveice10.mc.protocol.data.game.item.component.Filterable;
|
||||
import com.github.steveice10.mc.protocol.data.game.item.component.WrittenBookContent;
|
||||
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
||||
import com.github.steveice10.opennbt.tag.builtin.ListTag;
|
||||
import com.github.steveice10.opennbt.tag.builtin.StringTag;
|
||||
import com.github.steveice10.opennbt.tag.builtin.Tag;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.cloudburstmc.nbt.NbtMap;
|
||||
|
@ -47,7 +43,6 @@ import java.util.List;
|
|||
|
||||
public class WrittenBookItem extends Item {
|
||||
public static final int MAXIMUM_PAGE_EDIT_LENGTH = 1024;
|
||||
public static final int MAXIMUM_PAGE_LENGTH = 32768;
|
||||
public static final int MAXIMUM_PAGE_COUNT = 100; // Java edition limit. Bedrock edition has a limit of 50 pages.
|
||||
public static final int MAXIMUM_TITLE_LENGTH = 16;
|
||||
|
||||
|
@ -73,33 +68,8 @@ public class WrittenBookItem extends Item {
|
|||
builder.putList("pages", NbtType.COMPOUND, bedrockPages);
|
||||
|
||||
builder.putString("title", bookContent.getTitle().getRaw())
|
||||
.putString("author", bookContent.getAuthor());
|
||||
.putString("author", bookContent.getAuthor())
|
||||
.putInt("generation", bookContent.getGeneration());
|
||||
// TODO isResolved
|
||||
}
|
||||
|
||||
private boolean isValidWrittenBook(CompoundTag tag) {
|
||||
if (!(tag.get("title") instanceof StringTag title)) {
|
||||
return false;
|
||||
}
|
||||
if (title.getValue().length() > (MAXIMUM_TITLE_LENGTH * 2)) {
|
||||
// Java rejects books with titles more than 2x the maximum length allowed in the input box
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!(tag.get("author") instanceof StringTag)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!(tag.get("pages") instanceof ListTag pages)) {
|
||||
return false;
|
||||
}
|
||||
for (Tag pageTag : pages) {
|
||||
if (pageTag instanceof StringTag page) {
|
||||
if (page.getValue().length() > MAXIMUM_PAGE_LENGTH) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,11 +25,11 @@
|
|||
|
||||
package org.geysermc.geyser.translator.inventory;
|
||||
|
||||
import com.github.steveice10.mc.protocol.data.game.item.ItemStack;
|
||||
import com.github.steveice10.mc.protocol.data.game.inventory.ContainerType;
|
||||
import com.github.steveice10.mc.protocol.data.game.item.ItemStack;
|
||||
import com.github.steveice10.mc.protocol.data.game.item.component.DataComponentType;
|
||||
import com.github.steveice10.mc.protocol.data.game.item.component.DataComponents;
|
||||
import com.github.steveice10.mc.protocol.data.game.recipe.Ingredient;
|
||||
import com.github.steveice10.opennbt.tag.builtin.IntTag;
|
||||
import com.github.steveice10.opennbt.tag.builtin.Tag;
|
||||
import it.unimi.dsi.fastutil.ints.*;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
@ -909,10 +909,11 @@ public abstract class InventoryTranslator {
|
|||
// As of 1.16.210: Bedrock needs confirmation on what the current item durability is.
|
||||
// If 0 is sent, then Bedrock thinks the item is not damaged
|
||||
int durability = 0;
|
||||
if (itemStack.getNbt() != null) {
|
||||
Tag damage = itemStack.getNbt().get("Damage");
|
||||
if (damage instanceof IntTag) {
|
||||
durability = ItemUtils.getCorrectBedrockDurability(itemStack.asItem(), ((IntTag) damage).getValue());
|
||||
DataComponents components = itemStack.getComponents();
|
||||
if (components != null) {
|
||||
Integer damage = components.get(DataComponentType.DAMAGE);
|
||||
if (damage != null) {
|
||||
durability = ItemUtils.getCorrectBedrockDurability(itemStack.asItem(), damage);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue