use of com.viaversion.viabackwards.api.data.MappedLegacyBlockItem in project ViaBackwards by ViaVersion.
the class LegacyBlockItemRewriter method handleBlock.
@Nullable
public Block handleBlock(int blockId, int data) {
MappedLegacyBlockItem settings = replacementData.get(blockId);
if (settings == null || !settings.isBlock())
return null;
Block block = settings.getBlock();
// For some blocks, the data can still be useful (:
if (block.getData() == -1) {
return block.withData(data);
}
return block;
}
use of com.viaversion.viabackwards.api.data.MappedLegacyBlockItem in project ViaBackwards by ViaVersion.
the class LegacyBlockItemRewriter method handleItemToClient.
@Override
@Nullable
public Item handleItemToClient(@Nullable Item item) {
if (item == null)
return null;
MappedLegacyBlockItem data = replacementData.get(item.identifier());
if (data == null) {
// Just rewrite the id
return super.handleItemToClient(item);
}
short originalData = item.data();
item.setIdentifier(data.getId());
// Keep original data if mapped data is set to -1
if (data.getData() != -1) {
item.setData(data.getData());
}
// Set display name
if (data.getName() != null) {
if (item.tag() == null) {
item.setTag(new CompoundTag());
}
CompoundTag display = item.tag().get("display");
if (display == null) {
item.tag().put("display", display = new CompoundTag());
}
StringTag nameTag = display.get("Name");
if (nameTag == null) {
display.put("Name", nameTag = new StringTag(data.getName()));
display.put(nbtTagName + "|customName", new ByteTag());
}
// Handle colors
String value = nameTag.getValue();
if (value.contains("%vb_color%")) {
display.put("Name", new StringTag(value.replace("%vb_color%", BlockColors.get(originalData))));
}
}
return item;
}
use of com.viaversion.viabackwards.api.data.MappedLegacyBlockItem in project ViaBackwards by ViaVersion.
the class LegacyBlockItemRewriter method handleChunk.
protected void handleChunk(Chunk chunk) {
// Map Block Entities
Map<Pos, CompoundTag> tags = new HashMap<>();
for (CompoundTag tag : chunk.getBlockEntities()) {
Tag xTag;
Tag yTag;
Tag zTag;
if ((xTag = tag.get("x")) == null || (yTag = tag.get("y")) == null || (zTag = tag.get("z")) == null) {
continue;
}
Pos pos = new Pos(((NumberTag) xTag).asInt() & 0xF, ((NumberTag) yTag).asInt(), ((NumberTag) zTag).asInt() & 0xF);
tags.put(pos, tag);
// 1.17
if (pos.getY() < 0 || pos.getY() > 255)
continue;
ChunkSection section = chunk.getSections()[pos.getY() >> 4];
if (section == null)
continue;
int block = section.getFlatBlock(pos.getX(), pos.getY() & 0xF, pos.getZ());
int btype = block >> 4;
MappedLegacyBlockItem settings = replacementData.get(btype);
if (settings != null && settings.hasBlockEntityHandler()) {
settings.getBlockEntityHandler().handleOrNewCompoundTag(block, tag);
}
}
for (int i = 0; i < chunk.getSections().length; i++) {
ChunkSection section = chunk.getSections()[i];
if (section == null)
continue;
boolean hasBlockEntityHandler = false;
// Map blocks
for (int j = 0; j < section.getPaletteSize(); j++) {
int block = section.getPaletteEntry(j);
int btype = block >> 4;
int meta = block & 0xF;
Block b = handleBlock(btype, meta);
if (b != null) {
section.setPaletteEntry(j, (b.getId() << 4) | (b.getData() & 0xF));
}
// We already know that is has a handler
if (hasBlockEntityHandler)
continue;
MappedLegacyBlockItem settings = replacementData.get(btype);
if (settings != null && settings.hasBlockEntityHandler()) {
hasBlockEntityHandler = true;
}
}
if (!hasBlockEntityHandler)
continue;
// We need to handle a Block Entity :(
for (int x = 0; x < 16; x++) {
for (int y = 0; y < 16; y++) {
for (int z = 0; z < 16; z++) {
int block = section.getFlatBlock(x, y, z);
int btype = block >> 4;
int meta = block & 15;
MappedLegacyBlockItem settings = replacementData.get(btype);
if (settings == null || !settings.hasBlockEntityHandler())
continue;
Pos pos = new Pos(x, (y + (i << 4)), z);
// Already handled above
if (tags.containsKey(pos))
continue;
CompoundTag tag = new CompoundTag();
tag.put("x", new IntTag(x + (chunk.getX() << 4)));
tag.put("y", new IntTag(y + (i << 4)));
tag.put("z", new IntTag(z + (chunk.getZ() << 4)));
settings.getBlockEntityHandler().handleOrNewCompoundTag(block, tag);
chunk.getBlockEntities().add(tag);
}
}
}
}
}
use of com.viaversion.viabackwards.api.data.MappedLegacyBlockItem in project ViaBackwards by ViaVersion.
the class BlockItemPackets1_11 method registerRewrites.
@Override
protected void registerRewrites() {
// Handle spawner block entity (map to itself with custom handler)
MappedLegacyBlockItem data = replacementData.computeIfAbsent(52, s -> new MappedLegacyBlockItem(52, (short) -1, null, false));
data.setBlockEntityHandler((b, tag) -> {
EntityIdRewriter.toClientSpawner(tag, true);
return tag;
});
enchantmentRewriter = new LegacyEnchantmentRewriter(nbtTagName);
enchantmentRewriter.registerEnchantment(71, "§cCurse of Vanishing");
enchantmentRewriter.registerEnchantment(10, "§cCurse of Binding");
// Curses do not display their level
enchantmentRewriter.setHideLevelForEnchants(71, 10);
}
Aggregations