Skip to content

Commit

Permalink
Version 1.2.3
Browse files Browse the repository at this point in the history
* Updated Tweed
* Updated Loom
* Updated mappings
+ Added additional refill capturing
+ Added configuration for refill rules (#15)
+ Added ability to swap armor items via the hotbar
  • Loading branch information
Siphalor committed Jun 8, 2019
1 parent ed35654 commit 564fb98
Show file tree
Hide file tree
Showing 18 changed files with 207 additions and 87 deletions.
24 changes: 12 additions & 12 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id 'fabric-loom' version '0.2.2-SNAPSHOT'
id 'fabric-loom' version '0.2.4-SNAPSHOT'
id 'maven-publish'
}

Expand Down Expand Up @@ -29,27 +29,27 @@ dependencies {
//to change the versions see the gradle.properties file
minecraft "com.mojang:minecraft:${project.minecraft_version}"
mappings "net.fabricmc:yarn:${project.minecraft_version}+build.${project.yarn_build}"
modCompile "net.fabricmc:fabric-loader:${project.loader_version}"
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"

modCompile "net.fabricmc.fabric-api:fabric-keybindings:+"
modImplementation "net.fabricmc.fabric-api:fabric-keybindings:+"
include "net.fabricmc.fabric-api:fabric-keybindings:+"
modCompile "net.fabricmc.fabric-api:fabric-resource-loader:+"
modImplementation "net.fabricmc.fabric-api:fabric-resource-loader:+"
include "net.fabricmc.fabric-api:fabric-resource-loader:+"
modCompile "net.fabricmc.fabric-api:fabric-events-interaction-v0:+"
modImplementation "net.fabricmc.fabric-api:fabric-events-interaction-v0:+"
include "net.fabricmc.fabric-api:fabric-events-interaction-v0:+"
modCompile "net.fabricmc.fabric-api:fabric-tag-extensions-v0:+"
modImplementation "net.fabricmc.fabric-api:fabric-tag-extensions-v0:+"
include "net.fabricmc.fabric-api:fabric-tag-extensions-v0:+"
modCompile "net.fabricmc.fabric-api:fabric-mining-levels-v0:+"
modImplementation "net.fabricmc.fabric-api:fabric-mining-levels-v0:+"
include "net.fabricmc.fabric-api:fabric-mining-levels-v0:+"

modCompile "net.fabricmc.fabric-api:fabric-item-groups:+"
modCompile "io.github.prospector.modmenu:ModMenu:+"
modImplementation "net.fabricmc.fabric-api:fabric-item-groups:+"
modImplementation "io.github.prospector.modmenu:ModMenu:+"

modCompile "com.github.siphalor:tweed-api:${project.tweed_version}"
modImplementation "com.github.siphalor:tweed-api:${project.tweed_version}"
include "com.github.siphalor:tweed-api:${project.tweed_version}"


modImplementation "cloth-config:ClothConfig:${project.clothconfig_version}"
include "cloth-config:ClothConfig:${project.clothconfig_version}"
modCompile "cloth-config:ClothConfig:${project.clothconfig_version}"
}

