Skip to content

Commit

Permalink
Merge pull request #1239 from SamB440/fix/legacy-side-connections
Browse files Browse the repository at this point in the history
Fix incorrect connecting block handling (legacy versions)
  • Loading branch information
AoElite authored Dec 19, 2023
2 parents ce83748 + d91b920 commit 649245a
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package ac.grim.grimac.utils.collisions.blocks.connecting;

import ac.grim.grimac.player.GrimPlayer;
import ac.grim.grimac.utils.collisions.datatypes.*;
import ac.grim.grimac.utils.collisions.datatypes.CollisionBox;
import ac.grim.grimac.utils.collisions.datatypes.ComplexCollisionBox;
import ac.grim.grimac.utils.collisions.datatypes.HexCollisionBox;
import ac.grim.grimac.utils.collisions.datatypes.NoCollisionBox;
import ac.grim.grimac.utils.collisions.datatypes.SimpleCollisionBox;
import ac.grim.grimac.utils.nmsutil.Materials;
import com.github.retrooper.packetevents.PacketEvents;
import com.github.retrooper.packetevents.manager.server.ServerVersion;
Expand Down Expand Up @@ -76,7 +80,7 @@ public boolean connectsTo(GrimPlayer player, ClientVersion v, int currX, int cur
} else {
if (fence == target) return true;

return checkCanConnect(player, targetBlock, target, fence);
return checkCanConnect(player, targetBlock, target, fence, direction);
}
}

Expand All @@ -85,7 +89,7 @@ boolean isBlacklisted(StateType m, StateType fence, ClientVersion clientVersion)
if (BlockTags.SHULKER_BOXES.contains(m)) return true;
if (BlockTags.TRAPDOORS.contains(m)) return true;

return m == StateTypes.CARVED_PUMPKIN || m == StateTypes.JACK_O_LANTERN || m == StateTypes.PUMPKIN || m == StateTypes.MELON ||
return m == StateTypes.ENCHANTING_TABLE || m == StateTypes.CARVED_PUMPKIN || m == StateTypes.JACK_O_LANTERN || m == StateTypes.PUMPKIN || m == StateTypes.MELON ||
m == StateTypes.BEACON || BlockTags.CAULDRONS.contains(m) || m == StateTypes.GLOWSTONE || m == StateTypes.SEA_LANTERN || m == StateTypes.ICE
|| m == StateTypes.PISTON || m == StateTypes.STICKY_PISTON || m == StateTypes.PISTON_HEAD || (!canConnectToGlassBlock()
&& BlockTags.GLASS_BLOCKS.contains(m));
Expand Down Expand Up @@ -113,7 +117,7 @@ protected int getAABBIndex(boolean north, boolean east, boolean south, boolean w
return i;
}

