Search in sources :

Example 1 with TemporaryCauldronInventory

use of de.siphalor.nbtcrafting.recipe.cauldron.TemporaryCauldronInventory in project nbt-crafting by Siphalor.

the class MixinCauldronBlock method onActivate.

@Inject(method = "onUse", at = @At("HEAD"), cancellable = true)
public void onActivate(BlockState blockState, World world, BlockPos blockPos, PlayerEntity playerEntity, Hand hand, BlockHitResult blockHitResult, CallbackInfoReturnable<ActionResult> callbackInfoReturnable) {
    if (!world.isClient()) {
        TemporaryCauldronInventory inventory = new TemporaryCauldronInventory(playerEntity, hand, world, blockPos);
        Optional<CauldronRecipe> cauldronRecipe = world.getRecipeManager().getFirstMatch(NbtCrafting.CAULDRON_RECIPE_TYPE, inventory, world);
        if (cauldronRecipe.isPresent()) {
            DefaultedList<ItemStack> remainingStacks = cauldronRecipe.get().getRemainingStacks(inventory);
            ItemStack itemStack = cauldronRecipe.get().craft(inventory);
            itemStack.onCraft(world, playerEntity, itemStack.getCount());
            if (!playerEntity.inventory.insertStack(remainingStacks.get(0))) {
                ItemEntity itemEntity = playerEntity.dropItem(remainingStacks.get(0), false);
                if (itemEntity != null) {
                    itemEntity.resetPickupDelay();
                    itemEntity.setOwner(playerEntity.getUuid());
                }
            }
            if (!playerEntity.inventory.insertStack(itemStack)) {
                ItemEntity itemEntity = playerEntity.dropItem(itemStack, false);
                if (itemEntity != null) {
                    itemEntity.resetPickupDelay();
                    itemEntity.setOwner(playerEntity.getUuid());
                }
            }
            callbackInfoReturnable.setReturnValue(ActionResult.SUCCESS);
        }
    }
}
Also used : CauldronRecipe(de.siphalor.nbtcrafting.recipe.cauldron.CauldronRecipe) ItemEntity(net.minecraft.entity.ItemEntity) TemporaryCauldronInventory(de.siphalor.nbtcrafting.recipe.cauldron.TemporaryCauldronInventory) ItemStack(net.minecraft.item.ItemStack) Inject(org.spongepowered.asm.mixin.injection.Inject)

Aggregations

CauldronRecipe (de.siphalor.nbtcrafting.recipe.cauldron.CauldronRecipe)1 TemporaryCauldronInventory (de.siphalor.nbtcrafting.recipe.cauldron.TemporaryCauldronInventory)1 ItemEntity (net.minecraft.entity.ItemEntity)1 ItemStack (net.minecraft.item.ItemStack)1 Inject (org.spongepowered.asm.mixin.injection.Inject)1