Skip to content
This repository was archived by the owner on Sep 2, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public void initialize() {
quickNum.register(new DoubleSetting("quicknumPrimaryAmount", 1.0));
quickNum.register(new DoubleSetting("quicknumSecondaryAmount", 10d));
quickNum.register(new DoubleSetting("quicknumTertiaryAmount", 0.1));
quickNum.register(new DoubleSetting("quicknumDelay", 0.2));
this.register(quickNum);

}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package io.github.homchom.recode.mod.mixin.render;

import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.inventory.Slot;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Invoker;

@Mixin(AbstractContainerScreen.class)
public interface MAbstractContainerScreen<T extends AbstractContainerMenu> {
@Invoker("isHovering")
boolean isHovering(Slot slot, double mouseX, double mouseY);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
import io.github.homchom.recode.mod.config.Config;
import io.github.homchom.recode.sys.util.ItemUtil;
import net.minecraft.ChatFormatting;
import net.minecraft.client.Minecraft;
import net.minecraft.client.MouseHandler;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.client.gui.screens.inventory.ContainerScreen;
import net.minecraft.client.gui.screens.inventory.CreativeModeInventoryScreen;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.*;
import net.minecraft.sounds.*;
import net.minecraft.world.inventory.*;
import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.world.item.ItemStack;
import org.spongepowered.asm.mixin.*;
import org.spongepowered.asm.mixin.injection.*;
Expand All @@ -32,100 +34,101 @@ public class MMouseHandler {

@Inject(method = "onScroll(JDD)V", at = @At("HEAD"))
private void onScroll(long window, double horiz, double vertical, CallbackInfo ci) {
Screen screen = LegacyRecode.MC.screen;
if (screen instanceof ContainerScreen && Config.getBoolean("quicknum")) {
AbstractContainerMenu handler = ((ContainerScreen) screen).getMenu();
List<Slot> slotList = handler.slots;
Minecraft mc = LegacyRecode.MC;
Screen screen = mc.screen;

double scale = LegacyRecode.MC.getWindow().getGuiScale();
if (screen instanceof MAbstractContainerScreen<?> containerScreen &&
mc.player != null && mc.gameMode != null && mc.player.isCreative() &&
Config.getBoolean("quicknum") && System.currentTimeMillis() >= cd
) {
List<Slot> slotList = mc.player.containerMenu.slots;
double scale = mc.getWindow().getGuiScale();

double mouseX = xpos;
double mouseY = ypos;
for (Slot slot : slotList) {
if (containerScreen.isHovering(slot, xpos / scale, ypos / scale) && ItemUtil.isVar(slot.getItem(), "num")) {
int slotIndex;
// Special case for when you're in the creative inventory
if (screen instanceof CreativeModeInventoryScreen creativeScreen) {
if (creativeScreen.getSelectedTab() != CreativeModeTab.TAB_INVENTORY.getId()) return;
if (slot.y >= 112) {
slotIndex = (slot.x - 9) / 18 + 36 + 2;
} else if (slot.y >= 54) {
slotIndex = (slot.y - 18) / 18 * 9 + (slot.x - 9) / 18 - 9 + 2;
} else {
return;
}
} else {
slotIndex = slot.index;
}
cd = System.currentTimeMillis() + (long)(Config.getDouble("quicknumDelay") * 1000);
ItemStack itemStack = slot.getItem().copy();

CompoundTag tag = itemStack.getTag();

for (Slot slot : slotList) {
double sX = Math.floor(((double) (screen.width - 176) / 2) + slot.x);
double sY = Math.floor(((double) (screen.height - 166) / 2) + slot.y);
sX *= scale;
sY *= scale;


if (sX < mouseX && mouseX < sX + (16 * scale)) {
if (sY < mouseY && mouseY < sY + (16 * scale)) {
if (System.currentTimeMillis() >= cd) {
if (LegacyRecode.MC.player != null && LegacyRecode.MC.gameMode != null && ItemUtil.isVar(slot.getItem(), "num")) {
if (LegacyRecode.MC.player.isCreative()) {
cd = System.currentTimeMillis() + 250;
ItemStack itemStack = slot.getItem().copy();

CompoundTag tag = itemStack.getTag();

if (tag == null) return;

CompoundTag publicBukkitValues = tag.getCompound("PublicBukkitValues");
String varItem = publicBukkitValues.getString("hypercube:varitem");

JsonObject parsedJson = JsonParser.parseString(varItem).getAsJsonObject();
JsonObject data = parsedJson.get("data").getAsJsonObject();

String name = data.get("name").getAsString();

try {
BigDecimal bigDecimal = new BigDecimal(name);

if (Screen.hasControlDown()) {
if (vertical > 0) {
bigDecimal = bigDecimal.add(BigDecimal.valueOf(Config.getDouble("quicknumSecondaryAmount")));
if (Config.getBoolean("quicknumSound"))
LegacyRecode.MC.player.playNotifySound(SoundEvents.NOTE_BLOCK_HAT, SoundSource.PLAYERS, 1, 1);
} else {
bigDecimal = bigDecimal.subtract(BigDecimal.valueOf(Config.getDouble("quicknumSecondaryAmount")));
if (Config.getBoolean("quicknumSound"))
LegacyRecode.MC.player.playNotifySound(SoundEvents.NOTE_BLOCK_HAT, SoundSource.PLAYERS, 1, 0);
}
} else if (Screen.hasShiftDown()) {
if (vertical > 0) {
bigDecimal = bigDecimal.add(BigDecimal.valueOf(Config.getDouble("quicknumTertiaryAmount")));
if (Config.getBoolean("quicknumSound"))
LegacyRecode.MC.player.playNotifySound(SoundEvents.NOTE_BLOCK_HAT, SoundSource.PLAYERS, 1, 1);
} else {
bigDecimal = bigDecimal.subtract(BigDecimal.valueOf(Config.getDouble("quicknumTertiaryAmount")));
if (Config.getBoolean("quicknumSound"))
LegacyRecode.MC.player.playNotifySound(SoundEvents.NOTE_BLOCK_HAT, SoundSource.PLAYERS, 1, 0);
}
} else {
if (vertical > 0) {
bigDecimal = bigDecimal.add(BigDecimal.valueOf(Config.getDouble("quicknumPrimaryAmount")));
if (Config.getBoolean("quicknumSound"))
LegacyRecode.MC.player.playNotifySound(SoundEvents.NOTE_BLOCK_HAT, SoundSource.PLAYERS, 1, 1);
} else {
bigDecimal = bigDecimal.subtract(BigDecimal.valueOf(Config.getDouble("quicknumPrimaryAmount")));
if (Config.getBoolean("quicknumSound"))
LegacyRecode.MC.player.playNotifySound(SoundEvents.NOTE_BLOCK_HAT, SoundSource.PLAYERS, 1, 0);
}
}

name = bigDecimal.toString();
if (name.endsWith(".0")) name = name.substring(0, name.length() - 2);

data.addProperty("name", name);
parsedJson.add("data", data);
publicBukkitValues.putString("hypercube:varitem", parsedJson.toString());
tag.put("PublicBukkitValues", publicBukkitValues);

itemStack.setTag(tag);
itemStack.setHoverName(Component.literal(name)
.withStyle(style -> style.withColor(TextColor.fromLegacyFormat(ChatFormatting.RED)).withItalic(false)));

ItemUtil.setContainerItem(slot.index, itemStack);
} catch (NumberFormatException e) {
if (Config.getBoolean("quicknumSound"))
LegacyRecode.MC.player.playNotifySound(SoundEvents.NOTE_BLOCK_DIDGERIDOO, SoundSource.PLAYERS, 1, 0);
}
}
if (tag == null) return;

CompoundTag publicBukkitValues = tag.getCompound("PublicBukkitValues");
String varItem = publicBukkitValues.getString("hypercube:varitem");

JsonObject parsedJson = JsonParser.parseString(varItem).getAsJsonObject();
JsonObject data = parsedJson.get("data").getAsJsonObject();

String name = data.get("name").getAsString();

try {
BigDecimal bigDecimal = new BigDecimal(name);

if (Screen.hasControlDown()) {
if (vertical > 0) {
bigDecimal = bigDecimal.add(BigDecimal.valueOf(Config.getDouble("quicknumSecondaryAmount")));
if (Config.getBoolean("quicknumSound"))
mc.player.playNotifySound(SoundEvents.NOTE_BLOCK_HAT, SoundSource.PLAYERS, 1, 1);
} else {
bigDecimal = bigDecimal.subtract(BigDecimal.valueOf(Config.getDouble("quicknumSecondaryAmount")));
if (Config.getBoolean("quicknumSound"))
mc.player.playNotifySound(SoundEvents.NOTE_BLOCK_HAT, SoundSource.PLAYERS, 1, 0);
}
} else if (Screen.hasShiftDown()) {
if (vertical > 0) {
bigDecimal = bigDecimal.add(BigDecimal.valueOf(Config.getDouble("quicknumTertiaryAmount")));
if (Config.getBoolean("quicknumSound"))
mc.player.playNotifySound(SoundEvents.NOTE_BLOCK_HAT, SoundSource.PLAYERS, 1, 1);
} else {
bigDecimal = bigDecimal.subtract(BigDecimal.valueOf(Config.getDouble("quicknumTertiaryAmount")));
if (Config.getBoolean("quicknumSound"))
mc.player.playNotifySound(SoundEvents.NOTE_BLOCK_HAT, SoundSource.PLAYERS, 1, 0);
}
} else {
if (vertical > 0) {
bigDecimal = bigDecimal.add(BigDecimal.valueOf(Config.getDouble("quicknumPrimaryAmount")));
if (Config.getBoolean("quicknumSound"))
mc.player.playNotifySound(SoundEvents.NOTE_BLOCK_HAT, SoundSource.PLAYERS, 1, 1);
} else {
bigDecimal = bigDecimal.subtract(BigDecimal.valueOf(Config.getDouble("quicknumPrimaryAmount")));
if (Config.getBoolean("quicknumSound"))
mc.player.playNotifySound(SoundEvents.NOTE_BLOCK_HAT, SoundSource.PLAYERS, 1, 0);
}
}

name = bigDecimal.toString();
if (name.endsWith(".0")) name = name.substring(0, name.length() - 2);

data.addProperty("name", name);
parsedJson.add("data", data);
publicBukkitValues.putString("hypercube:varitem", parsedJson.toString());
tag.put("PublicBukkitValues", publicBukkitValues);

itemStack.setTag(tag);
itemStack.setHoverName(Component.literal(name)
.withStyle(style -> style.withColor(TextColor.fromLegacyFormat(ChatFormatting.RED)).withItalic(false)));

ItemUtil.setContainerItem(slotIndex, itemStack);
} catch (NumberFormatException e) {
if (Config.getBoolean("quicknumSound"))
mc.player.playNotifySound(SoundEvents.NOTE_BLOCK_DIDGERIDOO, SoundSource.PLAYERS, 1, 0);
}

return;
}
}
}
Expand Down
36 changes: 24 additions & 12 deletions src/main/java/io/github/homchom/recode/sys/util/ItemUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import io.github.homchom.recode.LegacyRecode;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.screens.inventory.CreativeModeInventoryScreen;
import net.minecraft.core.*;
import net.minecraft.nbt.*;
import net.minecraft.network.chat.Component;
Expand Down Expand Up @@ -59,18 +60,29 @@ public static void setContainerItem(int slot, ItemStack itemStack) {
if (!mc.player.isCreative()) {
throw new IllegalStateException("Player is not in creative mode.");
}

// replace the 8th slot with the item we want to set.
ItemStack replacedItem = mc.player.getInventory().getItem(7);
LegacyRecode.MC.gameMode.handleCreativeModeItemAdd(itemStack, 43);
mc.player.getInventory().setItem(7, itemStack);

// simulates pressing the 8 key on the slot we want to change.
LegacyRecode.MC.gameMode.handleInventoryMouseClick(mc.player.containerMenu.containerId, slot, 7, ClickType.SWAP, LegacyRecode.MC.player);

// change the 8th slot back to what it was before.
LegacyRecode.MC.gameMode.handleCreativeModeItemAdd(replacedItem, 43);
mc.player.getInventory().setItem(7, replacedItem);
int slotCount = mc.player.containerMenu.slots.size();

// Check if you're trying to replace an item in your own inventory or in a container.
if (slot < slotCount - 36) { // Container case.
// replace the 8th slot with the item we want to set.
ItemStack replacedItem = mc.player.getInventory().getItem(7);
LegacyRecode.MC.gameMode.handleCreativeModeItemAdd(itemStack, 43);
mc.player.getInventory().setItem(7, itemStack);

// simulates pressing the 8 key on the slot we want to change.
LegacyRecode.MC.gameMode.handleInventoryMouseClick(mc.player.containerMenu.containerId, slot, 7, ClickType.SWAP, LegacyRecode.MC.player);

// change the 8th slot back to what it was before.
LegacyRecode.MC.gameMode.handleCreativeModeItemAdd(replacedItem, 43);
mc.player.getInventory().setItem(7, replacedItem);
} else { // Own inventory case.
// Transform index to in between 0 and 35.
int normalizedSlot = slot - slotCount + 36;

// Replace the slot with the item we want to set.
LegacyRecode.MC.gameMode.handleCreativeModeItemAdd(itemStack, normalizedSlot + 9);
mc.player.getInventory().setItem((normalizedSlot + 9) % 36, itemStack);
}
}

public static List<ItemStack> fromItemContainer(ItemStack container) {
Expand Down
4 changes: 3 additions & 1 deletion src/main/resources/assets/recode/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,10 @@
"config.recode.option.quicknumPrimaryAmount.tooltip": "Change how much a scroll changes the number.",
"config.recode.option.quicknumSecondaryAmount": "Secondary Amount",
"config.recode.option.quicknumSecondaryAmount.tooltip": "Change how much a scroll changes the number. (When holding CTRL)",
"config.recode.option.quicknumTertiaryAmount": "Secondary Amount",
"config.recode.option.quicknumTertiaryAmount": "Tertiary Amount",
"config.recode.option.quicknumTertiaryAmount.tooltip": "Change how much a scroll changes the number. (When holding SHIFT)",
"config.recode.option.quicknumDelay": "Delay",
"config.recode.option.quicknumDelay.tooltip": "Minimum delay between each number change.\nToo low values might cause issues.",

"config.recode.option.chestToolTip": "Chest Tooltip",
"config.recode.option.chestToolTip.tooltip": "Display chest params when you are in dev",
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/recodeLegacy.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"render.MStitcher",
"render.MWindow",
"render.TextureMapAccessor",
"render.MAbstractContainerScreen",
"render.screen.MCreativeInventoryScreen",
"render.screen.MOptionsScreen"
],
Expand Down