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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
package me.shedaniel.mixins;
import me.shedaniel.listenerdefinitions.GuiKeyDown;
import net.minecraft.client.gui.GuiTextField;
import net.minecraft.client.gui.inventory.GuiContainerCreative;
import net.minecraft.client.renderer.InventoryEffectRenderer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemGroup;
import net.minecraft.util.math.MathHelper;
import org.dimdev.riftloader.RiftLoader;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.mixin.Shadow;
import javax.annotation.Nullable;
import java.util.Objects;
@Mixin(GuiContainerCreative.class)
public abstract class MixinGuiContainerCreative extends InventoryEffectRenderer {
@Shadow
private static int selectedTabIndex = ItemGroup.BUILDING_BLOCKS.getIndex();
@Shadow
private GuiTextField searchField;
@Shadow
protected abstract boolean hasTmpInventory(@Nullable Slot p_208018_1_);
@Shadow
protected abstract void setCurrentCreativeTab(ItemGroup tab);
@Shadow
protected abstract void updateCreativeSearch();
@Shadow
private boolean field_195377_F;
@Shadow
protected abstract boolean needsScrollBars();
@Shadow
private float currentScroll;
public MixinGuiContainerCreative(Container inventorySlotsIn) {
super(inventorySlotsIn);
}
@Overwrite
public boolean keyPressed(int p_keyPressed_1_, int p_keyPressed_2_, int p_keyPressed_3_) {
this.field_195377_F = false;
if (selectedTabIndex != ItemGroup.SEARCH.getIndex()) {
if (selectedTabIndex != ItemGroup.INVENTORY.getIndex()) {
if (this.mc.gameSettings.keyBindChat.matchesKey(p_keyPressed_1_, p_keyPressed_2_)) {
this.field_195377_F = true;
this.setCurrentCreativeTab(ItemGroup.SEARCH);
return true;
}
} else for(GuiKeyDown listener : RiftLoader.instance.getListeners(GuiKeyDown.class))
if (listener.keyDown(p_keyPressed_1_, p_keyPressed_2_, p_keyPressed_3_))
return true;
} else {
boolean flag = !this.hasTmpInventory(this.hoveredSlot) || this.hoveredSlot != null && this.hoveredSlot.getHasStack();
if (flag && this.func_195363_d(p_keyPressed_1_, p_keyPressed_2_)) {
this.field_195377_F = true;
return true;
} else {
String s = this.searchField.getText();
if (this.searchField.keyPressed(p_keyPressed_1_, p_keyPressed_2_, p_keyPressed_3_)) {
if (!Objects.equals(s, this.searchField.getText()))
this.updateCreativeSearch();
return true;
}
}
}
return super.keyPressed(p_keyPressed_1_, p_keyPressed_2_, p_keyPressed_3_);
}
public boolean mouseScrolled(double p_mouseScrolled_1_) {
if (!this.needsScrollBars()) {
return super.mouseScrolled(p_mouseScrolled_1_);
} else {
int i = (((GuiContainerCreative.ContainerCreative) this.inventorySlots).itemList.size() + 9 - 1) / 9 - 5;
this.currentScroll = (float) ((double) this.currentScroll - p_mouseScrolled_1_ / (double) i);
this.currentScroll = MathHelper.clamp(this.currentScroll, 0.0F, 1.0F);
((GuiContainerCreative.ContainerCreative) this.inventorySlots).scrollTo(this.currentScroll);
return true;
}
}
}
|