Repository navigation
Expand file tree
/
Copy pathClientTickHandler.java
More file actions
56 lines (46 loc) · 2.29 KB
/
Copy pathClientTickHandler.java
File metadata and controls
56 lines (46 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package net.f3rr3.reshaped.client;
import net.f3rr3.reshaped.Reshaped;
import net.f3rr3.reshaped.client.gui.RadialMenuScreen;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.minecraft.block.Block;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.option.GraphicsMode;
import net.minecraft.item.BlockItem;
import net.minecraft.item.ItemStack;
import java.util.List;
public class ClientTickHandler {
private static GraphicsMode lastGraphicsMode;
public static void register() {
ClientTickEvents.END_CLIENT_TICK.register(client -> {
if (client.player == null || client.world == null) return;
GraphicsMode currentMode = MinecraftClient.getInstance().options.getGraphicsMode().getValue();
if (lastGraphicsMode != currentMode) {
lastGraphicsMode = currentMode;
ReshapedClient.refreshVariantRenderLayers();
}
// If a screen is already open, we don't need to do anything here
// The RadialMenuScreen itself handles closing if the key is released
if (client.currentScreen != null) return;
// Check if the trigger key is being held down
boolean isHeld = ModKeybindings.OPEN_RADIAL_MENU.isPressed();
if (isHeld) {
// Key is held, but no screen is open.
// Check if the current item is valid for the radial menu.
ItemStack stack = client.player.getMainHandStack();
if (stack.getItem() instanceof BlockItem blockItem) {
Block block = blockItem.getBlock();
if (Reshaped.MATRIX != null && Reshaped.MATRIX.hasBlock(block)) {
List<Block> column = Reshaped.MATRIX.getColumn(block);
if (!column.isEmpty()) {
int slot = client.player.getInventory().selectedSlot;
Block baseBlock = Reshaped.MATRIX.getBaseBlock(block);
// Open the menu!
client.setScreen(new RadialMenuScreen(column, slot, block, baseBlock));
}
}
}
}
MixedBlockParticleTracker.tick(client.world);
});
}
}