processResources {
Expand Down
7 changes: 4 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
# suppress inspection "UnusedProperty" for whole file
# Done to increase the memory available to gradle.
org.gradle.jvmargs=-Xmx1G

# Fabric Properties
# check these on https://fabricmc.net/use
minecraft_version=1.14.2
minecraft_version=1.14.3-pre2
yarn_build=2
loader_version=0.4.8+build.154

# Mod Properties
mod_id = mousewheelie
mod_version = 1.2.2
mod_version = 1.2.3
maven_group = de.siphalor
archives_base_name = mousewheelie

# Dependencies
tweed_version = 2.1.0-beta.7
tweed_version = 2.1.0-beta.9
clothconfig_version = 0.2.4.17
21 changes: 19 additions & 2 deletions src/main/java/de/siphalor/mousewheelie/client/ClientCore.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@
import net.fabricmc.fabric.api.client.keybinding.FabricKeyBinding;
import net.fabricmc.fabric.api.client.keybinding.KeyBindingRegistry;
import net.fabricmc.fabric.api.event.client.player.ClientPickBlockGatherCallback;
import net.fabricmc.fabric.api.event.player.UseItemCallback;
import net.fabricmc.fabric.api.tools.FabricToolTags;
import net.minecraft.client.util.InputUtil;
import net.minecraft.entity.EquipmentSlot;
import net.minecraft.entity.mob.MobEntity;
import net.minecraft.item.*;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Identifier;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.hit.HitResult;
Expand All @@ -24,7 +28,7 @@ public class ClientCore implements ClientModInitializer {

public static TweedClothBridge tweedClothBridge;

public static boolean awaitFoodSlotUpdate = false;
public static boolean awaitSlotUpdate = false;

@Override
public void onInitializeClient() {
Expand All @@ -47,6 +51,19 @@ public void onInitializeClient() {
return ItemStack.EMPTY;
});

UseItemCallback.EVENT.register((player, world, hand) -> {
ItemStack stack = player.getStackInHand(hand);
EquipmentSlot equipmentSlot = MobEntity.getPreferredEquipmentSlot(stack);
if(equipmentSlot != EquipmentSlot.MAINHAND && equipmentSlot != EquipmentSlot.OFFHAND) {
if(!player.getEquippedStack(equipmentSlot).isEmpty()) {
player.setStackInHand(hand, player.getEquippedStack(equipmentSlot));
player.setEquippedStack(equipmentSlot, stack);
return ActionResult.SUCCESS;
}
}
return ActionResult.PASS;
});

Config.initialize();

tweedClothBridge = new TweedClothBridge(Config.configFile);
Expand All @@ -57,6 +74,6 @@ public static boolean isTool(Item item) {
}

public static boolean isWeapon(Item item) {
return item instanceof BaseBowItem || item instanceof TridentItem || item instanceof SwordItem || FabricToolTags.SWORDS.contains(item);
return item instanceof RangedWeaponItem || item instanceof TridentItem || item instanceof SwordItem || FabricToolTags.SWORDS.contains(item);
}
}
5 changes: 4 additions & 1 deletion src/main/java/de/siphalor/mousewheelie/client/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import de.siphalor.mousewheelie.Core;
import de.siphalor.mousewheelie.client.util.ToolPickMode;
import de.siphalor.mousewheelie.client.util.inventory.SlotRefiller;
import de.siphalor.mousewheelie.client.util.inventory.SortMode;
import de.siphalor.tweed.config.ConfigCategory;
import de.siphalor.tweed.config.ConfigEnvironment;
Expand Down Expand Up @@ -45,8 +46,10 @@ public class Config {
public static BooleanEntry otherRefill = refillCategory.register("other", new BooleanEntry(true))
.setEnvironment(ConfigEnvironment.CLIENT)
.setComment("Refill on other occasions");
public static ConfigCategory refillRules = refillCategory.register("rules", new ConfigCategory())
.setComment("Enable/Disable specific rules for how to refill items");

public static void initialize() {

SlotRefiller.initialize();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
import net.minecraft.container.SlotActionType;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.network.chat.Component;
import net.minecraft.server.network.packet.PlayerActionC2SPacket;
import net.minecraft.text.Text;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import org.spongepowered.asm.mixin.Final;
Expand All @@ -31,7 +31,7 @@

@Mixin(AbstractContainerScreen.class)
public abstract class MixinAbstractContainerScreen extends Screen implements IContainerScreen {
protected MixinAbstractContainerScreen(Component textComponent_1) {
protected MixinAbstractContainerScreen(Text textComponent_1) {
super(textComponent_1);
}

Expand Down Expand Up @@ -142,7 +142,7 @@ public boolean mouseWheelie_onMouseScroll(double mouseX, double mouseY, double s
ItemStack referenceStack = hoveredStack.copy();
for(Slot slot : container.slotList) {
if(slotsInSameScope.apply(slot, hoveredSlot)) {
if(slot.getStack().isEqualIgnoreTags(referenceStack))
if(slot.getStack().isItemEqualIgnoreDamage(referenceStack))
onMouseClick(slot, slot.id, 0, SlotActionType.QUICK_MOVE);
}
}
Expand All @@ -155,7 +155,7 @@ public boolean mouseWheelie_onMouseScroll(double mouseX, double mouseY, double s
if(hasShiftDown() || hasControlDown()) {
for(Slot slot : container.slotList) {
if(slotsInSameScope.apply(slot, hoveredSlot)) continue;
if(slot.getStack().isEqualIgnoreTags(hoveredStack)) {
if(slot.getStack().isItemEqualIgnoreDamage(hoveredStack)) {
onMouseClick(slot, slot.id, 0, SlotActionType.QUICK_MOVE);
if(!hasControlDown())
break;
Expand All @@ -166,9 +166,9 @@ public boolean mouseWheelie_onMouseScroll(double mouseX, double mouseY, double s
int stackSize = Integer.MAX_VALUE;
for(Slot slot : container.slotList) {
if(slotsInSameScope.apply(slot, hoveredSlot)) continue;
if(slot.getStack().isEqualIgnoreTags(hoveredStack)) {
if(slot.getStack().getAmount() < stackSize) {
stackSize = slot.getStack().getAmount();
if(slot.getStack().isItemEqualIgnoreDamage(hoveredStack)) {
if(slot.getStack().getCount() < stackSize) {
stackSize = slot.getStack().getCount();
moveSlot = slot;
if(stackSize == 1) break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import net.minecraft.client.gui.screen.recipebook.AbstractFurnaceRecipeBookScreen;
import net.minecraft.container.Container;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.network.chat.Component;
import net.minecraft.text.Text;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
Expand All @@ -17,7 +17,7 @@ public abstract class MixinAbstractFurnaceScreen extends AbstractContainerScreen

@Shadow @Final public AbstractFurnaceRecipeBookScreen recipeBook;

public MixinAbstractFurnaceScreen(Container container_1, PlayerInventory playerInventory_1, Component textComponent_1) {
public MixinAbstractFurnaceScreen(Container container_1, PlayerInventory playerInventory_1, Text textComponent_1) {
super(container_1, playerInventory_1, textComponent_1);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ public void onGuiActionConfirmed(ConfirmGuiActionS2CPacket packet, CallbackInfo

@Inject(method = "onGuiSlotUpdate", at = @At(value = "INVOKE", target = "Lnet/minecraft/container/PlayerContainer;setStackInSlot(ILnet/minecraft/item/ItemStack;)V", shift = At.Shift.BEFORE))
public void onGuiSlotUpdate(GuiSlotUpdateS2CPacket packet, CallbackInfo callbackInfo) {
if(ClientCore.awaitFoodSlotUpdate) {
ClientCore.awaitFoodSlotUpdate = false;
if(ClientCore.awaitSlotUpdate) {
ClientCore.awaitSlotUpdate = false;
SlotRefiller.refill();
} else {
PlayerInventory inventory = client.player.inventory;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package de.siphalor.mousewheelie.client.mixin;

import de.siphalor.mousewheelie.client.Config;
import de.siphalor.mousewheelie.client.util.ISlot;
import de.siphalor.mousewheelie.client.util.inventory.SlotRefiller;
import net.minecraft.client.MinecraftClient;
import net.minecraft.container.Container;
import net.minecraft.container.PlayerContainer;
import net.minecraft.container.Slot;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.item.ItemStack;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;

import java.util.List;

@Mixin(Container.class)
public abstract class MixinContainer {
@Shadow public abstract Slot getSlot(int int_1);

private static boolean mouseWheelie_scheduleRefill = false;

@Inject(method = "updateSlotStacks", at = @At(value = "INVOKE", target = "Lnet/minecraft/container/Container;getSlot(I)Lnet/minecraft/container/Slot;", shift = At.Shift.BEFORE), locals = LocalCapture.CAPTURE_FAILSOFT)
public void onSlotUpdate(List<ItemStack> itemStacks, CallbackInfo callbackInfo, int index) {
if((Object) this instanceof PlayerContainer && Config.otherRefill.value) {
PlayerInventory inventory = MinecraftClient.getInstance().player.inventory;
if(inventory.selectedSlot == ((ISlot) getSlot(index)).mouseWheelie_getInvSlot()) {
ItemStack stack = inventory.getMainHandStack();
if (!stack.isEmpty() && itemStacks.get(index).isEmpty()) {
mouseWheelie_scheduleRefill = true;
SlotRefiller.set(inventory, stack.copy());
}
}
}
}

@Inject(method = "updateSlotStacks", at = @At(value = "INVOKE", target = "Lnet/minecraft/container/Slot;setStack(Lnet/minecraft/item/ItemStack;)V", shift = At.Shift.AFTER), locals = LocalCapture.CAPTURE_FAILSOFT)
public void onSlotUpdated(List<ItemStack> stacks, CallbackInfo callbackInfo, int index) {
if(mouseWheelie_scheduleRefill) {
mouseWheelie_scheduleRefill = false;
SlotRefiller.refill();
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@
import de.siphalor.mousewheelie.client.util.IScrollableRecipeBook;
import net.minecraft.client.gui.screen.ingame.AbstractContainerScreen;
import net.minecraft.client.gui.screen.ingame.CraftingTableScreen;
import net.minecraft.client.gui.screen.recipebook.RecipeBookScreen;
import net.minecraft.client.gui.screen.recipebook.RecipeBookWidget;
import net.minecraft.container.CraftingTableContainer;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.network.chat.Component;
import net.minecraft.text.Text;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;

@Mixin(CraftingTableScreen.class)
public abstract class MixinCraftingTableScreen extends AbstractContainerScreen<CraftingTableContainer> implements IScrollableRecipeBook {
@Shadow @Final private RecipeBookScreen recipeBookGui;
@Shadow @Final private RecipeBookWidget recipeBookGui;

public MixinCraftingTableScreen(CraftingTableContainer container_1, PlayerInventory playerInventory_1, Component textComponent_1) {
public MixinCraftingTableScreen(CraftingTableContainer container_1, PlayerInventory playerInventory_1, Text textComponent_1) {
super(container_1, playerInventory_1, textComponent_1);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import net.minecraft.client.gui.screen.ingame.CreativeInventoryScreen;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.item.ItemGroup;
import net.minecraft.network.chat.Component;
import net.minecraft.text.Text;
import net.minecraft.util.math.MathHelper;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
Expand All @@ -21,7 +21,7 @@ public abstract class MixinCreativeInventoryScreen extends AbstractInventoryScre

@Shadow protected abstract void setSelectedTab(ItemGroup itemGroup_1);

public MixinCreativeInventoryScreen(CreativeInventoryScreen.CreativeContainer container_1, PlayerInventory playerInventory_1, Component textComponent_1) {
public MixinCreativeInventoryScreen(CreativeInventoryScreen.CreativeContainer container_1, PlayerInventory playerInventory_1, Text textComponent_1) {
super(container_1, playerInventory_1, textComponent_1);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@
import de.siphalor.mousewheelie.client.util.IScrollableRecipeBook;
import net.minecraft.client.gui.screen.ingame.AbstractInventoryScreen;
import net.minecraft.client.gui.screen.ingame.InventoryScreen;
import net.minecraft.client.gui.screen.recipebook.RecipeBookScreen;
import net.minecraft.client.gui.screen.recipebook.RecipeBookWidget;
import net.minecraft.container.Container;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.network.chat.Component;
import net.minecraft.text.Text;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;

@Mixin(InventoryScreen.class)
public abstract class MixinInventoryScreen extends AbstractInventoryScreen implements IScrollableRecipeBook {
@Shadow @Final private RecipeBookScreen recipeBook;
@Shadow @Final private RecipeBookWidget recipeBook;

public MixinInventoryScreen(Container container_1, PlayerInventory playerInventory_1, Component textComponent_1) {
public MixinInventoryScreen(Container container_1, PlayerInventory playerInventory_1, Text textComponent_1) {
super(container_1, playerInventory_1, textComponent_1);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ protected void onItemUseFinish(CallbackInfo callbackInfo) {
if((Object) this instanceof PlayerEntity && Config.eatRefill.value) {
PlayerInventory playerInventory = ((PlayerEntity)(Object) this).inventory;
SlotRefiller.set(playerInventory, playerInventory.getMainHandStack().copy());
ClientCore.awaitFoodSlotUpdate = true;
ClientCore.awaitSlotUpdate = true;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import de.siphalor.mousewheelie.client.util.IRecipeBookGui;
import de.siphalor.mousewheelie.client.util.IRecipeBookResults;
import net.minecraft.client.gui.screen.recipebook.RecipeBookResults;
import net.minecraft.client.gui.screen.recipebook.RecipeBookScreen;
import net.minecraft.client.gui.screen.recipebook.RecipeBookWidget;
import net.minecraft.client.gui.screen.recipebook.RecipeGroupButtonWidget;
import net.minecraft.util.math.MathHelper;
import org.spongepowered.asm.mixin.Final;
Expand All @@ -13,7 +13,7 @@

import java.util.List;

@Mixin(RecipeBookScreen.class)
@Mixin(RecipeBookWidget.class)
public abstract class MixinRecipeBookScreen implements IRecipeBookGui {

@Shadow @Final protected RecipeBookResults recipesArea;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,18 @@ private void combineStacks() {
for(int i = stacks.length - 1; i >= 0; i--) {
stack = stacks[i];
if(stack.isEmpty()) continue;
int stackSize = stack.getAmount();
if(stackSize >= stack.getItem().getMaxAmount()) continue;
int stackSize = stack.getCount();
if(stackSize >= stack.getItem().getMaxCount()) continue;
clickEvents.add(new InteractionManager.ClickEvent(container.syncId, inventorySlots.get(i).id, 0, SlotActionType.PICKUP));
for(int j = 0; j < i; j++) {
ItemStack targetStack = stacks[j];
if(targetStack.isEmpty()) continue;
if(targetStack.getAmount() >= targetStack.getItem().getMaxAmount()) continue;
if(targetStack.getCount() >= targetStack.getItem().getMaxCount()) continue;
if(stack.getItem() == targetStack.getItem() && ItemStack.areTagsEqual(stack, targetStack)) {
int delta = targetStack.getItem().getMaxAmount() - targetStack.getAmount();
int delta = targetStack.getItem().getMaxCount() - targetStack.getCount();
delta = Math.min(delta, stackSize);
stackSize -= delta;
targetStack.setAmount(targetStack.getAmount() + delta);
targetStack.setCount(targetStack.getCount() + delta);
clickEvents.add(new InteractionManager.ClickEvent(container.syncId, inventorySlots.get(j).id, 0, SlotActionType.PICKUP));
if(stackSize <= 0) break;
}
Expand All @@ -81,7 +81,7 @@ private void combineStacks() {
clickEvents.clear();
if(stackSize > 0) {
InteractionManager.pushClickEvent(container.syncId, inventorySlots.get(i).id, 0, SlotActionType.PICKUP);
stack.setAmount(stackSize);
stack.setCount(stackSize);
} else {
stacks[i] = ItemStack.EMPTY;
}
Expand Down
Loading

0 comments on commit 564fb98

Please sign in to comment.