Skip to content

Commit

Permalink
Merge branch '1.15' into 1.14
Browse files Browse the repository at this point in the history
  • Loading branch information
Siphalor committed May 27, 2021
2 parents 1d48f8f + 2c0f4a7 commit ef45e59
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 101 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ plugins {
id 'fabric-loom' version '0.7-SNAPSHOT'
id 'maven-publish'
id 'com.matthewprenger.cursegradle' version '1.4.0'
id 'com.modrinth.minotaur' version '1.1.0'
id 'com.modrinth.minotaur' version '1.2.1'
id 'org.cadixdev.licenser' version '0.5.0'
}

Expand Down Expand Up @@ -214,7 +214,7 @@ if (project.hasProperty("siphalorModrinthApi")) {
versionName = "[${project.mod_mc_version_specifier}] ${project.mod_version}"
changelog = getProjectChangelog()
uploadFile = remapJar
releaseType = project.mod_release
versionType = project.mod_release
for (version in ((String) project.mod_mc_versions).split(";")) {
addGameVersion(version)
}
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ yarn_build=18:v2
loader_version=0.9.0+build.204
# Mod Properties
mod_id=mousewheelie
mod_version=1.7.1
mod_version=1.7.2
mod_release=release
mod_mc_version_specifier=1.14.4
mod_mc_versions=1.14.4
Expand Down
22 changes: 18 additions & 4 deletions src/main/java/de/siphalor/mousewheelie/client/MWClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,25 @@ public static boolean performRefill() {
Hand hand = refillHand;
refillHand = null;
if (MWConfig.refill.offHand && hand.equals(Hand.OFF_HAND)) {
InteractionManager.push(new InteractionManager.PacketEvent(new PlayerActionC2SPacket(PlayerActionC2SPacket.Action.SWAP_HELD_ITEMS, BlockPos.ORIGIN, Direction.DOWN), triggerType -> triggerType == InteractionManager.TriggerType.CONTAINER_SLOT_UPDATE && MWClient.lastUpdatedSlot == 45));
// interaction only gets pushed softly so it can be removed if the refill was not successful
InteractionManager.interactionEventQueue.add(
new InteractionManager.PacketEvent(
new PlayerActionC2SPacket(PlayerActionC2SPacket.Action.SWAP_HELD_ITEMS, BlockPos.ORIGIN, Direction.DOWN),
triggerType -> triggerType == InteractionManager.TriggerType.CONTAINER_SLOT_UPDATE && MWClient.lastUpdatedSlot == 45
)
);
}
SlotRefiller.refill();
if (MWConfig.refill.offHand && hand.equals(Hand.OFF_HAND)) {
InteractionManager.push(new InteractionManager.PacketEvent(new PlayerActionC2SPacket(PlayerActionC2SPacket.Action.SWAP_HELD_ITEMS, BlockPos.ORIGIN, Direction.DOWN), triggerType -> triggerType == InteractionManager.TriggerType.CONTAINER_SLOT_UPDATE && MWClient.lastUpdatedSlot == 45));
if (SlotRefiller.refill()) {
if (MWConfig.refill.offHand && hand.equals(Hand.OFF_HAND)) {
InteractionManager.push(
new InteractionManager.PacketEvent(
new PlayerActionC2SPacket(PlayerActionC2SPacket.Action.SWAP_HELD_ITEMS, BlockPos.ORIGIN, Direction.DOWN),
triggerType -> triggerType == InteractionManager.TriggerType.CONTAINER_SLOT_UPDATE && MWClient.lastUpdatedSlot == 45
)
);
}
} else {
InteractionManager.clear();
}

return true;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,94 +1,94 @@
/*
* Copyright 2021 Siphalor
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied.
* See the License for the specific language governing
* permissions and limitations under the License.
*/

package de.siphalor.mousewheelie.client.inventory;

import de.siphalor.mousewheelie.MWConfig;
import de.siphalor.mousewheelie.client.MWClient;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.network.ClientSidePacketRegistry;
import net.minecraft.block.BlockState;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.network.packet.c2s.play.PickFromInventoryC2SPacket;

@Environment(EnvType.CLIENT)
public class ToolPicker {
PlayerInventory inventory;

static int lastToolPickSlot = -1;

public ToolPicker(PlayerInventory inventory) {
this.inventory = inventory;
}

public int findToolFor(BlockState blockState) {
float bestBreakSpeed = 1.0F;
int bestSpeedSlot = -1;
int invSize = (MWConfig.toolPicking.pickFromInventory ? inventory.main.size() : 9);
for (int i = 1; i <= invSize; i++) {
int index = (i + lastToolPickSlot) % invSize;
if (index == inventory.selectedSlot) continue;
ItemStack stack = inventory.main.get(index);
if (stack.isEffectiveOn(blockState)) {
return index;
} else {
float breakSpeed = stack.getMiningSpeed(blockState);
if (breakSpeed > bestBreakSpeed) {
bestSpeedSlot = index;
bestBreakSpeed = breakSpeed;
}
}
}
if (bestBreakSpeed == -1) {
ItemStack stack = inventory.main.get(inventory.selectedSlot);
if (stack.isEffectiveOn(blockState) || stack.getMiningSpeed(blockState) > 1.0F)
return inventory.selectedSlot;
}
return bestSpeedSlot;
}

public boolean pickToolFor(BlockState blockState) {
return pick(findToolFor(blockState));
}

public int findWeapon() {
int invSize = (MWConfig.toolPicking.pickFromInventory ? inventory.main.size() : 9);
for (int i = 1; i <= invSize; i++) {
int index = (i + lastToolPickSlot) % invSize;
if (index == inventory.selectedSlot) continue;
if (MWClient.isWeapon(inventory.main.get(index).getItem()))
return index;
}
return -1;
}

public boolean pickWeapon() {
return pick(findWeapon());
}

private boolean pick(int index) {
lastToolPickSlot = index;
if (index != -1 && index != inventory.selectedSlot) {
PickFromInventoryC2SPacket packet = new PickFromInventoryC2SPacket(index);
ClientSidePacketRegistry.INSTANCE.sendToServer(packet);
return true;
}
return false;
}
}
/*
* Copyright 2021 Siphalor
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied.
* See the License for the specific language governing
* permissions and limitations under the License.
*/

package de.siphalor.mousewheelie.client.inventory;

import de.siphalor.mousewheelie.MWConfig;
import de.siphalor.mousewheelie.client.MWClient;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.block.BlockState;
import net.minecraft.client.MinecraftClient;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.network.packet.c2s.play.PickFromInventoryC2SPacket;

@Environment(EnvType.CLIENT)
public class ToolPicker {
PlayerInventory inventory;

static int lastToolPickSlot = -1;

public ToolPicker(PlayerInventory inventory) {
this.inventory = inventory;
}

public int findToolFor(BlockState blockState) {
float bestBreakSpeed = 1.0F;
int bestSpeedSlot = -1;
int invSize = (MWConfig.toolPicking.pickFromInventory ? inventory.main.size() : 9);
for (int i = 1; i <= invSize; i++) {
int index = (i + lastToolPickSlot) % invSize;
if (index == inventory.selectedSlot) continue;
ItemStack stack = inventory.main.get(index);
if (stack.isEffectiveOn(blockState)) {
return index;
} else {
float breakSpeed = stack.getMiningSpeed(blockState);
if (breakSpeed > bestBreakSpeed) {
bestSpeedSlot = index;
bestBreakSpeed = breakSpeed;
}
}
}
if (bestBreakSpeed == -1) {
ItemStack stack = inventory.main.get(inventory.selectedSlot);
if (stack.isEffectiveOn(blockState) || stack.getMiningSpeed(blockState) > 1.0F)
return inventory.selectedSlot;
}
return bestSpeedSlot;
}

public boolean pickToolFor(BlockState blockState) {
return pick(findToolFor(blockState));
}

public int findWeapon() {
int invSize = (MWConfig.toolPicking.pickFromInventory ? inventory.main.size() : 9);
for (int i = 1; i <= invSize; i++) {
int index = (i + lastToolPickSlot) % invSize;
if (index == inventory.selectedSlot) continue;
if (MWClient.isWeapon(inventory.main.get(index).getItem()))
return index;
}
return -1;
}

public boolean pickWeapon() {
return pick(findWeapon());
}

private boolean pick(int index) {
lastToolPickSlot = index;
if (index != -1 && index != inventory.selectedSlot) {
PickFromInventoryC2SPacket packet = new PickFromInventoryC2SPacket(index);
MinecraftClient.getInstance().getNetworkHandler().sendPacket(packet);
return true;
}
return false;
}
}

0 comments on commit ef45e59

Please sign in to comment.