Search in sources :

Example 81 with EntityPlayer

use of net.minecraft.entity.player.EntityPlayer in project Engine by VoltzEngine-Project.

the class PlayerKeyHandler method mouseHandler.

@SubscribeEvent
public void mouseHandler(MouseEvent e) {
    EntityPlayer player = Minecraft.getMinecraft().thePlayer;
    ItemStack stack = player.getCurrentEquippedItem();
    if (stack != null) {
        final Item item = stack.getItem();
        if (item instanceof IModeItem.IModeScrollItem) {
            if (player.isSneaking() && e.dwheel != 0) {
                int newMode = ((IModeItem.IModeScrollItem) stack.getItem()).cycleMode(stack, player, e.dwheel / 120);
                if (newMode != ((IModeItem.IModeScrollItem) stack.getItem()).getMode(stack)) {
                    Engine.instance.packetHandler.sendToServer(new PacketPlayerItemMode(player.inventory.currentItem, newMode));
                }
                e.setCanceled(true);
            }
        } else if (item instanceof IMouseButtonHandler && e.button != -1) {
            Engine.instance.packetHandler.sendToServer(new PacketMouseClick(player.inventory.currentItem, e.button, e.buttonstate));
            ((IMouseButtonHandler) item).mouseClick(stack, player, e.button, e.buttonstate);
            if (((IMouseButtonHandler) item).shouldCancelMouseEvent(stack, player, e.button, e.buttonstate)) {
                e.setCanceled(true);
            }
        }
    }
}
Also used : IModeItem(com.builtbroken.mc.api.items.tools.IModeItem) Item(net.minecraft.item.Item) PacketPlayerItemMode(com.builtbroken.mc.core.network.packet.user.PacketPlayerItemMode) PacketMouseClick(com.builtbroken.mc.core.network.packet.user.PacketMouseClick) IModeItem(com.builtbroken.mc.api.items.tools.IModeItem) IMouseButtonHandler(com.builtbroken.mc.api.items.IMouseButtonHandler) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemStack(net.minecraft.item.ItemStack) SubscribeEvent(cpw.mods.fml.common.eventhandler.SubscribeEvent)

Example 82 with EntityPlayer

use of net.minecraft.entity.player.EntityPlayer in project Engine by VoltzEngine-Project.

the class FXElectricBolt method renderParticle.

@Override
public void renderParticle(Tessellator tessellator, float partialframe, float cosYaw, float cosPitch, float sinYaw, float sinSinPitch, float cosSinPitch) {
    EntityPlayer renderentity = Minecraft.getMinecraft().thePlayer;
    int visibleDistance = 100;
    if (!Minecraft.getMinecraft().gameSettings.fancyGraphics) {
        visibleDistance /= 2;
    }
    if (renderentity.getDistance(this.posX, this.posY, this.posZ) > visibleDistance) {
        return;
    }
    tessellator.draw();
    GL11.glPushMatrix();
    GL11.glDepthMask(false);
    GL11.glEnable(3042);
    FMLClientHandler.instance().getClient().renderEngine.bindTexture(TEXTURE);
    /** Render the actual bolts. */
    tessellator.startDrawingQuads();
    tessellator.setBrightness(15728880);
    this.renderBolt(tessellator, partialframe, cosYaw, cosPitch, sinYaw, cosSinPitch, 0);
    tessellator.draw();
    // GL11.glBlendFunc(770, 771);
    tessellator.startDrawingQuads();
    tessellator.setBrightness(15728880);
    this.renderBolt(tessellator, partialframe, cosYaw, cosPitch, sinYaw, cosSinPitch, 1);
    tessellator.draw();
    GL11.glDisable(3042);
    GL11.glDepthMask(true);
    GL11.glPopMatrix();
    FMLClientHandler.instance().getClient().renderEngine.bindTexture(RenderUtility.PARTICLE_RESOURCE);
    tessellator.startDrawingQuads();
}
Also used : EntityPlayer(net.minecraft.entity.player.EntityPlayer)

