Merge branch 'master' into dev

This commit is contained in:
Myles 2018-12-05 19:10:52 +00:00
commit 7e8e3fef61
20 changed files with 229 additions and 214 deletions

View File

@ -12,6 +12,7 @@ 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 { static {
opposites.put(BlockFace.NORTH, BlockFace.SOUTH); opposites.put(BlockFace.NORTH, BlockFace.SOUTH);
opposites.put(BlockFace.SOUTH, BlockFace.NORTH); opposites.put(BlockFace.SOUTH, BlockFace.NORTH);

View File

@ -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()) {

View File

@ -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()];
} }

View File

@ -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;
} }
} }

View File

@ -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);
} }
} }

View File

@ -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;
} }
} }

View File

@ -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 {

View File

@ -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();

View File

@ -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);

View File

@ -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;

View File

@ -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);
} }
} }