3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-11-08 17:20:24 +01:00

Don't cycle through mappings in every connection handler

Dieser Commit ist enthalten in:
KennyTV 2019-01-19 19:19:24 +01:00
Ursprung 880df7a482
Commit 9d8a2a9680
17 geänderte Dateien mit 402 neuen und 351 gelöschten Zeilen

Datei anzeigen

@ -17,18 +17,23 @@ public abstract class AbstractFenceConnectionHandler extends ConnectionHandler {
private Map<Byte, Integer> connectedBlockStates = new HashMap<>(); private Map<Byte, Integer> connectedBlockStates = new HashMap<>();
private static final StairConnectionHandler STAIR_CONNECTION_HANDLER = new StairConnectionHandler(); private static final StairConnectionHandler STAIR_CONNECTION_HANDLER = new StairConnectionHandler();
public AbstractFenceConnectionHandler(String blockConnections, String key) { public AbstractFenceConnectionHandler(String blockConnections) {
this.blockConnections = blockConnections; this.blockConnections = blockConnections;
}
for (Map.Entry<String, Integer> blockState : ConnectionData.keyToId.entrySet()) { public ConnectionData.ConnectorInitAction getInitAction(final String key) {
if (key.equals(blockState.getKey().split("\\[")[0])) { final AbstractFenceConnectionHandler handler = this;
WrappedBlockData blockData = WrappedBlockData.fromString(blockState.getKey()); return new ConnectionData.ConnectorInitAction() {
if (blockData.hasData("waterlogged") && blockData.getValue("waterlogged").equals("true")) continue; @Override
blockStates.add(blockState.getValue()); public void check(WrappedBlockData blockData) {
ConnectionData.connectionHandlerMap.put(blockState.getValue(), this); if (key.equals(blockData.getMinecraftKey())) {
connectedBlockStates.put(getStates(blockData), blockState.getValue()); if (blockData.hasData("waterlogged") && blockData.getValue("waterlogged").equals("true")) return;
blockStates.add(blockData.getSavedBlockStateId());
ConnectionData.connectionHandlerMap.put(blockData.getSavedBlockStateId(), handler);
connectedBlockStates.put(getStates(blockData), blockData.getSavedBlockStateId());
} }
} }
};
} }
protected byte getStates(WrappedBlockData blockData) { protected byte getStates(WrappedBlockData blockData) {

Datei anzeigen

@ -17,23 +17,27 @@ public class AbstractStempConnectionHandler extends ConnectionHandler {
private Map<BlockFace, Integer> stemps = new HashMap<>(); private Map<BlockFace, Integer> stemps = new HashMap<>();
public AbstractStempConnectionHandler(String baseStateId, String blockId, String toKey) { public AbstractStempConnectionHandler(String baseStateId) {
this.baseStateId = ConnectionData.getId(baseStateId); this.baseStateId = ConnectionData.getId(baseStateId);
}
for (Map.Entry<String, Integer> entry : ConnectionData.keyToId.entrySet()) { public ConnectionData.ConnectorInitAction getInitAction(final String blockId, final String toKey) {
String key = entry.getKey().split("\\[")[0]; final AbstractStempConnectionHandler handler = this;
if (entry.getValue() == this.baseStateId || blockId.equals(key)) { return new ConnectionData.ConnectorInitAction() {
if (entry.getValue() != this.baseStateId) { @Override
this.blockId.add(entry.getValue()); public void check(WrappedBlockData blockData) {
if (blockData.getSavedBlockStateId() == baseStateId || blockId.equals(blockData.getMinecraftKey())) {
if (blockData.getSavedBlockStateId() != baseStateId) {
handler.blockId.add(blockData.getSavedBlockStateId());
} }
ConnectionData.connectionHandlerMap.put(entry.getValue(), this); ConnectionData.connectionHandlerMap.put(blockData.getSavedBlockStateId(), handler);
} }
if (key.equals(toKey)) { if (blockData.getMinecraftKey().equals(toKey)) {
WrappedBlockData data = WrappedBlockData.fromString(entry.getKey()); String facing = blockData.getValue("facing").toUpperCase();
String facing = data.getValue("facing").toUpperCase(); stemps.put(BlockFace.valueOf(facing), blockData.getSavedBlockStateId());
stemps.put(BlockFace.valueOf(facing), entry.getValue());
} }
} }
};
} }
@Override @Override

Datei anzeigen

@ -1,17 +1,22 @@
package us.myles.ViaVersion.protocols.protocol1_13to1_12_2.blockconnections; package us.myles.ViaVersion.protocols.protocol1_13to1_12_2.blockconnections;
import java.util.ArrayList;
import java.util.List;
public class BasicFenceConnectionHandler extends AbstractFenceConnectionHandler { public class BasicFenceConnectionHandler extends AbstractFenceConnectionHandler {
static void init() { static List<ConnectionData.ConnectorInitAction> init() {
new BasicFenceConnectionHandler("fenceConnections", "minecraft:oak_fence"); List<ConnectionData.ConnectorInitAction> actions = new ArrayList<>();
new BasicFenceConnectionHandler("fenceConnections", "minecraft:birch_fence"); actions.add(new BasicFenceConnectionHandler("fenceConnections").getInitAction("minecraft:oak_fence"));
new BasicFenceConnectionHandler("fenceConnections", "minecraft:jungle_fence"); actions.add(new BasicFenceConnectionHandler("fenceConnections").getInitAction("minecraft:birch_fence"));
new BasicFenceConnectionHandler("fenceConnections", "minecraft:dark_oak_fence"); actions.add(new BasicFenceConnectionHandler("fenceConnections").getInitAction("minecraft:jungle_fence"));
new BasicFenceConnectionHandler("fenceConnections", "minecraft:acacia_fence"); actions.add(new BasicFenceConnectionHandler("fenceConnections").getInitAction("minecraft:dark_oak_fence"));
new BasicFenceConnectionHandler("fenceConnections", "minecraft:spruce_fence"); actions.add(new BasicFenceConnectionHandler("fenceConnections").getInitAction("minecraft:acacia_fence"));
actions.add(new BasicFenceConnectionHandler("fenceConnections").getInitAction("minecraft:spruce_fence"));
return actions;
} }
public BasicFenceConnectionHandler(String blockConnections, String key) { public BasicFenceConnectionHandler(String blockConnections) {
super(blockConnections, key); super(blockConnections);
} }
} }

Datei anzeigen

@ -14,18 +14,19 @@ class ChestConnectionHandler extends ConnectionHandler {
private static Map<Byte, Integer> connectedStates = new HashMap<>(); private static Map<Byte, Integer> connectedStates = new HashMap<>();
private static Set<Integer> trappedChests = new HashSet<>(); private static Set<Integer> trappedChests = new HashSet<>();
static void init() { static ConnectionData.ConnectorInitAction init() {
ChestConnectionHandler connectionHandler = new ChestConnectionHandler(); final ChestConnectionHandler connectionHandler = new ChestConnectionHandler();
for (Map.Entry<String, Integer> blockState : ConnectionData.keyToId.entrySet()) { return new ConnectionData.ConnectorInitAction() {
String key = blockState.getKey().split("\\[")[0]; @Override
if (!key.equals("minecraft:chest") && !key.equals("minecraft:trapped_chest")) continue; public void check(WrappedBlockData blockData) {
WrappedBlockData blockData = WrappedBlockData.fromString(blockState.getKey()); if (!blockData.getMinecraftKey().equals("minecraft:chest") && !blockData.getMinecraftKey().equals("minecraft:trapped_chest")) return;
if (blockData.getValue("waterlogged").equals("true")) continue; if (blockData.getValue("waterlogged").equals("true")) return;
chestFacings.put(blockState.getValue(), BlockFace.valueOf(blockData.getValue("facing").toUpperCase())); chestFacings.put(blockData.getSavedBlockStateId(), BlockFace.valueOf(blockData.getValue("facing").toUpperCase()));
if (key.equalsIgnoreCase("minecraft:trapped_chest")) trappedChests.add(blockState.getValue()); if (blockData.getMinecraftKey().equalsIgnoreCase("minecraft:trapped_chest")) trappedChests.add(blockData.getSavedBlockStateId());
connectedStates.put(getStates(blockData), blockState.getValue()); connectedStates.put(getStates(blockData), blockData.getSavedBlockStateId());
ConnectionData.connectionHandlerMap.put(blockState.getValue(), connectionHandler); ConnectionData.connectionHandlerMap.put(blockData.getSavedBlockStateId(), connectionHandler);
} }
};
} }
private static Byte getStates(WrappedBlockData blockData) { private static Byte getStates(WrappedBlockData blockData) {

Datei anzeigen

@ -4,23 +4,35 @@ import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.minecraft.BlockFace; import us.myles.ViaVersion.api.minecraft.BlockFace;
import us.myles.ViaVersion.api.minecraft.Position; import us.myles.ViaVersion.api.minecraft.Position;
import java.util.ArrayList;
import java.util.List;
import java.util.Map; import java.util.Map;
public class ChorusPlantConnectionHandler extends AbstractFenceConnectionHandler { public class ChorusPlantConnectionHandler extends AbstractFenceConnectionHandler {
private int endstone; private int endstone;
static void init() { static List<ConnectionData.ConnectorInitAction> init() {
new ChorusPlantConnectionHandler("minecraft:chorus_plant"); List<ConnectionData.ConnectorInitAction> actions = new ArrayList<>(2);
ChorusPlantConnectionHandler handler = new ChorusPlantConnectionHandler();
actions.add(handler.getInitAction("minecraft:chorus_plant"));
actions.add(handler.getExtraAction());
return actions;
} }
public ChorusPlantConnectionHandler(String key) { public ChorusPlantConnectionHandler() {
super(null, key); super(null);
endstone = ConnectionData.getId("minecraft:end_stone"); endstone = ConnectionData.getId("minecraft:end_stone");
for (Map.Entry<String, Integer> entry : ConnectionData.keyToId.entrySet()) { }
if (entry.getKey().split("\\[")[0].equals("minecraft:chorus_flower")) {
getBlockStates().add(entry.getValue()); public ConnectionData.ConnectorInitAction getExtraAction() {
return new ConnectionData.ConnectorInitAction() {
@Override
public void check(WrappedBlockData blockData) {
if (blockData.getMinecraftKey().equals("minecraft:chorus_flower")) {
getBlockStates().add(blockData.getSavedBlockStateId());
} }
} }
};
} }
@Override @Override

Datei anzeigen

@ -16,11 +16,8 @@ import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.blockconnections.provi
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.blockconnections.providers.PacketBlockConnectionProvider; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.blockconnections.providers.PacketBlockConnectionProvider;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.MappingData; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.MappingData;
import java.util.HashMap; import java.util.*;
import java.util.HashSet;
import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.Set;
public class ConnectionData { public class ConnectionData {
static Map<Integer, String> idToKey = new HashMap<>(); static Map<Integer, String> idToKey = new HashMap<>();
@ -163,20 +160,27 @@ public class ConnectionData {
occludingStates.add(keyToId.get(jsonElement.getAsString())); occludingStates.add(keyToId.get(jsonElement.getAsString()));
} }
PumpkinConnectionHandler.init(); List<ConnectorInitAction> initActions = new ArrayList<>();
MelonConnectionHandler.init(); initActions.add(PumpkinConnectionHandler.init());
BasicFenceConnectionHandler.init(); initActions.add(MelonConnectionHandler.init());
NetherFenceConnectionHandler.init(); initActions.addAll(BasicFenceConnectionHandler.init());
WallConnectionHandler.init(); initActions.add(NetherFenceConnectionHandler.init());
MelonConnectionHandler.init(); initActions.addAll(WallConnectionHandler.init());
GlassConnectionHandler.init(); initActions.add(MelonConnectionHandler.init());
ChestConnectionHandler.init(); initActions.addAll(GlassConnectionHandler.init());
DoorConnectionHandler.init(); initActions.add(ChestConnectionHandler.init());
RedstoneConnectionHandler.init(); initActions.add(DoorConnectionHandler.init());
StairConnectionHandler.init(); initActions.add(RedstoneConnectionHandler.init());
FlowerConnectionHandler.init(); initActions.add(StairConnectionHandler.init());
ChorusPlantConnectionHandler.init(); initActions.add(FlowerConnectionHandler.init());
TripwireConnectionHandler.init(); initActions.addAll(ChorusPlantConnectionHandler.init());
initActions.add(TripwireConnectionHandler.init());
for (Entry<String, Integer> entry : keyToId.entrySet()) {
WrappedBlockData wrappedBlockData = WrappedBlockData.fromString(entry.getKey());
for (ConnectorInitAction action : initActions) {
action.check(wrappedBlockData);
}
}
if (Via.getConfig().getBlockConnectionMethod().equalsIgnoreCase("packet")) { if (Via.getConfig().getBlockConnectionMethod().equalsIgnoreCase("packet")) {
Via.getManager().getProviders().register(BlockConnectionProvider.class, new PacketBlockConnectionProvider()); Via.getManager().getProviders().register(BlockConnectionProvider.class, new PacketBlockConnectionProvider());
@ -207,4 +211,9 @@ public class ConnectionData {
public static String getKey(int id) { public static String getKey(int id) {
return idToKey.get(id); return idToKey.get(id);
} }
interface ConnectorInitAction {
void check(WrappedBlockData blockData);
}
} }

Datei anzeigen

@ -16,8 +16,8 @@ public class DoorConnectionHandler extends ConnectionHandler {
private static Map<Integer, DoorData> doorDataMap = new HashMap<>(); private static Map<Integer, DoorData> doorDataMap = new HashMap<>();
private static Map<Short, Integer> connectedStates = new HashMap<>(); private static Map<Short, Integer> connectedStates = new HashMap<>();
static void init() { static ConnectionData.ConnectorInitAction init() {
List<String> baseDoors = new LinkedList<>(); final List<String> baseDoors = new LinkedList<>();
baseDoors.add("minecraft:oak_door"); baseDoors.add("minecraft:oak_door");
baseDoors.add("minecraft:birch_door"); baseDoors.add("minecraft:birch_door");
baseDoors.add("minecraft:jungle_door"); baseDoors.add("minecraft:jungle_door");
@ -26,14 +26,14 @@ public class DoorConnectionHandler extends ConnectionHandler {
baseDoors.add("minecraft:spruce_door"); baseDoors.add("minecraft:spruce_door");
baseDoors.add("minecraft:iron_door"); baseDoors.add("minecraft:iron_door");
DoorConnectionHandler connectionHandler = new DoorConnectionHandler(); final DoorConnectionHandler connectionHandler = new DoorConnectionHandler();
for (Map.Entry<String, Integer> blockState : ConnectionData.keyToId.entrySet()) { return new ConnectionData.ConnectorInitAction() {
String key = blockState.getKey().split("\\[")[0]; @Override
int type = baseDoors.indexOf(key); public void check(WrappedBlockData blockData) {
if (type == -1) continue; int type = baseDoors.indexOf(blockData.getMinecraftKey());
if (type == -1) return;
WrappedBlockData blockData = WrappedBlockData.fromString(blockState.getKey()); int id = blockData.getSavedBlockStateId();
int id = blockState.getValue();
DoorData doorData = new DoorData( DoorData doorData = new DoorData(
blockData.getValue("half").equals("lower"), blockData.getValue("half").equals("lower"),
@ -50,6 +50,7 @@ public class DoorConnectionHandler extends ConnectionHandler {
ConnectionData.connectionHandlerMap.put(id, connectionHandler); ConnectionData.connectionHandlerMap.put(id, connectionHandler);
} }
};
} }
private static short getStates(DoorData doorData) { private static short getStates(DoorData doorData) {

Datei anzeigen

@ -14,8 +14,8 @@ import java.util.Set;
public class FlowerConnectionHandler extends ConnectionHandler { public class FlowerConnectionHandler extends ConnectionHandler {
private static Map<Integer, Integer> flowers = new HashMap<>(); private static Map<Integer, Integer> flowers = new HashMap<>();
static void init() { static ConnectionData.ConnectorInitAction init() {
Set<String> baseFlower = new HashSet<>(); final Set<String> baseFlower = new HashSet<>();
baseFlower.add("minecraft:rose_bush"); baseFlower.add("minecraft:rose_bush");
baseFlower.add("minecraft:sunflower"); baseFlower.add("minecraft:sunflower");
baseFlower.add("minecraft:peony"); baseFlower.add("minecraft:peony");
@ -23,17 +23,19 @@ public class FlowerConnectionHandler extends ConnectionHandler {
baseFlower.add("minecraft:large_fern"); baseFlower.add("minecraft:large_fern");
baseFlower.add("minecraft:lilac"); baseFlower.add("minecraft:lilac");
FlowerConnectionHandler handler = new FlowerConnectionHandler(); final FlowerConnectionHandler handler = new FlowerConnectionHandler();
for (Map.Entry<String, Integer> blockState : ConnectionData.keyToId.entrySet()) { return new ConnectionData.ConnectorInitAction() {
WrappedBlockData data = WrappedBlockData.fromString(blockState.getKey()); @Override
if (baseFlower.contains(data.getMinecraftKey())) { public void check(WrappedBlockData blockData) {
ConnectionData.connectionHandlerMap.put(blockState.getValue(), handler); if (baseFlower.contains(blockData.getMinecraftKey())) {
if (data.getValue("half").equals("lower")) { ConnectionData.connectionHandlerMap.put(blockData.getSavedBlockStateId(), handler);
data.set("half", "upper"); if (blockData.getValue("half").equals("lower")) {
flowers.put(blockState.getValue(), data.getBlockStateId()); blockData.set("half", "upper");
flowers.put(blockData.getSavedBlockStateId(), blockData.getBlockStateId());
} }
} }
} }
};
} }
@Override @Override

Datei anzeigen

@ -4,31 +4,36 @@ import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.minecraft.Position; import us.myles.ViaVersion.api.minecraft.Position;
import us.myles.ViaVersion.protocols.base.ProtocolInfo; import us.myles.ViaVersion.protocols.base.ProtocolInfo;
import java.util.ArrayList;
import java.util.List;
public class GlassConnectionHandler extends AbstractFenceConnectionHandler { public class GlassConnectionHandler extends AbstractFenceConnectionHandler {
static void init() { static List<ConnectionData.ConnectorInitAction> init() {
new GlassConnectionHandler("paneConnections", "minecraft:white_stained_glass_pane"); List<ConnectionData.ConnectorInitAction> actions = new ArrayList<>(18);
new GlassConnectionHandler("paneConnections", "minecraft:orange_stained_glass_pane"); actions.add(new GlassConnectionHandler("paneConnections").getInitAction("minecraft:white_stained_glass_pane"));
new GlassConnectionHandler("paneConnections", "minecraft:magenta_stained_glass_pane"); actions.add(new GlassConnectionHandler("paneConnections").getInitAction("minecraft:orange_stained_glass_pane"));
new GlassConnectionHandler("paneConnections", "minecraft:light_blue_stained_glass_pane"); actions.add(new GlassConnectionHandler("paneConnections").getInitAction("minecraft:magenta_stained_glass_pane"));
new GlassConnectionHandler("paneConnections", "minecraft:yellow_stained_glass_pane"); actions.add(new GlassConnectionHandler("paneConnections").getInitAction("minecraft:light_blue_stained_glass_pane"));
new GlassConnectionHandler("paneConnections", "minecraft:lime_stained_glass_pane"); actions.add(new GlassConnectionHandler("paneConnections").getInitAction("minecraft:yellow_stained_glass_pane"));
new GlassConnectionHandler("paneConnections", "minecraft:pink_stained_glass_pane"); actions.add(new GlassConnectionHandler("paneConnections").getInitAction("minecraft:lime_stained_glass_pane"));
new GlassConnectionHandler("paneConnections", "minecraft:gray_stained_glass_pane"); actions.add(new GlassConnectionHandler("paneConnections").getInitAction("minecraft:pink_stained_glass_pane"));
new GlassConnectionHandler("paneConnections", "minecraft:light_gray_stained_glass_pane"); actions.add(new GlassConnectionHandler("paneConnections").getInitAction("minecraft:gray_stained_glass_pane"));
new GlassConnectionHandler("paneConnections", "minecraft:cyan_stained_glass_pane"); actions.add(new GlassConnectionHandler("paneConnections").getInitAction("minecraft:light_gray_stained_glass_pane"));
new GlassConnectionHandler("paneConnections", "minecraft:purple_stained_glass_pane"); actions.add(new GlassConnectionHandler("paneConnections").getInitAction("minecraft:cyan_stained_glass_pane"));
new GlassConnectionHandler("paneConnections", "minecraft:blue_stained_glass_pane"); actions.add(new GlassConnectionHandler("paneConnections").getInitAction("minecraft:purple_stained_glass_pane"));
new GlassConnectionHandler("paneConnections", "minecraft:brown_stained_glass_pane"); actions.add(new GlassConnectionHandler("paneConnections").getInitAction("minecraft:blue_stained_glass_pane"));
new GlassConnectionHandler("paneConnections", "minecraft:green_stained_glass_pane"); actions.add(new GlassConnectionHandler("paneConnections").getInitAction("minecraft:brown_stained_glass_pane"));
new GlassConnectionHandler("paneConnections", "minecraft:red_stained_glass_pane"); actions.add(new GlassConnectionHandler("paneConnections").getInitAction("minecraft:green_stained_glass_pane"));
new GlassConnectionHandler("paneConnections", "minecraft:black_stained_glass_pane"); actions.add(new GlassConnectionHandler("paneConnections").getInitAction("minecraft:red_stained_glass_pane"));
new GlassConnectionHandler("paneConnections", "minecraft:glass_pane"); actions.add(new GlassConnectionHandler("paneConnections").getInitAction("minecraft:black_stained_glass_pane"));
new GlassConnectionHandler("paneConnections", "minecraft:iron_bars"); actions.add(new GlassConnectionHandler("paneConnections").getInitAction("minecraft:glass_pane"));
actions.add(new GlassConnectionHandler("paneConnections").getInitAction("minecraft:iron_bars"));
return actions;
} }
public GlassConnectionHandler(String blockConnections, String key) { public GlassConnectionHandler(String blockConnections) {
super(blockConnections, key); super(blockConnections);
} }
@Override @Override

Datei anzeigen

@ -2,11 +2,11 @@ package us.myles.ViaVersion.protocols.protocol1_13to1_12_2.blockconnections;
public class MelonConnectionHandler extends AbstractStempConnectionHandler { public class MelonConnectionHandler extends AbstractStempConnectionHandler {
public MelonConnectionHandler(String baseStateId, String blockId, String toKey) { public MelonConnectionHandler(String baseStateId) {
super(baseStateId, blockId, toKey); super(baseStateId);
} }
static void init() { static ConnectionData.ConnectorInitAction init() {
new MelonConnectionHandler("minecraft:melon_stem[age=7]", "minecraft:melon", "minecraft:attached_melon_stem"); return new MelonConnectionHandler("minecraft:melon_stem[age=7]").getInitAction("minecraft:melon", "minecraft:attached_melon_stem");
} }
} }

Datei anzeigen

@ -2,11 +2,11 @@ package us.myles.ViaVersion.protocols.protocol1_13to1_12_2.blockconnections;
public class NetherFenceConnectionHandler extends AbstractFenceConnectionHandler { public class NetherFenceConnectionHandler extends AbstractFenceConnectionHandler {
static void init() { static ConnectionData.ConnectorInitAction init() {
new NetherFenceConnectionHandler("netherFenceConnections", "minecraft:nether_brick_fence"); return new NetherFenceConnectionHandler("netherFenceConnections").getInitAction("minecraft:nether_brick_fence");
} }
public NetherFenceConnectionHandler(String blockConnections, String key) { public NetherFenceConnectionHandler(String blockConnections) {
super(blockConnections, key); super(blockConnections);
} }
} }

Datei anzeigen

@ -2,11 +2,11 @@ package us.myles.ViaVersion.protocols.protocol1_13to1_12_2.blockconnections;
public class PumpkinConnectionHandler extends AbstractStempConnectionHandler { public class PumpkinConnectionHandler extends AbstractStempConnectionHandler {
static void init() { static ConnectionData.ConnectorInitAction init() {
new PumpkinConnectionHandler("minecraft:pumpkin_stem[age=7]", "minecraft:carved_pumpkin", "minecraft:attached_pumpkin_stem"); return new PumpkinConnectionHandler("minecraft:pumpkin_stem[age=7]").getInitAction("minecraft:carved_pumpkin", "minecraft:attached_pumpkin_stem");
} }
public PumpkinConnectionHandler(String baseStateId, String blockId, String toKey) { public PumpkinConnectionHandler(String baseStateId) {
super(baseStateId, blockId, toKey); super(baseStateId);
} }
} }

Datei anzeigen

@ -14,18 +14,19 @@ public class RedstoneConnectionHandler extends ConnectionHandler {
private static Map<Short, Integer> connectedBlockStates = new HashMap<>(); private static Map<Short, Integer> connectedBlockStates = new HashMap<>();
private static Map<Integer, Integer> powerMappings = new HashMap<>(); private static Map<Integer, Integer> powerMappings = new HashMap<>();
static void init() { static ConnectionData.ConnectorInitAction init() {
RedstoneConnectionHandler connectionHandler = new RedstoneConnectionHandler(); final RedstoneConnectionHandler connectionHandler = new RedstoneConnectionHandler();
String redstoneKey = "minecraft:redstone_wire"; final String redstoneKey = "minecraft:redstone_wire";
for (Map.Entry<String, Integer> blockState : ConnectionData.keyToId.entrySet()) { return new ConnectionData.ConnectorInitAction() {
String key = blockState.getKey().split("\\[")[0]; @Override
if (!redstoneKey.equals(key)) continue; public void check(WrappedBlockData blockData) {
redstone.add(blockState.getValue()); if (!redstoneKey.equals(blockData.getMinecraftKey())) return;
ConnectionData.connectionHandlerMap.put(blockState.getValue(), connectionHandler); redstone.add(blockData.getSavedBlockStateId());
WrappedBlockData blockData = WrappedBlockData.fromStateId(blockState.getValue()); ConnectionData.connectionHandlerMap.put(blockData.getSavedBlockStateId(), connectionHandler);
connectedBlockStates.put(getStates(blockData), blockData.getBlockStateId()); connectedBlockStates.put(getStates(blockData), blockData.getSavedBlockStateId());
powerMappings.put(blockData.getBlockStateId(), Integer.valueOf(blockData.getValue("power"))); powerMappings.put(blockData.getSavedBlockStateId(), Integer.valueOf(blockData.getValue("power")));
} }
};
} }
private static short getStates(WrappedBlockData data) { private static short getStates(WrappedBlockData data) {

Datei anzeigen

@ -16,8 +16,8 @@ public class StairConnectionHandler extends ConnectionHandler {
private static Map<Integer, StairData> stairDataMap = new HashMap<>(); private static Map<Integer, StairData> stairDataMap = new HashMap<>();
private static Map<Short, Integer> connectedBlocks = new HashMap<>(); private static Map<Short, Integer> connectedBlocks = new HashMap<>();
static void init() { static ConnectionData.ConnectorInitAction init() {
List<String> baseStairs = new LinkedList<>(); final List<String> baseStairs = new LinkedList<>();
baseStairs.add("minecraft:oak_stairs"); baseStairs.add("minecraft:oak_stairs");
baseStairs.add("minecraft:cobblestone_stairs"); baseStairs.add("minecraft:cobblestone_stairs");
baseStairs.add("minecraft:brick_stairs"); baseStairs.add("minecraft:brick_stairs");
@ -36,14 +36,14 @@ public class StairConnectionHandler extends ConnectionHandler {
baseStairs.add("minecraft:prismarine_brick_stairs"); baseStairs.add("minecraft:prismarine_brick_stairs");
baseStairs.add("minecraft:dark_prismarine_stairs"); baseStairs.add("minecraft:dark_prismarine_stairs");
StairConnectionHandler connectionHandler = new StairConnectionHandler(); final StairConnectionHandler connectionHandler = new StairConnectionHandler();
for (Map.Entry<String, Integer> blockState : ConnectionData.keyToId.entrySet()) { return new ConnectionData.ConnectorInitAction() {
String key = blockState.getKey().split("\\[")[0]; @Override
int type = baseStairs.indexOf(key); public void check(WrappedBlockData blockData) {
if (type == -1) continue; int type = baseStairs.indexOf(blockData.getMinecraftKey());
if (type == -1) return;
WrappedBlockData blockData = WrappedBlockData.fromString(blockState.getKey()); if (blockData.getValue("waterlogged").equals("true")) return;
if (blockData.getValue("waterlogged").equals("true")) continue;
byte shape; byte shape;
switch (blockData.getValue("shape")) { switch (blockData.getValue("shape")) {
@ -52,7 +52,7 @@ public class StairConnectionHandler extends ConnectionHandler {
case "inner_right": shape = 2; break; case "inner_right": shape = 2; break;
case "outer_left": shape = 3; break; case "outer_left": shape = 3; break;
case "outer_right": shape = 4; break; case "outer_right": shape = 4; break;
default: continue; default: return;
} }
StairData stairData = new StairData( StairData stairData = new StairData(
@ -61,11 +61,12 @@ public class StairConnectionHandler extends ConnectionHandler {
BlockFace.valueOf(blockData.getValue("facing").toUpperCase()) BlockFace.valueOf(blockData.getValue("facing").toUpperCase())
); );
stairDataMap.put(blockState.getValue(), stairData); stairDataMap.put(blockData.getSavedBlockStateId(), stairData);
connectedBlocks.put(getStates(stairData), blockState.getValue()); connectedBlocks.put(getStates(stairData), blockData.getSavedBlockStateId());
ConnectionData.connectionHandlerMap.put(blockState.getValue(), connectionHandler); ConnectionData.connectionHandlerMap.put(blockData.getSavedBlockStateId(), connectionHandler);
} }
};
} }
private static short getStates(StairData stairData) { private static short getStates(StairData stairData) {
@ -98,15 +99,15 @@ public class StairConnectionHandler extends ConnectionHandler {
StairData relativeStair = stairDataMap.get(getBlockData(user, position.getRelative(facing))); StairData relativeStair = stairDataMap.get(getBlockData(user, position.getRelative(facing)));
if (relativeStair != null && relativeStair.isBottom() == stair.isBottom()) { if (relativeStair != null && relativeStair.isBottom() == stair.isBottom()) {
BlockFace facing2 = relativeStair.getFacing(); BlockFace facing2 = relativeStair.getFacing();
if (facing.getAxis() != facing2.getAxis() && checkOpposite(user, stair, position, facing2.opposite())){ if (facing.getAxis() != facing2.getAxis() && checkOpposite(user, stair, position, facing2.opposite())) {
return facing2 == rotateAntiClockwise(facing) ? 3 : 4; // outer_left : outer_right return facing2 == rotateAntiClockwise(facing) ? 3 : 4; // outer_left : outer_right
} }
} }
relativeStair = stairDataMap.get(getBlockData(user, position.getRelative(facing.opposite()))); relativeStair = stairDataMap.get(getBlockData(user, position.getRelative(facing.opposite())));
if(relativeStair != null && relativeStair.isBottom() == stair.isBottom()) { if (relativeStair != null && relativeStair.isBottom() == stair.isBottom()) {
BlockFace facing2 = relativeStair.getFacing(); BlockFace facing2 = relativeStair.getFacing();
if (facing.getAxis() != facing2.getAxis() && checkOpposite(user, stair, position, facing2)){ if (facing.getAxis() != facing2.getAxis() && checkOpposite(user, stair, position, facing2)) {
return facing2 == rotateAntiClockwise(facing) ? 1 : 2; // inner_left : inner_right return facing2 == rotateAntiClockwise(facing) ? 1 : 2; // inner_left : inner_right
} }
} }

Datei anzeigen

@ -15,29 +15,27 @@ public class TripwireConnectionHandler extends ConnectionHandler {
private static Map<Byte, Integer> connectedBlocks = new HashMap<>(); private static Map<Byte, Integer> connectedBlocks = new HashMap<>();
private static Map<Integer, BlockFace> tripwireHooks = new HashMap<>(); private static Map<Integer, BlockFace> tripwireHooks = new HashMap<>();
static void init() { static ConnectionData.ConnectorInitAction init() {
TripwireConnectionHandler connectionHandler = new TripwireConnectionHandler(); final TripwireConnectionHandler connectionHandler = new TripwireConnectionHandler();
for (Map.Entry<String, Integer> blockState : ConnectionData.keyToId.entrySet()) { return new ConnectionData.ConnectorInitAction() {
String key = blockState.getKey().split("\\[")[0]; @Override
public void check(WrappedBlockData blockData) {
if (key.equals("minecraft:tripwire_hook")) { if (blockData.getMinecraftKey().equals("minecraft:tripwire_hook")) {
WrappedBlockData blockData = WrappedBlockData.fromString(blockState.getKey()); tripwireHooks.put(blockData.getSavedBlockStateId(), BlockFace.valueOf(blockData.getValue("facing").toUpperCase()));
tripwireHooks.put(blockState.getValue(), BlockFace.valueOf(blockData.getValue("facing").toUpperCase())); } else if (blockData.getMinecraftKey().equals("minecraft:tripwire")) {
} else if (key.equals("minecraft:tripwire")) {
WrappedBlockData blockData = WrappedBlockData.fromString(blockState.getKey());
TripwireData tripwireData = new TripwireData( TripwireData tripwireData = new TripwireData(
blockData.getValue("attached").equals("true"), blockData.getValue("attached").equals("true"),
blockData.getValue("disarmed").equals("true"), blockData.getValue("disarmed").equals("true"),
blockData.getValue("powered").equals("true") blockData.getValue("powered").equals("true")
); );
tripwireDataMap.put(blockState.getValue(), tripwireData); tripwireDataMap.put(blockData.getSavedBlockStateId(), tripwireData);
connectedBlocks.put(getStates(blockData), blockState.getValue()); connectedBlocks.put(getStates(blockData), blockData.getSavedBlockStateId());
ConnectionData.connectionHandlerMap.put(blockState.getValue(), connectionHandler); ConnectionData.connectionHandlerMap.put(blockData.getSavedBlockStateId(), connectionHandler);
} }
} }
};
} }
private static byte getStates(WrappedBlockData blockData) { private static byte getStates(WrappedBlockData blockData) {

Datei anzeigen

@ -4,18 +4,23 @@ import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.minecraft.BlockFace; import us.myles.ViaVersion.api.minecraft.BlockFace;
import us.myles.ViaVersion.api.minecraft.Position; import us.myles.ViaVersion.api.minecraft.Position;
import java.util.ArrayList;
import java.util.List;
public class WallConnectionHandler extends AbstractFenceConnectionHandler { public class WallConnectionHandler extends AbstractFenceConnectionHandler {
private static final BlockFace[] BLOCK_FACES = {BlockFace.EAST, BlockFace.NORTH, BlockFace.SOUTH, BlockFace.WEST}; private static final BlockFace[] BLOCK_FACES = {BlockFace.EAST, BlockFace.NORTH, BlockFace.SOUTH, BlockFace.WEST};
private static final int[] OPPOSITES = {3, 2, 1, 0}; private static final int[] OPPOSITES = {3, 2, 1, 0};
static void init() { static List<ConnectionData.ConnectorInitAction> init() {
new WallConnectionHandler("cobbleWallConnections", "minecraft:cobblestone_wall"); List<ConnectionData.ConnectorInitAction> actions = new ArrayList<>(2);
new WallConnectionHandler("cobbleWallConnections", "minecraft:mossy_cobblestone_wall"); actions.add(new WallConnectionHandler("cobbleWallConnections").getInitAction("minecraft:cobblestone_wall"));
actions.add(new WallConnectionHandler("cobbleWallConnections").getInitAction("minecraft:mossy_cobblestone_wall"));
return actions;
} }
public WallConnectionHandler(String blockConnections, String key) { public WallConnectionHandler(String blockConnections) {
super(blockConnections, key); super(blockConnections);
} }
@Override @Override

Datei anzeigen

@ -9,6 +9,8 @@ import java.util.Map.Entry;
public class WrappedBlockData { public class WrappedBlockData {
@Getter @Getter
private String minecraftKey; private String minecraftKey;
@Getter
private int savedBlockStateId;
private LinkedHashMap<String, String> blockData = new LinkedHashMap<>(); private LinkedHashMap<String, String> blockData = new LinkedHashMap<>();
public static WrappedBlockData fromString(String s) { public static WrappedBlockData fromString(String s) {
@ -36,8 +38,8 @@ public class WrappedBlockData {
return fromString("minecraft:air"); return fromString("minecraft:air");
} }
private WrappedBlockData(String key) { private WrappedBlockData(String minecraftKey) {
minecraftKey = key; this.minecraftKey = minecraftKey;
} }
public String toString() { public String toString() {