package net.mcreator.puzzle_code.procedures;

import net.neoforged.neoforge.items.IItemHandlerModifiable;
import net.neoforged.neoforge.items.IItemHandler;
import net.neoforged.neoforge.common.extensions.ILevelExtension;
import net.neoforged.neoforge.capabilities.Capabilities;

import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.item.component.CustomData;
import net.minecraft.world.item.ItemStack;
import net.minecraft.core.component.DataComponents;
import net.minecraft.core.BlockPos;

public class SetDirectionDownDirectionCodeItemProcedure {
	public static void execute(LevelAccessor world, double x, double y, double z) {
		ItemStack ItemSlot = ItemStack.EMPTY;
		ItemSlot = (new Object() {
			public ItemStack getItemStack(LevelAccessor world, BlockPos pos, int slotid) {
				if (world instanceof ILevelExtension _ext) {
					IItemHandler _itemHandler = _ext.getCapability(Capabilities.ItemHandler.BLOCK, pos, null);
					if (_itemHandler != null)
						return _itemHandler.getStackInSlot(slotid).copy();
				}
				return ItemStack.EMPTY;
			}
		}.getItemStack(world, BlockPos.containing(x, y, z), 0)).copy();
		{
			final String _tagName = "directionCodeBlock";
			final double _tagValue = 0;
			CustomData.update(DataComponents.CUSTOM_DATA, ItemSlot, tag -> tag.putDouble(_tagName, _tagValue));
		}
		{
			final String _tagName = "direction";
			final String _tagValue = "DOWN";
			CustomData.update(DataComponents.CUSTOM_DATA, ItemSlot, tag -> tag.putString(_tagName, _tagValue));
		}
		if (world instanceof ILevelExtension _ext && _ext.getCapability(Capabilities.ItemHandler.BLOCK, BlockPos.containing(x, y, z), null) instanceof IItemHandlerModifiable _itemHandlerModifiable) {
			ItemStack _setstack = ItemSlot.copy();
			_setstack.setCount(new Object() {
				public int getAmount(LevelAccessor world, BlockPos pos, int slotid) {
					if (world instanceof ILevelExtension _ext) {
						IItemHandler _itemHandler = _ext.getCapability(Capabilities.ItemHandler.BLOCK, pos, null);
						if (_itemHandler != null)
							return _itemHandler.getStackInSlot(slotid).getCount();
					}
					return 0;
				}
			}.getAmount(world, BlockPos.containing(x, y, z), 0));
			_itemHandlerModifiable.setStackInSlot(0, _setstack);
		}
	}
}
