Compare commits

..

No commits in common. "d5873821abd4f8e1248b5ef65c29bcd7e91143bb" and "cb7b2243354d242fbfd9508b228b48e8b296443e" have entirely different histories.

5 changed files with 6 additions and 69 deletions

View File

@ -16,7 +16,7 @@ base {
}
group = "net.shadowfacts"
version = "0.2.0"
version = "0.1.0"
val minecraftVersion = "1.14.4"
val yarnMappings = "1.14.4+build.9"

View File

@ -1,49 +0,0 @@
package net.shadowfacts.autoswap.mixin;
import net.minecraft.item.ItemStack;
import net.minecraft.server.network.ServerPlayNetworkHandler;
import net.minecraft.server.network.ServerPlayerEntity;
import net.shadowfacts.autoswap.AutoSwap;
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;
/**
* @author shadowfacts
*/
@Mixin(ServerPlayNetworkHandler.class)
public abstract class MixinServerPlayNetworkHandler {
@Shadow
private ServerPlayerEntity player;
private ItemStack heldStackBeforeAttack = ItemStack.EMPTY;
@Inject(
method = "onPlayerInteractEntity",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/server/network/ServerPlayerEntity;attack(Lnet/minecraft/entity/Entity;)V"
)
)
private void beforePlayerAttack(CallbackInfo cb) {
this.heldStackBeforeAttack = player.inventory.getMainHandStack().copy();
}
@Inject(
method = "onPlayerInteractEntity",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/server/network/ServerPlayerEntity;attack(Lnet/minecraft/entity/Entity;)V",
shift = At.Shift.AFTER
)
)
private void afterPlayerAttack(CallbackInfo cb) {
AutoSwap.INSTANCE.afterAttack(player.inventory, heldStackBeforeAttack);
heldStackBeforeAttack = ItemStack.EMPTY;
}
}

View File

@ -1,5 +1,6 @@
package net.shadowfacts.autoswap.mixin;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemUsageContext;
import net.minecraft.server.network.ServerPlayerEntity;
@ -23,14 +24,12 @@ public abstract class MixinServerPlayerInteractionManager {
@Shadow
private ServerPlayerEntity player;
@Shadow
abstract boolean isCreative();
private ItemStack heldStackAtBeginningOfBreak = ItemStack.EMPTY;
@Inject(method = "tryBreakBlock", at = @At("HEAD"))
private void beginTryBreakBlock(BlockPos pos, CallbackInfoReturnable<Void> cb) {
heldStackAtBeginningOfBreak = player.inventory.getMainHandStack().copy();
PlayerInventory playerInv = player.inventory;
heldStackAtBeginningOfBreak = playerInv.getInvStack(playerInv.selectedSlot).copy();
}
@Inject(method = "tryBreakBlock", at = @At("RETURN"))
@ -46,7 +45,7 @@ public abstract class MixinServerPlayerInteractionManager {
private ActionResult useOnBlock(ItemStack self, ItemUsageContext context) {
ItemStack selfCopy = self.copy();
ActionResult result = self.useOnBlock(context);
if (!isCreative() && result == ActionResult.SUCCESS) {
if (result == ActionResult.SUCCESS) {
AutoSwap.INSTANCE.onUseOnItem(player, player.inventory, selfCopy);
}
return result;

View File

@ -44,16 +44,4 @@ object AutoSwap: ModInitializer {
}
}
fun afterAttack(playerInv: PlayerInventory, heldStackBeforeAttack: ItemStack) {
val heldStack = playerInv.mainHandStack
if (!heldStackBeforeAttack.isEmpty && heldStack.isEmpty) {
val index = playerInv.main.indexOfFirst {
ItemStack.areItemsEqualIgnoreDamage(heldStackBeforeAttack, it)
}
if (index >= 0) {
playerInv.swapSlotWithHotbar(index)
}
}
}
}

View File

@ -3,8 +3,7 @@
"package": "net.shadowfacts.autoswap.mixin",
"compatibilityLevel": "JAVA_8",
"mixins": [
"MixinServerPlayerInteractionManager",
"MixinServerPlayNetworkHandler"
"MixinServerPlayerInteractionManager"
],
"client": [
],