3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-10-03 08:41:05 +02:00

Merge branch 'master' into dev

Dieser Commit ist enthalten in:
Myles 2018-12-05 19:10:52 +00:00
Commit 7e8e3fef61
20 geänderte Dateien mit 229 neuen und 214 gelöschten Zeilen

Datei anzeigen

@ -1,7 +1,7 @@
sudo: false sudo: false
language: java language: java
jdk: jdk:
- oraclejdk8 - oraclejdk8
- openjdk11 - openjdk11

Datei anzeigen

@ -9,26 +9,27 @@ import java.util.Map;
@Getter @Getter
@AllArgsConstructor @AllArgsConstructor
public enum BlockFace { public enum BlockFace {
NORTH(0, 0, -1, EnumAxis.Z), SOUTH(0, 0, 1, EnumAxis.Z), EAST(1, 0, 0, EnumAxis.X), WEST(-1, 0, 0, EnumAxis.X), TOP(0, 1, 0, EnumAxis.Y), BOTTOM(0, -1, 0, EnumAxis.Y); NORTH(0, 0, -1, EnumAxis.Z), SOUTH(0, 0, 1, EnumAxis.Z), EAST(1, 0, 0, EnumAxis.X), WEST(-1, 0, 0, EnumAxis.X), TOP(0, 1, 0, EnumAxis.Y), BOTTOM(0, -1, 0, EnumAxis.Y);
private static Map<BlockFace, BlockFace> opposites = new HashMap<>(); private static Map<BlockFace, BlockFace> opposites = new HashMap<>();
static {
opposites.put(BlockFace.NORTH, BlockFace.SOUTH);
opposites.put(BlockFace.SOUTH, BlockFace.NORTH);
opposites.put(BlockFace.EAST, BlockFace.WEST);
opposites.put(BlockFace.WEST, BlockFace.EAST);
opposites.put(BlockFace.TOP, BlockFace.BOTTOM);
opposites.put(BlockFace.BOTTOM, BlockFace.TOP);
}
private int modX, modY, modZ; static {
private EnumAxis axis; opposites.put(BlockFace.NORTH, BlockFace.SOUTH);
opposites.put(BlockFace.SOUTH, BlockFace.NORTH);
opposites.put(BlockFace.EAST, BlockFace.WEST);
opposites.put(BlockFace.WEST, BlockFace.EAST);
opposites.put(BlockFace.TOP, BlockFace.BOTTOM);
opposites.put(BlockFace.BOTTOM, BlockFace.TOP);
}
public BlockFace opposite() { private int modX, modY, modZ;
return opposites.get(this); private EnumAxis axis;
}
public enum EnumAxis { public BlockFace opposite() {
X, Y, Z; return opposites.get(this);
} }
public enum EnumAxis {
X, Y, Z;
}
} }

Datei anzeigen

