aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authorUnknown <shekwancheung0528@gmail.com>2018-12-31 20:18:15 +0800
committerUnknown <shekwancheung0528@gmail.com>2018-12-31 20:18:15 +0800
commit872b21827de48ffbc87a009c52e74711ba2bd4b3 (patch)
treec61f22f5e32ff0ee6f459b30589a7472583e4f99 /src/main/java
parent9d8d3225f7e2c49a02f6be9e947565e5222cbf1b (diff)
downloadRoughlyEnoughItems-872b21827de48ffbc87a009c52e74711ba2bd4b3.tar.gz
RoughlyEnoughItems-872b21827de48ffbc87a009c52e74711ba2bd4b3.tar.bz2
RoughlyEnoughItems-872b21827de48ffbc87a009c52e74711ba2bd4b3.zip
Better Mixin
Diffstat (limited to 'src/main/java')
-rwxr-xr-xsrc/main/java/me/shedaniel/gui/widget/REISlot.java1
-rwxr-xr-xsrc/main/java/me/shedaniel/mixins/MixinGuiContainer.java1
-rw-r--r--src/main/java/me/shedaniel/mixins/MixinGuiContainerCreative.java102
3 files changed, 38 insertions, 66 deletions
diff --git a/src/main/java/me/shedaniel/gui/widget/REISlot.java b/src/main/java/me/shedaniel/gui/widget/REISlot.java
index fe10c34b8..1dc21b158 100755
--- a/src/main/java/me/shedaniel/gui/widget/REISlot.java
+++ b/src/main/java/me/shedaniel/gui/widget/REISlot.java
@@ -113,7 +113,6 @@ public class REISlot extends Control {
if (!player.inventory.getItemStack().isEmpty()) {
return false;
}
-
if (REIRenderHelper.reiGui.canCheat() && this.cheatable) {
if (getStack() != null && !getStack().isEmpty()) {
ItemStack cheatedStack = getStack().copy();
diff --git a/src/main/java/me/shedaniel/mixins/MixinGuiContainer.java b/src/main/java/me/shedaniel/mixins/MixinGuiContainer.java
index b4c0dbab3..10f9d6e3f 100755
--- a/src/main/java/me/shedaniel/mixins/MixinGuiContainer.java
+++ b/src/main/java/me/shedaniel/mixins/MixinGuiContainer.java
@@ -50,7 +50,6 @@ public abstract class MixinGuiContainer implements IGuiEventListenerDeferred, IM
}
if (handled)
ci.cancel();
-
}
@Inject(method = "keyPressed", at = @At("HEAD"), cancellable = true)
diff --git a/src/main/java/me/shedaniel/mixins/MixinGuiContainerCreative.java b/src/main/java/me/shedaniel/mixins/MixinGuiContainerCreative.java
index 57f24b048..948a5a274 100644
--- a/src/main/java/me/shedaniel/mixins/MixinGuiContainerCreative.java
+++ b/src/main/java/me/shedaniel/mixins/MixinGuiContainerCreative.java
@@ -1,94 +1,68 @@
package me.shedaniel.mixins;
+import me.shedaniel.listenerdefinitions.GuiCickListener;
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;
+import org.spongepowered.asm.mixin.injection.At;
+import org.spongepowered.asm.mixin.injection.Inject;
+import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
@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;
+ public abstract int getSelectedTabIndex();
@Shadow
protected abstract boolean needsScrollBars();
- @Shadow
- private float currentScroll;
-
- public MixinGuiContainerCreative(Container inventorySlotsIn) {
- super(inventorySlotsIn);
+ public MixinGuiContainerCreative(Container container_1) {
+ super(container_1);
}
- @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;
- }
+ @Inject(method = "keyPressed(III)Z", at = @At("HEAD"), cancellable = true)
+ public void keyPressed(int p_keyPressed_1_, int p_keyPressed_2_, int p_keyPressed_3_, CallbackInfoReturnable<Boolean> ci) {
+ boolean handled = false;
+ if (getSelectedTabIndex() != ItemGroup.SEARCH.getIndex()) {
+ if (getSelectedTabIndex() == ItemGroup.INVENTORY.getIndex()) {
+ for(GuiKeyDown listener : RiftLoader.instance.getListeners(GuiKeyDown.class))
+ if (listener.keyDown(p_keyPressed_1_, p_keyPressed_2_, p_keyPressed_3_)) {
+ ci.setReturnValue(true);
+ handled = true;
+ }
}
}
- return super.keyPressed(p_keyPressed_1_, p_keyPressed_2_, p_keyPressed_3_);
+ if (handled)
+ ci.cancel();
}
- @Overwrite
- public boolean mouseScrolled(double p_mouseScrolled_1_) {
+ @Inject(method = "mouseScrolled(D)Z", at = @At("HEAD"), cancellable = true)
+ public void mouseScrolled(double p_mouseScrolled_1_, CallbackInfoReturnable<Boolean> ci) {
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;
+ ci.setReturnValue(super.mouseScrolled(p_mouseScrolled_1_));
+ ci.cancel();
+ }
+ }
+
+ @Inject(method = "mouseClicked", at = @At("HEAD"), cancellable = true)
+ private void onMouseClicked(double p_mouseClicked_1_, double p_mouseClicked_3_, int p_mouseClicked_5_, CallbackInfoReturnable<Boolean> ci) {
+ if (getSelectedTabIndex() != ItemGroup.INVENTORY.getIndex())
+ return;
+ boolean handled = false;
+ for(GuiCickListener listener : RiftLoader.instance.getListeners(GuiCickListener.class)) {
+ if (listener.onClick((int) p_mouseClicked_1_, (int) p_mouseClicked_3_, p_mouseClicked_5_)) {
+ ci.setReturnValue(true);
+ handled = true;
+ }
}
+ if (handled)
+ ci.cancel();
}
}