Improve hitbox checking
This commit is contained in:
@@ -5,6 +5,7 @@ import com.raoulvdberge.refinedstorage.container.ConstructorContainer;
|
||||
import com.raoulvdberge.refinedstorage.container.factory.PositionalTileContainerProvider;
|
||||
import com.raoulvdberge.refinedstorage.tile.ConstructorTile;
|
||||
import com.raoulvdberge.refinedstorage.util.BlockUtils;
|
||||
import com.raoulvdberge.refinedstorage.util.CollisionUtils;
|
||||
import com.raoulvdberge.refinedstorage.util.NetworkUtils;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
@@ -54,41 +55,45 @@ public class ConstructorBlock extends CableBlock {
|
||||
public VoxelShape getShape(BlockState state, IBlockReader world, BlockPos pos, ISelectionContext ctx) {
|
||||
VoxelShape shape = super.getShape(state, world, pos, ctx);
|
||||
|
||||
Direction direction = state.get(getDirection().getProperty());
|
||||
|
||||
if (direction == Direction.NORTH) {
|
||||
shape = VoxelShapes.or(shape, HEAD_NORTH);
|
||||
}
|
||||
|
||||
if (direction == Direction.EAST) {
|
||||
shape = VoxelShapes.or(shape, HEAD_EAST);
|
||||
}
|
||||
|
||||
if (direction == Direction.SOUTH) {
|
||||
shape = VoxelShapes.or(shape, HEAD_SOUTH);
|
||||
}
|
||||
|
||||
if (direction == Direction.WEST) {
|
||||
shape = VoxelShapes.or(shape, HEAD_WEST);
|
||||
}
|
||||
|
||||
if (direction == Direction.UP) {
|
||||
shape = VoxelShapes.or(shape, HEAD_UP);
|
||||
}
|
||||
|
||||
if (direction == Direction.DOWN) {
|
||||
shape = VoxelShapes.or(shape, HEAD_DOWN);
|
||||
}
|
||||
shape = VoxelShapes.or(shape, getHeadShape(state));
|
||||
|
||||
return shape;
|
||||
}
|
||||
|
||||
private VoxelShape getHeadShape(BlockState state) {
|
||||
Direction direction = state.get(getDirection().getProperty());
|
||||
|
||||
if (direction == Direction.NORTH) {
|
||||
return HEAD_NORTH;
|
||||
}
|
||||
|
||||
if (direction == Direction.EAST) {
|
||||
return HEAD_EAST;
|
||||
}
|
||||
|
||||
if (direction == Direction.SOUTH) {
|
||||
return HEAD_SOUTH;
|
||||
}
|
||||
|
||||
if (direction == Direction.WEST) {
|
||||
return HEAD_WEST;
|
||||
}
|
||||
|
||||
if (direction == Direction.UP) {
|
||||
return HEAD_UP;
|
||||
}
|
||||
|
||||
if (direction == Direction.DOWN) {
|
||||
return HEAD_DOWN;
|
||||
}
|
||||
|
||||
return VoxelShapes.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("deprecation")
|
||||
public ActionResultType onBlockActivated(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand handIn, BlockRayTraceResult hit) {
|
||||
if (!world.isRemote) {
|
||||
public ActionResultType onBlockActivated(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockRayTraceResult hit) {
|
||||
if (!world.isRemote && CollisionUtils.isInBounds(getHeadShape(state), pos, hit.getHitVec())) {
|
||||
return NetworkUtils.attemptModify(world, pos, hit.getFace(), player, () -> NetworkHooks.openGui(
|
||||
(ServerPlayerEntity) player,
|
||||
new PositionalTileContainerProvider<ConstructorTile>(
|
||||
|
@@ -5,6 +5,7 @@ import com.raoulvdberge.refinedstorage.container.DestructorContainer;
|
||||
import com.raoulvdberge.refinedstorage.container.factory.PositionalTileContainerProvider;
|
||||
import com.raoulvdberge.refinedstorage.tile.DestructorTile;
|
||||
import com.raoulvdberge.refinedstorage.util.BlockUtils;
|
||||
import com.raoulvdberge.refinedstorage.util.CollisionUtils;
|
||||
import com.raoulvdberge.refinedstorage.util.NetworkUtils;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
@@ -54,39 +55,45 @@ public class DestructorBlock extends CableBlock {
|
||||
public VoxelShape getShape(BlockState state, IBlockReader world, BlockPos pos, ISelectionContext ctx) {
|
||||
VoxelShape shape = super.getShape(state, world, pos, ctx);
|
||||
|
||||
shape = VoxelShapes.or(shape, getHeadShape(state));
|
||||
|
||||
return shape;
|
||||
}
|
||||
|
||||
private VoxelShape getHeadShape(BlockState state) {
|
||||
Direction direction = state.get(getDirection().getProperty());
|
||||
|
||||
if (direction == Direction.NORTH) {
|
||||
shape = VoxelShapes.or(shape, HEAD_NORTH);
|
||||
return HEAD_NORTH;
|
||||
}
|
||||
|
||||
if (direction == Direction.EAST) {
|
||||
shape = VoxelShapes.or(shape, HEAD_EAST);
|
||||
return HEAD_EAST;
|
||||
}
|
||||
|
||||
if (direction == Direction.SOUTH) {
|
||||
shape = VoxelShapes.or(shape, HEAD_SOUTH);
|
||||
return HEAD_SOUTH;
|
||||
}
|
||||
|
||||
if (direction == Direction.WEST) {
|
||||
shape = VoxelShapes.or(shape, HEAD_WEST);
|
||||
return HEAD_WEST;
|
||||
}
|
||||
|
||||
if (direction == Direction.UP) {
|
||||
shape = VoxelShapes.or(shape, HEAD_UP);
|
||||
return HEAD_UP;
|
||||
}
|
||||
|
||||
if (direction == Direction.DOWN) {
|
||||
shape = VoxelShapes.or(shape, HEAD_DOWN);
|
||||
return HEAD_DOWN;
|
||||
}
|
||||
|
||||
return shape;
|
||||
return VoxelShapes.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("deprecation")
|
||||
public ActionResultType onBlockActivated(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand handIn, BlockRayTraceResult hit) {
|
||||
if (!world.isRemote) {
|
||||
if (!world.isRemote && CollisionUtils.isInBounds(getHeadShape(state), pos, hit.getHitVec())) {
|
||||
return NetworkUtils.attemptModify(world, pos, hit.getFace(), player, () -> NetworkHooks.openGui(
|
||||
(ServerPlayerEntity) player,
|
||||
new PositionalTileContainerProvider<DestructorTile>(
|
||||
|
@@ -5,6 +5,7 @@ import com.raoulvdberge.refinedstorage.container.ExporterContainer;
|
||||
import com.raoulvdberge.refinedstorage.container.factory.PositionalTileContainerProvider;
|
||||
import com.raoulvdberge.refinedstorage.tile.ExporterTile;
|
||||
import com.raoulvdberge.refinedstorage.util.BlockUtils;
|
||||
import com.raoulvdberge.refinedstorage.util.CollisionUtils;
|
||||
import com.raoulvdberge.refinedstorage.util.NetworkUtils;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
@@ -71,33 +72,39 @@ public class ExporterBlock extends CableBlock {
|
||||
public VoxelShape getShape(BlockState state, IBlockReader world, BlockPos pos, ISelectionContext ctx) {
|
||||
VoxelShape shape = super.getShape(state, world, pos, ctx);
|
||||
|
||||
shape = VoxelShapes.or(shape, getLineShape(state));
|
||||
|
||||
return shape;
|
||||
}
|
||||
|
||||
private VoxelShape getLineShape(BlockState state) {
|
||||
Direction direction = state.get(getDirection().getProperty());
|
||||
|
||||
if (direction == Direction.NORTH) {
|
||||
shape = VoxelShapes.or(shape, LINE_NORTH);
|
||||
return LINE_NORTH;
|
||||
}
|
||||
|
||||
if (direction == Direction.EAST) {
|
||||
shape = VoxelShapes.or(shape, LINE_EAST);
|
||||
return LINE_EAST;
|
||||
}
|
||||
|
||||
if (direction == Direction.SOUTH) {
|
||||
shape = VoxelShapes.or(shape, LINE_SOUTH);
|
||||
return LINE_SOUTH;
|
||||
}
|
||||
|
||||
if (direction == Direction.WEST) {
|
||||
shape = VoxelShapes.or(shape, LINE_WEST);
|
||||
return LINE_WEST;
|
||||
}
|
||||
|
||||
if (direction == Direction.UP) {
|
||||
shape = VoxelShapes.or(shape, LINE_UP);
|
||||
return LINE_UP;
|
||||
}
|
||||
|
||||
if (direction == Direction.DOWN) {
|
||||
shape = VoxelShapes.or(shape, LINE_DOWN);
|
||||
return LINE_DOWN;
|
||||
}
|
||||
|
||||
return shape;
|
||||
return VoxelShapes.empty();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -108,8 +115,8 @@ public class ExporterBlock extends CableBlock {
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("deprecation")
|
||||
public ActionResultType onBlockActivated(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand handIn, BlockRayTraceResult hit) {
|
||||
if (!world.isRemote) {
|
||||
public ActionResultType onBlockActivated(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockRayTraceResult hit) {
|
||||
if (!world.isRemote && CollisionUtils.isInBounds(getLineShape(state), pos, hit.getHitVec())) {
|
||||
return NetworkUtils.attemptModify(world, pos, hit.getFace(), player, () -> NetworkHooks.openGui(
|
||||
(ServerPlayerEntity) player,
|
||||
new PositionalTileContainerProvider<ExporterTile>(
|
||||
|
@@ -7,6 +7,7 @@ import com.raoulvdberge.refinedstorage.container.ExternalStorageContainer;
|
||||
import com.raoulvdberge.refinedstorage.container.factory.PositionalTileContainerProvider;
|
||||
import com.raoulvdberge.refinedstorage.tile.ExternalStorageTile;
|
||||
import com.raoulvdberge.refinedstorage.util.BlockUtils;
|
||||
import com.raoulvdberge.refinedstorage.util.CollisionUtils;
|
||||
import com.raoulvdberge.refinedstorage.util.NetworkUtils;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
@@ -51,33 +52,39 @@ public class ExternalStorageBlock extends CableBlock {
|
||||
public VoxelShape getShape(BlockState state, IBlockReader world, BlockPos pos, ISelectionContext ctx) {
|
||||
VoxelShape shape = super.getShape(state, world, pos, ctx);
|
||||
|
||||
shape = VoxelShapes.or(shape, getHeadShape(state));
|
||||
|
||||
return shape;
|
||||
}
|
||||
|
||||
private VoxelShape getHeadShape(BlockState state) {
|
||||
Direction direction = state.get(getDirection().getProperty());
|
||||
|
||||
if (direction == Direction.NORTH) {
|
||||
shape = VoxelShapes.or(shape, HEAD_NORTH);
|
||||
return HEAD_NORTH;
|
||||
}
|
||||
|
||||
if (direction == Direction.EAST) {
|
||||
shape = VoxelShapes.or(shape, HEAD_EAST);
|
||||
return HEAD_EAST;
|
||||
}
|
||||
|
||||
if (direction == Direction.SOUTH) {
|
||||
shape = VoxelShapes.or(shape, HEAD_SOUTH);
|
||||
return HEAD_SOUTH;
|
||||
}
|
||||
|
||||
if (direction == Direction.WEST) {
|
||||
shape = VoxelShapes.or(shape, HEAD_WEST);
|
||||
return HEAD_WEST;
|
||||
}
|
||||
|
||||
if (direction == Direction.UP) {
|
||||
shape = VoxelShapes.or(shape, HEAD_UP);
|
||||
return HEAD_UP;
|
||||
}
|
||||
|
||||
if (direction == Direction.DOWN) {
|
||||
shape = VoxelShapes.or(shape, HEAD_DOWN);
|
||||
return HEAD_DOWN;
|
||||
}
|
||||
|
||||
return shape;
|
||||
return VoxelShapes.empty();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -88,8 +95,8 @@ public class ExternalStorageBlock extends CableBlock {
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("deprecation")
|
||||
public ActionResultType onBlockActivated(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand handIn, BlockRayTraceResult hit) {
|
||||
if (!world.isRemote) {
|
||||
public ActionResultType onBlockActivated(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockRayTraceResult hit) {
|
||||
if (!world.isRemote && CollisionUtils.isInBounds(getHeadShape(state), pos, hit.getHitVec())) {
|
||||
return NetworkUtils.attemptModify(world, pos, hit.getFace(), player, () -> NetworkHooks.openGui(
|
||||
(ServerPlayerEntity) player,
|
||||
new PositionalTileContainerProvider<ExternalStorageTile>(
|
||||
|
@@ -5,6 +5,7 @@ import com.raoulvdberge.refinedstorage.container.ImporterContainer;
|
||||
import com.raoulvdberge.refinedstorage.container.factory.PositionalTileContainerProvider;
|
||||
import com.raoulvdberge.refinedstorage.tile.ImporterTile;
|
||||
import com.raoulvdberge.refinedstorage.util.BlockUtils;
|
||||
import com.raoulvdberge.refinedstorage.util.CollisionUtils;
|
||||
import com.raoulvdberge.refinedstorage.util.NetworkUtils;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
@@ -71,33 +72,39 @@ public class ImporterBlock extends CableBlock {
|
||||
public VoxelShape getShape(BlockState state, IBlockReader world, BlockPos pos, ISelectionContext ctx) {
|
||||
VoxelShape shape = super.getShape(state, world, pos, ctx);
|
||||
|
||||
shape = VoxelShapes.or(shape, getLineShape(state));
|
||||
|
||||
return shape;
|
||||
}
|
||||
|
||||
private VoxelShape getLineShape(BlockState state) {
|
||||
Direction direction = state.get(getDirection().getProperty());
|
||||
|
||||
if (direction == Direction.NORTH) {
|
||||
shape = VoxelShapes.or(shape, LINE_NORTH);
|
||||
return LINE_NORTH;
|
||||
}
|
||||
|
||||
if (direction == Direction.EAST) {
|
||||
shape = VoxelShapes.or(shape, LINE_EAST);
|
||||
return LINE_EAST;
|
||||
}
|
||||
|
||||
if (direction == Direction.SOUTH) {
|
||||
shape = VoxelShapes.or(shape, LINE_SOUTH);
|
||||
return LINE_SOUTH;
|
||||
}
|
||||
|
||||
if (direction == Direction.WEST) {
|
||||
shape = VoxelShapes.or(shape, LINE_WEST);
|
||||
return LINE_WEST;
|
||||
}
|
||||
|
||||
if (direction == Direction.UP) {
|
||||
shape = VoxelShapes.or(shape, LINE_UP);
|
||||
return LINE_UP;
|
||||
}
|
||||
|
||||
if (direction == Direction.DOWN) {
|
||||
shape = VoxelShapes.or(shape, LINE_DOWN);
|
||||
return LINE_DOWN;
|
||||
}
|
||||
|
||||
return shape;
|
||||
return VoxelShapes.empty();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -108,8 +115,8 @@ public class ImporterBlock extends CableBlock {
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("deprecation")
|
||||
public ActionResultType onBlockActivated(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand handIn, BlockRayTraceResult hit) {
|
||||
if (!world.isRemote) {
|
||||
public ActionResultType onBlockActivated(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockRayTraceResult hit) {
|
||||
if (!world.isRemote && CollisionUtils.isInBounds(getLineShape(state), pos, hit.getHitVec())) {
|
||||
return NetworkUtils.attemptModify(world, pos, hit.getFace(), player, () -> NetworkHooks.openGui(
|
||||
(ServerPlayerEntity) player,
|
||||
new PositionalTileContainerProvider<ImporterTile>(
|
||||
|
@@ -1,13 +1,19 @@
|
||||
package com.raoulvdberge.refinedstorage.util;
|
||||
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.util.math.shapes.VoxelShape;
|
||||
|
||||
public final class CollisionUtils {
|
||||
public static AxisAlignedBB getBounds(int fromX, int fromY, int fromZ, int toX, int toY, int toZ) {
|
||||
return new AxisAlignedBB((float) fromX / 16F, (float) fromY / 16F, (float) fromZ / 16F, (float) toX / 16F, (float) toY / 16F, (float) toZ / 16F);
|
||||
}
|
||||
public static boolean isInBounds(VoxelShape shape, BlockPos pos, Vec3d hit) {
|
||||
AxisAlignedBB aabb = shape.getBoundingBox().offset(pos);
|
||||
|
||||
public static boolean isInBounds(AxisAlignedBB aabb, float hitX, float hitY, float hitZ) {
|
||||
return hitX >= aabb.minX && hitX <= aabb.maxX && hitY >= aabb.minY && hitY <= aabb.maxY && hitZ >= aabb.minZ && hitZ <= aabb.maxZ;
|
||||
return hit.x >= aabb.minX
|
||||
&& hit.x <= aabb.maxX
|
||||
&& hit.y >= aabb.minY
|
||||
&& hit.y <= aabb.maxY
|
||||
&& hit.z >= aabb.minZ
|
||||
&& hit.z <= aabb.maxZ;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user