Mirror von
https://github.com/ViaVersion/ViaBackwards.git
synchronisiert 2024-12-26 16:12:43 +01:00
Remap 1.13 piston tile entity
Dieser Commit ist enthalten in:
Ursprung
cba2566c21
Commit
01018fe600
@ -0,0 +1,92 @@
|
||||
package nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.block_entity_handlers;
|
||||
|
||||
import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.data.BackwardsMappings;
|
||||
import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.providers.BackwardsBlockEntityProvider;
|
||||
import us.myles.ViaVersion.api.Via;
|
||||
import us.myles.ViaVersion.api.data.UserConnection;
|
||||
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.blockconnections.ConnectionData;
|
||||
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.MappingData;
|
||||
import us.myles.viaversion.libs.gson.JsonElement;
|
||||
import us.myles.viaversion.libs.gson.JsonObject;
|
||||
import us.myles.viaversion.libs.opennbt.tag.builtin.CompoundTag;
|
||||
import us.myles.viaversion.libs.opennbt.tag.builtin.IntTag;
|
||||
import us.myles.viaversion.libs.opennbt.tag.builtin.StringTag;
|
||||
import us.myles.viaversion.libs.opennbt.tag.builtin.Tag;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.StringJoiner;
|
||||
|
||||
public class PistonHandler implements BackwardsBlockEntityProvider.BackwardsBlockEntityHandler {
|
||||
|
||||
private final Map<String, Integer> pistonIds = new HashMap<>();
|
||||
|
||||
public PistonHandler() {
|
||||
if (Via.getConfig().isServersideBlockConnections()) {
|
||||
Map<String, Integer> keyToId;
|
||||
try {
|
||||
keyToId = (Map<String, Integer>) ConnectionData.class.getDeclaredField("keyToId").get(null);
|
||||
} catch (IllegalAccessException | NoSuchFieldException e) {
|
||||
e.printStackTrace();
|
||||
return;
|
||||
}
|
||||
|
||||
for (Map.Entry<String, Integer> entry : keyToId.entrySet()) {
|
||||
if (!entry.getKey().contains("piston")) continue;
|
||||
|
||||
addEnries(entry.getKey(), entry.getValue());
|
||||
}
|
||||
} else {
|
||||
JsonObject mappings = MappingData.loadData("mapping-1.13.json").getAsJsonObject("blocks");
|
||||
for (Map.Entry<String, JsonElement> blockState : mappings.entrySet()) {
|
||||
String key = blockState.getValue().getAsString();
|
||||
if (!key.contains("piston")) continue;
|
||||
|
||||
addEnries(key, Integer.parseInt(blockState.getKey()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// There doesn't seem to be a nicer way around it :(
|
||||
private void addEnries(String data, int id) {
|
||||
id = BackwardsMappings.blockMappings.getNewBlock(id);
|
||||
pistonIds.put(data, id);
|
||||
|
||||
String substring = data.substring(10);
|
||||
if (!substring.startsWith("piston") && !substring.startsWith("sticky_piston")) return;
|
||||
|
||||
// Swap properties and add them to the map
|
||||
String[] split = data.substring(0, data.length() - 1).split("\\[");
|
||||
String[] properties = split[1].split(",");
|
||||
data = split[0] + "[" + properties[1] + "," + properties[0] + "]";
|
||||
pistonIds.put(data, id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompoundTag transform(UserConnection user, int blockId, CompoundTag tag) {
|
||||
CompoundTag blockState = tag.get("blockState");
|
||||
String dataFromTag = getDataFromTag(blockState);
|
||||
if (dataFromTag == null) return tag;
|
||||
|
||||
int id = pistonIds.get(dataFromTag);
|
||||
tag.put(new IntTag("blockId", id >> 4));
|
||||
tag.put(new IntTag("blockData", id & 15));
|
||||
return tag;
|
||||
}
|
||||
|
||||
// The type hasn't actually been updated in the blockstorage, so we need to construct it
|
||||
private String getDataFromTag(CompoundTag tag) {
|
||||
StringTag name = tag.get("Name");
|
||||
if (name == null) return null;
|
||||
|
||||
CompoundTag properties = tag.get("Properties");
|
||||
if (properties == null) return name.getValue();
|
||||
|
||||
StringJoiner joiner = new StringJoiner(",", name.getValue() + "[", "]");
|
||||
for (Tag property : properties) {
|
||||
if (!(property instanceof StringTag)) continue;
|
||||
joiner.add(property.getName() + "=" + ((StringTag) property).getValue());
|
||||
}
|
||||
return joiner.toString();
|
||||
}
|
||||
}
|
@ -33,6 +33,7 @@ public class BackwardsBlockEntityProvider implements Provider {
|
||||
handlers.put("minecraft:banner", new BannerHandler());
|
||||
handlers.put("minecraft:skull", new SkullHandler());
|
||||
handlers.put("minecraft:mob_spawner", new SpawnerHandler());
|
||||
handlers.put("minecraft:piston", new PistonHandler());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -10,18 +10,18 @@
|
||||
|
||||
package nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.storage;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
import us.myles.ViaVersion.api.data.StoredObject;
|
||||
import us.myles.ViaVersion.api.data.UserConnection;
|
||||
import us.myles.ViaVersion.api.minecraft.Position;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class BackwardsBlockStorage extends StoredObject {
|
||||
// This BlockStorage is very exclusive (;
|
||||
private static final Set<Integer> whitelist = Sets.newConcurrentHashSet();
|
||||
private static final Set<Integer> whitelist = new HashSet<>();
|
||||
|
||||
static {
|
||||
// Flower pots
|
||||
@ -42,6 +42,17 @@ public class BackwardsBlockStorage extends StoredObject {
|
||||
// Skulls
|
||||
for (int i = 5447; i <= 5566; i++)
|
||||
whitelist.add(i);
|
||||
|
||||
// pistons
|
||||
for (int i = 1028; i <= 1039; i++) {
|
||||
whitelist.add(i);
|
||||
}
|
||||
for (int i = 1047; i <= 1082; i++) {
|
||||
whitelist.add(i);
|
||||
}
|
||||
for (int i = 1099; i <= 1110; i++) {
|
||||
whitelist.add(i);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -54,8 +65,7 @@ public class BackwardsBlockStorage extends StoredObject {
|
||||
public void checkAndStore(Position position, int block) {
|
||||
if (!whitelist.contains(block)) {
|
||||
// Remove if not whitelisted
|
||||
if (blocks.containsKey(position))
|
||||
blocks.remove(position);
|
||||
blocks.remove(position);
|
||||
return;
|
||||
}
|
||||
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren