И как им пользоваться?RayTraceResult
Если кинете тем, будет неплохоМиллион раз обсуждали, поиск...
Иногда можно потратить лишних 5 секунд и вбить в поисковик то, что ищешь. И найти ответ. Он для этого и создан:Если кинете тем, будет неплохо
public class EventHandThirstUpdate {
@SideOnly(Side.CLIENT)
@SubscribeEvent
public void hadDrinken(PlayerInteractEvent.RightClickBlock event){
final World world = (World)Minecraft.getMinecraft().world;
EntityPlayer player = (EntityPlayer) event.getEntity();
ItemStack is = player.getHeldItem(EnumHand.MAIN_HAND);
RayTraceResult raytraceresult = this.rayTrace(world, player, true);
if (raytraceresult.typeOfHit == RayTraceResult.Type.BLOCK)
{
BlockPos blockpos = raytraceresult.getBlockPos();
IPlayerCap capabilities = event.getEntity().getCapability(PlayerCapProvider.LEVEL_CAP, null);
if (world.getBlockState(blockpos).getMaterial() == Material.WATER)
{
if(is.isEmpty()){
capabilities.reduceWaterLevel(5);
player.world.playSound(player, blockpos, SoundEvents.ENTITY_GENERIC_DRINK, SoundCategory.NEUTRAL, 0.8F, 1.0F);
NetworkHandler.network.sendToServer(new HUDSyncMessageServer(capabilities.getWaterLevel()));
}
}
}
}
protected RayTraceResult rayTrace(World worldIn, EntityPlayer playerIn, boolean useLiquids)
{
float f = playerIn.rotationPitch;
float f1 = playerIn.rotationYaw;
double d0 = playerIn.posX;
double d1 = playerIn.posY + (double)playerIn.getEyeHeight();
double d2 = playerIn.posZ;
Vec3d vec3d = new Vec3d(d0, d1, d2);
float f2 = MathHelper.cos(-f1 * 0.017453292F - (float)Math.PI);
float f3 = MathHelper.sin(-f1 * 0.017453292F - (float)Math.PI);
float f4 = -MathHelper.cos(-f * 0.017453292F);
float f5 = MathHelper.sin(-f * 0.017453292F);
float f6 = f3 * f4;
float f7 = f2 * f4;
double d3 = 5.0D;
if (playerIn instanceof net.minecraft.entity.player.EntityPlayerMP)
{
d3 = ((net.minecraft.entity.player.EntityPlayerMP)playerIn).interactionManager.getBlockReachDistance();
}
Vec3d vec3d1 = vec3d.addVector((double)f6 * d3, (double)f5 * d3, (double)f7 * d3);
return worldIn.rayTraceBlocks(vec3d, vec3d1, useLiquids, !useLiquids, false);
}
}
А потом получаешь classcastexceptionКастишь его в энтити-предмет. Потом проверяешь уже на энтити-предмет...
Наоборот, иначе будут вылетать иногда эксепшиныКастишь его в энтити-предмет. Потом проверяешь уже на энтити-предмет
RayTraceResult.Type.ENTITY(EntityItem)
Какой код пишет максик можно понять по его советам..Кастишь его в энтити-предмет. Потом проверяешь уже на энтити-предмет.
@SideOnly(Side.CLIENT)
@SubscribeEvent
public void hadDrinken(PlayerInteractEvent.RightClickBlock event) {
final World world = Minecraft.getMinecraft().world;
EntityPlayer player = (EntityPlayer) event.getEntity();
ItemStack is = player.getHeldItem(EnumHand.MAIN_HAND);
RayTraceResult rtr = rayTrace(world, player, true);
if (rtr.typeOfHit == RayTraceResult.Type.ENTITY) {
Entity lookedEntity = rtr.entityHit;
if (lookedEntity != null && lookedEntity instanceof EntityItem) {
EntityItem item = (EntityItem) lookedEntity;
//TODO ur code.
}
}
}
protected RayTraceResult rayTrace(World worldIn, EntityPlayer playerIn, boolean useLiquids) {
float f = playerIn.rotationPitch;
float f1 = playerIn.rotationYaw;
double d0 = playerIn.posX;
double d1 = playerIn.posY + playerIn.getEyeHeight();
double d2 = playerIn.posZ;
Vec3d vec3d = new Vec3d(d0, d1, d2);
float f2 = MathHelper.cos(-f1 * 0.017453292F - (float) Math.PI);
float f3 = MathHelper.sin(-f1 * 0.017453292F - (float) Math.PI);
float f4 = -MathHelper.cos(-f * 0.017453292F);
float f5 = MathHelper.sin(-f * 0.017453292F);
float f6 = f3 * f4;
float f7 = f2 * f4;
double d3 = 5.0D;
if (playerIn instanceof net.minecraft.entity.player.EntityPlayerMP)
d3 = ((net.minecraft.entity.player.EntityPlayerMP) playerIn).interactionManager.getBlockReachDistance();
Vec3d vec3d1 = vec3d.addVector(f6 * d3, f5 * d3, f7 * d3);
return worldIn.rayTraceBlocks(vec3d, vec3d1, useLiquids, !useLiquids, false);
}
Как будто вообще в стену говорю.Ну попробуй так сделать. Проверка не пройдет, ничего не выйдет.
>rayTraceBlocks
Не смущает?)
Самый шикарный, потому что работает. Все, я больше ничего не знаю!)Какой код пишет максик можно понять по его советам..
rtr = null почему-тоКакой код пишет максик можно понять по его советам..
~~~
По теме:
Вот измененный, готовый код.
Код:@SideOnly(Side.CLIENT) @SubscribeEvent public void hadDrinken(PlayerInteractEvent.RightClickBlock event) { final World world = Minecraft.getMinecraft().world; EntityPlayer player = (EntityPlayer) event.getEntity(); ItemStack is = player.getHeldItem(EnumHand.MAIN_HAND); RayTraceResult rtr = rayTrace(world, player, true); if (rtr.typeOfHit == RayTraceResult.Type.ENTITY) { Entity lookedEntity = rtr.entityHit; if (lookedEntity != null && lookedEntity instanceof EntityItem) { EntityItem item = (EntityItem) lookedEntity; //TODO ur code. } } } protected RayTraceResult rayTrace(World worldIn, EntityPlayer playerIn, boolean useLiquids) { float f = playerIn.rotationPitch; float f1 = playerIn.rotationYaw; double d0 = playerIn.posX; double d1 = playerIn.posY + playerIn.getEyeHeight(); double d2 = playerIn.posZ; Vec3d vec3d = new Vec3d(d0, d1, d2); float f2 = MathHelper.cos(-f1 * 0.017453292F - (float) Math.PI); float f3 = MathHelper.sin(-f1 * 0.017453292F - (float) Math.PI); float f4 = -MathHelper.cos(-f * 0.017453292F); float f5 = MathHelper.sin(-f * 0.017453292F); float f6 = f3 * f4; float f7 = f2 * f4; double d3 = 5.0D; if (playerIn instanceof net.minecraft.entity.player.EntityPlayerMP) d3 = ((net.minecraft.entity.player.EntityPlayerMP) playerIn).interactionManager.getBlockReachDistance(); Vec3d vec3d1 = vec3d.addVector(f6 * d3, f5 * d3, f7 * d3); return worldIn.rayTraceBlocks(vec3d, vec3d1, useLiquids, !useLiquids, false); }
>тут же совет уровня МаксикаКакой код пишет максик можно понять по его советам..
Я всего лишь не много изменил его код.>тут же совет уровня Максика
Браво.