Java Code Examples for net.minecraft.util.math.Direction#rotateYCounterclockwise()

The following examples show how to use net.minecraft.util.math.Direction#rotateYCounterclockwise() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AutoBuildTemplate.java    From Wurst7 with GNU General Public License v3.0 6 votes vote down vote up
public LinkedHashSet<BlockPos> getPositions(BlockPos startPos,
	Direction direction)
{
	Direction front = direction;
	Direction left = front.rotateYCounterclockwise();
	LinkedHashSet<BlockPos> positions = new LinkedHashSet<>();
	
	for(int[] block : blocks)
	{
		BlockPos pos = startPos;
		pos = pos.offset(left, block[0]);
		pos = pos.up(block[1]);
		pos = pos.offset(front, block[2]);
		positions.add(pos);
	}
	
	return positions;
}
 
Example 2
Source File: TinyPumpkinBlockEntity.java    From the-hallow with MIT License 5 votes vote down vote up
public ActionResult use(PlayerEntity player, Hand hand, BlockHitResult hit) {
	Direction facing = getCachedState().get(HorizontalFacingBlock.FACING);
	Direction hitSide = hit.getSide();
	if (hitSide != facing.rotateYClockwise() && hitSide != facing.rotateYCounterclockwise()) {
		return ActionResult.PASS;
	}
	
	if (!world.isClient) {
		ItemStack handStack = player.getStackInHand(hand);
		boolean isLeft = hitSide == facing.rotateYCounterclockwise();
		ItemStack heldItem = isLeft ? leftItem : rightItem;
		if (!heldItem.isEmpty()) {
			ItemScatterer.spawn(world, pos, DefaultedList.copyOf(ItemStack.EMPTY, heldItem));
			if (isLeft) {
				leftItem = ItemStack.EMPTY;
			} else {
				rightItem = ItemStack.EMPTY;
			}
			sync();
			markDirty();
		} else if (!handStack.isEmpty()) {
			if (isLeft) {
				leftItem = handStack.copy();
				leftItem.setCount(1);
			} else {
				rightItem = handStack.copy();
				rightItem.setCount(1);
			}
			handStack.decrement(1);
			sync();
			markDirty();
		}
	}
	
	return ActionResult.SUCCESS;
}
 
Example 3
Source File: InstantBunkerHack.java    From Wurst7 with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onEnable()
{
	if(!MC.player.isOnGround())
	{
		ChatUtils.error("Can't build this in mid-air.");
		setEnabled(false);
		return;
	}
	
	ItemStack stack = MC.player.inventory.getMainHandStack();
	
	if(!(stack.getItem() instanceof BlockItem))
	{
		ChatUtils.error("You must have blocks in the main hand.");
		setEnabled(false);
		return;
	}
	
	if(stack.getCount() < 57 && !MC.player.isCreative())
		ChatUtils.warning("Not enough blocks. Bunker may be incomplete.");
	
	// get start pos and facings
	BlockPos startPos = new BlockPos(MC.player.getPos());
	Direction facing = MC.player.getHorizontalFacing();
	Direction facing2 = facing.rotateYCounterclockwise();
	
	// set positions
	positions.clear();
	for(int[] pos : template)
		positions.add(startPos.up(pos[1]).offset(facing, pos[2])
			.offset(facing2, pos[0]));
	
	if(!"".isEmpty())// mode.getSelected() == 1)
	{
		// initialize building process
		blockIndex = 0;
		building = true;
		IMC.setItemUseCooldown(4);
	}
	
	startTimer = 2;
	MC.player.jump();
	
	EVENTS.add(UpdateListener.class, this);
	EVENTS.add(RenderListener.class, this);
}