Example 83 with EntityPlayer

use of net.minecraft.entity.player.EntityPlayer in project Engine by VoltzEngine-Project.

the class FXElectricBolt2 method renderParticle.

@Override
public void renderParticle(Tessellator tessellator, float partialframe, float cosYaw, float cosPitch, float sinYaw, float sinSinPitch, float cosSinPitch) {
    EntityPlayer player = Minecraft.getMinecraft().thePlayer;
    tessellator.draw();
    GL11.glPushMatrix();
    GL11.glDepthMask(false);
    GL11.glEnable(3042);
    glShadeModel(GL_SMOOTH);
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    FMLClientHandler.instance().getClient().renderEngine.bindTexture(TEXTURE);
    /**
		 * Render the actual bolts.
		 */
    tessellator.startDrawingQuads();
    tessellator.setBrightness(15728880);
    Pos playerVector = new Pos(sinYaw * -cosPitch, -cosSinPitch / cosYaw, cosYaw * cosPitch);
    int renderlength = (int) ((this.particleAge + partialframe + (int) (this.boltLength * 3.0F)) / (int) (this.boltLength * 3.0F) * this.segmentCount);
    for (BoltSegment segment : this.segments) {
        if (segment != null && segment.id <= renderlength) {
            double renderWidth = this.boltWidth * ((new Pos(player).distance(segment.start) / 5f + 1f) * (1 + segment.alpha) * 0.5f);
            renderWidth = Math.min(this.boltWidth, Math.max(renderWidth, 0));
            if (segment.difference.magnitude() > 0 && segment.difference.magnitude() != Double.NaN && segment.difference.magnitude() != Double.POSITIVE_INFINITY && renderWidth > 0 && renderWidth != Double.NaN && renderWidth != Double.POSITIVE_INFINITY) {
                Pos diffPrev = playerVector.cross(segment.prevDiff).multiply(renderWidth / segment.sinPrev);
                Pos diffNext = playerVector.cross(segment.nextDiff).multiply(renderWidth / segment.sinNext);
                Pos startVec = segment.start;
                Pos endVec = segment.end;
                float rx1 = (float) (startVec.x() - interpPosX);
                float ry1 = (float) (startVec.y() - interpPosY);
                float rz1 = (float) (startVec.z() - interpPosZ);
                float rx2 = (float) (endVec.x() - interpPosX);
                float ry2 = (float) (endVec.y() - interpPosY);
                float rz2 = (float) (endVec.z() - interpPosZ);
                tessellator.setColorRGBA_F(this.particleRed, this.particleGreen, this.particleBlue, (1.0F - (this.particleAge >= 0 ? ((float) this.particleAge / (float) this.particleMaxAge) : 0.0F) * 0.6f) * segment.alpha);
                tessellator.addVertexWithUV(rx2 - diffNext.x(), ry2 - diffNext.y(), rz2 - diffNext.z(), 0.5D, 0.0D);
                tessellator.addVertexWithUV(rx1 - diffPrev.x(), ry1 - diffPrev.y(), rz1 - diffPrev.z(), 0.5D, 0.0D);
                tessellator.addVertexWithUV(rx1 + diffPrev.x(), ry1 + diffPrev.y(), rz1 + diffPrev.z(), 0.5D, 1.0D);
                tessellator.addVertexWithUV(rx2 + diffNext.x(), ry2 + diffNext.y(), rz2 + diffNext.z(), 0.5D, 1.0D);
                if (segment.next == null) {
                    Pos roundEnd = segment.end.clone().add(segment.difference.clone().normalize().multiply(renderWidth));
                    float rx3 = (float) (roundEnd.x() - interpPosX);
                    float ry3 = (float) (roundEnd.y() - interpPosY);
                    float rz3 = (float) (roundEnd.z() - interpPosZ);
                    tessellator.addVertexWithUV(rx3 - diffNext.x(), ry3 - diffNext.y(), rz3 - diffNext.z(), 0.0D, 0.0D);
                    tessellator.addVertexWithUV(rx2 - diffNext.x(), ry2 - diffNext.y(), rz2 - diffNext.z(), 0.5D, 0.0D);
                    tessellator.addVertexWithUV(rx2 + diffNext.x(), ry2 + diffNext.y(), rz2 + diffNext.z(), 0.5D, 1.0D);
                    tessellator.addVertexWithUV(rx3 + diffNext.x(), ry3 + diffNext.y(), rz3 + diffNext.z(), 0.0D, 1.0D);
                }
                if (segment.prev == null) {
                    Pos roundEnd = segment.start.clone().subtract(segment.difference.clone().normalize().multiply(renderWidth));
                    float rx3 = (float) (roundEnd.x() - interpPosX);
                    float ry3 = (float) (roundEnd.y() - interpPosY);
                    float rz3 = (float) (roundEnd.z() - interpPosZ);
                    tessellator.addVertexWithUV(rx1 - diffPrev.x(), ry1 - diffPrev.y(), rz1 - diffPrev.z(), 0.5D, 0.0D);
                    tessellator.addVertexWithUV(rx3 - diffPrev.x(), ry3 - diffPrev.y(), rz3 - diffPrev.z(), 0.0D, 0.0D);
                    tessellator.addVertexWithUV(rx3 + diffPrev.x(), ry3 + diffPrev.y(), rz3 + diffPrev.z(), 0.0D, 1.0D);
                    tessellator.addVertexWithUV(rx1 + diffPrev.x(), ry1 + diffPrev.y(), rz1 + diffPrev.z(), 0.5D, 1.0D);
                }
            }
        }
    }
    tessellator.draw();
    GL11.glDisable(3042);
    GL11.glDepthMask(true);
    GL11.glPopMatrix();
    FMLClientHandler.instance().getClient().renderEngine.bindTexture(PARTICLE_RESOURCE);
    tessellator.startDrawingQuads();
}
Also used : Pos(com.builtbroken.mc.imp.transform.vector.Pos) EntityPlayer(net.minecraft.entity.player.EntityPlayer)

