mirror of
https://github.com/GeyserMC/Geyser.git
synced 2024-08-14 23:57:35 +00:00
Add support for banner block entities
Colored banners still need to be implemented. The color for banners themselves is set as part of the block entity on bedrock meanwhile in java edition its set as part of the block state.
This commit is contained in:
parent
bc2df705ef
commit
da645abec4
2 changed files with 82 additions and 0 deletions
|
@ -175,6 +175,7 @@ public class TranslatorsInit {
|
|||
blockEntityTranslators.put("Empty", new EmptyBlockEntityTranslator("empty", "Empty"));
|
||||
blockEntityTranslators.put("Sign", new SignBlockEntityTranslator("minecraft:sign", "Sign"));
|
||||
blockEntityTranslators.put("Campfire", new CampfireBlockEntityTranslator("minecraft:campfire", "Campfire"));
|
||||
blockEntityTranslators.put("Banner", new BannerBlockEntityTranslator("minecraft:banner", "Banner"));
|
||||
}
|
||||
|
||||
private static void registerInventoryTranslators() {
|
||||
|
|
|
@ -0,0 +1,81 @@
|
|||
/*
|
||||
* Copyright (c) 2019 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.connector.network.translators.block.entity;
|
||||
|
||||
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
||||
import com.github.steveice10.opennbt.tag.builtin.ListTag;
|
||||
import com.nukkitx.nbt.CompoundTagBuilder;
|
||||
import com.nukkitx.nbt.tag.StringTag;
|
||||
import com.nukkitx.nbt.tag.Tag;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class BannerBlockEntityTranslator extends BlockEntityTranslator {
|
||||
|
||||
public BannerBlockEntityTranslator(String javaId, String bedrockId) {
|
||||
super(javaId, bedrockId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Tag<?>> translateTag(CompoundTag tag) {
|
||||
List<Tag<?>> tags = new ArrayList<>();
|
||||
ListTag patterns = tag.get("Patterns");
|
||||
List<com.nukkitx.nbt.tag.CompoundTag> tagsList = new ArrayList<>();
|
||||
for (com.github.steveice10.opennbt.tag.builtin.Tag patternTag : patterns.getValue()) {
|
||||
tagsList.add(getPattern((CompoundTag) patternTag));
|
||||
}
|
||||
com.nukkitx.nbt.tag.ListTag<com.nukkitx.nbt.tag.CompoundTag> bedrockPatterns =
|
||||
new com.nukkitx.nbt.tag.ListTag<>("Patterns", com.nukkitx.nbt.tag.CompoundTag.class, tagsList);
|
||||
tags.add(bedrockPatterns);
|
||||
|
||||
if (tag.contains("CustomName")) {
|
||||
tags.add(new StringTag("CustomName", (String) tag.get("CustomName").getValue()));
|
||||
}
|
||||
return tags;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompoundTag getDefaultJavaTag(int x, int y, int z) {
|
||||
CompoundTag tag = getConstantJavaTag(x, y, z);
|
||||
tag.put(new ListTag("Patterns"));
|
||||
return tag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public com.nukkitx.nbt.tag.CompoundTag getDefaultBedrockTag(int x, int y, int z) {
|
||||
CompoundTagBuilder tagBuilder = getConstantBedrockTag(x, y, z).toBuilder();
|
||||
tagBuilder.listTag("Patterns", com.nukkitx.nbt.tag.CompoundTag.class, new ArrayList<>());
|
||||
return tagBuilder.buildRootTag();
|
||||
}
|
||||
|
||||
protected com.nukkitx.nbt.tag.CompoundTag getPattern(CompoundTag pattern) {
|
||||
return CompoundTagBuilder.builder()
|
||||
.intTag("Color", (int) pattern.get("Color").getValue())
|
||||
.stringTag("Pattern", (String) pattern.get("Pattern").getValue())
|
||||
.buildRootTag();
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue