當前位置: 首頁>>代碼示例>>Java>>正文


Java RayTraceResult.getBlockPos方法代碼示例

本文整理匯總了Java中net.minecraft.util.math.RayTraceResult.getBlockPos方法的典型用法代碼示例。如果您正苦於以下問題:Java RayTraceResult.getBlockPos方法的具體用法?Java RayTraceResult.getBlockPos怎麽用?Java RayTraceResult.getBlockPos使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在net.minecraft.util.math.RayTraceResult的用法示例。


在下文中一共展示了RayTraceResult.getBlockPos方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: onClientTick

import net.minecraft.util.math.RayTraceResult; //導入方法依賴的package包/類
@SubscribeEvent
public static void onClientTick(ClientTickEvent event) throws Throwable {
    if (event.phase == Phase.START && (!Configs.creativeOnly || Minecraft.getMinecraft().player.isCreative())) {
        int timer = (int) getDelayTimer.invoke(Minecraft.getMinecraft());
        RayTraceResult hover = Minecraft.getMinecraft().objectMouseOver;
        if (hover != null && hover.typeOfHit == Type.BLOCK) {
            BlockPos pos = hover.getBlockPos();
            if (timer > 0 && !pos.equals(lastTargetPos) && (lastTargetPos == null || !pos.equals(lastTargetPos.offset(lastTargetSide)))) {
                setDelayTimer.invoke(Minecraft.getMinecraft(), 0);
            } else if (Configs.forceNewLoc && timer == 0 && pos.equals(lastTargetPos) && hover.sideHit == lastTargetSide) {
                setDelayTimer.invoke(Minecraft.getMinecraft(), 4);
            }
            lastTargetPos = pos.toImmutable();
            lastTargetSide = hover.sideHit;
        }
    }
}
 
開發者ID:tterrag1098,項目名稱:BetterPlacement,代碼行數:18,代碼來源:BetterPlacement.java

示例2: onGameOverlay

import net.minecraft.util.math.RayTraceResult; //導入方法依賴的package包/類
@SubscribeEvent
public void onGameOverlay(RenderGameOverlayEvent.Post event)
{
	if(event.getType() == RenderGameOverlayEvent.ElementType.ALL && Minecraft.getMinecraft().currentScreen == null)
	{
           Minecraft minecraft = Minecraft.getMinecraft();
           EntityPlayer player = minecraft.player;
           RayTraceResult posHit = minecraft.objectMouseOver;
           if(posHit != null && posHit.getBlockPos() != null)
           {
               Block blockHit = minecraft.world.getBlockState(posHit.getBlockPos()).getBlock();
               if(blockHit instanceof IHudDisplay)
                   ((IHudDisplay)blockHit).displayHud(minecraft, player, posHit, event.getResolution());
               TileEntity tileHit = minecraft.world.getTileEntity(posHit.getBlockPos());
               if(tileHit instanceof IHudDisplay)
               	((IHudDisplay)tileHit).displayHud(minecraft, player, posHit, event.getResolution());
           }
	}
}
 
開發者ID:kenijey,項目名稱:harshencastle,代碼行數:20,代碼來源:HandlerGameOverlay.java

示例3: onImpact

import net.minecraft.util.math.RayTraceResult; //導入方法依賴的package包/類
protected void onImpact(RayTraceResult result) {
	if (!this.world.isRemote && this.world instanceof WorldServer) {
		if (result.typeOfHit == RayTraceResult.Type.ENTITY && result.entityHit != null
				&& !result.entityHit.equals(this.caster)) {
			Entity entity = result.entityHit;
			if (!entity.isImmuneToFire()) {
				entity.setFire(7);
			}
		} else if (result.typeOfHit == RayTraceResult.Type.BLOCK && result.getBlockPos() != null
				&& result.sideHit != null) {
			BlockPos offsetPos = result.getBlockPos().offset(result.sideHit);
			if (this.world.getBlockState(offsetPos).getMaterial() != Material.WATER
					&& (this.world.isAirBlock(offsetPos)
							|| this.world.getBlockState(offsetPos).getBlock().isReplaceable(this.world, offsetPos))
					&& Blocks.FIRE.canPlaceBlockAt(this.world, offsetPos)) {
				this.world.setBlockState(offsetPos, Blocks.FIRE.getDefaultState(), 11);
			}
		}
	}
}
 
開發者ID:the-realest-stu,項目名稱:Infernum,代碼行數:21,代碼來源:EntityFireBreath.java

示例4: execute

import net.minecraft.util.math.RayTraceResult; //導入方法依賴的package包/類
@Override
protected void execute(HVSession session, CommandArgSet args) throws CommandException {
    Entity e = session.owner.getCommandSenderEntity();
    if (e == null) {
        throw new CommandException("There is no entity to look with!");
    }
    RayTraceResult result = RayTraceHelper.rayTraceEntity(e, 128);
    if (result == null || result.typeOfHit != RayTraceResult.Type.BLOCK) {
        throw new CommandException("Not looking at a block!");
    }
    BlockPos position = result.getBlockPos();
    Vector3i vec = new Vector3i(position.getX(), position.getY(), position.getZ());
    positionSetter.accept(session, vec);
}
 
開發者ID:kenzierocks,項目名稱:HardVox,代碼行數:15,代碼來源:LookPositionCommand.java

示例5: onHitGround

import net.minecraft.util.math.RayTraceResult; //導入方法依賴的package包/類
@Override
public void onHitGround(int x, int y, int z, RayTraceResult mop) {
	super.onHitGround(x, y, z, mop);
	this.setPosition(mop.hitVec.x + mop.sideHit.getFrontOffsetX() * 0.1,
			mop.hitVec.y + mop.sideHit.getFrontOffsetY() * 0.1f,
			mop.hitVec.z + mop.sideHit.getFrontOffsetZ() * 0.1);
	this.sticked = true;
	this.stickedBlock = mop.getBlockPos();
}
 
開發者ID:rafradek,項目名稱:Mods,代碼行數:10,代碼來源:EntityStickProjectile.java

示例6: drawSelectionBox

import net.minecraft.util.math.RayTraceResult; //導入方法依賴的package包/類
/**
 * Draws the selection box for the player.
 */
public void drawSelectionBox(EntityPlayer player, RayTraceResult movingObjectPositionIn, int execute, float partialTicks)
{
    if (execute == 0 && movingObjectPositionIn.typeOfHit == RayTraceResult.Type.BLOCK)
    {
        GlStateManager.enableBlend();
        GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
        GlStateManager.glLineWidth(2.0F);
        GlStateManager.disableTexture2D();

        if (Config.isShaders())
        {
            Shaders.disableTexture2D();
        }

        GlStateManager.depthMask(false);
        BlockPos blockpos = movingObjectPositionIn.getBlockPos();
        IBlockState iblockstate = this.theWorld.getBlockState(blockpos);

        if (iblockstate.getMaterial() != Material.AIR && this.theWorld.getWorldBorder().contains(blockpos))
        {
            double d0 = player.lastTickPosX + (player.posX - player.lastTickPosX) * (double)partialTicks;
            double d1 = player.lastTickPosY + (player.posY - player.lastTickPosY) * (double)partialTicks;
            double d2 = player.lastTickPosZ + (player.posZ - player.lastTickPosZ) * (double)partialTicks;
            drawSelectionBoundingBox(iblockstate.getSelectedBoundingBox(this.theWorld, blockpos).expandXyz(0.0020000000949949026D).offset(-d0, -d1, -d2), 0.0F, 0.0F, 0.0F, 0.4F);
        }

        GlStateManager.depthMask(true);
        GlStateManager.enableTexture2D();

        if (Config.isShaders())
        {
            Shaders.enableTexture2D();
        }

        GlStateManager.disableBlend();
    }
}
 
開發者ID:sudofox,項目名稱:Backmemed,代碼行數:41,代碼來源:RenderGlobal.java

示例7: checkWheelKey

import net.minecraft.util.math.RayTraceResult; //導入方法依賴的package包/類
private void checkWheelKey() {
    if (KeyBindings.keyOpenWheel.isPressed()) {
        EntityPlayerSP player = MinecraftTools.getPlayer(Minecraft.getMinecraft());
        RayTraceResult mouseOver = Minecraft.getMinecraft().objectMouseOver;
        if (mouseOver != null && mouseOver.typeOfHit == RayTraceResult.Type.BLOCK) {
            BlockPos pos = mouseOver.getBlockPos();
            player.openGui(InteractionWheel.instance, GuiProxy.GUI_WHEEL, player.getEntityWorld(), pos.getX(), pos.getY(), pos.getZ());
        } else {
            player.openGui(InteractionWheel.instance, GuiProxy.GUI_WHEEL, player.getEntityWorld(), player.getPosition().getX(), player.getPosition().getY(), player.getPosition().getZ());
        }
    }
}
 
開發者ID:McJty,項目名稱:interactionwheel,代碼行數:13,代碼來源:InputHandler.java

示例8: onItemRightClick

import net.minecraft.util.math.RayTraceResult; //導入方法依賴的package包/類
@Override
public ActionResult<ItemStack> onItemRightClick(ItemStack stack, World worldIn, EntityPlayer playerIn, EnumHand hand) {
	init(stack);
	if (getFluidStored(stack) >= FLUID_CAPACITY) {
		return new ActionResult<ItemStack>(EnumActionResult.FAIL, stack);
	}
	RayTraceResult ray = rayTrace(worldIn, playerIn, true);
	if (ray == null || ray.typeOfHit == null || hand == null) {
		return new ActionResult<ItemStack>(EnumActionResult.FAIL, stack);
	}
	if (ray.typeOfHit == RayTraceResult.Type.BLOCK && hand == EnumHand.MAIN_HAND && !worldIn.isRemote) {
		BlockPos blockpos = ray.getBlockPos();
		IBlockState iblockstate = worldIn.getBlockState(blockpos);
		Material material = iblockstate.getMaterial();

		if (material == Material.WATER && iblockstate.getValue(BlockLiquid.LEVEL).intValue() == 0) {
			worldIn.setBlockState(blockpos, Blocks.AIR.getDefaultState(), 11);
			playerIn.addStat(StatList.getObjectUseStats(this));
			playerIn.playSound(SoundEvents.ITEM_BUCKET_FILL, 1.0F, 1.0F);
			addFluid(stack, 1000);
			return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, stack);
		}
		else if (iblockstate.getBlock().hasTileEntity(iblockstate) && worldIn.getTileEntity(blockpos).hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, ray.sideHit)) {
			IFluidHandler fluidHandler = worldIn.getTileEntity(blockpos).getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, ray.sideHit);
			for (IFluidTankProperties property : fluidHandler.getTankProperties()) {
				if (property.getContents().getFluid() == FluidRegistry.WATER && property.getContents().amount >= 1000 && property.canDrain()) {
					fluidHandler.drain(new FluidStack(FluidRegistry.WATER, 1000), true);
					addFluid(stack, 1000);
				}
			}
		}

	}
	return new ActionResult<ItemStack>(EnumActionResult.FAIL, stack);
}
 
開發者ID:p455w0rd,項目名稱:ToughExpansion,代碼行數:36,代碼來源:ItemThirstQuencher.java

示例9: updateTargetedBlock

import net.minecraft.util.math.RayTraceResult; //導入方法依賴的package包/類
private void updateTargetedBlock() {
  targetBlockPos = null;
  targetBlockSide = null;

  EntityPlayerSP player = Minecraft.getMinecraft().player;
  double distance = Minecraft.getMinecraft().playerController.getBlockReachDistance();
  RayTraceResult r = RayTracer.rayTrace(player, distance, 1, false);

  if (r != null && Type.BLOCK.equals(r.typeOfHit)) {
    targetBlockPos = r.getBlockPos();
    targetBlockSide = r.sideHit;
  }
}
 
開發者ID:ToroCraft,項目名稱:PowerProbe,代碼行數:14,代碼來源:MouseReleaseHandler.java

示例10: getBlockLookedAt

import net.minecraft.util.math.RayTraceResult; //導入方法依賴的package包/類
private BlockPos getBlockLookedAt(EntityPlayerSP player) {
  RayTraceResult r = RayTracer.rayTrace(player, 15, 1);
  if (r != null && r.typeOfHit.equals(RayTraceResult.Type.BLOCK)) {
    return r.getBlockPos();
  }
  return null;
}
 
開發者ID:ToroCraft,項目名稱:PowerProbe,代碼行數:8,代碼來源:PowerOverlayRender.java

示例11: onItemRightClick

import net.minecraft.util.math.RayTraceResult; //導入方法依賴的package包/類
@Override
public ActionResult<ItemStack> onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn, EnumHand hand)
{
    RayTraceResult raytraceresult = this.rayTrace(worldIn, playerIn, true);

    if (raytraceresult == null)
    {
        return new ActionResult(EnumActionResult.PASS, itemStackIn);
    }
    else
    {
        if (raytraceresult.typeOfHit == RayTraceResult.Type.BLOCK)
        {
            BlockPos blockpos = raytraceresult.getBlockPos();

            if (!worldIn.isBlockModifiable(playerIn, blockpos) || !playerIn.canPlayerEdit(blockpos.offset(raytraceresult.sideHit), raytraceresult.sideHit, itemStackIn))
            {
                return new ActionResult(EnumActionResult.FAIL, itemStackIn);
            }

            BlockPos blockpos1 = blockpos.up();
            IBlockState iblockstate = worldIn.getBlockState(blockpos);

            if (iblockstate.getMaterial() == Material.LAVA && ((Integer)iblockstate.getValue(BlockLiquid.LEVEL)).intValue() == 0 && worldIn.isAirBlock(blockpos1))
            {
                worldIn.setBlockState(blockpos1, UCBlocks.lavalily.getDefaultState(), 11);

                if (!playerIn.capabilities.isCreativeMode)
                    --itemStackIn.stackSize;
                
                worldIn.playSound(playerIn, blockpos, SoundEvents.BLOCK_WATERLILY_PLACE, SoundCategory.BLOCKS, 1.0F, 1.0F);
                return new ActionResult(EnumActionResult.SUCCESS, itemStackIn);
            }
        }
        return new ActionResult(EnumActionResult.FAIL, itemStackIn);
    }
}
 
開發者ID:bafomdad,項目名稱:uniquecrops,代碼行數:38,代碼來源:BlockLavaLily.java

示例12: update

import net.minecraft.util.math.RayTraceResult; //導入方法依賴的package包/類
@Override
public void update() {

	if (worldObj.isRemote)
		return;
	
	if (this.worldObj.getTotalWorldTime() % 10L != 0)
		return;
	
	boolean wasLooking = this.isLooking();
	int range = 10;
	List<EntityPlayer> players = worldObj.getEntitiesWithinAABB(EntityPlayer.class, new AxisAlignedBB(pos.add(-range, -range, -range), pos.add(range, range, range)));
	
	boolean looker = false;
	for (EntityPlayer player : players) {
		ItemStack helm = player.getItemStackFromSlot(EntityEquipmentSlot.HEAD);
		if (helm != null && helm.getItem() == Item.getItemFromBlock(Blocks.PUMPKIN))
			continue;
		
		RayTraceResult rtr = this.rayTraceFromEntity(worldObj, player, true, range);
		if (rtr != null && rtr.getBlockPos() != null && rtr.getBlockPos().equals(getPos())) {
			looker = true;
			break;
		}
		if (!wasLooking && ((WeepingBells)worldObj.getBlockState(getPos()).getBlock()).isWeepingCropGrown(worldObj.getBlockState(getPos())) && !player.capabilities.isCreativeMode) {
			if (getTarget(worldObj, getPos()).canEntityBeSeen(player)) {
				player.attackEntityFrom(DamageSource.outOfWorld, 1.0F);
			}
		}
	}
	if (looker != wasLooking && !worldObj.isRemote)
		setLooking(looker);
}
 
開發者ID:bafomdad,項目名稱:uniquecrops,代碼行數:34,代碼來源:TileShyPlant.java

示例13: onBucketUse

import net.minecraft.util.math.RayTraceResult; //導入方法依賴的package包/類
@SubscribeEvent
public void onBucketUse(FillBucketEvent event)
{
	if (event.getWorld().isRemote) { return; }

	RayTraceResult target = event.getTarget();

	if (target == null) { return; }	// Nevermind?

	BlockPos pos = target.getBlockPos();

	if (pos == null) { return; }	// Nevermind?

	Main.console("[TERRITORIAL DEALINGS] Bucket used by player " + event.getEntityPlayer().getName() + " at x " + pos.getX() + " / y " + pos.getY() + " / z " + pos.getZ() + ".");

	Chunk chunk = event.getEntityPlayer().worldObj.getChunkFromBlockCoords(pos);

	if (TerritoryHandler.canPlayerEditChunk(event.getEntityPlayer(), chunk))	// Checks out
	{
		Main.console("[TERRITORIAL DEALINGS] Player is allowed to edit this chunk. Doing nothing.");
	}
	else
	{
		Main.console("[TERRITORIAL DEALINGS] Player is not allowed to edit this chunk. Cancelling.");
		event.setCanceled(true);	// Not having it
	}
}
 
開發者ID:Domochevsky,項目名稱:minecraft-territorialdealings,代碼行數:28,代碼來源:EventListener.java

示例14: onItemRightClick

