本文整理匯總了Java中net.minecraft.util.math.RayTraceResult類的典型用法代碼示例。如果您正苦於以下問題:Java RayTraceResult類的具體用法?Java RayTraceResult怎麽用?Java RayTraceResult使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
RayTraceResult類屬於net.minecraft.util.math包,在下文中一共展示了RayTraceResult類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: onImpact
import net.minecraft.util.math.RayTraceResult; //導入依賴的package包/類
@Override
public void onImpact(RayTraceResult result)
{
if (!this.getEntityWorld().isRemote)
{
Stats statsCap = (Stats) player.getCapability(CapabilityPlayerStats.STATS, null);
if (result.entityHit != null && result.entityHit instanceof EntityLivingBase && statsCap != null)
{
NBTTagCompound nbt = NBTHelper.loadStackNBT(stack);
double magicalPower = statsCap.getMagicalPower();
double damage = (Math.random() * (nbt.getInteger("MaxDamage") - nbt.getInteger("MinDamage"))) + (nbt.getInteger("MinDamage") + (int) magicalPower);
// apply damage
result.entityHit.attackEntityFrom(DamageSource.causePlayerDamage(player), (float) damage);
result.entityHit.hurtResistantTime = 0; // set hurt resistant time to zero because other calculations might be added.
// apply attributes
EventLivingHurtAttack.useWeaponAttributes((float) damage, player, (EntityLivingBase) result.entityHit, stack, NBTHelper.loadStackNBT(stack));
}
}
}
示例2: 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;
}
}
}
示例3: onImpact
import net.minecraft.util.math.RayTraceResult; //導入依賴的package包/類
/**
* Called when this EntityThrowable hits a block or entity.
*/
protected void onImpact(RayTraceResult result)
{
if (!this.worldObj.isRemote)
{
this.worldObj.playEvent(2002, new BlockPos(this), 0);
int i = 3 + this.worldObj.rand.nextInt(5) + this.worldObj.rand.nextInt(5);
while (i > 0)
{
int j = EntityXPOrb.getXPSplit(i);
i -= j;
this.worldObj.spawnEntityInWorld(new EntityXPOrb(this.worldObj, this.posX, this.posY, this.posZ, j));
}
this.setDead();
}
}
示例4: onBucketUse
import net.minecraft.util.math.RayTraceResult; //導入依賴的package包/類
public static ActionResult<ItemStack> onBucketUse(EntityPlayer player, World world, ItemStack stack, RayTraceResult target)
{
FillBucketEvent event = new FillBucketEvent(player, stack, world, target);
if (MinecraftForge.EVENT_BUS.post(event)) return new ActionResult<ItemStack>(EnumActionResult.FAIL, stack);
if (event.getResult() == Result.ALLOW)
{
if (player.capabilities.isCreativeMode)
return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, stack);
if (--stack.stackSize <= 0)
return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, event.getFilledBucket());
if (!player.inventory.addItemStackToInventory(event.getFilledBucket()))
player.dropItem(event.getFilledBucket(), false);
return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, stack);
}
return null;
}
示例5: onImpact
import net.minecraft.util.math.RayTraceResult; //導入依賴的package包/類
@Override
public void onImpact(RayTraceResult result) {
if (fallingTile == null) {
this.setDead();
return;
}
BlockPos pos = new BlockPos(result.hitVec);
if (result.typeOfHit == RayTraceResult.Type.BLOCK) {
IBlockState state = worldObj.getBlockState(pos);
if (!(state.getBlock() instanceof BlockCrops)) {
worldObj.setBlockState(pos.offset(result.sideHit), fallingTile, 3);
this.setDead();
return;
}
}
else this.setDead();
}
示例6: updatePoint
import net.minecraft.util.math.RayTraceResult; //導入依賴的package包/類
@Override
public void updatePoint(float partialTicks) {
RayTraceResult result = entity.rayTrace(traceDistance, partialTicks);
if (result == null) {
return;
}
BlockPos pos = result.getBlockPos();
int x = pos.getX();
int y = pos.getY();
int z = pos.getZ();
if (this.lastX != x || this.lastY != y || this.lastZ != z) {
this.lastX = x;
this.lastY = y;
this.lastZ = z;
this.point = new Vector3(x, y, z);
this.box.setPosition(this.point.subtract(PointCube.MIN_VEC), this.point.add(PointCube.MAX_VEC));
this.notifyObservers();
}
}
示例7: onImpact
import net.minecraft.util.math.RayTraceResult; //導入依賴的package包/類
@Override
protected void onImpact(RayTraceResult result)
{
if (result.typeOfHit == Type.ENTITY && result.entityHit != null)
{
result.entityHit.attackEntityFrom(this.createDamageSource(), this.getDamage());
}
else
{
if (result.typeOfHit == Type.BLOCK)
{
BlockPos blockpos = result.getBlockPos();
IBlockState iblockstate = this.world.getBlockState(blockpos);
this.inGround = true;
this.reflectImpactTileData(result.getBlockPos());
if (iblockstate.getMaterial() != Material.AIR)
{
iblockstate.getBlock().onEntityCollidedWithBlock(this.world, blockpos, iblockstate, this);
}
}
}
}
示例8: performEffect
import net.minecraft.util.math.RayTraceResult; //導入依賴的package包/類
@Override
public void performEffect(RayTraceResult rtrace, EntityLivingBase caster, World world) {
if (rtrace.typeOfHit == Type.ENTITY && rtrace.entityHit instanceof EntityLivingBase) {
EntityLivingBase entity = (EntityLivingBase) rtrace.entityHit;
EnumHand hand = null;
if (!entity.getHeldItemMainhand().isEmpty()) hand = EnumHand.MAIN_HAND;
else if (!entity.getHeldItemOffhand().isEmpty()) hand = EnumHand.OFF_HAND;
if (hand != null) {
ItemStack stack = entity.getHeldItem(hand).copy();
entity.setHeldItem(hand, ItemStack.EMPTY);
if (!(entity instanceof EntityPlayer) && stack.isItemStackDamageable() && stack.getItemDamage() == 0) {
stack.setItemDamage((int) (stack.getMaxDamage() * (0.5D + 0.5D * Math.random())));
}
EntityItem ei = new EntityItem(world, entity.posX, entity.posY, entity.posZ, stack);
ei.setPickupDelay(200);
ei.setNoDespawn();
if (!world.isRemote) world.spawnEntity(ei);
}
}
}
示例9: sendClickBlockToController
import net.minecraft.util.math.RayTraceResult; //導入依賴的package包/類
private void sendClickBlockToController(boolean leftClick)
{
if (!leftClick)
{
this.leftClickCounter = 0;
}
if (this.leftClickCounter <= 0 && !this.player.isHandActive())
{
if (leftClick && this.objectMouseOver != null && this.objectMouseOver.typeOfHit == RayTraceResult.Type.BLOCK)
{
BlockPos blockpos = this.objectMouseOver.getBlockPos();
if (this.world.getBlockState(blockpos).getMaterial() != Material.AIR && this.playerController.onPlayerDamageBlock(blockpos, this.objectMouseOver.sideHit))
{
this.effectRenderer.addBlockHitEffects(blockpos, this.objectMouseOver.sideHit);
this.player.swingArm(EnumHand.MAIN_HAND);
}
}
else
{
this.playerController.resetBlockRemoving();
}
}
}
示例10: prepare
import net.minecraft.util.math.RayTraceResult; //導入依賴的package包/類
public void prepare(World p_190056_1_, TextureManager p_190056_2_, FontRenderer p_190056_3_, Entity p_190056_4_, RayTraceResult p_190056_5_, float p_190056_6_)
{
if (this.worldObj != p_190056_1_)
{
this.setWorld(p_190056_1_);
}
this.renderEngine = p_190056_2_;
this.entity = p_190056_4_;
this.fontRenderer = p_190056_3_;
this.cameraHitResult = p_190056_5_;
this.entityYaw = p_190056_4_.prevRotationYaw + (p_190056_4_.rotationYaw - p_190056_4_.prevRotationYaw) * p_190056_6_;
this.entityPitch = p_190056_4_.prevRotationPitch + (p_190056_4_.rotationPitch - p_190056_4_.prevRotationPitch) * p_190056_6_;
this.entityX = p_190056_4_.lastTickPosX + (p_190056_4_.posX - p_190056_4_.lastTickPosX) * (double)p_190056_6_;
this.entityY = p_190056_4_.lastTickPosY + (p_190056_4_.posY - p_190056_4_.lastTickPosY) * (double)p_190056_6_;
this.entityZ = p_190056_4_.lastTickPosZ + (p_190056_4_.posZ - p_190056_4_.lastTickPosZ) * (double)p_190056_6_;
}
示例11: rayTraceResistance
import net.minecraft.util.math.RayTraceResult; //導入依賴的package包/類
private float rayTraceResistance(Vector3 start, Vector3 end, float prevresistance) {
RayTraceResult hit = world.rayTraceBlocks(start.vec3(), end.vec3());
if (hit == null)
return prevresistance;
if (hit.typeOfHit == Type.BLOCK) {
IBlockState state = world.getBlockState(hit.getBlockPos());
if (state.getBlock().isAir(state, world, hit.getBlockPos()))
return prevresistance;
/*if(Block.blocksList[blockID] instanceof ISpecialResistance)
{
ISpecialResistance isr = (ISpecialResistance) Block.blocksList[blockID];
return prevresistance + (isr.getSpecialExplosionResistance(world, hit.blockX, hit.blockY, hit.blockZ,
start.x, start.y, start.z, wrapper) + 0.3F);
}
else
{*/
return prevresistance + state.getBlock().getExplosionResistance(wrapper) + 0.3F;
//}
}
return prevresistance;
}
示例12: 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);
}
}
}
}
示例13: sendClickBlockToController
import net.minecraft.util.math.RayTraceResult; //導入依賴的package包/類
private void sendClickBlockToController(boolean leftClick)
{
if (!leftClick)
{
this.leftClickCounter = 0;
}
if (this.leftClickCounter <= 0 && !this.thePlayer.isHandActive())
{
if (leftClick && this.objectMouseOver != null && this.objectMouseOver.typeOfHit == RayTraceResult.Type.BLOCK)
{
BlockPos blockpos = this.objectMouseOver.getBlockPos();
if (!this.theWorld.isAirBlock(blockpos) && this.playerController.onPlayerDamageBlock(blockpos, this.objectMouseOver.sideHit))
{
this.effectRenderer.addBlockHitEffects(blockpos, this.objectMouseOver);
this.thePlayer.swingArm(EnumHand.MAIN_HAND);
}
}
else
{
this.playerController.resetBlockRemoving();
}
}
}
示例14: onItemRightClick
import net.minecraft.util.math.RayTraceResult; //導入依賴的package包/類
@Override
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) {
ItemStack stack = player.getHeldItem(hand); //Not entirely convinced it works
RayTraceResult result = world.isRemote ? RayTraceHelper.tracePlayerHighlight((EntityPlayerSP) player) : RayTraceHelper.tracePlayerHighlight((EntityPlayerMP) player);
if(result.typeOfHit != RayTraceResult.Type.BLOCK) {
if(!world.isRemote) {
Vector3 vec = Vector3.create(player.posX, player.posY + player.getEyeHeight(), player.posZ);
vec.add(Vector3.create(player.getLookVec()).multiply(2.5D));
BlockPos pos = new BlockPos(vec.toVec3d());
IBlockState replaced = world.getBlockState(pos);
if(world.isAirBlock(pos) || replaced.getBlock().isReplaceable(world, pos)) {
IBlockState state = ModBlocks.ANGSTROM.getDefaultState();
SoundType type = ModBlocks.ANGSTROM.getSoundType(state, world, pos, player);
world.setBlockState(pos, state);
world.playSound(null, pos.getX(), pos.getY(), pos.getZ(), type.getPlaceSound(), SoundCategory.BLOCKS, 0.75F, 0.8F);
}
if(!player.capabilities.isCreativeMode) {
stack.shrink(1);
}
}
return ActionResult.newResult(EnumActionResult.SUCCESS, stack);
}
return ActionResult.newResult(EnumActionResult.PASS, stack);
}
示例15: updateTask
import net.minecraft.util.math.RayTraceResult; //導入依賴的package包/類
/**
* Updates the task
*/
@Override
public void updateTask() {
Random random = enderman.getRNG();
World world = EasyMappings.world(enderman);
int i = MathUtils.floor(enderman.posX - 2.0D + random.nextDouble() * 4.0D);
int j = MathUtils.floor(enderman.posY + random.nextDouble() * 3.0D);
int k = MathUtils.floor(enderman.posZ - 2.0D + random.nextDouble() * 4.0D);
BlockPos blockpos = new BlockPos(i, j, k);
IBlockState iblockstate = world.getBlockState(blockpos);
Block block = iblockstate.getBlock();
RayTraceResult raytraceresult = world.rayTraceBlocks(new Vec3d(MathUtils.floor(enderman.posX) + 0.5F, j + 0.5F, MathUtils.floor(enderman.posZ) + 0.5F), new Vec3d(i + 0.5F, j + 0.5F, k + 0.5F), false, true, false);
boolean flag = raytraceresult != null && raytraceresult.getBlockPos().equals(blockpos);
if (EntityEvolvedEnderman.getCarriable(block) && flag) {
enderman.setHeldBlockState(iblockstate);
world.setBlockToAir(blockpos);
}
}