Mirror von
https://github.com/ViaVersion/ViaBackwards.git
synchronisiert 2024-09-07 21:32:52 +02:00
Minor optimizations to legacy block rewriting
Dieser Commit ist enthalten in:
Ursprung
96b9a023c1
Commit
b62c8c46e3
@ -29,12 +29,11 @@ import us.myles.viaversion.libs.opennbt.tag.builtin.*;
|
|||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
|
||||||
|
|
||||||
public abstract class BlockItemRewriter<T extends BackwardsProtocol> extends Rewriter<T> {
|
public abstract class BlockItemRewriter<T extends BackwardsProtocol> extends Rewriter<T> {
|
||||||
|
|
||||||
private static final CompoundTagConverter converter = new CompoundTagConverter();
|
private static final CompoundTagConverter converter = new CompoundTagConverter();
|
||||||
private final Map<Integer, BlockItemSettings> replacementData = new ConcurrentHashMap<>();
|
private final Map<Integer, BlockItemSettings> replacementData = new HashMap<>();
|
||||||
protected String nbtTagName;
|
protected String nbtTagName;
|
||||||
protected boolean jsonNameFormat = true;
|
protected boolean jsonNameFormat = true;
|
||||||
|
|
||||||
@ -60,6 +59,18 @@ public abstract class BlockItemRewriter<T extends BackwardsProtocol> extends Rew
|
|||||||
ItemUtil.copyItem(i, data.getRepItem());
|
ItemUtil.copyItem(i, data.getRepItem());
|
||||||
if (i.getTag() == null) {
|
if (i.getTag() == null) {
|
||||||
i.setTag(new CompoundTag(""));
|
i.setTag(new CompoundTag(""));
|
||||||
|
} else {
|
||||||
|
// Handle colors
|
||||||
|
CompoundTag tag = i.getTag().get("display");
|
||||||
|
if (tag != null) {
|
||||||
|
StringTag nameTag = tag.get("Name");
|
||||||
|
if (nameTag != null) {
|
||||||
|
String value = nameTag.getValue();
|
||||||
|
if (value.contains("%vb_color%")) {
|
||||||
|
tag.put(new StringTag("Name", value.replace("%vb_color%", BlockColors.get(original.getData()))));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Backup data for toServer
|
// Backup data for toServer
|
||||||
@ -72,16 +83,6 @@ public abstract class BlockItemRewriter<T extends BackwardsProtocol> extends Rew
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle colors
|
|
||||||
if (i.getTag().contains("display")) {
|
|
||||||
CompoundTag tag = i.getTag().get("display");
|
|
||||||
if (tag.contains("Name")) {
|
|
||||||
String value = (String) tag.get("Name").getValue();
|
|
||||||
tag.put(new StringTag("Name",
|
|
||||||
value.replaceAll("%viabackwards_color%", BlockColors.get((int) original.getData()))));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
i.setAmount(original.getAmount());
|
i.setAmount(original.getAmount());
|
||||||
// Keep original data when -1
|
// Keep original data when -1
|
||||||
if (i.getData() == -1) {
|
if (i.getData() == -1) {
|
||||||
@ -125,22 +126,22 @@ public abstract class BlockItemRewriter<T extends BackwardsProtocol> extends Rew
|
|||||||
int type = idx >> 4;
|
int type = idx >> 4;
|
||||||
int meta = idx & 15;
|
int meta = idx & 15;
|
||||||
|
|
||||||
if (!containsBlock(type))
|
|
||||||
return idx;
|
|
||||||
|
|
||||||
Block b = handleBlock(type, meta);
|
Block b = handleBlock(type, meta);
|
||||||
|
if (b == null) return idx;
|
||||||
|
|
||||||
return (b.getId() << 4 | (b.getData() & 15));
|
return (b.getId() << 4 | (b.getData() & 15));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Block handleBlock(int block, int data) {
|
public Block handleBlock(int blockId, int data) {
|
||||||
if (!containsBlock(block))
|
BlockItemSettings settings = replacementData.get(blockId);
|
||||||
return null;
|
if (settings == null || !settings.hasRepBlock()) return null;
|
||||||
|
|
||||||
Block b = replacementData.get(block).getRepBlock().clone();
|
Block block = settings.getRepBlock();
|
||||||
// For some blocks, the data can still be useful (:
|
// For some blocks, the data can still be useful (:
|
||||||
if (b.getData() == -1)
|
if (block.getData() == -1) {
|
||||||
b.setData(data);
|
return block.withData(data);
|
||||||
return b;
|
}
|
||||||
|
return block;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void handleChunk(Chunk chunk) {
|
protected void handleChunk(Chunk chunk) {
|
||||||
@ -160,14 +161,16 @@ public abstract class BlockItemRewriter<T extends BackwardsProtocol> extends Rew
|
|||||||
if (section == null) continue;
|
if (section == null) continue;
|
||||||
int block = section.getFlatBlock(pos.getX(), pos.getY() & 0xF, pos.getZ());
|
int block = section.getFlatBlock(pos.getX(), pos.getY() & 0xF, pos.getZ());
|
||||||
int btype = block >> 4;
|
int btype = block >> 4;
|
||||||
if (!hasBlockEntityHandler(btype)) continue;
|
|
||||||
replacementData.get(btype).getBlockEntityHandler().handleOrNewCompoundTag(block, tag);
|
BlockItemSettings settings = replacementData.get(btype);
|
||||||
|
if (settings != null && settings.hasEntityHandler()) {
|
||||||
|
settings.getBlockEntityHandler().handleOrNewCompoundTag(block, tag);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < chunk.getSections().length; i++) {
|
for (int i = 0; i < chunk.getSections().length; i++) {
|
||||||
ChunkSection section = chunk.getSections()[i];
|
ChunkSection section = chunk.getSections()[i];
|
||||||
if (section == null)
|
if (section == null) continue;
|
||||||
continue;
|
|
||||||
|
|
||||||
boolean hasBlockEntityHandler = false;
|
boolean hasBlockEntityHandler = false;
|
||||||
|
|
||||||
@ -177,12 +180,18 @@ public abstract class BlockItemRewriter<T extends BackwardsProtocol> extends Rew
|
|||||||
int btype = block >> 4;
|
int btype = block >> 4;
|
||||||
int meta = block & 0xF;
|
int meta = block & 0xF;
|
||||||
|
|
||||||
if (containsBlock(btype)) {
|
Block b = handleBlock(btype, meta);
|
||||||
Block b = handleBlock(btype, meta);
|
if (b != null) {
|
||||||
section.setPaletteEntry(j, (b.getId() << 4) | (b.getData() & 0xF));
|
section.setPaletteEntry(j, (b.getId() << 4) | (b.getData() & 0xF));
|
||||||
}
|
}
|
||||||
|
|
||||||
hasBlockEntityHandler = hasBlockEntityHandler || hasBlockEntityHandler(btype);
|
// We already know that is has a handler
|
||||||
|
if (hasBlockEntityHandler) continue;
|
||||||
|
|
||||||
|
BlockItemSettings settings = replacementData.get(btype);
|
||||||
|
if (section != null && settings.hasEntityHandler()) {
|
||||||
|
hasBlockEntityHandler = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!hasBlockEntityHandler) continue;
|
if (!hasBlockEntityHandler) continue;
|
||||||
@ -195,7 +204,8 @@ public abstract class BlockItemRewriter<T extends BackwardsProtocol> extends Rew
|
|||||||
int btype = block >> 4;
|
int btype = block >> 4;
|
||||||
int meta = block & 15;
|
int meta = block & 15;
|
||||||
|
|
||||||
if (!hasBlockEntityHandler(btype)) continue;
|
BlockItemSettings settings = replacementData.get(btype);
|
||||||
|
if (settings == null || !settings.hasEntityHandler()) continue;
|
||||||
|
|
||||||
Pos pos = new Pos(x, (y + (i << 4)), z);
|
Pos pos = new Pos(x, (y + (i << 4)), z);
|
||||||
|
|
||||||
@ -206,7 +216,8 @@ public abstract class BlockItemRewriter<T extends BackwardsProtocol> extends Rew
|
|||||||
tag.put(new IntTag("x", x + (chunk.getX() << 4)));
|
tag.put(new IntTag("x", x + (chunk.getX() << 4)));
|
||||||
tag.put(new IntTag("y", y + (i << 4)));
|
tag.put(new IntTag("y", y + (i << 4)));
|
||||||
tag.put(new IntTag("z", z + (chunk.getZ() << 4)));
|
tag.put(new IntTag("z", z + (chunk.getZ() << 4)));
|
||||||
replacementData.get(btype).getBlockEntityHandler().handleOrNewCompoundTag(block, tag);
|
|
||||||
|
settings.getBlockEntityHandler().handleOrNewCompoundTag(block, tag);
|
||||||
chunk.getBlockEntities().add(tag);
|
chunk.getBlockEntities().add(tag);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -356,7 +356,7 @@ public class BlockItemPackets1_11 extends BlockItemRewriter<Protocol1_10To1_11>
|
|||||||
// ShulkerBoxes to Dropper
|
// ShulkerBoxes to Dropper
|
||||||
for (int i = 219; i < 235; i++)
|
for (int i = 219; i < 235; i++)
|
||||||
rewrite(i).repItem(new Item(158, (byte) 1, (short) 0, getNamedTag("1.11 " + BlockColors.get(i - 219) + " Shulker Box")))
|
rewrite(i).repItem(new Item(158, (byte) 1, (short) 0, getNamedTag("1.11 " + BlockColors.get(i - 219) + " Shulker Box")))
|
||||||
.repBlock(new Block(158, 0));
|
.repBlock(new Block(158));
|
||||||
|
|
||||||
// Observer to Dispenser
|
// Observer to Dispenser
|
||||||
rewrite(218).repItem(new Item(23, (byte) 1, (short) 0, getNamedTag("1.11 Observer"))).repBlock(new Block(23, -1));
|
rewrite(218).repItem(new Item(23, (byte) 1, (short) 0, getNamedTag("1.11 Observer"))).repBlock(new Block(23, -1));
|
||||||
|
@ -10,41 +10,29 @@
|
|||||||
|
|
||||||
package nl.matsv.viabackwards.protocol.protocol1_11_1to1_12.data;
|
package nl.matsv.viabackwards.protocol.protocol1_11_1to1_12.data;
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class BlockColors {
|
public class BlockColors {
|
||||||
private static final Map<Integer, String> COLORS = new HashMap<>();
|
private static final String[] COLORS = new String[16];
|
||||||
private static int count = 0;
|
|
||||||
|
|
||||||
static {
|
static {
|
||||||
add("White");
|
COLORS[0] = "White";
|
||||||
add("Orange");
|
COLORS[1] = "Orange";
|
||||||
add("Magenta");
|
COLORS[2] = "Magenta";
|
||||||
add("Light Blue");
|
COLORS[3] = "Light Blue";
|
||||||
add("Yellow");
|
COLORS[4] = "Yellow";
|
||||||
add("Lime");
|
COLORS[5] = "Lime";
|
||||||
add("Pink");
|
COLORS[6] = "Pink";
|
||||||
add("Gray");
|
COLORS[7] = "Gray";
|
||||||
add("Light Gray");
|
COLORS[8] = "Light Gray";
|
||||||
add("Cyan");
|
COLORS[9] = "Cyan";
|
||||||
add("Purple");
|
COLORS[10] = "Purple";
|
||||||
add("Blue");
|
COLORS[11] = "Blue";
|
||||||
add("Brown");
|
COLORS[12] = "Brown";
|
||||||
add("Green");
|
COLORS[13] = "Green";
|
||||||
add("Red");
|
COLORS[14] = "Red";
|
||||||
add("Black");
|
COLORS[15] = "Black";
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void add(String value) {
|
public static String get(int key) {
|
||||||
COLORS.put(count++, value);
|
return key >= 0 && key < COLORS.length ? COLORS[key] : "Unknown color";
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean has(Integer key) {
|
|
||||||
return COLORS.containsKey(key);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String get(Integer key) {
|
|
||||||
return COLORS.getOrDefault(key, "Unknown color");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -269,12 +269,12 @@ public class BlockItemPackets1_12 extends BlockItemRewriter<Protocol1_11_1To1_12
|
|||||||
protected void registerRewrites() {
|
protected void registerRewrites() {
|
||||||
// Concrete -> Stained clay? (Also got a new name Terracota?)
|
// Concrete -> Stained clay? (Also got a new name Terracota?)
|
||||||
rewrite(251)
|
rewrite(251)
|
||||||
.repItem(new Item(159, (byte) 1, (short) -1, getNamedTag("1.12 %viabackwards_color% Concrete")))
|
.repItem(new Item(159, (byte) 1, (short) -1, getNamedTag("1.12 %vb_color% Concrete")))
|
||||||
.repBlock(new Block(159, -1));
|
.repBlock(new Block(159, -1));
|
||||||
|
|
||||||
// Concrete Powder -> Wool
|
// Concrete Powder -> Wool
|
||||||
rewrite(252)
|
rewrite(252)
|
||||||
.repItem(new Item(35, (byte) 1, (short) -1, getNamedTag("1.12 %viabackwards_color% Concrete Powder")))
|
.repItem(new Item(35, (byte) 1, (short) -1, getNamedTag("1.12 %vb_color% Concrete Powder")))
|
||||||
.repBlock(new Block(35, -1));
|
.repBlock(new Block(35, -1));
|
||||||
|
|
||||||
// Knowledge book -> book
|
// Knowledge book -> book
|
||||||
@ -296,6 +296,6 @@ public class BlockItemPackets1_12 extends BlockItemRewriter<Protocol1_11_1To1_12
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Handle beds
|
// Handle beds
|
||||||
rewrite(355).repItem(new Item(355, (byte) 1, (short) 0, getNamedTag("1.12 %viabackwards_color% Bed")));
|
rewrite(355).repItem(new Item(355, (byte) 1, (short) 0, getNamedTag("1.12 %vb_color% Bed")));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -183,10 +183,10 @@ public class BlockItemPackets1_10 extends BlockItemRewriter<Protocol1_9_4To1_10>
|
|||||||
@Override
|
@Override
|
||||||
protected void registerRewrites() {
|
protected void registerRewrites() {
|
||||||
rewrite(255).repItem(new Item(166, (byte) 1, (short) 0, getNamedTag("1.10 Structure Block"))); // Structure block only item since the structure block is in 1.9
|
rewrite(255).repItem(new Item(166, (byte) 1, (short) 0, getNamedTag("1.10 Structure Block"))); // Structure block only item since the structure block is in 1.9
|
||||||
rewrite(217).repItem(new Item(287, (byte) 1, (short) 0, getNamedTag("1.10 Structure Void"))).repBlock(new Block(287, 0)); // Structure void to string
|
rewrite(217).repItem(new Item(287, (byte) 1, (short) 0, getNamedTag("1.10 Structure Void"))).repBlock(new Block(287)); // Structure void to string
|
||||||
rewrite(213).repItem(new Item(159, (byte) 1, (short) 1, getNamedTag("1.10 Magma Block"))).repBlock(new Block(159, 1)); // Magma block to orange clay
|
rewrite(213).repItem(new Item(159, (byte) 1, (short) 1, getNamedTag("1.10 Magma Block"))).repBlock(new Block(159, 1)); // Magma block to orange clay
|
||||||
rewrite(214).repItem(new Item(159, (byte) 1, (short) 14, getNamedTag("1.10 Nether Wart Block"))).repBlock(new Block(159, 14)); // Nether wart block to red clay
|
rewrite(214).repItem(new Item(159, (byte) 1, (short) 14, getNamedTag("1.10 Nether Wart Block"))).repBlock(new Block(159, 14)); // Nether wart block to red clay
|
||||||
rewrite(215).repItem(new Item(112, (byte) 1, (short) 0, getNamedTag("1.10 Red Nether Bricks"))).repBlock(new Block(112, 0)); // Red nether brick to nether brick
|
rewrite(215).repItem(new Item(112, (byte) 1, (short) 0, getNamedTag("1.10 Red Nether Bricks"))).repBlock(new Block(112)); // Red nether brick to nether brick
|
||||||
rewrite(216).repItem(new Item(155, (byte) 1, (short) 0, getNamedTag("1.10 Bone Block"))).repBlock(new Block(155, 0)); // Bone block to quartz
|
rewrite(216).repItem(new Item(155, (byte) 1, (short) 0, getNamedTag("1.10 Bone Block"))).repBlock(new Block(155)); // Bone block to quartz
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,18 +10,32 @@
|
|||||||
|
|
||||||
package nl.matsv.viabackwards.utils;
|
package nl.matsv.viabackwards.utils;
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
@AllArgsConstructor
|
|
||||||
@EqualsAndHashCode
|
@EqualsAndHashCode
|
||||||
@Data
|
|
||||||
public class Block {
|
public class Block {
|
||||||
private int id;
|
private final int id;
|
||||||
private int data;
|
private final int data;
|
||||||
|
|
||||||
public Block clone() {
|
public Block(final int id, final int data) {
|
||||||
return new Block(id, data);
|
this.id = id;
|
||||||
|
this.data = data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Block(final int id) {
|
||||||
|
this.id = id;
|
||||||
|
this.data = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getData() {
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Block withData(final int data) {
|
||||||
|
return new Block(this.id, data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren