Search in sources :

Example 1 with EntityObsidianBoat

use of nex.entity.item.EntityObsidianBoat in project NetherEx by LogicTechCorp.

the class ItemObsidianBoat method onItemRightClick.

@Override
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) {
    ItemStack stack = player.getHeldItem(hand);
    float f1 = player.prevRotationPitch + (player.rotationPitch - player.prevRotationPitch) * 1.0F;
    float f2 = player.prevRotationYaw + (player.rotationYaw - player.prevRotationYaw) * 1.0F;
    double d0 = player.prevPosX + (player.posX - player.prevPosX) * 1.0D;
    double d1 = player.prevPosY + (player.posY - player.prevPosY) * 1.0D + (double) player.getEyeHeight();
    double d2 = player.prevPosZ + (player.posZ - player.prevPosZ) * 1.0D;
    Vec3d vec3d = new Vec3d(d0, d1, d2);
    float f3 = MathHelper.cos(-f2 * 0.017453292F - (float) Math.PI);
    float f4 = MathHelper.sin(-f2 * 0.017453292F - (float) Math.PI);
    float f5 = -MathHelper.cos(-f1 * 0.017453292F);
    float f6 = MathHelper.sin(-f1 * 0.017453292F);
    float f7 = f4 * f5;
    float f8 = f3 * f5;
    Vec3d vec3d1 = vec3d.addVector((double) f7 * 5.0D, (double) f6 * 5.0D, (double) f8 * 5.0D);
    RayTraceResult raytraceresult = world.rayTraceBlocks(vec3d, vec3d1, true);
    if (raytraceresult == null) {
        return new ActionResult(EnumActionResult.PASS, stack);
    } else {
        Vec3d vec3d2 = player.getLook(1.0F);
        boolean flag = false;
        List<Entity> entities = world.getEntitiesWithinAABBExcludingEntity(player, player.getEntityBoundingBox().addCoord(vec3d2.xCoord * 5.0D, vec3d2.yCoord * 5.0D, vec3d2.zCoord * 5.0D).expandXyz(1.0D));
        for (Entity entity : entities) {
            if (entity.canBeCollidedWith()) {
                AxisAlignedBB axisalignedbb = entity.getEntityBoundingBox().expandXyz((double) entity.getCollisionBorderSize());
                if (axisalignedbb.isVecInside(vec3d)) {
                    flag = true;
                }
            }
        }
        if (flag) {
            return new ActionResult(EnumActionResult.PASS, stack);
        } else if (raytraceresult.typeOfHit != RayTraceResult.Type.BLOCK) {
            return new ActionResult(EnumActionResult.PASS, stack);
        } else {
            Block block = world.getBlockState(raytraceresult.getBlockPos()).getBlock();
            boolean flag1 = block == Blocks.WATER || block == Blocks.FLOWING_WATER;
            EntityObsidianBoat boat = new EntityObsidianBoat(world, raytraceresult.hitVec.xCoord, flag1 ? raytraceresult.hitVec.yCoord - 0.12D : raytraceresult.hitVec.yCoord, raytraceresult.hitVec.zCoord);
            boat.rotationYaw = player.rotationYaw;
            if (!world.getCollisionBoxes(boat, boat.getEntityBoundingBox().expandXyz(-0.1D)).isEmpty()) {
                return new ActionResult(EnumActionResult.FAIL, stack);
            } else {
                if (!world.isRemote) {
                    world.spawnEntity(boat);
                }
                if (!player.capabilities.isCreativeMode) {
                    stack.shrink(1);
                }
                return new ActionResult(EnumActionResult.SUCCESS, stack);
            }
        }
    }
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) Entity(net.minecraft.entity.Entity) ActionResult(net.minecraft.util.ActionResult) EnumActionResult(net.minecraft.util.EnumActionResult) EntityObsidianBoat(nex.entity.item.EntityObsidianBoat) RayTraceResult(net.minecraft.util.math.RayTraceResult) Block(net.minecraft.block.Block) ItemStack(net.minecraft.item.ItemStack) Vec3d(net.minecraft.util.math.Vec3d)

Example 2 with EntityObsidianBoat

use of nex.entity.item.EntityObsidianBoat in project NetherEx by LogicTechCorp.

the class EventHandler method onLivingAttacked.

@SubscribeEvent
public static void onLivingAttacked(LivingAttackEvent event) {
    EntityLivingBase entity = (EntityLivingBase) event.getEntity();
    World world = entity.getEntityWorld();
    BlockPos pos = entity.getPosition();
    DamageSource source = event.getSource();
    if (source.isFireDamage()) {
        if (!entity.isImmuneToFire() && entity.isRiding() && entity.getRidingEntity() instanceof EntityObsidianBoat) {
            event.setCanceled(true);
        }
    }
    if (entity instanceof EntityPlayer) {
        EntityPlayer player = (EntityPlayer) entity;
        if (source.isFireDamage()) {
            if (ArmorUtil.isWearingFullArmorSet(player, NetherExMaterials.ARMOR_HIDE_SALAMANDER)) {
                event.setCanceled(true);
            }
        }
        if (player.dimension == -1) {
            if (source == DamageSource.LAVA && player.isPotionActive(MobEffects.FIRE_RESISTANCE)) {
                player.addStat(NetherExAchievements.STAYIN_FROSTY);
            }
        }
    }
}
Also used : DamageSource(net.minecraft.util.DamageSource) EntityObsidianBoat(nex.entity.item.EntityObsidianBoat) EntityLivingBase(net.minecraft.entity.EntityLivingBase) EntityPlayer(net.minecraft.entity.player.EntityPlayer) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 3 with EntityObsidianBoat

use of nex.entity.item.EntityObsidianBoat in project NetherEx by LogicTechCorp.

the class EventHandler method onRenderBlockOverlay.

@SubscribeEvent
@SideOnly(Side.CLIENT)
public static void onRenderBlockOverlay(RenderBlockOverlayEvent event) {
    RenderBlockOverlayEvent.OverlayType type = event.getOverlayType();
    EntityPlayer player = event.getPlayer();
    World world = player.getEntityWorld();
    if (type == RenderBlockOverlayEvent.OverlayType.FIRE) {
        if (player.isRiding() && player.getRidingEntity() instanceof EntityObsidianBoat || ArmorUtil.isWearingFullArmorSet(player, NetherExMaterials.ARMOR_HIDE_SALAMANDER)) {
            event.setCanceled(true);
        }
    }
}
Also used : EntityObsidianBoat(nex.entity.item.EntityObsidianBoat) EntityPlayer(net.minecraft.entity.player.EntityPlayer) World(net.minecraft.world.World) RenderBlockOverlayEvent(net.minecraftforge.client.event.RenderBlockOverlayEvent) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Aggregations

EntityObsidianBoat (nex.entity.item.EntityObsidianBoat)3 EntityPlayer (net.minecraft.entity.player.EntityPlayer)2 World (net.minecraft.world.World)2 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)2 Block (net.minecraft.block.Block)1 Entity (net.minecraft.entity.Entity)1 EntityLivingBase (net.minecraft.entity.EntityLivingBase)1 ItemStack (net.minecraft.item.ItemStack)1 ActionResult (net.minecraft.util.ActionResult)1 DamageSource (net.minecraft.util.DamageSource)1 EnumActionResult (net.minecraft.util.EnumActionResult)1 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)1 BlockPos (net.minecraft.util.math.BlockPos)1 RayTraceResult (net.minecraft.util.math.RayTraceResult)1 Vec3d (net.minecraft.util.math.Vec3d)1 RenderBlockOverlayEvent (net.minecraftforge.client.event.RenderBlockOverlayEvent)1 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)1