<commit_before>package de.longor.talecraft.items;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ActionResult;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.TextComponentString;
import net.minecraft.util.text.TextFormatting;
import net.minecraft.world.World;
import net.minecraftforge.fml.common.FMLCommonHandler;

public class NudgeItem extends TCItem {

	@Override
	public EnumActionResult onItemUse(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
		if(world.isRemote)
			return EnumActionResult.PASS;

		nudge(player);

		return EnumActionResult.SUCCESS;
	}

	@Override
	public ActionResult<ItemStack> onItemRightClick(ItemStack stack, World world, EntityPlayer player, EnumHand hand) {
		if(world.isRemote)
			return ActionResult.newResult(EnumActionResult.PASS, stack);

		nudge(player);

		return ActionResult.newResult(EnumActionResult.SUCCESS, stack);
	}

	private void nudge(EntityPlayer player) {
		if(player == null)
			return;

		// Get WORLD
		World world = player.worldObj;

		if(world.isRemote)
			return;

		// Get SIDE
		EnumFacing side = null;

		if(player.rotationPitch > 45) {
			side = EnumFacing.DOWN;
		} else if(player.rotationPitch < -45) {
			side = EnumFacing.UP;
		} else {
			side = player.getHorizontalFacing();
		}

		// If SNEAKING do INVERT FACING
		if(player.isSneaking()) {
			side = side.getOpposite();
		}

		// Get BOUNDS
		int[] bounds = WandItem.getBoundsFromPlayerOrNull(player);

		if(bounds == null) {
			player.addChatMessage(new TextComponentString(TextFormatting.RED+"Bounds invalid."));
			return;
		}

		long bounds_volume = WandItem.getBoundsVolume(bounds);

		if(bounds_volume > (32*32*32)) {
			player.addChatMessage(new TextComponentString(TextFormatting.RED+"Selection is too big: " + bounds_volume));
			return;
		}

		// playerIn.addChatMessage(new ChatComponentText(TextFormatting.AQUA+"Nudge: " + direction + " " + bounds_volume));

		int ix = bounds[0];
		int iy = bounds[1];
		int iz = bounds[2];
		int ax = bounds[3];
		int ay = bounds[4];
		int az = bounds[5];

		int new_ix = ix;
		int new_iy = iy;
		int new_iz = iz;

		switch(side) {
		// x
		case EAST:	new_ix++; break;
		case WEST:	new_ix--; break;
		// y
		case UP:	new_iy++; break;
		case DOWN:	new_iy--; break;
		// z
		case SOUTH:	new_iz++; break;
		case NORTH:	new_iz--; break;
		// ?!
		default: return;
		}

		int moveX = new_ix - ix;
		int moveY = new_iy - iy;
		int moveZ = new_iz - iz;

		StringBuilder builder = new StringBuilder(128);

		builder.append("/clone ");

		builder.append(ix).append(' ');
		builder.append(iy).append(' ');
		builder.append(iz).append(' ');

		builder.append(ax).append(' ');
		builder.append(ay).append(' ');
		builder.append(az).append(' ');

		builder.append(new_ix).append(' ');
		builder.append(new_iy).append(' ');
		builder.append(new_iz).append(' ');

		builder.append("replace");
		builder.append(' ');
		builder.append("move");

		// playerIn.addChatMessage(new ChatComponentText(EnumChatFormatting.GOLD+builder.toString()));
		FMLCommonHandler.instance().getMinecraftServerInstance().getCommandManager().executeCommand(player, builder.toString());

		ix += moveX;
		iy += moveY;
		iz += moveZ;<commit_msg>Nudge Tool: Implemented bounds-nudging.<commit_after>package de.longor.talecraft.items;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ActionResult;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.TextComponentString;
import net.minecraft.util.text.TextFormatting;
import net.minecraft.world.World;
import net.minecraftforge.fml.common.FMLCommonHandler;

public class NudgeItem extends TCItem {

	@Override
	public EnumActionResult onItemUse(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
		if(world.isRemote)
			return EnumActionResult.PASS;
		return EnumActionResult.SUCCESS;
	}

	@Override
	public ActionResult<ItemStack> onItemRightClick(ItemStack stack, World world, EntityPlayer player, EnumHand hand) {
		if(world.isRemote)
			return ActionResult.newResult(EnumActionResult.PASS, stack);

		nudge(player, player.isSneaking());

		return ActionResult.newResult(EnumActionResult.SUCCESS, stack);
	}

	private void nudge(EntityPlayer player, boolean moveByBounds) {
		if(player == null)
			return;

		// Get WORLD
		World world = player.worldObj;

		if(world.isRemote)
			return;

		// Get SIDE
		EnumFacing side = null;

		if(player.rotationPitch > 45) {
			side = EnumFacing.DOWN;
		} else if(player.rotationPitch < -45) {
			side = EnumFacing.UP;
		} else {
			side = player.getHorizontalFacing();
		}

		// If SNEAKING do INVERT FACING
		if(player.isSneaking()) {
			side = side.getOpposite();
		}

		// Get BOUNDS
		int[] bounds = WandItem.getBoundsFromPlayerOrNull(player);

		if(bounds == null) {
			player.addChatMessage(new TextComponentString(TextFormatting.RED+"Bounds invalid."));
			return;
		}

		long bounds_volume = WandItem.getBoundsVolume(bounds);

		if(bounds_volume > (32*32*32)) {
			player.addChatMessage(new TextComponentString(TextFormatting.RED+"Selection is too big: " + bounds_volume));
			return;
		}

		// playerIn.addChatMessage(new ChatComponentText(TextFormatting.AQUA+"Nudge: " + direction + " " + bounds_volume));
		
		// Selection Bounds
		int ix = bounds[0];
		int iy = bounds[1];
		int iz = bounds[2];
		int ax = bounds[3];
		int ay = bounds[4];
		int az = bounds[5];
		
		// Selection Size
		int sx = ax-ix+1;
		int sy = ay-iy+1;
		int sz = az-iz+1;
		
		// Selection Movement
		int new_ix = ix;
		int new_iy = iy;
		int new_iz = iz;
		
		if(moveByBounds) {
			switch(side) {
				// x
				case EAST:	new_ix +=-sx; break;
				case WEST:	new_ix -=-sx; break;
				// y
				case UP:	  new_iy +=-sy; break;
				case DOWN:	new_iy -=-sy; break;
				// z
				case SOUTH:	new_iz +=-sz; break;
				case NORTH:	new_iz -=-sz; break;
				// ?!
				default: return;
			}
		} else {
			switch(side) {
				// x
				case EAST:	new_ix++; break;
				case WEST:	new_ix--; break;
				// y
				case UP:	  new_iy++; break;
				case DOWN:	new_iy--; break;
				// z
				case SOUTH:	new_iz++; break;
				case NORTH:	new_iz--; break;
				// ?!
				default: return;
			}
		}
		
		int moveX = new_ix - ix;
		int moveY = new_iy - iy;
		int moveZ = new_iz - iz;
		
		// Lets by terribly lazy and use an existing minecraft command to do the actual movement.
		
		StringBuilder builder = new StringBuilder(128);

		builder.append("/clone ");

		builder.append(ix).append(' ');
		builder.append(iy).append(' ');
		builder.append(iz).append(' ');

		builder.append(ax).append(' ');
		builder.append(ay).append(' ');
		builder.append(az).append(' ');

		builder.append(new_ix).append(' ');
		builder.append(new_iy).append(' ');
		builder.append(new_iz).append(' ');

		builder.append("replace");
		builder.append(' ');
		builder.append("move");

		// playerIn.addChatMessage(new ChatComponentText(EnumChatFormatting.GOLD+builder.toString()));
		FMLCommonHandler.instance().getMinecraftServerInstance().getCommandManager().executeCommand(player, builder.toString());

		ix += moveX;
		iy += moveY;
		iz += moveZ;
{'fraction_non_alphanumeric': 0.13639361561799235, 'fraction_numerical': 0.005408257485819813, 'mean_word_length': 3.8664955070603337, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2884396', 'n_tokens_mistral': 2919, 'n_tokens_neox': 2566, 'n_words': 546}