本文整理汇总了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;
}
}
}
示例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());
}
}
}
示例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);
}
}
}
}
示例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);
}
示例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();
}
示例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();
}
}
示例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());
}
}
}
示例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);
}
示例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;
}
}
示例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;
}
示例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);
}
}
示例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);
}
示例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
}
}
示例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);
}
}
}
示例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);
}
}