Skip to content

Commit 74546df

Browse files
committed
fix: solve visual bug in air place highlight
1 parent 1673146 commit 74546df

File tree

1 file changed

+29
-38
lines changed

1 file changed

+29
-38
lines changed

src/main/java/tools/redstone/redstonetools/features/toggleable/AirPlaceFeature.java

+29-38
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import com.google.auto.service.AutoService;
44
import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderEvents;
55
import net.minecraft.block.BlockState;
6-
import net.minecraft.block.Blocks;
76
import net.minecraft.client.MinecraftClient;
87
import net.minecraft.client.network.ClientPlayerEntity;
98
import net.minecraft.client.render.Camera;
@@ -31,46 +30,13 @@
3130
@Feature(name = "Air Place", description = "Allows you to place blocks in the air.", command = "airplace")
3231
public class AirPlaceFeature extends ToggleableFeature {
3332

34-
public static boolean canAirPlace(PlayerEntity player) {
35-
ItemStack itemStack = ItemUtils.getMainItem(player);
36-
37-
// empty slot
38-
if (itemStack == null || itemStack.getItem() == Items.AIR)
39-
return false;
40-
41-
// rocket boost for elytra
42-
if (itemStack.getItem() == Items.FIREWORK_ROCKET &&
43-
player.getEquippedStack(EquipmentSlot.CHEST).getItem() == Items.ELYTRA &&
44-
player.isFallFlying())
45-
return false;
46-
47-
return true;
48-
}
49-
50-
public static HitResult findAirPlacePosition(MinecraftClient client) {
51-
if (client.player == null)
52-
return null;
53-
ClientPlayerEntity player = client.player;
54-
55-
float reach = AirPlaceFeature.reach.getValue();
56-
return player.raycast(reach, 0, false);
57-
}
58-
59-
public static BlockHitResult findAirPlaceBlockHit(PlayerEntity playerEntity) {
60-
var hit = RaycastUtils.rayCastFromEye(playerEntity, reach.getValue());
61-
return new BlockHitResult(hit.getPos(), hit.getSide(), hit.getBlockPos(), false);
62-
}
63-
6433
public static final Argument<Float> reach = Argument
6534
.ofType(floatArg(3.0f))
6635
.withDefault(5.0f);
67-
6836
public static final Argument<Boolean> showOutline = Argument
6937
.ofType(BoolSerializer.bool())
7038
.withDefault(true);
7139

72-
private static final BlockState FULL_BLOCK_STATE = Blocks.BEDROCK.getDefaultState();
73-
7440
{
7541
// register ghost block renderer
7642
WorldRenderEvents.BEFORE_BLOCK_OUTLINE.register((context, blockOutlineContext) -> {
@@ -88,11 +54,10 @@ public static BlockHitResult findAirPlaceBlockHit(PlayerEntity playerEntity) {
8854
if (!canAirPlace(client.player))
8955
return true;
9056

91-
HitResult hitResult = findAirPlacePosition(client);
57+
BlockHitResult hitResult = findAirPlaceBlockHit(client.player);
9258
if (hitResult == null)
9359
return true;
94-
Vec3d pos = hitResult.getPos();
95-
BlockPos blockPos = new BlockPos((int) pos.x, (int) pos.y, (int) pos.z);
60+
BlockPos blockPos = hitResult.getBlockPos();
9661

9762
BlockState blockState = ItemUtils.getUseState(client.player,
9863
ItemUtils.getMainItem(client.player),
@@ -107,7 +72,7 @@ public static BlockHitResult findAirPlaceBlockHit(PlayerEntity playerEntity) {
10772
try {
10873
VertexConsumer consumer = context.consumers().getBuffer(RenderLayer.getLines());
10974

110-
((WorldRendererAccessor)context.worldRenderer()).invokeDrawBlockOutline(
75+
((WorldRendererAccessor) context.worldRenderer()).invokeDrawBlockOutline(
11176
context.matrixStack(),
11277
consumer,
11378
client.player,
@@ -123,4 +88,30 @@ public static BlockHitResult findAirPlaceBlockHit(PlayerEntity playerEntity) {
12388
});
12489
}
12590

91+
public static boolean canAirPlace(PlayerEntity player) {
92+
ItemStack itemStack = ItemUtils.getMainItem(player);
93+
94+
return
95+
// empty slot
96+
(itemStack != null && itemStack.getItem() != Items.AIR) &&
97+
// rocket boost for elytra
98+
(itemStack.getItem() != Items.FIREWORK_ROCKET ||
99+
player.getEquippedStack(EquipmentSlot.CHEST).getItem() != Items.ELYTRA ||
100+
!player.isFallFlying());
101+
}
102+
103+
public static HitResult findAirPlacePosition(MinecraftClient client) {
104+
if (client.player == null)
105+
return null;
106+
ClientPlayerEntity player = client.player;
107+
108+
float reach = AirPlaceFeature.reach.getValue();
109+
return player.raycast(reach, 0, false);
110+
}
111+
112+
public static BlockHitResult findAirPlaceBlockHit(PlayerEntity playerEntity) {
113+
var hit = RaycastUtils.rayCastFromEye(playerEntity, reach.getValue());
114+
return new BlockHitResult(hit.getPos(), hit.getSide(), hit.getBlockPos(), false);
115+
}
116+
126117
}

0 commit comments

Comments
 (0)