Example 84 with EntityPlayer

use of net.minecraft.entity.player.EntityPlayer in project Railcraft by Railcraft.

the class FirestoneTickHandler method tick.

@SubscribeEvent
public void tick(LivingEvent.LivingUpdateEvent event) {
    EntityLivingBase entity = event.getEntityLiving();
    if (Game.isClient(entity.worldObj))
        return;
    clock++;
    if (clock % 4 != 0)
        return;
    if (entity instanceof EntityPlayer && ((EntityPlayer) entity).openContainer != ((EntityPlayer) entity).inventoryContainer)
        return;
    IInventoryObject inv = InventoryFactory.get(entity);
    if (inv != null) {
        for (IInvSlot slot : InventoryIterator.getRailcraft(inv)) {
            ItemStack stack = slot.getStack();
            FirestoneTools.trySpawnFire(entity.worldObj, entity.getPosition(), stack);
        }
    }
}
Also used : IInvSlot(mods.railcraft.common.util.inventory.iterators.IInvSlot) IInventoryObject(mods.railcraft.common.util.inventory.wrappers.IInventoryObject) EntityLivingBase(net.minecraft.entity.EntityLivingBase) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemStack(net.minecraft.item.ItemStack) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 85 with EntityPlayer

use of net.minecraft.entity.player.EntityPlayer in project Railcraft by Railcraft.

the class MiscTools method rayTracePlayerLook.

