3
3
import com .google .auto .service .AutoService ;
4
4
import net .fabricmc .fabric .api .client .rendering .v1 .WorldRenderEvents ;
5
5
import net .minecraft .block .BlockState ;
6
- import net .minecraft .block .Blocks ;
7
6
import net .minecraft .client .MinecraftClient ;
8
7
import net .minecraft .client .network .ClientPlayerEntity ;
9
8
import net .minecraft .client .render .Camera ;
31
30
@ Feature (name = "Air Place" , description = "Allows you to place blocks in the air." , command = "airplace" )
32
31
public class AirPlaceFeature extends ToggleableFeature {
33
32
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
-
64
33
public static final Argument <Float > reach = Argument
65
34
.ofType (floatArg (3.0f ))
66
35
.withDefault (5.0f );
67
-
68
36
public static final Argument <Boolean > showOutline = Argument
69
37
.ofType (BoolSerializer .bool ())
70
38
.withDefault (true );
71
39
72
- private static final BlockState FULL_BLOCK_STATE = Blocks .BEDROCK .getDefaultState ();
73
-
74
40
{
75
41
// register ghost block renderer
76
42
WorldRenderEvents .BEFORE_BLOCK_OUTLINE .register ((context , blockOutlineContext ) -> {
@@ -88,11 +54,10 @@ public static BlockHitResult findAirPlaceBlockHit(PlayerEntity playerEntity) {
88
54
if (!canAirPlace (client .player ))
89
55
return true ;
90
56
91
- HitResult hitResult = findAirPlacePosition (client );
57
+ BlockHitResult hitResult = findAirPlaceBlockHit (client . player );
92
58
if (hitResult == null )
93
59
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 ();
96
61
97
62
BlockState blockState = ItemUtils .getUseState (client .player ,
98
63
ItemUtils .getMainItem (client .player ),
@@ -107,7 +72,7 @@ public static BlockHitResult findAirPlaceBlockHit(PlayerEntity playerEntity) {
107
72
try {
108
73
VertexConsumer consumer = context .consumers ().getBuffer (RenderLayer .getLines ());
109
74
110
- ((WorldRendererAccessor )context .worldRenderer ()).invokeDrawBlockOutline (
75
+ ((WorldRendererAccessor ) context .worldRenderer ()).invokeDrawBlockOutline (
111
76
context .matrixStack (),
112
77
consumer ,
113
78
client .player ,
@@ -123,4 +88,30 @@ public static BlockHitResult findAirPlaceBlockHit(PlayerEntity playerEntity) {
123
88
});
124
89
}
125
90
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
+
126
117
}
0 commit comments