public boolean checkCanConnect(GrimPlayer player, WrappedBlockState state, StateType one, StateType two) {
public boolean checkCanConnect(GrimPlayer player, WrappedBlockState state, StateType one, StateType two, BlockFace direction) {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ public class DynamicFence extends DynamicConnecting implements CollisionFactory

public static SimpleCollisionBox[] LEGACY_BOUNDING_BOXES = new SimpleCollisionBox[] {new SimpleCollisionBox(0.375D, 0.0D, 0.375D, 0.625D, 1.0D, 0.625D), new SimpleCollisionBox(0.375D, 0.0D, 0.375D, 0.625D, 1.0D, 1.0D), new SimpleCollisionBox(0.0D, 0.0D, 0.375D, 0.625D, 1.0D, 0.625D), new SimpleCollisionBox(0.0D, 0.0D, 0.375D, 0.625D, 1.0D, 1.0D), new SimpleCollisionBox(0.375D, 0.0D, 0.0D, 0.625D, 1.0D, 0.625D), new SimpleCollisionBox(0.375D, 0.0D, 0.0D, 0.625D, 1.0D, 1.0D), new SimpleCollisionBox(0.0D, 0.0D, 0.0D, 0.625D, 1.0D, 0.625D), new SimpleCollisionBox(0.0D, 0.0D, 0.0D, 0.625D, 1.0D, 1.0D), new SimpleCollisionBox(0.375D, 0.0D, 0.375D, 1.0D, 1.0D, 0.625D), new SimpleCollisionBox(0.375D, 0.0D, 0.375D, 1.0D, 1.0D, 1.0D), new SimpleCollisionBox(0.0D, 0.0D, 0.375D, 1.0D, 1.0D, 0.625D), new SimpleCollisionBox(0.0D, 0.0D, 0.375D, 1.0D, 1.0D, 1.0D), new SimpleCollisionBox(0.375D, 0.0D, 0.0D, 1.0D, 1.0D, 0.625D), new SimpleCollisionBox(0.375D, 0.0D, 0.0D, 1.0D, 1.0D, 1.0D), new SimpleCollisionBox(0.0D, 0.0D, 0.0D, 1.0D, 1.0D, 0.625D), new SimpleCollisionBox(0.0D, 0.0D, 0.0D, 1.0D, 1.0D, 1.0D)};


@Override
public CollisionBox fetch(GrimPlayer player, ClientVersion version, WrappedBlockState block, int x, int y, int z) {
boolean east;
Expand All @@ -49,10 +48,10 @@ public CollisionBox fetch(GrimPlayer player, ClientVersion version, WrappedBlock
}

@Override
public boolean checkCanConnect(GrimPlayer player, WrappedBlockState state, StateType one, StateType two) {
public boolean checkCanConnect(GrimPlayer player, WrappedBlockState state, StateType one, StateType two, BlockFace direction) {
if (BlockTags.FENCES.contains(one))
return !(one == StateTypes.NETHER_BRICK_FENCE) && !(two == StateTypes.NETHER_BRICK_FENCE);
else
return BlockTags.FENCES.contains(one) || CollisionData.getData(one).getMovementCollisionBox(player, player.getClientVersion(), state, 0, 0, 0).isFullBlock();
return BlockTags.FENCES.contains(one) || CollisionData.getData(one).getMovementCollisionBox(player, player.getClientVersion(), state, 0, 0, 0).isSideFullBlock(direction);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,11 @@ public boolean canConnectToGlassBlock() {
return true;
}


@Override
public boolean checkCanConnect(GrimPlayer player, WrappedBlockState state, StateType one, StateType two) {
public boolean checkCanConnect(GrimPlayer player, WrappedBlockState state, StateType one, StateType two, BlockFace direction) {
if (BlockTags.GLASS_PANES.contains(one) || one == StateTypes.IRON_BARS)
return true;
else
return CollisionData.getData(one).getMovementCollisionBox(player, player.getClientVersion(), state, 0, 0, 0).isFullBlock();
return CollisionData.getData(one).getMovementCollisionBox(player, player.getClientVersion(), state, 0, 0, 0).isSideFullBlock(direction);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.github.retrooper.packetevents.protocol.world.states.enums.South;
import com.github.retrooper.packetevents.protocol.world.states.enums.West;
import com.github.retrooper.packetevents.protocol.world.states.type.StateType;
import com.github.retrooper.packetevents.protocol.world.states.type.StateTypes;

public class DynamicWall extends DynamicConnecting implements CollisionFactory {
public static final CollisionBox[] BOXES = makeShapes(4.0F, 3.0F, 16.0F, 0.0F, 16.0F, false);
Expand Down Expand Up @@ -181,7 +182,7 @@ public CollisionBox fetch(GrimPlayer player, ClientVersion version, WrappedBlock
}

@Override
public boolean checkCanConnect(GrimPlayer player, WrappedBlockState state, StateType one, StateType two) {
return BlockTags.WALLS.contains(one) || CollisionData.getData(one).getMovementCollisionBox(player, player.getClientVersion(), state, 0, 0, 0).isFullBlock();
public boolean checkCanConnect(GrimPlayer player, WrappedBlockState state, StateType one, StateType two, BlockFace direction) {
return BlockTags.WALLS.contains(one) || CollisionData.getData(one).getMovementCollisionBox(player, player.getClientVersion(), state, 0, 0, 0).isSideFullBlock(direction);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package ac.grim.grimac.utils.collisions.datatypes;

import com.github.retrooper.packetevents.protocol.world.BlockFace;

import java.util.List;

public interface CollisionBox {
Expand All @@ -16,4 +18,8 @@ public interface CollisionBox {
boolean isNull();

boolean isFullBlock();

default boolean isSideFullBlock(BlockFace axis) {
return isFullBlock();
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ac.grim.grimac.utils.collisions.datatypes;

import ac.grim.grimac.utils.nmsutil.Ray;
import com.github.retrooper.packetevents.protocol.world.BlockFace;
import com.github.retrooper.packetevents.util.Vector3d;
import com.github.retrooper.packetevents.util.Vector3i;
import org.bukkit.Location;
Expand Down Expand Up @@ -240,6 +241,29 @@ public boolean isFullBlock() {
return isFullBlock;
}

@Override
public boolean isSideFullBlock(BlockFace axis) {
if (isFullBlock) {
return true;
}

// Get the direction of block we are trying to connect to -> towards the block that is trying to connect
final BlockFace faceToSourceConnector = axis.getOppositeFace();
switch (faceToSourceConnector) {
case EAST:
case WEST:
return this.minX == 0 && this.maxX == 1;
case UP:
case DOWN:
return this.minY == 0 && this.maxY == 1;
case NORTH:
case SOUTH:
return this.minZ == 0 && this.maxZ == 1;
}

return false;
}

public boolean isFullBlockNoCache() {
return minX == 0 && minY == 0 && minZ == 0 && maxX == 1 && maxY == 1 && maxZ == 1;
}
Expand Down

0 comments on commit 649245a

Please sign in to comment.