88import net .fabricmc .fabric .api .client .keybinding .v1 .KeyBindingHelper ;
99import net .fabricmc .fabric .api .client .networking .v1 .ClientPlayConnectionEvents ;
1010import net .fabricmc .fabric .api .client .networking .v1 .ClientPlayNetworking ;
11- import net .fabricmc .fabric .api .client .rendering .v1 .WorldRenderContext ;
12- import net .fabricmc .fabric .api .client .rendering .v1 .WorldRenderEvents ;
11+ import net .fabricmc .fabric .api .client .rendering .v1 .world . WorldRenderContext ;
12+ import net .fabricmc .fabric .api .client .rendering .v1 .world . WorldRenderEvents ;
1313import net .fabricmc .fabric .api .event .player .AttackBlockCallback ;
1414import net .fabricmc .fabric .api .event .player .UseBlockCallback ;
1515import net .fabricmc .fabric .api .event .player .UseItemCallback ;
1616import net .fabricmc .fabric .api .networking .v1 .PacketSender ;
1717import net .minecraft .client .MinecraftClient ;
18- import net .minecraft .client .gui .screen .Screen ;
1918import net .minecraft .client .network .ClientPlayNetworkHandler ;
2019import net .minecraft .client .network .ClientPlayerEntity ;
2120import net .minecraft .client .option .KeyBinding ;
2221import net .minecraft .client .util .InputUtil ;
22+ import net .minecraft .client .util .Window ;
2323import net .minecraft .item .Item ;
2424import net .minecraft .item .ItemStack ;
2525import net .minecraft .text .Text ;
4141import java .util .stream .Collectors ;
4242
4343@ SuppressWarnings ("UnstableApiUsage" )
44- public class BlockMeterClient implements ClientModInitializer {
45- /**
46- * Currently running Instance of BlockMeterClient
47- */
44+ public class BlockMeterClient implements ClientModInitializer , InputUtils {
45+ /// Currently running Instance of BlockMeterClient
4846 private static BlockMeterClient instance ;
4947
50- /**
51- * Accessor for the BlockMeterClient Instance
52- *
53- * @return running Instance of BlockMeterClient
54- */
48+ /// Currently running Instance of BlockMeterClient
5549 public static BlockMeterClient getInstance () {
5650 return instance ;
5751 }
@@ -60,54 +54,38 @@ private static ClientPlayerEntity getPlayer() {
6054 return Objects .requireNonNull (MinecraftClient .getInstance ().player );
6155 }
6256
63- /**
64- * ConfigManager of BlockMeter
65- */
57+ private static Window getWindow () {
58+ return MinecraftClient .getInstance ().getWindow ();
59+ }
60+
6661 private static ConfigManager <ModConfig > confMgr ;
6762
68- /**
69- * Accessor for the ModConfigManager
70- *
71- * @return ConfigManager for handling the Config
72- */
63+ /// Accessor for the ModConfigManager
7364 public static ConfigManager <ModConfig > getConfigManager () {
74-
7565 return confMgr ;
7666 }
7767
7868 public static ModConfig getConfig () {
7969 return confMgr .getConfig ();
8070 }
8171
82- /**
83- * The current state of the BlockMeter (activated/deactivated)
84- */
72+ /// The current state of the BlockMeter (activated/deactivated)
8573 private boolean active ;
8674
87- /**
88- * The Item selected as BlockMeter
89- */
75+ /// The Item selected as BlockMeter
9076 private Item currentItem ;
9177
92- /**
93- * The List of Measuring-Boxes currently created by the current User
94- */
78+ /// The List of Measuring-Boxes currently created by the current User
9579 private final List <ClientMeasureBox > boxes = new ArrayList <>();
9680
97- /**
98- * A Map of Lists of Boxes currently created by other Users, with Text being the
99- * Username
100- */
81+ /// A Map of Lists of Boxes currently created by other Users, with Text being the
82+ /// Username
10183 private Map <String , List <ClientMeasureBox >> otherUsersBoxes ;
10284
103- /**
104- * The QuickMenu for changing of Color etc.
105- */
85+ /// The QuickMenu for changing of Color etc.
10686 private final OptionsGui quickMenu ;
10787
108- /**
109- * The QuickMenu for selecting on of multiple Boxes.
110- */
88+ /// The QuickMenu for selecting on of multiple Boxes.
11189 private final SelectBoxGui selectBoxGui ;
11290 private final EditBoxGui editBoxGui ;
11391
@@ -185,7 +163,7 @@ public boolean undo() {
185163 }
186164
187165 public void renderOverlay (WorldRenderContext context ) {
188- final Identifier currentDimension = getPlayer ().clientWorld .getRegistryKey ().getValue ();
166+ final Identifier currentDimension = getPlayer ().getEntityWorld () .getRegistryKey ().getValue ();
189167
190168 final ModConfig cfg = AutoConfig .getConfigHolder (ModConfig .class ).getConfig ();
191169
@@ -241,17 +219,19 @@ public ClientMeasureBox getCurrentBox() {
241219
242220 @ Override
243221 public void onInitializeClient () {
222+ var category = KeyBinding .Category .create (Identifier .of ("category.blockmeter.key" ));
223+ var window = MinecraftClient .getInstance ().getWindow ();
244224 final KeyBinding keyBinding = KeyBindingHelper .registerKeyBinding (new KeyBinding ("key.blockmeter.assign" ,
245- InputUtil .Type .KEYSYM , GLFW .GLFW_KEY_M , " category.blockmeter.key" ));
225+ InputUtil .Type .KEYSYM , GLFW .GLFW_KEY_M , category ));
246226 final KeyBinding keyBindingMenu = new KeyBinding ("key.blockmeter.menu" , InputUtil .Type .KEYSYM ,
247- GLFW .GLFW_KEY_LEFT_ALT , " category.blockmeter.key" );
227+ GLFW .GLFW_KEY_LEFT_ALT , category );
248228 KeyBindingHelper .registerKeyBinding (keyBindingMenu );
249229
250230 final KeyBinding keyBindingMeasureWithItem = new KeyBinding ("key.blockmeter.useItem" , -1 ,
251- " category.blockmeter.key" );
231+ category );
252232 KeyBindingHelper .registerKeyBinding (keyBindingMeasureWithItem );
253233 final KeyBinding keyBindingMeasure = new KeyBinding ("key.blockmeter.measure" , InputUtil .Type .MOUSE ,
254- GLFW .GLFW_MOUSE_BUTTON_4 , " category.blockmeter.key" );
234+ GLFW .GLFW_MOUSE_BUTTON_4 , category );
255235 KeyBindingHelper .registerKeyBinding (keyBindingMeasure );
256236
257237 WorldRenderEvents .BEFORE_DEBUG_RENDER .register (this ::renderOverlay );
@@ -267,10 +247,10 @@ public void onInitializeClient() {
267247 confMgr = (ConfigManager <ModConfig >) AutoConfig .register (ModConfig .class , Toml4jConfigSerializer ::new );
268248 ClientTickEvents .START_CLIENT_TICK .register (e -> {
269249 if (keyBinding .wasPressed ()) {
270- if (Screen . hasShiftDown ()) {
250+ if (isShift ()) {
271251 if (undo ())
272252 getPlayer ().sendMessage (Text .translatable ("blockmeter.clearLast" ), true );
273- } else if (Screen . hasControlDown ()) {
253+ } else if (isCtrl ()) {
274254 if (clear ())
275255 getPlayer ().sendMessage (Text .translatable ("blockmeter.clearAll" ), true );
276256 } else if (this .active ) {
@@ -348,7 +328,7 @@ public void onInitializeClient() {
348328 var outside = this .boxes .stream ()
349329 .filter (box -> box .miningRestriction == ClientMeasureBox .MiningRestriction .Outside )
350330 .anyMatch (box -> box .contains (pos ));
351- if (!Screen . hasShiftDown () && (inside || outside )) {
331+ if (!isShift () && (inside || outside )) {
352332 return ActionResult .FAIL ;
353333 } else {
354334 return ActionResult .PASS ;
@@ -382,7 +362,7 @@ private void onBlockMeterClick(final BlockPos block) {
382362 ClientMeasureBox currentBox = getCurrentBox ();
383363
384364 if (currentBox == null ) {
385- if (Screen . hasShiftDown ()) {
365+ if (isShift ()) {
386366 ClientMeasureBox [] boxes = findBoxes (block );
387367 switch (boxes .length ) {
388368 case 0 :
@@ -398,7 +378,7 @@ private void onBlockMeterClick(final BlockPos block) {
398378 }
399379 } else {
400380 final ClientMeasureBox box = ClientMeasureBox .getBox (block ,
401- getPlayer ().getWorld ().getRegistryKey ().getValue ());
381+ getPlayer ().getEntityWorld ().getRegistryKey ().getValue ());
402382 this .boxes .add (box );
403383 }
404384 } else {
0 commit comments