aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/io
diff options
context:
space:
mode:
authorjani270 <69345714+jani270@users.noreply.github.com>2021-08-07 21:08:32 +0200
committerGitHub <noreply@github.com>2021-08-07 21:08:32 +0200
commit9cceb9cbf0e8da94022ddaf7d00b3565a1c83557 (patch)
treec856a219fc320d3699fc6dda6d1267ce3e9badb8 /src/main/java/io
parent9ea25e893514550cb7bb587b31a2534787d98dd1 (diff)
parent9f2ae5b34c08f8fab9c52c26f56df399229a2435 (diff)
downloadNotEnoughUpdates-9cceb9cbf0e8da94022ddaf7d00b3565a1c83557.tar.gz
NotEnoughUpdates-9cceb9cbf0e8da94022ddaf7d00b3565a1c83557.tar.bz2
NotEnoughUpdates-9cceb9cbf0e8da94022ddaf7d00b3565a1c83557.zip
Merge branch 'DoKM:master' into yep
Diffstat (limited to 'src/main/java/io')
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/SlotLocking.java32
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinEntityPlayerSP.java2
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinInventoryPlayer.java12
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinMinecraft.java11
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/SlotLocking.java13
5 files changed, 67 insertions, 3 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/SlotLocking.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/SlotLocking.java
index 1925811d..256cf03f 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/SlotLocking.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/SlotLocking.java
@@ -26,6 +26,7 @@ import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.event.GuiScreenEvent;
import net.minecraftforge.fml.common.eventhandler.EventPriority;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
+import net.minecraftforge.fml.common.gameevent.TickEvent;
import org.apache.commons.lang3.tuple.Triple;
import org.lwjgl.input.Keyboard;
import org.lwjgl.input.Mouse;
@@ -87,6 +88,36 @@ public class SlotLocking {
}
}
+ public void changedSlot(int slotNumber){
+ int pingModifier = NotEnoughUpdates.INSTANCE.config.slotLocking.slotLockSwapDelay;
+ if(pingModifier == 0){ return; };
+ long currentTimeMilis = System.currentTimeMillis();
+
+ for (int i = 0; i < slotChanges.length; i++) {
+ if(i != slotNumber && slotChanges[i] != 0 && slotChanges[i] < (currentTimeMilis+pingModifier)){
+ slotChanges[i] = 0;
+ }
+ }
+ slotChanges[slotNumber] = currentTimeMilis;
+ }
+
+ public boolean isSwapedSlotLocked(){
+ int pingModifier = NotEnoughUpdates.INSTANCE.config.slotLocking.slotLockSwapDelay;
+ if(pingModifier == 0){ return false; };
+ long currentTimeMilis = System.currentTimeMillis();
+
+ for (int i = 0; i < slotChanges.length; i++) {
+ if(slotChanges[i] != 0 && slotChanges[i] < (currentTimeMilis+pingModifier)){
+ if(isSlotIndexLocked(i)){
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ private long[] slotChanges = new long[9];
+
public void saveConfig(File file) {
try {
file.createNewFile();
@@ -576,5 +607,6 @@ public class SlotLocking {
return locked != null && (locked.locked || (NotEnoughUpdates.INSTANCE.config.slotLocking.bindingAlsoLocks && locked.boundTo != -1));
}
+
}
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinEntityPlayerSP.java b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinEntityPlayerSP.java
index f82cc88f..35ee3a63 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinEntityPlayerSP.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinEntityPlayerSP.java
@@ -22,7 +22,7 @@ public class MixinEntityPlayerSP {
}
int slot = Minecraft.getMinecraft().thePlayer.inventory.currentItem;
- if(SlotLocking.getInstance().isSlotIndexLocked(slot)) {
+ if(SlotLocking.getInstance().isSlotIndexLocked(slot) || SlotLocking.getInstance().isSwapedSlotLocked()) {
ci.cancel();
Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.RED+
"NotEnoughUpdates has prevented you from dropping that locked item!"));
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinInventoryPlayer.java b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinInventoryPlayer.java
index d31ab00a..f60a4839 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinInventoryPlayer.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinInventoryPlayer.java
@@ -1,5 +1,6 @@
package io.github.moulberry.notenoughupdates.mixins;
+import io.github.moulberry.notenoughupdates.miscfeatures.SlotLocking;
import io.github.moulberry.notenoughupdates.miscgui.InventoryStorageSelector;
import net.minecraft.entity.player.InventoryPlayer;
import org.spongepowered.asm.mixin.Mixin;
@@ -11,10 +12,19 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
public class MixinInventoryPlayer {
@Inject(method="changeCurrentItem", at=@At("RETURN"))
- public void changeCurrentItem(int direction, CallbackInfo ci) {
+ public void changeCurrentItemReturn(int direction, CallbackInfo ci) {
InventoryPlayer $this = (InventoryPlayer)(Object)this;
$this.currentItem = InventoryStorageSelector.getInstance().onScroll(direction, $this.currentItem);
+
+
+ }
+
+ @Inject(method="changeCurrentItem", at=@At("HEAD"))
+ public void changeCurrentItemHead(int direction, CallbackInfo ci) {
+ InventoryPlayer $this = (InventoryPlayer)(Object)this;
+
+ SlotLocking.getInstance().changedSlot($this.currentItem);
}
}
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinMinecraft.java b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinMinecraft.java
index 81ab8ec0..e2b4a156 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinMinecraft.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinMinecraft.java
@@ -1,9 +1,12 @@
package io.github.moulberry.notenoughupdates.mixins;
import io.github.moulberry.notenoughupdates.NotEnoughUpdates;
+import io.github.moulberry.notenoughupdates.miscfeatures.SlotLocking;
+
import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.WorldClient;
import net.minecraft.client.renderer.EntityRenderer;
+import org.spongepowered.asm.lib.Opcodes;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
@@ -14,7 +17,8 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(Minecraft.class)
public class MixinMinecraft {
- @Shadow public WorldClient theWorld;
+ //Commented as they were'nt being loaded before
+/* @Shadow public WorldClient theWorld;
@Shadow public EntityRenderer entityRenderer;
@@ -33,6 +37,11 @@ public class MixinMinecraft {
@Redirect(method="loadWorld(Lnet/minecraft/client/multiplayer/WorldClient;Ljava/lang/String;)V",
at=@At(value = "INVOKE", target = "Ljava/lang/System;gc()V"))
public void loadWorld_gc() {
+ }*/
+
+ @Inject(method = "runTick", at = @At(value = "FIELD", target = "Lnet/minecraft/entity/player/InventoryPlayer;currentItem:I", opcode = Opcodes.PUTFIELD))
+ public void currentItemMixin(CallbackInfo ci){
+ SlotLocking.getInstance().changedSlot(Minecraft.getMinecraft().thePlayer.inventory.currentItem);
}
}
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/SlotLocking.java b/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/SlotLocking.java
index 3da885a0..98358d83 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/SlotLocking.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/SlotLocking.java
@@ -51,6 +51,19 @@ public class SlotLocking {
@Expose
@ConfigOption(
+ name = "Item Swap drop delay",
+ desc = "Set the delay between swapping to another item and being able to drop it.\n"+
+ "This is to fix a bug that allowed you to drop slot locked items."
+ )
+ @ConfigEditorSlider(
+ minValue = 0,
+ maxValue = 500,
+ minStep = 5
+ )
+ public int slotLockSwapDelay = 100;
+
+ @Expose
+ @ConfigOption(
name = "Slot Lock Sound",
desc = "Play a ding when locking/unlocking slots"
)