Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-12-27 08:30:09 +01:00
Minor blockconnection cleanup, reduce map lookups
Dieser Commit ist enthalten in:
Ursprung
6eeecb271b
Commit
7f6c429a55
@ -24,6 +24,7 @@ import us.myles.ViaVersion.bukkit.providers.BukkitViaBulkChunkTranslator;
|
|||||||
import us.myles.ViaVersion.bukkit.providers.BukkitViaMovementTransmitter;
|
import us.myles.ViaVersion.bukkit.providers.BukkitViaMovementTransmitter;
|
||||||
import us.myles.ViaVersion.protocols.base.ProtocolInfo;
|
import us.myles.ViaVersion.protocols.base.ProtocolInfo;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_12to1_11_1.providers.InventoryQuickMoveProvider;
|
import us.myles.ViaVersion.protocols.protocol1_12to1_11_1.providers.InventoryQuickMoveProvider;
|
||||||
|
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.blockconnections.ConnectionData;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.blockconnections.providers.BlockConnectionProvider;
|
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.blockconnections.providers.BlockConnectionProvider;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.BulkChunkTranslatorProvider;
|
import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.BulkChunkTranslatorProvider;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.HandItemProvider;
|
import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.HandItemProvider;
|
||||||
@ -143,7 +144,9 @@ public class BukkitViaLoader implements ViaPlatformLoader {
|
|||||||
}
|
}
|
||||||
if (ProtocolRegistry.SERVER_PROTOCOL < ProtocolVersion.v1_13.getId()) {
|
if (ProtocolRegistry.SERVER_PROTOCOL < ProtocolVersion.v1_13.getId()) {
|
||||||
if (Via.getConfig().getBlockConnectionMethod().equalsIgnoreCase("world")) {
|
if (Via.getConfig().getBlockConnectionMethod().equalsIgnoreCase("world")) {
|
||||||
Via.getManager().getProviders().use(BlockConnectionProvider.class, new BukkitBlockConnectionProvider());
|
BukkitBlockConnectionProvider blockConnectionProvider = new BukkitBlockConnectionProvider();
|
||||||
|
Via.getManager().getProviders().use(BlockConnectionProvider.class, blockConnectionProvider);
|
||||||
|
ConnectionData.blockConnectionProvider = blockConnectionProvider;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package us.myles.ViaVersion.protocols.protocol1_13to1_12_2.blockconnections;
|
package us.myles.ViaVersion.protocols.protocol1_13to1_12_2.blockconnections;
|
||||||
|
|
||||||
import lombok.Getter;
|
|
||||||
import us.myles.ViaVersion.api.data.UserConnection;
|
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;
|
||||||
@ -13,28 +12,24 @@ import java.util.Map;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public abstract class AbstractFenceConnectionHandler extends ConnectionHandler {
|
public abstract class AbstractFenceConnectionHandler extends ConnectionHandler {
|
||||||
private final String blockConnections;
|
|
||||||
@Getter
|
|
||||||
private Set<Integer> blockStates = new HashSet<>();
|
|
||||||
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();
|
||||||
|
private final String blockConnections;
|
||||||
|
private final Set<Integer> blockStates = new HashSet<>();
|
||||||
|
private final Map<Byte, Integer> connectedBlockStates = new HashMap<>();
|
||||||
|
|
||||||
public AbstractFenceConnectionHandler(String blockConnections) {
|
protected AbstractFenceConnectionHandler(String blockConnections) {
|
||||||
this.blockConnections = blockConnections;
|
this.blockConnections = blockConnections;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConnectionData.ConnectorInitAction getInitAction(final String key) {
|
public ConnectionData.ConnectorInitAction getInitAction(final String key) {
|
||||||
final AbstractFenceConnectionHandler handler = this;
|
final AbstractFenceConnectionHandler handler = this;
|
||||||
return new ConnectionData.ConnectorInitAction() {
|
return blockData -> {
|
||||||
@Override
|
|
||||||
public void check(WrappedBlockData blockData) {
|
|
||||||
if (key.equals(blockData.getMinecraftKey())) {
|
if (key.equals(blockData.getMinecraftKey())) {
|
||||||
if (blockData.hasData("waterlogged") && blockData.getValue("waterlogged").equals("true")) return;
|
if (blockData.hasData("waterlogged") && blockData.getValue("waterlogged").equals("true")) return;
|
||||||
blockStates.add(blockData.getSavedBlockStateId());
|
blockStates.add(blockData.getSavedBlockStateId());
|
||||||
ConnectionData.connectionHandlerMap.put(blockData.getSavedBlockStateId(), handler);
|
ConnectionData.connectionHandlerMap.put(blockData.getSavedBlockStateId(), handler);
|
||||||
connectedBlockStates.put(getStates(blockData), blockData.getSavedBlockStateId());
|
connectedBlockStates.put(getStates(blockData), blockData.getSavedBlockStateId());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -69,8 +64,14 @@ public abstract class AbstractFenceConnectionHandler extends ConnectionHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected boolean connects(BlockFace side, int blockState, boolean pre1_12) {
|
protected boolean connects(BlockFace side, int blockState, boolean pre1_12) {
|
||||||
return blockStates.contains(blockState) || blockConnections != null
|
if (blockStates.contains(blockState)) return true;
|
||||||
&& ConnectionData.blockConnectionData.containsKey(blockState)
|
if (blockConnections == null) return false;
|
||||||
&& ConnectionData.blockConnectionData.get(blockState).connectsTo(blockConnections, side.opposite(), pre1_12);
|
|
||||||
|
BlockData blockData = ConnectionData.blockConnectionData.get(blockState);
|
||||||
|
return blockData != null && blockData.connectsTo(blockConnections, side.opposite(), pre1_12);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Set<Integer> getBlockStates() {
|
||||||
|
return blockStates;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,29 +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.HashMap;
|
import java.util.*;
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Locale;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
public class AbstractStempConnectionHandler extends ConnectionHandler {
|
public abstract class AbstractStempConnectionHandler extends ConnectionHandler {
|
||||||
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 int baseStateId;
|
private final int baseStateId;
|
||||||
private Set<Integer> blockId = new HashSet<>();
|
private final Set<Integer> blockId = new HashSet<>();
|
||||||
|
|
||||||
private Map<BlockFace, Integer> stemps = new HashMap<>();
|
private final Map<BlockFace, Integer> stemps = new HashMap<>();
|
||||||
|
|
||||||
public AbstractStempConnectionHandler(String baseStateId) {
|
protected AbstractStempConnectionHandler(String baseStateId) {
|
||||||
this.baseStateId = ConnectionData.getId(baseStateId);
|
this.baseStateId = ConnectionData.getId(baseStateId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConnectionData.ConnectorInitAction getInitAction(final String blockId, final String toKey) {
|
public ConnectionData.ConnectorInitAction getInitAction(final String blockId, final String toKey) {
|
||||||
final AbstractStempConnectionHandler handler = this;
|
final AbstractStempConnectionHandler handler = this;
|
||||||
return new ConnectionData.ConnectorInitAction() {
|
return blockData -> {
|
||||||
@Override
|
|
||||||
public void check(WrappedBlockData blockData) {
|
|
||||||
if (blockData.getSavedBlockStateId() == baseStateId || blockId.equals(blockData.getMinecraftKey())) {
|
if (blockData.getSavedBlockStateId() == baseStateId || blockId.equals(blockData.getMinecraftKey())) {
|
||||||
if (blockData.getSavedBlockStateId() != baseStateId) {
|
if (blockData.getSavedBlockStateId() != baseStateId) {
|
||||||
handler.blockId.add(blockData.getSavedBlockStateId());
|
handler.blockId.add(blockData.getSavedBlockStateId());
|
||||||
@ -37,7 +31,6 @@ public class AbstractStempConnectionHandler extends ConnectionHandler {
|
|||||||
String facing = blockData.getValue("facing").toUpperCase(Locale.ROOT);
|
String facing = blockData.getValue("facing").toUpperCase(Locale.ROOT);
|
||||||
stemps.put(BlockFace.valueOf(facing), blockData.getSavedBlockStateId());
|
stemps.put(BlockFace.valueOf(facing), blockData.getSavedBlockStateId());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@ import java.util.HashMap;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class BlockData {
|
public class BlockData {
|
||||||
private Map<String, boolean[]> connectData = new HashMap<>();
|
private final Map<String, boolean[]> connectData = new HashMap<>();
|
||||||
|
|
||||||
public void put(String key, boolean[] booleans) {
|
public void put(String key, boolean[] booleans) {
|
||||||
connectData.put(key, booleans);
|
connectData.put(key, booleans);
|
||||||
|
@ -4,31 +4,25 @@ 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.HashMap;
|
import java.util.*;
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Locale;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
class ChestConnectionHandler extends ConnectionHandler {
|
class ChestConnectionHandler extends ConnectionHandler {
|
||||||
private static Map<Integer, BlockFace> chestFacings = new HashMap<>();
|
private static final Map<Integer, BlockFace> chestFacings = new HashMap<>();
|
||||||
private static Map<Byte, Integer> connectedStates = new HashMap<>();
|
private static final Map<Byte, Integer> connectedStates = new HashMap<>();
|
||||||
private static Set<Integer> trappedChests = new HashSet<>();
|
private static final Set<Integer> trappedChests = new HashSet<>();
|
||||||
|
|
||||||
static ConnectionData.ConnectorInitAction init() {
|
static ConnectionData.ConnectorInitAction init() {
|
||||||
final ChestConnectionHandler connectionHandler = new ChestConnectionHandler();
|
final ChestConnectionHandler connectionHandler = new ChestConnectionHandler();
|
||||||
return new ConnectionData.ConnectorInitAction() {
|
return blockData -> {
|
||||||
@Override
|
|
||||||
public void check(WrappedBlockData blockData) {
|
|
||||||
if (!blockData.getMinecraftKey().equals("minecraft:chest") && !blockData.getMinecraftKey().equals("minecraft:trapped_chest"))
|
if (!blockData.getMinecraftKey().equals("minecraft:chest") && !blockData.getMinecraftKey().equals("minecraft:trapped_chest"))
|
||||||
return;
|
return;
|
||||||
if (blockData.getValue("waterlogged").equals("true")) return;
|
if (blockData.getValue("waterlogged").equals("true")) return;
|
||||||
chestFacings.put(blockData.getSavedBlockStateId(), BlockFace.valueOf(blockData.getValue("facing").toUpperCase(Locale.ROOT)));
|
chestFacings.put(blockData.getSavedBlockStateId(), BlockFace.valueOf(blockData.getValue("facing").toUpperCase(Locale.ROOT)));
|
||||||
if (blockData.getMinecraftKey().equalsIgnoreCase("minecraft:trapped_chest"))
|
if (blockData.getMinecraftKey().equalsIgnoreCase("minecraft:trapped_chest")) {
|
||||||
trappedChests.add(blockData.getSavedBlockStateId());
|
trappedChests.add(blockData.getSavedBlockStateId());
|
||||||
|
}
|
||||||
connectedStates.put(getStates(blockData), blockData.getSavedBlockStateId());
|
connectedStates.put(getStates(blockData), blockData.getSavedBlockStateId());
|
||||||
ConnectionData.connectionHandlerMap.put(blockData.getSavedBlockStateId(), connectionHandler);
|
ConnectionData.connectionHandlerMap.put(blockData.getSavedBlockStateId(), connectionHandler);
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,14 +3,12 @@ package us.myles.ViaVersion.protocols.protocol1_13to1_12_2.blockconnections;
|
|||||||
import us.myles.ViaVersion.api.data.UserConnection;
|
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 us.myles.ViaVersion.api.protocol.ProtocolVersion;
|
|
||||||
import us.myles.ViaVersion.protocols.base.ProtocolInfo;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class ChorusPlantConnectionHandler extends AbstractFenceConnectionHandler {
|
public class ChorusPlantConnectionHandler extends AbstractFenceConnectionHandler {
|
||||||
private int endstone;
|
private final int endstone;
|
||||||
|
|
||||||
static List<ConnectionData.ConnectorInitAction> init() {
|
static List<ConnectionData.ConnectorInitAction> init() {
|
||||||
List<ConnectionData.ConnectorInitAction> actions = new ArrayList<>(2);
|
List<ConnectionData.ConnectorInitAction> actions = new ArrayList<>(2);
|
||||||
@ -26,13 +24,10 @@ public class ChorusPlantConnectionHandler extends AbstractFenceConnectionHandler
|
|||||||
}
|
}
|
||||||
|
|
||||||
public ConnectionData.ConnectorInitAction getExtraAction() {
|
public ConnectionData.ConnectorInitAction getExtraAction() {
|
||||||
return new ConnectionData.ConnectorInitAction() {
|
return blockData -> {
|
||||||
@Override
|
|
||||||
public void check(WrappedBlockData blockData) {
|
|
||||||
if (blockData.getMinecraftKey().equals("minecraft:chorus_flower")) {
|
if (blockData.getMinecraftKey().equals("minecraft:chorus_flower")) {
|
||||||
getBlockStates().add(blockData.getSavedBlockStateId());
|
getBlockStates().add(blockData.getSavedBlockStateId());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,6 +21,8 @@ import java.util.*;
|
|||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
public class ConnectionData {
|
public class ConnectionData {
|
||||||
|
private static final BlockChangeRecord[] A = new BlockChangeRecord[0];
|
||||||
|
public static BlockConnectionProvider blockConnectionProvider;
|
||||||
static Map<Integer, String> idToKey = new HashMap<>();
|
static Map<Integer, String> idToKey = new HashMap<>();
|
||||||
static Map<String, Integer> keyToId = new HashMap<>();
|
static Map<String, Integer> keyToId = new HashMap<>();
|
||||||
static Map<Integer, ConnectionHandler> connectionHandlerMap = new HashMap<>();
|
static Map<Integer, ConnectionHandler> connectionHandlerMap = new HashMap<>();
|
||||||
@ -28,10 +30,9 @@ public class ConnectionData {
|
|||||||
static Set<Integer> occludingStates = new HashSet<>();
|
static Set<Integer> occludingStates = new HashSet<>();
|
||||||
|
|
||||||
public static void update(UserConnection user, Position position) {
|
public static void update(UserConnection user, Position position) {
|
||||||
BlockConnectionProvider connectionProvider = Via.getManager().getProviders().get(BlockConnectionProvider.class);
|
|
||||||
for (BlockFace face : BlockFace.values()) {
|
for (BlockFace face : BlockFace.values()) {
|
||||||
Position pos = position.getRelative(face);
|
Position pos = position.getRelative(face);
|
||||||
int blockState = connectionProvider.getBlockData(user, pos.getX(), pos.getY(), pos.getZ());
|
int blockState = blockConnectionProvider.getBlockData(user, pos.getX(), pos.getY(), pos.getZ());
|
||||||
ConnectionHandler handler = connectionHandlerMap.get(blockState);
|
ConnectionHandler handler = connectionHandlerMap.get(blockState);
|
||||||
if (handler == null) continue;
|
if (handler == null) continue;
|
||||||
|
|
||||||
@ -112,7 +113,7 @@ public class ConnectionData {
|
|||||||
PacketWrapper wrapper = new PacketWrapper(0x0F, null, user);
|
PacketWrapper wrapper = new PacketWrapper(0x0F, null, user);
|
||||||
wrapper.write(Type.INT, chunkX + chunkDeltaX);
|
wrapper.write(Type.INT, chunkX + chunkDeltaX);
|
||||||
wrapper.write(Type.INT, chunkZ + chunkDeltaZ);
|
wrapper.write(Type.INT, chunkZ + chunkDeltaZ);
|
||||||
wrapper.write(Type.BLOCK_CHANGE_RECORD_ARRAY, updates.toArray(new BlockChangeRecord[0]));
|
wrapper.write(Type.BLOCK_CHANGE_RECORD_ARRAY, updates.toArray(A));
|
||||||
try {
|
try {
|
||||||
wrapper.send(Protocol1_13To1_12_2.class, true, true);
|
wrapper.send(Protocol1_13To1_12_2.class, true, true);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@ -124,7 +125,7 @@ public class ConnectionData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void updateBlock(UserConnection user, Position pos, List<BlockChangeRecord> records) {
|
public static void updateBlock(UserConnection user, Position pos, List<BlockChangeRecord> records) {
|
||||||
int blockState = Via.getManager().getProviders().get(BlockConnectionProvider.class).getBlockData(user, pos.getX(), pos.getY(), pos.getZ());
|
int blockState = blockConnectionProvider.getBlockData(user, pos.getX(), pos.getY(), pos.getZ());
|
||||||
ConnectionHandler handler = getConnectionHandler(blockState);
|
ConnectionHandler handler = getConnectionHandler(blockState);
|
||||||
if (handler == null) return;
|
if (handler == null) return;
|
||||||
|
|
||||||
@ -132,26 +133,22 @@ public class ConnectionData {
|
|||||||
records.add(new BlockChangeRecord((short) (((pos.getX() & 0xF) << 4) | (pos.getZ() & 0xF)), pos.getY(), newBlockState));
|
records.add(new BlockChangeRecord((short) (((pos.getX() & 0xF) << 4) | (pos.getZ() & 0xF)), pos.getY(), newBlockState));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static BlockConnectionProvider getProvider() {
|
|
||||||
return Via.getManager().getProviders().get(BlockConnectionProvider.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void updateBlockStorage(UserConnection userConnection, int x, int y, int z, int blockState) {
|
public static void updateBlockStorage(UserConnection userConnection, int x, int y, int z, int blockState) {
|
||||||
if (!needStoreBlocks()) return;
|
if (!needStoreBlocks()) return;
|
||||||
if (ConnectionData.isWelcome(blockState)) {
|
if (ConnectionData.isWelcome(blockState)) {
|
||||||
ConnectionData.getProvider().storeBlock(userConnection, x, y, z, blockState);
|
blockConnectionProvider.storeBlock(userConnection, x, y, z, blockState);
|
||||||
} else {
|
} else {
|
||||||
ConnectionData.getProvider().removeBlock(userConnection, x, y, z);
|
blockConnectionProvider.removeBlock(userConnection, x, y, z);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void clearBlockStorage(UserConnection connection) {
|
public static void clearBlockStorage(UserConnection connection) {
|
||||||
if (!needStoreBlocks()) return;
|
if (!needStoreBlocks()) return;
|
||||||
getProvider().clearStorage(connection);
|
blockConnectionProvider.clearStorage(connection);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean needStoreBlocks() {
|
public static boolean needStoreBlocks() {
|
||||||
return getProvider().storesBlocks();
|
return blockConnectionProvider.storesBlocks();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void connectBlocks(UserConnection user, Chunk chunk) {
|
public static void connectBlocks(UserConnection user, Chunk chunk) {
|
||||||
@ -260,7 +257,8 @@ public class ConnectionData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (Via.getConfig().getBlockConnectionMethod().equalsIgnoreCase("packet")) {
|
if (Via.getConfig().getBlockConnectionMethod().equalsIgnoreCase("packet")) {
|
||||||
Via.getManager().getProviders().register(BlockConnectionProvider.class, new PacketBlockConnectionProvider());
|
blockConnectionProvider = new PacketBlockConnectionProvider();
|
||||||
|
Via.getManager().getProviders().register(BlockConnectionProvider.class, blockConnectionProvider);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -289,6 +287,7 @@ public class ConnectionData {
|
|||||||
return idToKey.get(id);
|
return idToKey.get(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@FunctionalInterface
|
||||||
interface ConnectorInitAction {
|
interface ConnectorInitAction {
|
||||||
|
|
||||||
void check(WrappedBlockData blockData);
|
void check(WrappedBlockData blockData);
|
||||||
|
@ -6,14 +6,10 @@ import us.myles.ViaVersion.api.minecraft.Position;
|
|||||||
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.blockconnections.providers.BlockConnectionProvider;
|
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.blockconnections.providers.BlockConnectionProvider;
|
||||||
|
|
||||||
public abstract class ConnectionHandler {
|
public abstract class ConnectionHandler {
|
||||||
|
|
||||||
public abstract int connect(UserConnection user, Position position, int blockState);
|
public abstract int connect(UserConnection user, Position position, int blockState);
|
||||||
|
|
||||||
public int getBlockData(UserConnection user, Position position) {
|
public int getBlockData(UserConnection user, Position position) {
|
||||||
return Via.getManager().getProviders().get(BlockConnectionProvider.class).getBlockData(user, position.getX(), position.getY(), position.getZ());
|
return Via.getManager().getProviders().get(BlockConnectionProvider.class).getBlockData(user, position.getX(), position.getY(), position.getZ());
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean canConnect(int id) {
|
|
||||||
ConnectionHandler handler = ConnectionData.connectionHandlerMap.get(id);
|
|
||||||
return handler != null && handler == this;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,21 +1,14 @@
|
|||||||
package us.myles.ViaVersion.protocols.protocol1_13to1_12_2.blockconnections;
|
package us.myles.ViaVersion.protocols.protocol1_13to1_12_2.blockconnections;
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.ToString;
|
|
||||||
import us.myles.ViaVersion.api.data.UserConnection;
|
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.HashMap;
|
import java.util.*;
|
||||||
import java.util.LinkedList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Locale;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class DoorConnectionHandler extends ConnectionHandler {
|
public class DoorConnectionHandler extends ConnectionHandler {
|
||||||
private static Map<Integer, DoorData> doorDataMap = new HashMap<>();
|
private static final Map<Integer, DoorData> doorDataMap = new HashMap<>();
|
||||||
private static Map<Short, Integer> connectedStates = new HashMap<>();
|
private static final Map<Short, Integer> connectedStates = new HashMap<>();
|
||||||
|
|
||||||
static ConnectionData.ConnectorInitAction init() {
|
static ConnectionData.ConnectorInitAction init() {
|
||||||
final List<String> baseDoors = new LinkedList<>();
|
final List<String> baseDoors = new LinkedList<>();
|
||||||
@ -28,9 +21,7 @@ public class DoorConnectionHandler extends ConnectionHandler {
|
|||||||
baseDoors.add("minecraft:iron_door");
|
baseDoors.add("minecraft:iron_door");
|
||||||
|
|
||||||
final DoorConnectionHandler connectionHandler = new DoorConnectionHandler();
|
final DoorConnectionHandler connectionHandler = new DoorConnectionHandler();
|
||||||
return new ConnectionData.ConnectorInitAction() {
|
return blockData -> {
|
||||||
@Override
|
|
||||||
public void check(WrappedBlockData blockData) {
|
|
||||||
int type = baseDoors.indexOf(blockData.getMinecraftKey());
|
int type = baseDoors.indexOf(blockData.getMinecraftKey());
|
||||||
if (type == -1) return;
|
if (type == -1) return;
|
||||||
|
|
||||||
@ -50,7 +41,6 @@ public class DoorConnectionHandler extends ConnectionHandler {
|
|||||||
connectedStates.put(getStates(doorData), id);
|
connectedStates.put(getStates(doorData), id);
|
||||||
|
|
||||||
ConnectionData.connectionHandlerMap.put(id, connectionHandler);
|
ConnectionData.connectionHandlerMap.put(id, connectionHandler);
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -87,16 +77,47 @@ public class DoorConnectionHandler extends ConnectionHandler {
|
|||||||
if (doorData.isRightHinge()) s |= 8;
|
if (doorData.isRightHinge()) s |= 8;
|
||||||
s |= lowerHalf.getFacing().ordinal() << 4;
|
s |= lowerHalf.getFacing().ordinal() << 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
Integer newBlockState = connectedStates.get(s);
|
Integer newBlockState = connectedStates.get(s);
|
||||||
return newBlockState == null ? blockState : newBlockState;
|
return newBlockState == null ? blockState : newBlockState;
|
||||||
}
|
}
|
||||||
|
|
||||||
@AllArgsConstructor
|
private static final class DoorData {
|
||||||
@Getter
|
|
||||||
@ToString
|
|
||||||
private static class DoorData {
|
|
||||||
private final boolean lower, rightHinge, powered, open;
|
private final boolean lower, rightHinge, powered, open;
|
||||||
private final BlockFace facing;
|
private final BlockFace facing;
|
||||||
private int type;
|
private final int type;
|
||||||
|
|
||||||
|
private DoorData(boolean lower, boolean rightHinge, boolean powered, boolean open, BlockFace facing, int type) {
|
||||||
|
this.lower = lower;
|
||||||
|
this.rightHinge = rightHinge;
|
||||||
|
this.powered = powered;
|
||||||
|
this.open = open;
|
||||||
|
this.facing = facing;
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isLower() {
|
||||||
|
return lower;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isRightHinge() {
|
||||||
|
return rightHinge;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isPowered() {
|
||||||
|
return powered;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isOpen() {
|
||||||
|
return open;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BlockFace getFacing() {
|
||||||
|
return facing;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getType() {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,7 @@ import java.util.Set;
|
|||||||
|
|
||||||
|
|
||||||
public class FlowerConnectionHandler extends ConnectionHandler {
|
public class FlowerConnectionHandler extends ConnectionHandler {
|
||||||
private static Map<Integer, Integer> flowers = new HashMap<>();
|
private static final Map<Integer, Integer> flowers = new HashMap<>();
|
||||||
|
|
||||||
static ConnectionData.ConnectorInitAction init() {
|
static ConnectionData.ConnectorInitAction init() {
|
||||||
final Set<String> baseFlower = new HashSet<>();
|
final Set<String> baseFlower = new HashSet<>();
|
||||||
@ -24,9 +24,7 @@ public class FlowerConnectionHandler extends ConnectionHandler {
|
|||||||
baseFlower.add("minecraft:lilac");
|
baseFlower.add("minecraft:lilac");
|
||||||
|
|
||||||
final FlowerConnectionHandler handler = new FlowerConnectionHandler();
|
final FlowerConnectionHandler handler = new FlowerConnectionHandler();
|
||||||
return new ConnectionData.ConnectorInitAction() {
|
return blockData -> {
|
||||||
@Override
|
|
||||||
public void check(WrappedBlockData blockData) {
|
|
||||||
if (baseFlower.contains(blockData.getMinecraftKey())) {
|
if (baseFlower.contains(blockData.getMinecraftKey())) {
|
||||||
ConnectionData.connectionHandlerMap.put(blockData.getSavedBlockStateId(), handler);
|
ConnectionData.connectionHandlerMap.put(blockData.getSavedBlockStateId(), handler);
|
||||||
if (blockData.getValue("half").equals("lower")) {
|
if (blockData.getValue("half").equals("lower")) {
|
||||||
@ -34,21 +32,21 @@ public class FlowerConnectionHandler extends ConnectionHandler {
|
|||||||
flowers.put(blockData.getSavedBlockStateId(), blockData.getBlockStateId());
|
flowers.put(blockData.getSavedBlockStateId(), blockData.getBlockStateId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int connect(UserConnection user, Position position, int blockState) {
|
public int connect(UserConnection user, Position position, int blockState) {
|
||||||
int blockBelowId = getBlockData(user, position.getRelative(BlockFace.BOTTOM));
|
int blockBelowId = getBlockData(user, position.getRelative(BlockFace.BOTTOM));
|
||||||
if (flowers.containsKey(blockBelowId)) {
|
Integer connectBelow = flowers.get(blockBelowId);
|
||||||
|
if (connectBelow != null) {
|
||||||
int blockAboveId = getBlockData(user, position.getRelative(BlockFace.TOP));
|
int blockAboveId = getBlockData(user, position.getRelative(BlockFace.TOP));
|
||||||
if (Via.getConfig().isStemWhenBlockAbove()) {
|
if (Via.getConfig().isStemWhenBlockAbove()) {
|
||||||
if (blockAboveId == 0) {
|
if (blockAboveId == 0) {
|
||||||
return flowers.get(blockBelowId);
|
return connectBelow;
|
||||||
}
|
}
|
||||||
} else if (!flowers.containsKey(blockAboveId)) {
|
} else if (!flowers.containsKey(blockAboveId)) {
|
||||||
return flowers.get(blockBelowId);
|
return connectBelow;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return blockState;
|
return blockState;
|
||||||
|
@ -39,8 +39,10 @@ public class GlassConnectionHandler extends AbstractFenceConnectionHandler {
|
|||||||
@Override
|
@Override
|
||||||
protected byte getStates(UserConnection user, Position position, int blockState) {
|
protected byte getStates(UserConnection user, Position position, int blockState) {
|
||||||
byte states = super.getStates(user, position, blockState);
|
byte states = super.getStates(user, position, blockState);
|
||||||
return states == 0
|
if (states != 0) return states;
|
||||||
&& user.get(ProtocolInfo.class).getServerProtocolVersion() <= 47
|
|
||||||
&& user.get(ProtocolInfo.class).getServerProtocolVersion() != -1 ? 0xF : states;
|
ProtocolInfo protocolInfo = user.get(ProtocolInfo.class);
|
||||||
|
return protocolInfo.getServerProtocolVersion() <= 47
|
||||||
|
&& protocolInfo.getServerProtocolVersion() != -1 ? 0xF : states;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,22 +10,19 @@ import java.util.Map;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class RedstoneConnectionHandler extends ConnectionHandler {
|
public class RedstoneConnectionHandler extends ConnectionHandler {
|
||||||
private static Set<Integer> redstone = new HashSet<>();
|
private static final Set<Integer> redstone = new HashSet<>();
|
||||||
private static Map<Short, Integer> connectedBlockStates = new HashMap<>();
|
private static final Map<Short, Integer> connectedBlockStates = new HashMap<>();
|
||||||
private static Map<Integer, Integer> powerMappings = new HashMap<>();
|
private static final Map<Integer, Integer> powerMappings = new HashMap<>();
|
||||||
|
|
||||||
static ConnectionData.ConnectorInitAction init() {
|
static ConnectionData.ConnectorInitAction init() {
|
||||||
final RedstoneConnectionHandler connectionHandler = new RedstoneConnectionHandler();
|
final RedstoneConnectionHandler connectionHandler = new RedstoneConnectionHandler();
|
||||||
final String redstoneKey = "minecraft:redstone_wire";
|
final String redstoneKey = "minecraft:redstone_wire";
|
||||||
return new ConnectionData.ConnectorInitAction() {
|
return blockData -> {
|
||||||
@Override
|
|
||||||
public void check(WrappedBlockData blockData) {
|
|
||||||
if (!redstoneKey.equals(blockData.getMinecraftKey())) return;
|
if (!redstoneKey.equals(blockData.getMinecraftKey())) return;
|
||||||
redstone.add(blockData.getSavedBlockStateId());
|
redstone.add(blockData.getSavedBlockStateId());
|
||||||
ConnectionData.connectionHandlerMap.put(blockData.getSavedBlockStateId(), connectionHandler);
|
ConnectionData.connectionHandlerMap.put(blockData.getSavedBlockStateId(), connectionHandler);
|
||||||
connectedBlockStates.put(getStates(blockData), blockData.getSavedBlockStateId());
|
connectedBlockStates.put(getStates(blockData), blockData.getSavedBlockStateId());
|
||||||
powerMappings.put(blockData.getSavedBlockStateId(), Integer.valueOf(blockData.getValue("power")));
|
powerMappings.put(blockData.getSavedBlockStateId(), Integer.valueOf(blockData.getValue("power")));
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,8 +11,8 @@ import java.util.Map;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class SnowyGrassConnectionHandler extends ConnectionHandler {
|
public class SnowyGrassConnectionHandler extends ConnectionHandler {
|
||||||
private static Map<Pair<Integer, Boolean>, Integer> grassBlocks = new HashMap<>();
|
private static final Map<Pair<Integer, Boolean>, Integer> grassBlocks = new HashMap<>();
|
||||||
private static Set<Integer> snows = new HashSet<>();
|
private static final Set<Integer> snows = new HashSet<>();
|
||||||
|
|
||||||
static ConnectionData.ConnectorInitAction init() {
|
static ConnectionData.ConnectorInitAction init() {
|
||||||
final Set<String> snowyGrassBlocks = new HashSet<>();
|
final Set<String> snowyGrassBlocks = new HashSet<>();
|
||||||
@ -21,9 +21,7 @@ public class SnowyGrassConnectionHandler extends ConnectionHandler {
|
|||||||
snowyGrassBlocks.add("minecraft:mycelium");
|
snowyGrassBlocks.add("minecraft:mycelium");
|
||||||
|
|
||||||
final SnowyGrassConnectionHandler handler = new SnowyGrassConnectionHandler();
|
final SnowyGrassConnectionHandler handler = new SnowyGrassConnectionHandler();
|
||||||
return new ConnectionData.ConnectorInitAction() {
|
return blockData -> {
|
||||||
@Override
|
|
||||||
public void check(WrappedBlockData blockData) {
|
|
||||||
if (snowyGrassBlocks.contains(blockData.getMinecraftKey())) {
|
if (snowyGrassBlocks.contains(blockData.getMinecraftKey())) {
|
||||||
ConnectionData.connectionHandlerMap.put(blockData.getSavedBlockStateId(), handler);
|
ConnectionData.connectionHandlerMap.put(blockData.getSavedBlockStateId(), handler);
|
||||||
blockData.set("snowy", "true");
|
blockData.set("snowy", "true");
|
||||||
@ -35,7 +33,6 @@ public class SnowyGrassConnectionHandler extends ConnectionHandler {
|
|||||||
ConnectionData.connectionHandlerMap.put(blockData.getSavedBlockStateId(), handler);
|
ConnectionData.connectionHandlerMap.put(blockData.getSavedBlockStateId(), handler);
|
||||||
snows.add(blockData.getSavedBlockStateId());
|
snows.add(blockData.getSavedBlockStateId());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,21 +1,14 @@
|
|||||||
package us.myles.ViaVersion.protocols.protocol1_13to1_12_2.blockconnections;
|
package us.myles.ViaVersion.protocols.protocol1_13to1_12_2.blockconnections;
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.ToString;
|
|
||||||
import us.myles.ViaVersion.api.data.UserConnection;
|
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.HashMap;
|
import java.util.*;
|
||||||
import java.util.LinkedList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Locale;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class StairConnectionHandler extends ConnectionHandler {
|
public class StairConnectionHandler extends ConnectionHandler {
|
||||||
private static Map<Integer, StairData> stairDataMap = new HashMap<>();
|
private static final Map<Integer, StairData> stairDataMap = new HashMap<>();
|
||||||
private static Map<Short, Integer> connectedBlocks = new HashMap<>();
|
private static final Map<Short, Integer> connectedBlocks = new HashMap<>();
|
||||||
|
|
||||||
static ConnectionData.ConnectorInitAction init() {
|
static ConnectionData.ConnectorInitAction init() {
|
||||||
final List<String> baseStairs = new LinkedList<>();
|
final List<String> baseStairs = new LinkedList<>();
|
||||||
@ -38,9 +31,7 @@ public class StairConnectionHandler extends ConnectionHandler {
|
|||||||
baseStairs.add("minecraft:dark_prismarine_stairs");
|
baseStairs.add("minecraft:dark_prismarine_stairs");
|
||||||
|
|
||||||
final StairConnectionHandler connectionHandler = new StairConnectionHandler();
|
final StairConnectionHandler connectionHandler = new StairConnectionHandler();
|
||||||
return new ConnectionData.ConnectorInitAction() {
|
return blockData -> {
|
||||||
@Override
|
|
||||||
public void check(WrappedBlockData blockData) {
|
|
||||||
int type = baseStairs.indexOf(blockData.getMinecraftKey());
|
int type = baseStairs.indexOf(blockData.getMinecraftKey());
|
||||||
if (type == -1) return;
|
if (type == -1) return;
|
||||||
|
|
||||||
@ -48,12 +39,23 @@ public class StairConnectionHandler extends ConnectionHandler {
|
|||||||
|
|
||||||
byte shape;
|
byte shape;
|
||||||
switch (blockData.getValue("shape")) {
|
switch (blockData.getValue("shape")) {
|
||||||
case "straight": shape = 0; break;
|
case "straight":
|
||||||
case "inner_left": shape = 1; break;
|
shape = 0;
|
||||||
case "inner_right": shape = 2; break;
|
break;
|
||||||
case "outer_left": shape = 3; break;
|
case "inner_left":
|
||||||
case "outer_right": shape = 4; break;
|
shape = 1;
|
||||||
default: return;
|
break;
|
||||||
|
case "inner_right":
|
||||||
|
shape = 2;
|
||||||
|
break;
|
||||||
|
case "outer_left":
|
||||||
|
shape = 3;
|
||||||
|
break;
|
||||||
|
case "outer_right":
|
||||||
|
shape = 4;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
StairData stairData = new StairData(
|
StairData stairData = new StairData(
|
||||||
@ -66,7 +68,6 @@ public class StairConnectionHandler extends ConnectionHandler {
|
|||||||
connectedBlocks.put(getStates(stairData), blockData.getSavedBlockStateId());
|
connectedBlocks.put(getStates(stairData), blockData.getSavedBlockStateId());
|
||||||
|
|
||||||
ConnectionData.connectionHandlerMap.put(blockData.getSavedBlockStateId(), connectionHandler);
|
ConnectionData.connectionHandlerMap.put(blockData.getSavedBlockStateId(), connectionHandler);
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -136,12 +137,32 @@ public class StairConnectionHandler extends ConnectionHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@AllArgsConstructor
|
private static final class StairData {
|
||||||
@Getter
|
|
||||||
@ToString
|
|
||||||
private static class StairData {
|
|
||||||
private final boolean bottom;
|
private final boolean bottom;
|
||||||
private final byte shape, type;
|
private final byte shape, type;
|
||||||
private final BlockFace facing;
|
private final BlockFace facing;
|
||||||
|
|
||||||
|
private StairData(boolean bottom, byte shape, byte type, BlockFace facing) {
|
||||||
|
this.bottom = bottom;
|
||||||
|
this.shape = shape;
|
||||||
|
this.type = type;
|
||||||
|
this.facing = facing;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isBottom() {
|
||||||
|
return bottom;
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte getShape() {
|
||||||
|
return shape;
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte getType() {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BlockFace getFacing() {
|
||||||
|
return facing;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,5 @@
|
|||||||
package us.myles.ViaVersion.protocols.protocol1_13to1_12_2.blockconnections;
|
package us.myles.ViaVersion.protocols.protocol1_13to1_12_2.blockconnections;
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.ToString;
|
|
||||||
import us.myles.ViaVersion.api.data.UserConnection;
|
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;
|
||||||
@ -12,15 +9,13 @@ import java.util.Locale;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class TripwireConnectionHandler extends ConnectionHandler {
|
public class TripwireConnectionHandler extends ConnectionHandler {
|
||||||
private static Map<Integer, TripwireData> tripwireDataMap = new HashMap<>();
|
private static final Map<Integer, TripwireData> tripwireDataMap = new HashMap<>();
|
||||||
private static Map<Byte, Integer> connectedBlocks = new HashMap<>();
|
private static final Map<Byte, Integer> connectedBlocks = new HashMap<>();
|
||||||
private static Map<Integer, BlockFace> tripwireHooks = new HashMap<>();
|
private static final Map<Integer, BlockFace> tripwireHooks = new HashMap<>();
|
||||||
|
|
||||||
static ConnectionData.ConnectorInitAction init() {
|
static ConnectionData.ConnectorInitAction init() {
|
||||||
final TripwireConnectionHandler connectionHandler = new TripwireConnectionHandler();
|
final TripwireConnectionHandler connectionHandler = new TripwireConnectionHandler();
|
||||||
return new ConnectionData.ConnectorInitAction() {
|
return blockData -> {
|
||||||
@Override
|
|
||||||
public void check(WrappedBlockData blockData) {
|
|
||||||
if (blockData.getMinecraftKey().equals("minecraft:tripwire_hook")) {
|
if (blockData.getMinecraftKey().equals("minecraft:tripwire_hook")) {
|
||||||
tripwireHooks.put(blockData.getSavedBlockStateId(), BlockFace.valueOf(blockData.getValue("facing").toUpperCase(Locale.ROOT)));
|
tripwireHooks.put(blockData.getSavedBlockStateId(), BlockFace.valueOf(blockData.getValue("facing").toUpperCase(Locale.ROOT)));
|
||||||
} else if (blockData.getMinecraftKey().equals("minecraft:tripwire")) {
|
} else if (blockData.getMinecraftKey().equals("minecraft:tripwire")) {
|
||||||
@ -35,7 +30,6 @@ public class TripwireConnectionHandler extends ConnectionHandler {
|
|||||||
|
|
||||||
ConnectionData.connectionHandlerMap.put(blockData.getSavedBlockStateId(), connectionHandler);
|
ConnectionData.connectionHandlerMap.put(blockData.getSavedBlockStateId(), connectionHandler);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -82,10 +76,25 @@ public class TripwireConnectionHandler extends ConnectionHandler {
|
|||||||
return newBlockState == null ? blockState : newBlockState;
|
return newBlockState == null ? blockState : newBlockState;
|
||||||
}
|
}
|
||||||
|
|
||||||
@AllArgsConstructor
|
private static final class TripwireData {
|
||||||
@Getter
|
|
||||||
@ToString
|
|
||||||
private static class TripwireData {
|
|
||||||
private final boolean attached, disarmed, powered;
|
private final boolean attached, disarmed, powered;
|
||||||
|
|
||||||
|
private TripwireData(final boolean attached, final boolean disarmed, final boolean powered) {
|
||||||
|
this.attached = attached;
|
||||||
|
this.disarmed = disarmed;
|
||||||
|
this.powered = powered;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isAttached() {
|
||||||
|
return attached;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isDisarmed() {
|
||||||
|
return disarmed;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isPowered() {
|
||||||
|
return powered;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,17 +1,14 @@
|
|||||||
package us.myles.ViaVersion.protocols.protocol1_13to1_12_2.blockconnections;
|
package us.myles.ViaVersion.protocols.protocol1_13to1_12_2.blockconnections;
|
||||||
|
|
||||||
import lombok.Getter;
|
|
||||||
import us.myles.ViaVersion.api.Via;
|
import us.myles.ViaVersion.api.Via;
|
||||||
|
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
public class WrappedBlockData {
|
public class WrappedBlockData {
|
||||||
@Getter
|
private final String minecraftKey;
|
||||||
private String minecraftKey;
|
private final int savedBlockStateId;
|
||||||
@Getter
|
private final LinkedHashMap<String, String> blockData = new LinkedHashMap<>();
|
||||||
private int savedBlockStateId;
|
|
||||||
private LinkedHashMap<String, String> blockData = new LinkedHashMap<>();
|
|
||||||
|
|
||||||
public static WrappedBlockData fromString(String s) {
|
public static WrappedBlockData fromString(String s) {
|
||||||
String[] array = s.split("\\[");
|
String[] array = s.split("\\[");
|
||||||
@ -43,6 +40,7 @@ public class WrappedBlockData {
|
|||||||
this.savedBlockStateId = savedBlockStateId;
|
this.savedBlockStateId = savedBlockStateId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
StringBuilder sb = new StringBuilder(minecraftKey + "[");
|
StringBuilder sb = new StringBuilder(minecraftKey + "[");
|
||||||
for (Entry<String, String> entry : blockData.entrySet()) {
|
for (Entry<String, String> entry : blockData.entrySet()) {
|
||||||
@ -51,12 +49,21 @@ public class WrappedBlockData {
|
|||||||
return sb.substring(0, sb.length() - 1) + "]";
|
return sb.substring(0, sb.length() - 1) + "]";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getMinecraftKey() {
|
||||||
|
return minecraftKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getSavedBlockStateId() {
|
||||||
|
return savedBlockStateId;
|
||||||
|
}
|
||||||
|
|
||||||
public int getBlockStateId() {
|
public int getBlockStateId() {
|
||||||
return ConnectionData.getId(toString());
|
return ConnectionData.getId(toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
public WrappedBlockData set(String data, Object value) {
|
public WrappedBlockData set(String data, Object value) {
|
||||||
if (!hasData(data)) throw new UnsupportedOperationException("No blockdata found for " + data + " at " + minecraftKey);
|
if (!hasData(data))
|
||||||
|
throw new UnsupportedOperationException("No blockdata found for " + data + " at " + minecraftKey);
|
||||||
blockData.put(data, value.toString());
|
blockData.put(data, value.toString());
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
package us.myles.ViaVersion.protocols.protocol1_13to1_12_2.blockconnections.providers;
|
package us.myles.ViaVersion.protocols.protocol1_13to1_12_2.blockconnections.providers;
|
||||||
|
|
||||||
import us.myles.ViaVersion.api.data.UserConnection;
|
import us.myles.ViaVersion.api.data.UserConnection;
|
||||||
import us.myles.ViaVersion.api.minecraft.Position;
|
|
||||||
import us.myles.ViaVersion.api.platform.providers.Provider;
|
import us.myles.ViaVersion.api.platform.providers.Provider;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.MappingData;
|
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.MappingData;
|
||||||
|
|
||||||
public class BlockConnectionProvider implements Provider {
|
public class BlockConnectionProvider implements Provider {
|
||||||
|
|
||||||
public int getBlockData(UserConnection connection, int x, int y, int z) {
|
public int getBlockData(UserConnection connection, int x, int y, int z) {
|
||||||
int oldId = getWorldBlockData(connection, x, y, z);
|
int oldId = getWorldBlockData(connection, x, y, z);
|
||||||
return MappingData.blockMappings.getNewId(oldId);
|
return MappingData.blockMappings.getNewId(oldId);
|
||||||
|
@ -12,13 +12,13 @@ import us.myles.ViaVersion.api.protocol.Protocol;
|
|||||||
import us.myles.ViaVersion.api.remapper.PacketHandler;
|
import us.myles.ViaVersion.api.remapper.PacketHandler;
|
||||||
import us.myles.ViaVersion.api.remapper.PacketRemapper;
|
import us.myles.ViaVersion.api.remapper.PacketRemapper;
|
||||||
import us.myles.ViaVersion.api.type.Type;
|
import us.myles.ViaVersion.api.type.Type;
|
||||||
|
import us.myles.ViaVersion.api.type.types.Particle;
|
||||||
import us.myles.ViaVersion.packets.State;
|
import us.myles.ViaVersion.packets.State;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.Protocol1_13To1_12_2;
|
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.Protocol1_13To1_12_2;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.blockconnections.ConnectionData;
|
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.blockconnections.ConnectionData;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.blockconnections.ConnectionHandler;
|
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.blockconnections.ConnectionHandler;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.MappingData;
|
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.MappingData;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.NamedSoundRewriter;
|
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.NamedSoundRewriter;
|
||||||
import us.myles.ViaVersion.api.type.types.Particle;
|
|
||||||
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.ParticleRewriter;
|
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.ParticleRewriter;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.providers.BlockEntityProvider;
|
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.providers.BlockEntityProvider;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.providers.PaintingProvider;
|
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.providers.PaintingProvider;
|
||||||
@ -264,7 +264,7 @@ public class WorldPackets {
|
|||||||
public void handle(PacketWrapper wrapper) throws Exception {
|
public void handle(PacketWrapper wrapper) throws Exception {
|
||||||
int x = wrapper.passthrough(Type.INT);
|
int x = wrapper.passthrough(Type.INT);
|
||||||
int z = wrapper.passthrough(Type.INT);
|
int z = wrapper.passthrough(Type.INT);
|
||||||
ConnectionData.getProvider().unloadChunk(wrapper.user(), x, z);
|
ConnectionData.blockConnectionProvider.unloadChunk(wrapper.user(), x, z);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -355,7 +355,7 @@ public class WorldPackets {
|
|||||||
for (int x = 0; x < 16; x++) {
|
for (int x = 0; x < 16; x++) {
|
||||||
int block = section.getFlatBlock(x, y, z);
|
int block = section.getFlatBlock(x, y, z);
|
||||||
if (ConnectionData.isWelcome(block)) {
|
if (ConnectionData.isWelcome(block)) {
|
||||||
ConnectionData.getProvider().storeBlock(wrapper.user(), x + (chunk.getX() << 4),
|
ConnectionData.blockConnectionProvider.storeBlock(wrapper.user(), x + (chunk.getX() << 4),
|
||||||
y + (i << 4),
|
y + (i << 4),
|
||||||
z + (chunk.getZ() << 4),
|
z + (chunk.getZ() << 4),
|
||||||
block);
|
block);
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren