3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-12-27 08:30:09 +01:00

Tripwire connections

Dieser Commit ist enthalten in:
Gerrygames 2018-11-19 09:28:37 +01:00
Ursprung eb1571d3e4
Commit b60c56f464
3 geänderte Dateien mit 96 neuen und 3 gelöschten Zeilen

Datei anzeigen

@ -176,6 +176,7 @@ public class ConnectionData {
StairConnectionHandler.init(); StairConnectionHandler.init();
FlowerConnectionHandler.init(); FlowerConnectionHandler.init();
ChorusPlantConnectionHandler.init(); ChorusPlantConnectionHandler.init();
TripwireConnectionHandler.init();
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());

Datei anzeigen

@ -6,10 +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 connection, Position position, int blockState); public abstract int connect(UserConnection user, Position position, int blockState);
public int getBlockData(UserConnection connection, Position position) { public int getBlockData(UserConnection user, Position position) {
return Via.getManager().getProviders().get(BlockConnectionProvider.class).getBlockdata(connection, position); return Via.getManager().getProviders().get(BlockConnectionProvider.class).getBlockdata(user, position);
} }
public boolean canConnect(int id) { public boolean canConnect(int id) {

Datei anzeigen

@ -0,0 +1,92 @@
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.minecraft.BlockFace;
import us.myles.ViaVersion.api.minecraft.Position;
import java.util.HashMap;
import java.util.Map;
public class TripwireConnectionHandler extends ConnectionHandler {
private static Map<Integer, TripwireData> tripwireDataMap = new HashMap<>();
private static Map<Byte, Integer> connectedBlocks = new HashMap<>();
private static Map<Integer, BlockFace> tripwireHooks = new HashMap<>();
static void init() {
TripwireConnectionHandler connectionHandler = new TripwireConnectionHandler();
for (Map.Entry<String, Integer> blockState : ConnectionData.keyToId.entrySet()) {
String key = blockState.getKey().split("\\[")[0];
if (key.equals("minecraft:tripwire_hook")) {
WrappedBlockData blockData = WrappedBlockData.fromString(blockState.getKey());
tripwireHooks.put(blockState.getValue(), BlockFace.valueOf(blockData.getValue("facing").toUpperCase()));
} else if (key.equals("minecraft:tripwire")) {
WrappedBlockData blockData = WrappedBlockData.fromString(blockState.getKey());
TripwireData tripwireData = new TripwireData(
blockData.getValue("attached").equals("true"),
blockData.getValue("disarmed").equals("true"),
blockData.getValue("powered").equals("true")
);
tripwireDataMap.put(blockState.getValue(), tripwireData);
connectedBlocks.put(getStates(blockData), blockState.getValue());
ConnectionData.connectionHandlerMap.put(blockState.getValue(), connectionHandler);
}
}
}
private static byte getStates(WrappedBlockData blockData) {
byte b = 0;
if (blockData.getValue("attached").equals("true")) b |= 1;
if (blockData.getValue("disarmed").equals("true")) b |= 2;
if (blockData.getValue("powered").equals("true")) b |= 4;
if (blockData.getValue("east").equals("true")) b |= 8;
if (blockData.getValue("north").equals("true")) b |= 16;
if (blockData.getValue("south").equals("true")) b |= 32;
if (blockData.getValue("west").equals("true")) b |= 64;
return b;
}
@Override
public int connect(UserConnection user, Position position, int blockState) {
TripwireData tripwireData = tripwireDataMap.get(blockState);
if (tripwireData == null) return blockState;
byte b = 0;
if (tripwireData.isAttached()) b |= 1;
if (tripwireData.isDisarmed()) b |= 2;
if (tripwireData.isPowered()) b |= 4;
int east = getBlockData(user, position.getRelative(BlockFace.EAST));
int north = getBlockData(user, position.getRelative(BlockFace.NORTH));
int south = getBlockData(user, position.getRelative(BlockFace.SOUTH));
int west = getBlockData(user, position.getRelative(BlockFace.WEST));
if (tripwireDataMap.containsKey(east) || tripwireHooks.get(east) == BlockFace.WEST) {
b |= 8;
}
if (tripwireDataMap.containsKey(north) || tripwireHooks.get(north) == BlockFace.SOUTH) {
b |= 16;
}
if (tripwireDataMap.containsKey(south) || tripwireHooks.get(south) == BlockFace.NORTH) {
b |= 32;
}
if (tripwireDataMap.containsKey(west) || tripwireHooks.get(west) == BlockFace.EAST) {
b |= 64;
}
Integer newBlockState = connectedBlocks.get(b);
return newBlockState == null ? blockState : newBlockState;
}
@AllArgsConstructor
@Getter
@ToString
private static class TripwireData {
private final boolean attached, disarmed, powered;
}
}