@Nullable
public static RayTraceResult rayTracePlayerLook(EntityPlayer player) {
    Entity pointedEntity = null;
    final double reach = player.capabilities.isCreativeMode ? 5.0F : 4.5F;
    Vec3d eyePos = new Vec3d(player.posX, player.posY + player.getEyeHeight(), player.posZ);
    Vec3d lookVec = player.getLook(1);
    Vec3d rayVec = eyePos.addVector(lookVec.xCoord * reach, lookVec.yCoord * reach, lookVec.zCoord * reach);
    Vec3d hitPos = null;
    List<Entity> foundEntities = player.worldObj.getEntitiesInAABBexcluding(player, player.getEntityBoundingBox().addCoord(lookVec.xCoord * reach, lookVec.yCoord * reach, lookVec.zCoord * reach).expand(1.0D, 1.0D, 1.0D), com.google.common.base.Predicates.and(EntitySelectors.NOT_SPECTATING, e -> e != null && e.canBeCollidedWith()));
    double smallestDistance = reach;
    for (Entity entity : foundEntities) {
        AxisAlignedBB axisalignedbb = entity.getEntityBoundingBox().expandXyz(entity.getCollisionBorderSize());
        RayTraceResult raytraceresult = axisalignedbb.calculateIntercept(eyePos, rayVec);
        if (axisalignedbb.isVecInside(eyePos)) {
            if (smallestDistance >= 0.0D) {
                pointedEntity = entity;
                hitPos = raytraceresult == null ? eyePos : raytraceresult.hitVec;
                smallestDistance = 0.0D;
            }
        } else if (raytraceresult != null) {
            double hitDistance = eyePos.distanceTo(raytraceresult.hitVec);
            if (hitDistance < smallestDistance || smallestDistance == 0.0D) {
                if (entity.getLowestRidingEntity() == player.getLowestRidingEntity() && !player.canRiderInteract()) {
                    if (smallestDistance == 0.0D) {
                        pointedEntity = entity;
                        hitPos = raytraceresult.hitVec;
                    }
                } else {
                    pointedEntity = entity;
                    hitPos = raytraceresult.hitVec;
                    smallestDistance = hitDistance;
                }
            }
        }
    }
    if (pointedEntity != null && (smallestDistance < reach)) {
        return new RayTraceResult(pointedEntity, hitPos);
    }
    return ForgeHooks.rayTraceEyes(player, reach);
}
Also used : Entity(net.minecraft.entity.Entity) EntitySelectors(net.minecraft.util.EntitySelectors) ForgeHooks(net.minecraftforge.common.ForgeHooks) MethodsReturnNonnullByDefault(mcp.MethodsReturnNonnullByDefault) BlockPistonBase(net.minecraft.block.BlockPistonBase) net.minecraft.util.math(net.minecraft.util.math) World(net.minecraft.world.World) Predicate(java.util.function.Predicate) EntityMinecart(net.minecraft.entity.item.EntityMinecart) EnumFacing(net.minecraft.util.EnumFacing) Random(java.util.Random) TrackTools(mods.railcraft.common.blocks.tracks.TrackTools) ParametersAreNonnullByDefault(javax.annotation.ParametersAreNonnullByDefault) List(java.util.List) EntityLivingBase(net.minecraft.entity.EntityLivingBase) EntityPlayer(net.minecraft.entity.player.EntityPlayer) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) Entity(net.minecraft.entity.Entity) Nullable(javax.annotation.Nullable)

Aggregations

EntityPlayer (net.minecraft.entity.player.EntityPlayer)625 ItemStack (net.minecraft.item.ItemStack)169 EntityLivingBase (net.minecraft.entity.EntityLivingBase)104 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)81 Entity (net.minecraft.entity.Entity)77 World (net.minecraft.world.World)73 BlockPos (net.minecraft.util.math.BlockPos)61 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)49 SubscribeEvent (cpw.mods.fml.common.eventhandler.SubscribeEvent)44 TileEntity (net.minecraft.tileentity.TileEntity)43 PotionEffect (net.minecraft.potion.PotionEffect)41 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)38 EntityItem (net.minecraft.entity.item.EntityItem)37 Block (net.minecraft.block.Block)36 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)35 ArrayList (java.util.ArrayList)33 IBlockState (net.minecraft.block.state.IBlockState)33 List (java.util.List)28 TextComponentString (net.minecraft.util.text.TextComponentString)27 AxisAlignedBB (net.minecraft.util.AxisAlignedBB)23