import net.minecraft.util.math.RayTraceResult; //導入方法依賴的package包/類
public ActionResult<ItemStack> onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn, EnumHand hand)
{
    if (worldIn.isRemote)
    {
        return new ActionResult(EnumActionResult.PASS, itemStackIn);
    }
    else
    {
        RayTraceResult raytraceresult = this.rayTrace(worldIn, playerIn, true);

        if (raytraceresult != null && raytraceresult.typeOfHit == RayTraceResult.Type.BLOCK)
        {
            BlockPos blockpos = raytraceresult.getBlockPos();

            if (!(worldIn.getBlockState(blockpos).getBlock() instanceof BlockLiquid))
            {
                return new ActionResult(EnumActionResult.PASS, itemStackIn);
            }
            else if (worldIn.isBlockModifiable(playerIn, blockpos) && playerIn.canPlayerEdit(blockpos, raytraceresult.sideHit, itemStackIn))
            {
                Entity entity = spawnCreature(worldIn, getEntityIdFromItem(itemStackIn), (double)blockpos.getX() + 0.5D, (double)blockpos.getY() + 0.5D, (double)blockpos.getZ() + 0.5D);

                if (entity == null)
                {
                    return new ActionResult(EnumActionResult.PASS, itemStackIn);
                }
                else
                {
                    if (entity instanceof EntityLivingBase && itemStackIn.hasDisplayName())
                    {
                        entity.setCustomNameTag(itemStackIn.getDisplayName());
                    }

                    applyItemEntityDataToEntity(worldIn, playerIn, itemStackIn, entity);

                    if (!playerIn.capabilities.isCreativeMode)
                    {
                        --itemStackIn.stackSize;
                    }

                    playerIn.addStat(StatList.getObjectUseStats(this));
                    return new ActionResult(EnumActionResult.SUCCESS, itemStackIn);
                }
            }
            else
            {
                return new ActionResult(EnumActionResult.FAIL, itemStackIn);
            }
        }
        else
        {
            return new ActionResult(EnumActionResult.PASS, itemStackIn);
        }
    }
}
 
開發者ID:F1r3w477,項目名稱:CustomWorldGen,代碼行數:56,代碼來源:ItemMonsterPlacer.java

示例15: onItemRightClick

import net.minecraft.util.math.RayTraceResult; //導入方法依賴的package包/類
public ActionResult<ItemStack> onItemRightClick(World itemStackIn, EntityPlayer worldIn, EnumHand playerIn)
{
    ItemStack itemstack = worldIn.getHeldItem(playerIn);
    RayTraceResult raytraceresult = this.rayTrace(itemStackIn, worldIn, true);

    if (raytraceresult == null)
    {
        return new ActionResult(EnumActionResult.PASS, itemstack);
    }
    else
    {
        if (raytraceresult.typeOfHit == RayTraceResult.Type.BLOCK)
        {
            BlockPos blockpos = raytraceresult.getBlockPos();

            if (!itemStackIn.isBlockModifiable(worldIn, blockpos) || !worldIn.canPlayerEdit(blockpos.offset(raytraceresult.sideHit), raytraceresult.sideHit, itemstack))
            {
                return new ActionResult(EnumActionResult.FAIL, itemstack);
            }

            BlockPos blockpos1 = blockpos.up();
            IBlockState iblockstate = itemStackIn.getBlockState(blockpos);

            if (iblockstate.getMaterial() == Material.WATER && ((Integer)iblockstate.getValue(BlockLiquid.LEVEL)).intValue() == 0 && itemStackIn.isAirBlock(blockpos1))
            {
                itemStackIn.setBlockState(blockpos1, Blocks.WATERLILY.getDefaultState(), 11);

                if (!worldIn.capabilities.isCreativeMode)
                {
                    itemstack.func_190918_g(1);
                }

                worldIn.addStat(StatList.getObjectUseStats(this));
                itemStackIn.playSound(worldIn, blockpos, SoundEvents.BLOCK_WATERLILY_PLACE, SoundCategory.BLOCKS, 1.0F, 1.0F);
                return new ActionResult(EnumActionResult.SUCCESS, itemstack);
            }
        }

        return new ActionResult(EnumActionResult.FAIL, itemstack);
    }
}
 
開發者ID:sudofox,項目名稱:Backmemed,代碼行數:42,代碼來源:ItemLilyPad.java


注:本文中的net.minecraft.util.math.RayTraceResult.getBlockPos方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。