3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-12-28 00:50:13 +01:00

Merge pull request #1735 from KennyTV/abstraction

Add fire connection handler
Dieser Commit ist enthalten in:
Myles 2020-05-02 15:35:38 +01:00 committet von GitHub
Commit d5ff2b5b63
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 4AEE18F83AFDEB23
7 geänderte Dateien mit 88 neuen und 10 gelöschten Zeilen

Datei anzeigen

@ -24,6 +24,7 @@ import us.myles.ViaVersion.protocols.protocol1_12to1_11_1.storage.EntityTracker1
import us.myles.ViaVersion.protocols.protocol1_9_1_2to1_9_3_4.types.Chunk1_9_3_4Type;
import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9To1_8;
import us.myles.ViaVersion.util.GsonUtil;
public class Protocol1_12To1_11_1 extends Protocol {
@ -81,7 +82,7 @@ public class Protocol1_12To1_11_1 extends Protocol {
public void handle(PacketWrapper wrapper) throws Exception {
if (!Via.getConfig().is1_12NBTArrayFix()) return;
try {
JsonElement obj = new JsonParser().parse(wrapper.get(Type.STRING, 0));
JsonElement obj = GsonUtil.getJsonParser().parse(wrapper.get(Type.STRING, 0));
if (!TranslateRewriter.toClient(obj, wrapper.user())) {
wrapper.cancel();
return;

Datei anzeigen

@ -289,12 +289,12 @@ public class Protocol1_13To1_12_2 extends Protocol {
int index;
int length;
// If no input or new word (then it's the start)
if (input.endsWith(" ") || input.length() == 0) {
if (input.endsWith(" ") || input.isEmpty()) {
index = input.length();
length = 0;
} else {
// Otherwise find the last space (+1 as we include it)
int lastSpace = input.lastIndexOf(" ") + 1;
int lastSpace = input.lastIndexOf(' ') + 1;
index = lastSpace;
length = input.length() - lastSpace;
}
@ -1212,7 +1212,7 @@ public class Protocol1_13To1_12_2 extends Protocol {
// The Display Name is just colours which overwrites the suffix
// It also overwrites for ANY colour in name but most plugins
// will just send colour as 'invisible' character
if (ChatColor.stripColor(name).length() == 0) {
if (ChatColor.stripColor(name).isEmpty()) {
StringBuilder newName = new StringBuilder();
for (int i = 1; i < name.length(); i += 2) {
char colorChar = name.charAt(i);

Datei anzeigen

@ -249,6 +249,7 @@ public class ConnectionData {
initActions.addAll(ChorusPlantConnectionHandler.init());
initActions.add(TripwireConnectionHandler.init());
initActions.add(SnowyGrassConnectionHandler.init());
initActions.add(FireConnectionHandler.init());
if (Via.getConfig().isVineClimbFix()) {
initActions.add(VineConnectionHandler.init());
}

Datei anzeigen

@ -0,0 +1,71 @@
package us.myles.ViaVersion.protocols.protocol1_13to1_12_2.blockconnections;
import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.minecraft.BlockFace;
import us.myles.ViaVersion.api.minecraft.Position;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
public class FireConnectionHandler extends ConnectionHandler {
private static final String[] WOOD_TYPES = {"oak", "spruce", "birch", "jungle", "acacia", "dark_oak"};
private static final Map<Byte, Integer> connectedBlocks = new HashMap<>();
private static final Set<Integer> flammableBlocks = new HashSet<>();
private static void addWoodTypes(Set<String> set, String suffix) {
for (String woodType : WOOD_TYPES) {
set.add("minecraft:" + woodType + suffix);
}
}
static ConnectionData.ConnectorInitAction init() {
Set<String> flammabeIds = new HashSet<>();
flammabeIds.add("minecraft:tnt");
flammabeIds.add("minecraft:vine");
flammabeIds.add("minecraft:bookshelf");
flammabeIds.add("minecraft:hay_block");
flammabeIds.add("minecraft:deadbush");
addWoodTypes(flammabeIds, "_slab");
addWoodTypes(flammabeIds, "_log");
addWoodTypes(flammabeIds, "_planks");
addWoodTypes(flammabeIds, "_leaves");
addWoodTypes(flammabeIds, "_fence");
addWoodTypes(flammabeIds, "_fence_gate");
addWoodTypes(flammabeIds, "_stairs");
FireConnectionHandler connectionHandler = new FireConnectionHandler();
return blockData -> {
String key = blockData.getMinecraftKey();
if (key.contains("_wool") || key.contains("_carpet") || flammabeIds.contains(key)) {
flammableBlocks.add(blockData.getSavedBlockStateId());
} else if (key.equals("minecraft:fire")) {
int id = blockData.getSavedBlockStateId();
connectedBlocks.put(getStates(blockData), id);
ConnectionData.connectionHandlerMap.put(id, connectionHandler);
}
};
}
private static byte getStates(WrappedBlockData blockData) {
byte states = 0;
if (blockData.getValue("east").equals("true")) states |= 1;
if (blockData.getValue("north").equals("true")) states |= 2;
if (blockData.getValue("south").equals("true")) states |= 4;
if (blockData.getValue("up").equals("true")) states |= 8;
if (blockData.getValue("west").equals("true")) states |= 16;
return states;
}
@Override
public int connect(UserConnection user, Position position, int blockState) {
byte states = 0;
if (flammableBlocks.contains(getBlockData(user, position.getRelative(BlockFace.EAST)))) states |= 1;
if (flammableBlocks.contains(getBlockData(user, position.getRelative(BlockFace.NORTH)))) states |= 2;
if (flammableBlocks.contains(getBlockData(user, position.getRelative(BlockFace.SOUTH)))) states |= 4;
if (flammableBlocks.contains(getBlockData(user, position.getRelative(BlockFace.TOP)))) states |= 8;
if (flammableBlocks.contains(getBlockData(user, position.getRelative(BlockFace.WEST)))) states |= 16;
return connectedBlocks.get(states);
}
}

Datei anzeigen

@ -1,6 +1,5 @@
package us.myles.ViaVersion.protocols.protocol1_16to1_15_2;
import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.protocol.Protocol;
@ -130,7 +129,7 @@ public class Protocol1_16To1_15_2 extends Protocol {
cancelIncoming(State.PLAY, 0x0F); // Generate jisaw
cancelIncoming(State.PLAY, 0x28); // Jigsaw update
cancelIncoming(State.PLAY, 0x28); // Jigsaw update
registerIncoming(State.PLAY, 0x0F, 0x10);
registerIncoming(State.PLAY, 0x10, 0x11);

Datei anzeigen

@ -1,7 +1,6 @@
package us.myles.ViaVersion.protocols.protocol1_9to1_8.packets;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.entities.Entity1_10Types;
@ -22,6 +21,7 @@ import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.CommandBlockProv
import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.MainHandProvider;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.ClientChunks;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.EntityTracker1_9;
import us.myles.ViaVersion.util.GsonUtil;
public class PlayerPackets {
public static void register(Protocol protocol) {
@ -36,7 +36,7 @@ public class PlayerPackets {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
try {
JsonObject obj = (JsonObject) new JsonParser().parse(wrapper.get(Type.STRING, 0));
JsonObject obj = (JsonObject) GsonUtil.getJsonParser().parse(wrapper.get(Type.STRING, 0));
ChatRewriter.toClient(obj, wrapper.user());
wrapper.set(Type.STRING, 0, obj.toString());
} catch (Exception e) {

Datei anzeigen

@ -2,9 +2,11 @@ package us.myles.ViaVersion.util;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonParser;
public final class GsonUtil {
private static final Gson gson = getGsonBuilder().create();
private static final JsonParser JSON_PARSER = new JsonParser();
private static final Gson GSON = getGsonBuilder().create();
/**
* Get google's Gson magic
@ -12,7 +14,7 @@ public final class GsonUtil {
* @return Gson instance
*/
public static Gson getGson() {
return gson;
return GSON;
}
/**
@ -23,4 +25,8 @@ public final class GsonUtil {
public static GsonBuilder getGsonBuilder() {
return new GsonBuilder();
}
public static JsonParser getJsonParser() {
return JSON_PARSER;
}
}