Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix barrier display component #27

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ public static List<BoundingBox3D> getCollisionBoundingBoxes(Vector3D blockPosVec
* @return the block position that the player is looking at
*/
public static Vector3D getLookingAt() {
return Interface.get().map(Interface::getLookingAt).orElse(null);
return Interface.get().map(w -> w.getLookingAt(20.0)).orElse(null);
}

public static Vector3D getLookingAt(double distance) {
return Interface.get().map(w -> w.getLookingAt(distance)).orElse(null);
}

/**
Expand All @@ -32,6 +36,10 @@ public static String getLookingAtBlock() {
return Optional.ofNullable(getLookingAt()).map(WorldInteraction::getBlockName).orElse(null);
}

public static String getLookingAtBlock(double distance) {
return Optional.ofNullable(getLookingAt(distance)).map(WorldInteraction::getBlockName).orElse(null);
}

public static String getBlockName(Vector3D blockPos) {
return Interface.get().map(w -> w.getBlockName(blockPos)).orElse(null);
}
Expand All @@ -56,7 +64,7 @@ static Optional<Interface> get() {

List<BoundingBox3D> getCollisionBoundingBoxes(Vector3D blockPosVec);

Vector3D getLookingAt();
Vector3D getLookingAt(double distance);

String getBlockName(Vector3D blockPos);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class BarrierDisplayComponent extends ResizableComponent {

@Override
public void render(Vector2D mouse) {
String lookingAtBlock = WorldInteraction.getLookingAtBlock();
String lookingAtBlock = WorldInteraction.getLookingAtBlock(4.5);
boolean lookingAtBarrier = lookingAtBlock != null && lookingAtBlock.equals("minecraft:barrier");

Color color = lookingAtBarrier ? Theme.warnText : Theme.defaultText;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ public List<BoundingBox3D> getCollisionBoundingBoxes(Vector3D blockPosVector) {
return boundingBoxes;
}

public Vector3D getLookingAt() {
public Vector3D getLookingAt(double distance) {
if (MinecraftClient.getInstance().getCameraEntity() == null)
return null;

HitResult hitResult = MinecraftClient.getInstance().getCameraEntity().raycast(20, 0, false);
HitResult hitResult = MinecraftClient.getInstance().getCameraEntity().raycast(distance, 0, false);
if (hitResult instanceof BlockHitResult) {
BlockPos blockPos = ((BlockHitResult) hitResult).getBlockPos();
return new Vector3D(blockPos.getX(), blockPos.getY(), blockPos.getZ());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@ public List<BoundingBox3D> getCollisionBoundingBoxes(Vector3D blockPosVector) {
return boundingBoxes;
}

public Vector3D getLookingAt() {
public Vector3D getLookingAt(double distance) {
if (MinecraftClient.getInstance().getCameraEntity() == null)
return null;

HitResult hitResult = MinecraftClient.getInstance().getCameraEntity().raycast(20, 0, false);
HitResult hitResult = MinecraftClient.getInstance().getCameraEntity().raycast(distance, 0, false);
if (hitResult instanceof BlockHitResult) {
BlockPos blockPos = ((BlockHitResult) hitResult).getBlockPos();
return new Vector3D(blockPos.getX(), blockPos.getY(), blockPos.getZ());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ public List<BoundingBox3D> getCollisionBoundingBoxes(Vector3D blockPosVector) {
/**
* Is called in {@link WorldInteraction.Interface}
*/
public Vector3D getLookingAt() {
public Vector3D getLookingAt(double distance) {
if (Minecraft.getInstance().getCameraEntity() == null) return null;
HitResult hitResult = Minecraft.getInstance().getCameraEntity().pick(20, 0, false);
HitResult hitResult = Minecraft.getInstance().getCameraEntity().pick(distance, 0, false);
if (hitResult instanceof BlockHitResult) {
BlockPos blockPos = ((BlockHitResult) hitResult).getBlockPos();
return new Vector3D(blockPos.getX(), blockPos.getY(), blockPos.getZ());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ public List<BoundingBox3D> getCollisionBoundingBoxes(Vector3D blockPosVector) {
/**
* Is called in {@link WorldInteraction.Interface}
*/
public Vector3D getLookingAt() {
public Vector3D getLookingAt(double distance) {
if (Minecraft.getInstance().getCameraEntity() == null) return null;
HitResult hitResult = Minecraft.getInstance().getCameraEntity().pick(20, 0, false);
HitResult hitResult = Minecraft.getInstance().getCameraEntity().pick(distance, 0, false);
if (hitResult instanceof BlockHitResult) {
BlockPos blockPos = ((BlockHitResult) hitResult).getBlockPos();
return new Vector3D(blockPos.getX(), blockPos.getY(), blockPos.getZ());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ public List<BoundingBox3D> getCollisionBoundingBoxes(Vector3D blockPosVec) {
/**
* Is called in {@link WorldInteraction.Interface}
*/
public Vector3D getLookingAt() {
BlockPos blockPos = Minecraft.getMinecraft().thePlayer.rayTrace(20, 0).getBlockPos();
public Vector3D getLookingAt(double distance) {
BlockPos blockPos = Minecraft.getMinecraft().thePlayer.rayTrace(distance, 0).getBlockPos();
if (blockPos == null) return null;
return new Vector3D(blockPos.getX(), blockPos.getY(), blockPos.getZ());
}
Expand All @@ -82,14 +82,12 @@ public Vector3D getLookingAt() {
*/
public String getBlockName(Vector3D blockPos) {
String blockName = "";
//if (Minecraft.getMinecraft().objectMouseOver != null && Minecraft.getMinecraft().objectMouseOver.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK && Minecraft.getMinecraft().objectMouseOver.getBlockPos() != null && !(Minecraft.getMinecraft().thePlayer.hasReducedDebug() || Minecraft.getMinecraft().gameSettings.reducedDebugInfo)) {
BlockPos blockpos = new BlockPos(blockPos.getX(), blockPos.getY(), blockPos.getZ());
IBlockState iblockstate = Minecraft.getMinecraft().theWorld.getBlockState(blockpos);
if (Minecraft.getMinecraft().theWorld.getWorldType() != WorldType.DEBUG_WORLD) {
iblockstate = iblockstate.getBlock().getActualState(iblockstate, Minecraft.getMinecraft().theWorld, blockpos);
}
blockName = String.valueOf(Block.blockRegistry.getNameForObject(iblockstate.getBlock()));
//}
return blockName;
}

Expand Down