mirror of
https://github.com/ViaVersion/ViaBackwards.git
synced 2024-12-22 16:57:40 +01:00
Merge branch 'refs/heads/dev' into preview
# Conflicts: # common/src/main/java/com/viaversion/viabackwards/api/data/BackwardsMappings.java
This commit is contained in:
commit
27dd2e39bd
@ -159,7 +159,7 @@ public class BackwardsMappings extends MappingDataBase {
|
|||||||
|
|
||||||
public @Nullable String mappedEntityName(final String entityName) {
|
public @Nullable String mappedEntityName(final String entityName) {
|
||||||
if (entityNames == null) {
|
if (entityNames == null) {
|
||||||
ViaBackwards.getPlatform().getLogger().log(Level.SEVERE, "No entity mappings found when requesting them for " + entityName, new RuntimeException());
|
getLogger().log(Level.SEVERE, "No entity mappings found when requesting them for " + entityName, new RuntimeException());
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return entityNames.get(entityName);
|
return entityNames.get(entityName);
|
||||||
|
@ -27,13 +27,19 @@ public class MappedLegacyBlockItem {
|
|||||||
private final short data;
|
private final short data;
|
||||||
private final String name;
|
private final String name;
|
||||||
private final IdAndData block;
|
private final IdAndData block;
|
||||||
|
private final Type type;
|
||||||
private BlockEntityHandler blockEntityHandler;
|
private BlockEntityHandler blockEntityHandler;
|
||||||
|
|
||||||
public MappedLegacyBlockItem(int id, short data, @Nullable String name, boolean block) {
|
public MappedLegacyBlockItem(int id) {
|
||||||
|
this(id, (short) -1, null, Type.ITEM);
|
||||||
|
}
|
||||||
|
|
||||||
|
public MappedLegacyBlockItem(int id, short data, @Nullable String name, Type type) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.data = data;
|
this.data = data;
|
||||||
this.name = name != null ? "§f" + name : null;
|
this.name = name != null ? "§f" + name : null;
|
||||||
this.block = block ? data != -1 ? new IdAndData(id, data) : new IdAndData(id) : null;
|
this.block = type != Type.ITEM ? data != -1 ? new IdAndData(id, data) : new IdAndData(id) : null;
|
||||||
|
this.type = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getId() {
|
public int getId() {
|
||||||
@ -48,8 +54,8 @@ public class MappedLegacyBlockItem {
|
|||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isBlock() {
|
public Type getType() {
|
||||||
return block != null;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IdAndData getBlock() {
|
public IdAndData getBlock() {
|
||||||
@ -73,4 +79,21 @@ public class MappedLegacyBlockItem {
|
|||||||
|
|
||||||
CompoundTag handleOrNewCompoundTag(int block, CompoundTag tag);
|
CompoundTag handleOrNewCompoundTag(int block, CompoundTag tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public enum Type {
|
||||||
|
|
||||||
|
ITEM("items"),
|
||||||
|
BLOCK_ITEM("block-items"),
|
||||||
|
BLOCK("blocks");
|
||||||
|
|
||||||
|
final String name;
|
||||||
|
|
||||||
|
Type(final String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -106,10 +106,14 @@ public abstract class EntityRewriterBase<C extends ClientboundPacketType, T exte
|
|||||||
private void addDisplayVisibilityMeta(List<Metadata> metadataList) {
|
private void addDisplayVisibilityMeta(List<Metadata> metadataList) {
|
||||||
if (alwaysShowOriginalMobName()) {
|
if (alwaysShowOriginalMobName()) {
|
||||||
removeMeta(displayVisibilityIndex, metadataList);
|
removeMeta(displayVisibilityIndex, metadataList);
|
||||||
metadataList.add(new Metadata(displayVisibilityIndex, displayVisibilityMetaType, true));
|
metadataList.add(new Metadata(displayVisibilityIndex, displayVisibilityMetaType, getDisplayVisibilityMetaValue()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected Object getDisplayVisibilityMetaValue() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
protected boolean alwaysShowOriginalMobName() {
|
protected boolean alwaysShowOriginalMobName() {
|
||||||
return ViaBackwards.getConfig().alwaysShowOriginalMobName();
|
return ViaBackwards.getConfig().alwaysShowOriginalMobName();
|
||||||
}
|
}
|
||||||
|
@ -62,18 +62,25 @@ public abstract class LegacyBlockItemRewriter<C extends ClientboundPacketType, S
|
|||||||
protected LegacyBlockItemRewriter(T protocol, String name) {
|
protected LegacyBlockItemRewriter(T protocol, String name) {
|
||||||
super(protocol, Type.ITEM1_8, Type.ITEM1_8_SHORT_ARRAY, false);
|
super(protocol, Type.ITEM1_8, Type.ITEM1_8_SHORT_ARRAY, false);
|
||||||
final JsonObject jsonObject = readMappingsFile("item-mappings-" + name + ".json");
|
final JsonObject jsonObject = readMappingsFile("item-mappings-" + name + ".json");
|
||||||
for (Map.Entry<String, JsonElement> dataEntry : jsonObject.entrySet()) {
|
for (final MappedLegacyBlockItem.Type value : MappedLegacyBlockItem.Type.values()) {
|
||||||
addMapping(dataEntry.getKey(), dataEntry.getValue().getAsJsonObject(), replacementData);
|
addMappings(value, jsonObject, replacementData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addMapping(String key, JsonObject object, Int2ObjectMap<MappedLegacyBlockItem> mappings) {
|
private void addMappings(MappedLegacyBlockItem.Type type, JsonObject object, Int2ObjectMap<MappedLegacyBlockItem> mappings) {
|
||||||
|
if (object.has(type.getName())) {
|
||||||
|
final JsonObject mappingsObject = object.getAsJsonObject(type.getName());
|
||||||
|
for (Map.Entry<String, JsonElement> dataEntry : mappingsObject.entrySet()) {
|
||||||
|
addMapping(dataEntry.getKey(), dataEntry.getValue().getAsJsonObject(), type, mappings);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addMapping(String key, JsonObject object, MappedLegacyBlockItem.Type type, Int2ObjectMap<MappedLegacyBlockItem> mappings) {
|
||||||
int id = object.getAsJsonPrimitive("id").getAsInt();
|
int id = object.getAsJsonPrimitive("id").getAsInt();
|
||||||
JsonPrimitive jsonData = object.getAsJsonPrimitive("data");
|
JsonPrimitive jsonData = object.getAsJsonPrimitive("data");
|
||||||
short data = jsonData != null ? jsonData.getAsShort() : 0;
|
short data = jsonData != null ? jsonData.getAsShort() : 0;
|
||||||
String name = object.getAsJsonPrimitive("name").getAsString();
|
String name = type != MappedLegacyBlockItem.Type.BLOCK ? object.getAsJsonPrimitive("name").getAsString() : null;
|
||||||
JsonPrimitive blockField = object.getAsJsonPrimitive("block");
|
|
||||||
boolean block = blockField != null && blockField.getAsBoolean();
|
|
||||||
|
|
||||||
if (key.indexOf('-') == -1) {
|
if (key.indexOf('-') == -1) {
|
||||||
int unmappedId;
|
int unmappedId;
|
||||||
@ -87,7 +94,7 @@ public abstract class LegacyBlockItemRewriter<C extends ClientboundPacketType, S
|
|||||||
unmappedId = IdAndData.toRawData(Integer.parseInt(key));
|
unmappedId = IdAndData.toRawData(Integer.parseInt(key));
|
||||||
}
|
}
|
||||||
|
|
||||||
mappings.put(unmappedId, new MappedLegacyBlockItem(id, data, name, block));
|
mappings.put(unmappedId, new MappedLegacyBlockItem(id, data, name, type));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -97,12 +104,12 @@ public abstract class LegacyBlockItemRewriter<C extends ClientboundPacketType, S
|
|||||||
int to = Integer.parseInt(split[1]);
|
int to = Integer.parseInt(split[1]);
|
||||||
|
|
||||||
// Special block color handling
|
// Special block color handling
|
||||||
if (name.contains("%color%")) {
|
if (name != null && name.contains("%color%")) {
|
||||||
for (int i = from; i <= to; i++) {
|
for (int i = from; i <= to; i++) {
|
||||||
mappings.put(IdAndData.toRawData(i), new MappedLegacyBlockItem(id, data, name.replace("%color%", BlockColors.get(i - from)), block));
|
mappings.put(IdAndData.toRawData(i), new MappedLegacyBlockItem(id, data, name.replace("%color%", BlockColors.get(i - from)), type));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
MappedLegacyBlockItem mappedBlockItem = new MappedLegacyBlockItem(id, data, name, block);
|
MappedLegacyBlockItem mappedBlockItem = new MappedLegacyBlockItem(id, data, name, type);
|
||||||
for (int i = from; i <= to; i++) {
|
for (int i = from; i <= to; i++) {
|
||||||
mappings.put(IdAndData.toRawData(i), mappedBlockItem);
|
mappings.put(IdAndData.toRawData(i), mappedBlockItem);
|
||||||
}
|
}
|
||||||
@ -146,7 +153,7 @@ public abstract class LegacyBlockItemRewriter<C extends ClientboundPacketType, S
|
|||||||
if (item == null) return null;
|
if (item == null) return null;
|
||||||
|
|
||||||
MappedLegacyBlockItem data = getMappedBlockItem(item.identifier(), item.data());
|
MappedLegacyBlockItem data = getMappedBlockItem(item.identifier(), item.data());
|
||||||
if (data == null) {
|
if (data == null || data.getType() == MappedLegacyBlockItem.Type.BLOCK) {
|
||||||
// Just rewrite the id
|
// Just rewrite the id
|
||||||
return super.handleItemToClient(connection, item);
|
return super.handleItemToClient(connection, item);
|
||||||
}
|
}
|
||||||
@ -219,7 +226,9 @@ public abstract class LegacyBlockItemRewriter<C extends ClientboundPacketType, S
|
|||||||
|
|
||||||
public @Nullable IdAndData handleBlock(int blockId, int data) {
|
public @Nullable IdAndData handleBlock(int blockId, int data) {
|
||||||
MappedLegacyBlockItem settings = getMappedBlockItem(blockId, data);
|
MappedLegacyBlockItem settings = getMappedBlockItem(blockId, data);
|
||||||
if (settings == null || !settings.isBlock()) return null;
|
if (settings == null || settings.getType() == MappedLegacyBlockItem.Type.ITEM) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
IdAndData block = settings.getBlock();
|
IdAndData block = settings.getBlock();
|
||||||
// For some blocks, the data can still be useful (:
|
// For some blocks, the data can still be useful (:
|
||||||
|
@ -274,7 +274,7 @@ public class BlockItemPackets1_11 extends LegacyBlockItemRewriter<ClientboundPac
|
|||||||
@Override
|
@Override
|
||||||
protected void registerRewrites() {
|
protected void registerRewrites() {
|
||||||
// Handle spawner block entity (map to itself with custom handler)
|
// Handle spawner block entity (map to itself with custom handler)
|
||||||
MappedLegacyBlockItem data = replacementData.computeIfAbsent(IdAndData.toRawData(52), s -> new MappedLegacyBlockItem(52, (short) -1, null, false));
|
MappedLegacyBlockItem data = replacementData.computeIfAbsent(IdAndData.toRawData(52), s -> new MappedLegacyBlockItem(52));
|
||||||
data.setBlockEntityHandler((b, tag) -> {
|
data.setBlockEntityHandler((b, tag) -> {
|
||||||
EntityIdRewriter.toClientSpawner(tag, true);
|
EntityIdRewriter.toClientSpawner(tag, true);
|
||||||
return tag;
|
return tag;
|
||||||
|
@ -1,33 +1,32 @@
|
|||||||
{
|
{
|
||||||
|
"items": {
|
||||||
"255": {
|
"255": {
|
||||||
"id": 217,
|
"id": 217,
|
||||||
"name": "1.10 Structure Block"
|
"name": "1.10 Structure Block"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
"block-items": {
|
||||||
"217": {
|
"217": {
|
||||||
"id": 287,
|
"id": 287,
|
||||||
"name": "1.10 Structure Void",
|
"name": "1.10 Structure Void"
|
||||||
"block": true
|
|
||||||
},
|
},
|
||||||
"213": {
|
"213": {
|
||||||
"id": 159,
|
"id": 159,
|
||||||
"data": 1,
|
"data": 1,
|
||||||
"name": "1.10 Magma Block",
|
"name": "1.10 Magma Block"
|
||||||
"block": true
|
|
||||||
},
|
},
|
||||||
"214": {
|
"214": {
|
||||||
"id": 159,
|
"id": 159,
|
||||||
"data": 14,
|
"data": 14,
|
||||||
"name": "1.10 Nether Wart Block",
|
"name": "1.10 Nether Wart Block"
|
||||||
"block": true
|
|
||||||
},
|
},
|
||||||
"215": {
|
"215": {
|
||||||
"id": 112,
|
"id": 112,
|
||||||
"name": "1.10 Red Nether Bricks",
|
"name": "1.10 Red Nether Bricks"
|
||||||
"block": true
|
|
||||||
},
|
},
|
||||||
"216": {
|
"216": {
|
||||||
"id": 155,
|
"id": 155,
|
||||||
"name": "1.10 Bone Block",
|
"name": "1.10 Bone Block"
|
||||||
"block": true
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,6 +1,8 @@
|
|||||||
{
|
{
|
||||||
|
"items": {
|
||||||
"452": {
|
"452": {
|
||||||
"id": 265,
|
"id": 265,
|
||||||
"name": "1.11.1 Iron Nugget"
|
"name": "1.11.1 Iron Nugget"
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
@ -1,10 +1,5 @@
|
|||||||
{
|
{
|
||||||
"218": {
|
"items": {
|
||||||
"id": 23,
|
|
||||||
"data": -1,
|
|
||||||
"name": "1.11 Observer",
|
|
||||||
"block": true
|
|
||||||
},
|
|
||||||
"449": {
|
"449": {
|
||||||
"id": 418,
|
"id": 418,
|
||||||
"name": "1.11 Totem of Undying"
|
"name": "1.11 Totem of Undying"
|
||||||
@ -12,10 +7,17 @@
|
|||||||
"450": {
|
"450": {
|
||||||
"id": 433,
|
"id": 433,
|
||||||
"name": "1.11 Shulker Shell"
|
"name": "1.11 Shulker Shell"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"block-items": {
|
||||||
|
"218": {
|
||||||
|
"id": 23,
|
||||||
|
"data": -1,
|
||||||
|
"name": "1.11 Observer"
|
||||||
},
|
},
|
||||||
"219-234": {
|
"219-234": {
|
||||||
"id": 158,
|
"id": 158,
|
||||||
"name": "1.11 %color% Shulker Box",
|
"name": "1.11 %color% Shulker Box"
|
||||||
"block": true
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,16 +1,5 @@
|
|||||||
{
|
{
|
||||||
"251": {
|
"items": {
|
||||||
"id": 159,
|
|
||||||
"data": -1,
|
|
||||||
"name": "1.12 %vb_color% Concrete",
|
|
||||||
"block": true
|
|
||||||
},
|
|
||||||
"252": {
|
|
||||||
"id": 35,
|
|
||||||
"data": -1,
|
|
||||||
"name": "1.12 %vb_color% Concrete Powder",
|
|
||||||
"block": true
|
|
||||||
},
|
|
||||||
"453": {
|
"453": {
|
||||||
"id": 340,
|
"id": 340,
|
||||||
"name": "1.12 Knowledge Book"
|
"name": "1.12 Knowledge Book"
|
||||||
@ -18,10 +7,22 @@
|
|||||||
"355": {
|
"355": {
|
||||||
"id": 355,
|
"id": 355,
|
||||||
"name": "1.12 %vb_color% Bed"
|
"name": "1.12 %vb_color% Bed"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"block-items": {
|
||||||
|
"251": {
|
||||||
|
"id": 159,
|
||||||
|
"data": -1,
|
||||||
|
"name": "1.12 %vb_color% Concrete"
|
||||||
|
},
|
||||||
|
"252": {
|
||||||
|
"id": 35,
|
||||||
|
"data": -1,
|
||||||
|
"name": "1.12 %vb_color% Concrete Powder"
|
||||||
},
|
},
|
||||||
"235-250": {
|
"235-250": {
|
||||||
"id": 159,
|
"id": 159,
|
||||||
"name": "1.12 %color% Glazed Terracotta",
|
"name": "1.12 %color% Glazed Terracotta"
|
||||||
"block": true
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user