This repository has been archived on 2023-11-26. You can view files and clone it, but cannot push or open issues or pull requests.
SlightlyVanilla/src/main/java/com/thebrokenrail/slightlyvanilla/mixin/MixinItem.java

37 lines
1.6 KiB
Java

package com.thebrokenrail.slightlyvanilla.mixin;
import com.thebrokenrail.slightlyvanilla.SlightlyVanilla;
import com.thebrokenrail.slightlyvanilla.entity.SlimeballEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.TypedActionResult;
import net.minecraft.world.World;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
@Mixin(Item.class)
public class MixinItem {
@Inject(at = @At("HEAD"), method = "use", cancellable = true)
public void use(World world, PlayerEntity playerEntity, Hand hand, CallbackInfoReturnable<TypedActionResult<ItemStack>> info) {
ItemStack stack = playerEntity.getStackInHand(hand);
if (stack.getItem() == Items.SLIME_BALL && SlightlyVanilla.getConfig().throwableSlimeballs) {
if (!world.isClient()) {
SlimeballEntity entity = new SlimeballEntity(world, playerEntity);
entity.setItem(stack);
entity.setProperties(playerEntity, playerEntity.pitch, playerEntity.yaw, 0.0f, 1.5f, 1.0f);
world.spawnEntity(entity);
}
if (!playerEntity.isCreative()) {
stack.decrement(1);
}
info.setReturnValue(new TypedActionResult<>(ActionResult.SUCCESS, stack));
}
}
}