@ -9,13 +9,13 @@ import java.util.List;
@AllArgsConstructor @AllArgsConstructor
@Data @Data
public class BaseChunk implements Chunk { public class BaseChunk implements Chunk {
protected int x; protected int x;
protected int z; protected int z;
protected boolean groundUp; protected boolean groundUp;
protected int bitmask; protected int bitmask;
protected ChunkSection[] sections; protected ChunkSection[] sections;
protected int[] biomeData; protected int[] biomeData;
protected List<CompoundTag> blockEntities; protected List<CompoundTag> blockEntities;
@Override @Override
public boolean isBiomeData() { public boolean isBiomeData() {

Datei anzeigen

@ -98,22 +98,22 @@ public class ChunkSection {
} }
public void replacePaletteEntry(int oldId, int newId) { public void replacePaletteEntry(int oldId, int newId) {
Integer index = inversePalette.remove(oldId); Integer index = inversePalette.remove(oldId);
if (index == null) return; if (index == null) return;
inversePalette.put(newId, index); inversePalette.put(newId, index);
for (int i = 0; i < palette.size(); i++) { for (int i = 0; i < palette.size(); i++) {
if (palette.get(i) == oldId) palette.set(i, newId); if (palette.get(i) == oldId) palette.set(i, newId);
} }
} }
public void addPaletteEntry(int id) { public void addPaletteEntry(int id) {
inversePalette.put(id, palette.size()); inversePalette.put(id, palette.size());
palette.add(id); palette.add(id);
} }
public void clearPalette() { public void clearPalette() {
palette.clear(); palette.clear();
inversePalette.clear(); inversePalette.clear();
} }
/** /**
@ -124,14 +124,14 @@ public class ChunkSection {
* @param id The raw or flat id of the block * @param id The raw or flat id of the block
*/ */
public void setFlatBlock(int idx, int id) { public void setFlatBlock(int idx, int id) {
Integer index = inversePalette.get(id); Integer index = inversePalette.get(id);
if (index == null) { if (index == null) {
index = palette.size(); index = palette.size();
palette.add(id); palette.add(id);
inversePalette.put(id, index); inversePalette.put(id, index);
} }
blocks[idx] = index; blocks[idx] = index;
} }
/** /**

Datei anzeigen

@ -22,13 +22,13 @@ public class Protocol1_13_2To1_13_1 extends Protocol {
WorldPackets.register(this); WorldPackets.register(this);
EntityPackets.register(this); EntityPackets.register(this);
//Edit Book //Edit Book
registerIncoming(State.PLAY, 0x0B, 0x0B, new PacketRemapper() { registerIncoming(State.PLAY, 0x0B, 0x0B, new PacketRemapper() {
@Override @Override
public void registerMap() { public void registerMap() {
map(Type.FLAT_VAR_INT_ITEM, Type.FLAT_ITEM); map(Type.FLAT_VAR_INT_ITEM, Type.FLAT_ITEM);
} }
}); });
// Advancements // Advancements
registerOutgoing(State.PLAY, 0x51, 0x51, new PacketRemapper() { registerOutgoing(State.PLAY, 0x51, 0x51, new PacketRemapper() {

Datei anzeigen

@ -16,7 +16,7 @@ public abstract class AbstractFenceConnectionHandler extends ConnectionHandler {
private Set<Integer> blockStates = new HashSet<>(); private Set<Integer> blockStates = new HashSet<>();
private Map<Byte, Integer> connectedBlockStates = new HashMap<>(); private Map<Byte, Integer> connectedBlockStates = new HashMap<>();
public AbstractFenceConnectionHandler(String blockConnections, String key){ public AbstractFenceConnectionHandler(String blockConnections, String key) {
this.blockConnections = blockConnections; this.blockConnections = blockConnections;
for (Map.Entry<String, Integer> blockState : ConnectionData.keyToId.entrySet()) { for (Map.Entry<String, Integer> blockState : ConnectionData.keyToId.entrySet()) {

Datei anzeigen

@ -8,11 +8,11 @@ import java.util.Map;
public class BlockData { public class BlockData {
private Map<String, Boolean[]> connectData = new HashMap<>(); private 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);
} }
public boolean connectsTo(String blockConnection, BlockFace face){ public boolean connectsTo(String blockConnection, BlockFace face) {
final Boolean[] booleans = connectData.get(blockConnection); final Boolean[] booleans = connectData.get(blockConnection);
return booleans != null && booleans[face.ordinal()]; return booleans != null && booleans[face.ordinal()];
} }

Datei anzeigen

@ -10,52 +10,52 @@ import java.util.Map;
import java.util.Set; import java.util.Set;
class ChestConnectionHandler extends ConnectionHandler { class ChestConnectionHandler extends ConnectionHandler {
private static Map<Integer, BlockFace> chestFacings = new HashMap<>(); private static Map<Integer, BlockFace> chestFacings = new HashMap<>();
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 void init() {
ChestConnectionHandler connectionHandler = new ChestConnectionHandler(); ChestConnectionHandler connectionHandler = new ChestConnectionHandler();
for (Map.Entry<String, Integer> blockState : ConnectionData.keyToId.entrySet()) { for (Map.Entry<String, Integer> blockState : ConnectionData.keyToId.entrySet()) {
String key = blockState.getKey().split("\\[")[0]; String key = blockState.getKey().split("\\[")[0];
if (!key.equals("minecraft:chest") && !key.equals("minecraft:trapped_chest")) continue; if (!key.equals("minecraft:chest") && !key.equals("minecraft:trapped_chest")) continue;
WrappedBlockData blockData = WrappedBlockData.fromString(blockState.getKey()); WrappedBlockData blockData = WrappedBlockData.fromString(blockState.getKey());
if (blockData.getValue("waterlogged").equals("true")) continue; if (blockData.getValue("waterlogged").equals("true")) continue;
chestFacings.put(blockState.getValue(), BlockFace.valueOf(blockData.getValue("facing").toUpperCase())); chestFacings.put(blockState.getValue(), BlockFace.valueOf(blockData.getValue("facing").toUpperCase()));
if (key.equalsIgnoreCase("minecraft:trapped_chest")) trappedChests.add(blockState.getValue()); if (key.equalsIgnoreCase("minecraft:trapped_chest")) trappedChests.add(blockState.getValue());
connectedStates.put(getStates(blockData), blockState.getValue()); connectedStates.put(getStates(blockData), blockState.getValue());
ConnectionData.connectionHandlerMap.put(blockState.getValue(), connectionHandler); ConnectionData.connectionHandlerMap.put(blockState.getValue(), connectionHandler);
} }
} }
private static Byte getStates(WrappedBlockData blockData) { private static Byte getStates(WrappedBlockData blockData) {
byte states = 0; byte states = 0;
String type = blockData.getValue("type"); String type = blockData.getValue("type");
if (type.equals("left")) states |= 1; if (type.equals("left")) states |= 1;
if (type.equals("right")) states |= 2; if (type.equals("right")) states |= 2;
states |= (BlockFace.valueOf(blockData.getValue("facing").toUpperCase()).ordinal() << 2); states |= (BlockFace.valueOf(blockData.getValue("facing").toUpperCase()).ordinal() << 2);
if (blockData.getMinecraftKey().equals("minecraft:trapped_chest")) states |= 16; if (blockData.getMinecraftKey().equals("minecraft:trapped_chest")) states |= 16;
return states; return states;
} }
@Override @Override
public int connect(UserConnection user, Position position, int blockState) { public int connect(UserConnection user, Position position, int blockState) {
BlockFace facing = chestFacings.get(blockState); BlockFace facing = chestFacings.get(blockState);
byte states = 0; byte states = 0;
states |= (facing.ordinal() << 2); states |= (facing.ordinal() << 2);
boolean trapped = trappedChests.contains(blockState); boolean trapped = trappedChests.contains(blockState);
if (trapped) states |= 16; if (trapped) states |= 16;
int relative; int relative;
if (chestFacings.containsKey(relative = getBlockData(user, position.getRelative(BlockFace.NORTH))) && trapped == trappedChests.contains(relative)) { if (chestFacings.containsKey(relative = getBlockData(user, position.getRelative(BlockFace.NORTH))) && trapped == trappedChests.contains(relative)) {
states |= facing == BlockFace.WEST ? 1 : 2; states |= facing == BlockFace.WEST ? 1 : 2;
} else if (chestFacings.containsKey(relative = getBlockData(user, position.getRelative(BlockFace.SOUTH))) && trapped == trappedChests.contains(relative)) { } else if (chestFacings.containsKey(relative = getBlockData(user, position.getRelative(BlockFace.SOUTH))) && trapped == trappedChests.contains(relative)) {
states |= facing == BlockFace.EAST ? 1 : 2; states |= facing == BlockFace.EAST ? 1 : 2;
} else if (chestFacings.containsKey(relative = getBlockData(user, position.getRelative(BlockFace.WEST))) && trapped == trappedChests.contains(relative)) { } else if (chestFacings.containsKey(relative = getBlockData(user, position.getRelative(BlockFace.WEST))) && trapped == trappedChests.contains(relative)) {
states |= facing == BlockFace.NORTH ? 2 : 1; states |= facing == BlockFace.NORTH ? 2 : 1;
} else if (chestFacings.containsKey(relative = getBlockData(user, position.getRelative(BlockFace.EAST))) && trapped == trappedChests.contains(relative)) { } else if (chestFacings.containsKey(relative = getBlockData(user, position.getRelative(BlockFace.EAST))) && trapped == trappedChests.contains(relative)) {
states |= facing == BlockFace.SOUTH ? 2 : 1; states |= facing == BlockFace.SOUTH ? 2 : 1;
} }
Integer newBlockState = connectedStates.get(states); Integer newBlockState = connectedStates.get(states);
return newBlockState == null ? blockState : newBlockState; return newBlockState == null ? blockState : newBlockState;
} }
} }

Datei anzeigen

@ -8,12 +8,12 @@ import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.blockconnections.provi
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); return Via.getManager().getProviders().get(BlockConnectionProvider.class).getBlockdata(user, position);
} }
public boolean canConnect(int id) { public boolean canConnect(int id) {
ConnectionHandler handler = ConnectionData.connectionHandlerMap.get(id); ConnectionHandler handler = ConnectionData.connectionHandlerMap.get(id);
return handler != null && handler == this; return handler != null && handler == this;
} }
} }

Datei anzeigen

@ -39,11 +39,15 @@ public class RedstoneConnectionHandler extends ConnectionHandler {
} }
private static int getState(String value) { private static int getState(String value) {
switch (value){ switch (value) {
case "none": return 0; case "none":
case "side" : return 1; return 0;
case "up" : return 2; case "side":
default: return 0; return 1;
case "up":
return 2;
default:
return 0;
} }
} }

Datei anzeigen

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

Datei anzeigen

@ -5,8 +5,8 @@ import us.myles.ViaVersion.api.minecraft.BlockFace;
import us.myles.ViaVersion.api.minecraft.Position; import us.myles.ViaVersion.api.minecraft.Position;
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 void init() {
new WallConnectionHandler("cobbleWallConnections", "minecraft:cobblestone_wall"); new WallConnectionHandler("cobbleWallConnections", "minecraft:cobblestone_wall");
@ -32,7 +32,8 @@ public class WallConnectionHandler extends AbstractFenceConnectionHandler {
} }
public boolean up(UserConnection user, Position position) { public boolean up(UserConnection user, Position position) {
if(isWall(getBlockData(user, position.getRelative(BlockFace.BOTTOM))) || isWall(getBlockData(user, position.getRelative(BlockFace.TOP))))return true; if (isWall(getBlockData(user, position.getRelative(BlockFace.BOTTOM))) || isWall(getBlockData(user, position.getRelative(BlockFace.TOP))))
return true;
int blockFaces = getBlockFaces(user, position); int blockFaces = getBlockFaces(user, position);
if (blockFaces == 0 || blockFaces == 0xF) return true; if (blockFaces == 0 || blockFaces == 0xF) return true;
for (int i = 0; i < BLOCK_FACES.length; i++) { for (int i = 0; i < BLOCK_FACES.length; i++) {
@ -51,7 +52,7 @@ public class WallConnectionHandler extends AbstractFenceConnectionHandler {
return blockFaces; return blockFaces;
} }
private boolean isWall(int id){ private boolean isWall(int id) {
return getBlockStates().contains(id); return getBlockStates().contains(id);
} }
} }

Datei anzeigen

@ -16,19 +16,27 @@ public class BlockConnectionProvider implements Provider {
return -1; return -1;
} }
public void storeBlock(UserConnection connection, Position position, int blockState) {}; public void storeBlock(UserConnection connection, Position position, int blockState) {
public void removeBlock(UserConnection connection, Position position) {}; }
public void removeBlock(UserConnection connection, Position position) {
}
public void storeBlock(UserConnection connection, long x, long y, long z, int blockState) { public void storeBlock(UserConnection connection, long x, long y, long z, int blockState) {
storeBlock(connection, new Position(x, y, z), blockState); storeBlock(connection, new Position(x, y, z), blockState);
} }
public void clearStorage(UserConnection connection) {}; public void clearStorage(UserConnection connection) {
public void unloadChunk(UserConnection connection, int x, int z) {}; }
public boolean storesBlocks(){ public void unloadChunk(UserConnection connection, int x, int z) {
}
public boolean storesBlocks() {
return false; return false;
} }
} }

Datei anzeigen

@ -243,7 +243,7 @@ public class WorldPackets {
protocol.registerOutgoing(State.PLAY, 0x1D, 0x1F, new PacketRemapper() { protocol.registerOutgoing(State.PLAY, 0x1D, 0x1F, new PacketRemapper() {
@Override @Override
public void registerMap() { public void registerMap() {
if(Via.getConfig().isServersideBlockConnections()){ if (Via.getConfig().isServersideBlockConnections()) {
handler(new PacketHandler() { handler(new PacketHandler() {
@Override @Override
public void handle(PacketWrapper wrapper) throws Exception { public void handle(PacketWrapper wrapper) throws Exception {

Datei anzeigen

@ -34,29 +34,29 @@ public class BlockConnectionStorage extends StoredObject {
Pair pair = getPair(position); Pair pair = getPair(position);
Map<BlockPositon, Integer> map = getChunkMap(pair); Map<BlockPositon, Integer> map = getChunkMap(pair);
map.remove(new BlockPositon(position)); map.remove(new BlockPositon(position));
if(map.isEmpty()){ if (map.isEmpty()) {
blockStorage.remove(pair); blockStorage.remove(pair);
} }
} }
public void clear(){ public void clear() {
blockStorage.clear(); blockStorage.clear();
} }
public void unloadChunk(int x, int z){ public void unloadChunk(int x, int z) {
blockStorage.remove(new Pair<>(x, z)); blockStorage.remove(new Pair<>(x, z));
} }
private Map<BlockPositon, Integer> getChunkMap(Pair pair){ private Map<BlockPositon, Integer> getChunkMap(Pair pair) {
Map<BlockPositon, Integer> map = blockStorage.get(pair); Map<BlockPositon, Integer> map = blockStorage.get(pair);
if(map == null){ if (map == null) {
map = new HashMap<>(); map = new HashMap<>();
blockStorage.put(pair, map); blockStorage.put(pair, map);
} }
return map; return map;
} }
private Pair<Integer, Integer> getPair(Position position){ private Pair<Integer, Integer> getPair(Position position) {
int chunkX = (int) (position.getX() >> 4); int chunkX = (int) (position.getX() >> 4);
int chunkZ = (int) (position.getZ() >> 4); int chunkZ = (int) (position.getZ() >> 4);
return new Pair<>(chunkX, chunkZ); return new Pair<>(chunkX, chunkZ);
@ -65,8 +65,9 @@ public class BlockConnectionStorage extends StoredObject {
@EqualsAndHashCode @EqualsAndHashCode
@Data @Data
private class BlockPositon { private class BlockPositon {
int x,y,z; int x, y, z;
public BlockPositon(Position position){
public BlockPositon(Position position) {
x = position.getX().intValue(); x = position.getX().intValue();
y = position.getY().intValue(); y = position.getY().intValue();
z = position.getZ().intValue(); z = position.getZ().intValue();

Datei anzeigen

@ -122,8 +122,8 @@ public class WorldPackets {
@Override @Override
public void handle(PacketWrapper wrapper) throws Exception { public void handle(PacketWrapper wrapper) throws Exception {
ClientChunks clientChunks = wrapper.user().get(ClientChunks.class); ClientChunks clientChunks = wrapper.user().get(ClientChunks.class);
Chunk1_9to1_8Type type = new Chunk1_9to1_8Type(clientChunks); Chunk1_9to1_8Type type = new Chunk1_9to1_8Type(clientChunks);
Chunk1_8 chunk = (Chunk1_8) wrapper.read(type); Chunk1_8 chunk = (Chunk1_8) wrapper.read(type);
if (chunk.isUnloadPacket()) { if (chunk.isUnloadPacket()) {
wrapper.setId(0x1D); wrapper.setId(0x1D);
@ -313,7 +313,7 @@ public class WorldPackets {
if (Via.getConfig().isShieldBlocking()) { if (Via.getConfig().isShieldBlocking()) {
EntityTracker tracker = wrapper.user().get(EntityTracker.class); EntityTracker tracker = wrapper.user().get(EntityTracker.class);
if (item != null && Protocol1_9TO1_8.isSword(item.getIdentifier())) { if (item != null && Protocol1_9TO1_8.isSword(item.getId())) {
if (hand == 0) { if (hand == 0) {
if (!tracker.isBlocking()) { if (!tracker.isBlocking()) {
tracker.setBlocking(true); tracker.setBlocking(true);

Datei anzeigen

@ -113,7 +113,7 @@ public class Chunk1_9to1_8Type extends PartialType<Chunk, ClientChunks> {
// Read biome data // Read biome data
if (bytesLeft >= BIOME_DATA_LENGTH) { if (bytesLeft >= BIOME_DATA_LENGTH) {
biomeData = new int[BIOME_DATA_LENGTH]; biomeData = new int[BIOME_DATA_LENGTH];
for (int i = 0; i < BIOME_DATA_LENGTH; i++){ for (int i = 0; i < BIOME_DATA_LENGTH; i++) {
biomeData[i] = input.readByte() & 0xFF; biomeData[i] = input.readByte() & 0xFF;
} }
bytesLeft -= BIOME_DATA_LENGTH; bytesLeft -= BIOME_DATA_LENGTH;

Datei anzeigen

@ -24,7 +24,7 @@ public class SpongeBlockConnectionProvider extends BlockConnectionProvider {
try { try {
block = Class.forName("net.minecraft.block.Block"); block = Class.forName("net.minecraft.block.Block");
blockStateIds = ReflectionUtil.get( blockStateIds = ReflectionUtil.get(
ReflectionUtil.getStatic(block, "field_176229_d", Object.class), ReflectionUtil.getStatic(block, "field_176229_d", Object.class),
"field_148749_a", Map.class); "field_148749_a", Map.class);
} catch (ClassNotFoundException e) { } catch (ClassNotFoundException e) {
Via.getPlatform().getLogger().warning("net.minecraft.block.Block not found! Are you using Lantern?"); Via.getPlatform().getLogger().warning("net.minecraft.block.Block not found! Are you using Lantern?");

Datei anzeigen

@ -53,8 +53,8 @@ public class VelocityServerHandler {
// Check if ViaVersion can support that version // Check if ViaVersion can support that version
Object connection = ReflectionUtil.invoke(e.getPlayer(), "getConnection"); Object connection = ReflectionUtil.invoke(e.getPlayer(), "getConnection");
setNextProtocolVersion.invoke(connection, ProtocolVersion.getProtocolVersion(protocols == null setNextProtocolVersion.invoke(connection, ProtocolVersion.getProtocolVersion(protocols == null
? user.get(ProtocolInfo.class).getProtocolVersion() ? user.get(ProtocolInfo.class).getProtocolVersion()
: protocolId)); : protocolId));
} catch (IllegalAccessException | NoSuchMethodException | InvocationTargetException e1) { } catch (IllegalAccessException | NoSuchMethodException | InvocationTargetException e1) {
e1.printStackTrace(); e1.printStackTrace();
@ -133,7 +133,7 @@ public class VelocityServerHandler {
} }
Object connection = ReflectionUtil.invoke(e.getPlayer(), "getConnection"); Object connection = ReflectionUtil.invoke(e.getPlayer(), "getConnection");
ProtocolVersion version = (ProtocolVersion) ReflectionUtil.invoke(connection,"getNextProtocolVersion"); ProtocolVersion version = (ProtocolVersion) ReflectionUtil.invoke(connection, "getNextProtocolVersion");
setProtocolVersion.invoke(connection, version); setProtocolVersion.invoke(connection, version);
} }
} }

Datei anzeigen

@ -56,21 +56,21 @@ public class ProtocolDetectorService implements Runnable {
public static void probeServer(final RegisteredServer serverInfo) { public static void probeServer(final RegisteredServer serverInfo) {
final String key = serverInfo.getServerInfo().getName(); final String key = serverInfo.getServerInfo().getName();
serverInfo.ping().thenAccept((serverPing) -> { serverInfo.ping().thenAccept((serverPing) -> {
if (serverPing != null && serverPing.getVersion() != null) { if (serverPing != null && serverPing.getVersion() != null) {
detectedProtocolIds.put(key, serverPing.getVersion().getProtocol()); detectedProtocolIds.put(key, serverPing.getVersion().getProtocol());
if (((VelocityViaConfig) Via.getConfig()).isVelocityPingSave()) { if (((VelocityViaConfig) Via.getConfig()).isVelocityPingSave()) {
Map<String, Integer> servers = ((VelocityViaConfig) Via.getConfig()).getVelocityServerProtocols(); Map<String, Integer> servers = ((VelocityViaConfig) Via.getConfig()).getVelocityServerProtocols();
Integer protocol = servers.get(key); Integer protocol = servers.get(key);
if (protocol != null && protocol == serverPing.getVersion().getProtocol()) { if (protocol != null && protocol == serverPing.getVersion().getProtocol()) {
return; return;
}
// Ensure we're the only ones writing to the config
synchronized (Via.getPlatform().getConfigurationProvider()) {
servers.put(key, serverPing.getVersion().getProtocol());
}
// Save
Via.getPlatform().getConfigurationProvider().saveConfig();
} }
// Ensure we're the only ones writing to the config
synchronized (Via.getPlatform().getConfigurationProvider()) {
servers.put(key, serverPing.getVersion().getProtocol());
}
// Save
Via.getPlatform().getConfigurationProvider().saveConfig();
}
} }
}); });
} }