Search in sources :

Example 81 with EntityPlayerSP

use of net.minecraft.client.entity.EntityPlayerSP in project malmo by Microsoft.

the class ObservationFromFullInventoryImplementation method getInventoryJSON.

public static void getInventoryJSON(JsonObject json, String prefix, int maxSlot) {
    EntityPlayerSP player = Minecraft.getMinecraft().thePlayer;
    int nSlots = Math.min(player.inventory.getSizeInventory(), maxSlot);
    for (int i = 0; i < nSlots; i++) {
        ItemStack is = player.inventory.getStackInSlot(i);
        if (is != null) {
            json.addProperty(prefix + i + "_size", is.stackSize);
            DrawItem di = MinecraftTypeHelper.getDrawItemFromItemStack(is);
            String name = di.getType();
            if (di.getColour() != null)
                json.addProperty(prefix + i + "_colour", di.getColour().value());
            if (di.getVariant() != null)
                json.addProperty(prefix + i + "_variant", di.getVariant().getValue());
            json.addProperty(prefix + i + "_item", name);
        }
    }
}
Also used : DrawItem(com.microsoft.Malmo.Schemas.DrawItem) EntityPlayerSP(net.minecraft.client.entity.EntityPlayerSP) ItemStack(net.minecraft.item.ItemStack)

Example 82 with EntityPlayerSP

use of net.minecraft.client.entity.EntityPlayerSP in project malmo by Microsoft.

the class ObservationFromFullInventoryImplementation method writeObservationsToJSON.

@Override
public void writeObservationsToJSON(JsonObject json, MissionInit missionInit) {
    EntityPlayerSP player = Minecraft.getMinecraft().thePlayer;
    getInventoryJSON(json, "InventorySlot_", player.inventory.getSizeInventory());
}
Also used : EntityPlayerSP(net.minecraft.client.entity.EntityPlayerSP)

Example 83 with EntityPlayerSP

use of net.minecraft.client.entity.EntityPlayerSP in project MinecraftForge by MinecraftForge.

the class EntitySpawnHandler method spawnEntity.

private void spawnEntity(FMLMessage.EntitySpawnMessage spawnMsg) {
    ModContainer mc = Loader.instance().getIndexedModList().get(spawnMsg.modId);
    EntityRegistration er = EntityRegistry.instance().lookupModSpawn(mc, spawnMsg.modEntityTypeId);
    if (er == null) {
        throw new RuntimeException("Could not spawn mod entity ModID: " + spawnMsg.modId + " EntityID: " + spawnMsg.modEntityTypeId + " at ( " + spawnMsg.rawX + "," + spawnMsg.rawY + ", " + spawnMsg.rawZ + ") Please contact mod author or server admin.");
    }
    WorldClient wc = FMLClientHandler.instance().getWorldClient();
    Class<? extends Entity> cls = er.getEntityClass();
    try {
        Entity entity;
        if (er.hasCustomSpawning()) {
            entity = er.doCustomSpawning(spawnMsg);
        } else {
            entity = cls.getConstructor(World.class).newInstance(wc);
            int offset = spawnMsg.entityId - entity.getEntityId();
            entity.setEntityId(spawnMsg.entityId);
            entity.setUniqueId(spawnMsg.entityUUID);
            entity.setLocationAndAngles(spawnMsg.rawX, spawnMsg.rawY, spawnMsg.rawZ, spawnMsg.scaledYaw, spawnMsg.scaledPitch);
            if (entity instanceof EntityLiving) {
                ((EntityLiving) entity).rotationYawHead = spawnMsg.scaledHeadYaw;
            }
            Entity[] parts = entity.getParts();
            if (parts != null) {
                for (int j = 0; j < parts.length; j++) {
                    parts[j].setEntityId(parts[j].getEntityId() + offset);
                }
            }
        }
        EntityTracker.updateServerPosition(entity, spawnMsg.rawX, spawnMsg.rawY, spawnMsg.rawZ);
        EntityPlayerSP clientPlayer = FMLClientHandler.instance().getClientPlayerEntity();
        if (entity instanceof IThrowableEntity) {
            Entity thrower = clientPlayer.getEntityId() == spawnMsg.throwerId ? clientPlayer : wc.getEntityByID(spawnMsg.throwerId);
            ((IThrowableEntity) entity).setThrower(thrower);
        }
        if (spawnMsg.dataWatcherList != null) {
            entity.getDataManager().setEntryValues(spawnMsg.dataWatcherList);
        }
        if (spawnMsg.throwerId > 0) {
            entity.setVelocity(spawnMsg.speedScaledX, spawnMsg.speedScaledY, spawnMsg.speedScaledZ);
        }
        if (entity instanceof IEntityAdditionalSpawnData) {
            ((IEntityAdditionalSpawnData) entity).readSpawnData(spawnMsg.dataStream);
        }
        wc.addEntityToWorld(spawnMsg.entityId, entity);
    } catch (Exception e) {
        FMLLog.log(Level.ERROR, e, "A severe problem occurred during the spawning of an entity at ( " + spawnMsg.rawX + "," + spawnMsg.rawY + ", " + spawnMsg.rawZ + ")");
        throw Throwables.propagate(e);
    }
}
Also used : IEntityAdditionalSpawnData(net.minecraftforge.fml.common.registry.IEntityAdditionalSpawnData) Entity(net.minecraft.entity.Entity) IThrowableEntity(net.minecraftforge.fml.common.registry.IThrowableEntity) ModContainer(net.minecraftforge.fml.common.ModContainer) EntityLiving(net.minecraft.entity.EntityLiving) IThrowableEntity(net.minecraftforge.fml.common.registry.IThrowableEntity) WorldClient(net.minecraft.client.multiplayer.WorldClient) EntityPlayerSP(net.minecraft.client.entity.EntityPlayerSP) EntityRegistration(net.minecraftforge.fml.common.registry.EntityRegistry.EntityRegistration)

Example 84 with EntityPlayerSP

use of net.minecraft.client.entity.EntityPlayerSP in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class EntityDraggable method tickAddedVelocity.

//TODO: Finishme
public void tickAddedVelocity() {
    if (worldBelowFeet != null && !ValkyrienWarfareMod.physicsManager.isEntityFixed(draggableAsEntity)) {
        CoordTransformObject coordTransform = worldBelowFeet.wrapping.coordTransform;
        float rotYaw = draggableAsEntity.rotationYaw;
        float rotPitch = draggableAsEntity.rotationPitch;
        float prevYaw = draggableAsEntity.prevRotationYaw;
        float prevPitch = draggableAsEntity.prevRotationPitch;
        Vector oldPos = new Vector(draggableAsEntity);
        RotationMatrices.applyTransform(coordTransform.prevwToLTransform, coordTransform.prevWToLRotation, draggableAsEntity);
        RotationMatrices.applyTransform(coordTransform.lToWTransform, coordTransform.lToWRotation, draggableAsEntity);
        Vector newPos = new Vector(draggableAsEntity);
        //Move the entity back to its old position, the added velocity will be used afterwards
        draggableAsEntity.setPosition(oldPos.X, oldPos.Y, oldPos.Z);
        Vector addedVel = oldPos.getSubtraction(newPos);
        velocityAddedToPlayer = addedVel;
        draggableAsEntity.rotationYaw = rotYaw;
        draggableAsEntity.rotationPitch = rotPitch;
        draggableAsEntity.prevRotationYaw = prevYaw;
        draggableAsEntity.prevRotationPitch = prevPitch;
        Vector oldLookingPos = new Vector(draggableAsEntity.getLook(1.0F));
        RotationMatrices.applyTransform(coordTransform.prevWToLRotation, oldLookingPos);
        RotationMatrices.applyTransform(coordTransform.lToWRotation, oldLookingPos);
        double newPitch = Math.asin(oldLookingPos.Y) * -180D / Math.PI;
        double f4 = -Math.cos(-newPitch * 0.017453292D);
        double radianYaw = Math.atan2((oldLookingPos.X / f4), (oldLookingPos.Z / f4));
        radianYaw += Math.PI;
        radianYaw *= -180D / Math.PI;
        if (!(Double.isNaN(radianYaw) || Math.abs(newPitch) > 85)) {
            double wrappedYaw = MathHelper.wrapDegrees(radianYaw);
            double wrappedRotYaw = MathHelper.wrapDegrees(draggableAsEntity.rotationYaw);
            double yawDif = wrappedYaw - wrappedRotYaw;
            if (Math.abs(yawDif) > 180D) {
                if (yawDif < 0) {
                    yawDif += 360D;
                } else {
                    yawDif -= 360D;
                }
            }
            yawDif %= 360D;
            final double threshold = .1D;
            if (Math.abs(yawDif) < threshold) {
                yawDif = 0D;
            }
            yawDifVelocity = yawDif;
        }
    }
    boolean onGroundOrig = draggableAsEntity.onGround;
    if (!ValkyrienWarfareMod.physicsManager.isEntityFixed(draggableAsEntity)) {
        float originalWalked = draggableAsEntity.distanceWalkedModified;
        float originalWalkedOnStep = draggableAsEntity.distanceWalkedOnStepModified;
        boolean originallySneaking = draggableAsEntity.isSneaking();
        draggableAsEntity.setSneaking(false);
        if (draggableAsEntity.worldObj.isRemote && draggableAsEntity instanceof EntityPlayerSP) {
            EntityPlayerSP playerSP = (EntityPlayerSP) draggableAsEntity;
            MovementInput moveInput = playerSP.movementInput;
            originallySneaking = moveInput.sneak;
            moveInput.sneak = false;
        }
        draggableAsEntity.moveEntity(velocityAddedToPlayer.X, velocityAddedToPlayer.Y, velocityAddedToPlayer.Z);
        if (!(draggableAsEntity instanceof EntityPlayer)) {
            if (draggableAsEntity instanceof EntityArrow) {
                draggableAsEntity.prevRotationYaw = draggableAsEntity.rotationYaw;
                draggableAsEntity.rotationYaw -= yawDifVelocity;
            } else {
                draggableAsEntity.prevRotationYaw = draggableAsEntity.rotationYaw;
                draggableAsEntity.rotationYaw += yawDifVelocity;
            }
        } else {
            if (draggableAsEntity.worldObj.isRemote) {
                draggableAsEntity.prevRotationYaw = draggableAsEntity.rotationYaw;
                draggableAsEntity.rotationYaw += yawDifVelocity;
            }
        }
        //Do not add this movement as if the entity were walking it
        draggableAsEntity.distanceWalkedModified = originalWalked;
        draggableAsEntity.distanceWalkedOnStepModified = originalWalkedOnStep;
        draggableAsEntity.setSneaking(originallySneaking);
        if (draggableAsEntity.worldObj.isRemote && draggableAsEntity instanceof EntityPlayerSP) {
            EntityPlayerSP playerSP = (EntityPlayerSP) draggableAsEntity;
            MovementInput moveInput = playerSP.movementInput;
            moveInput.sneak = originallySneaking;
        }
    }
    if (onGroundOrig) {
        draggableAsEntity.onGround = onGroundOrig;
    }
    velocityAddedToPlayer.multiply(.99D);
    yawDifVelocity *= .95D;
}
Also used : CoordTransformObject(ValkyrienWarfareBase.PhysicsManagement.CoordTransformObject) EntityArrow(net.minecraft.entity.projectile.EntityArrow) EntityPlayer(net.minecraft.entity.player.EntityPlayer) EntityPlayerSP(net.minecraft.client.entity.EntityPlayerSP) Vector(ValkyrienWarfareBase.API.Vector) MovementInput(net.minecraft.util.MovementInput)

Example 85 with EntityPlayerSP

use of net.minecraft.client.entity.EntityPlayerSP in project RFToolsDimensions by McJty.

the class SkyRenderer method renderSky.

/**
 * Renders the sky with the partial tick time. Args: partialTickTime
 */
@SideOnly(Side.CLIENT)
private static void renderSky(float partialTickTime, GenericWorldProvider provider) {
    initialize();
    EntityPlayerSP player = Minecraft.getMinecraft().player;
    WorldClient world = Minecraft.getMinecraft().world;
    TextureManager renderEngine = Minecraft.getMinecraft().getTextureManager();
    GlStateManager.disableTexture2D();
    Vec3d vec3 = world.getSkyColor(player, partialTickTime);
    float skyRed = (float) vec3.x;
    float skyGreen = (float) vec3.y;
    float skyBlue = (float) vec3.z;
    boolean anaglyph = Minecraft.getMinecraft().gameSettings.anaglyph;
    if (anaglyph) {
        float f4 = (skyRed * 30.0F + skyGreen * 59.0F + skyBlue * 11.0F) / 100.0F;
        float f5 = (skyRed * 30.0F + skyGreen * 70.0F) / 100.0F;
        float f6 = (skyRed * 30.0F + skyBlue * 70.0F) / 100.0F;
        skyRed = f4;
        skyGreen = f5;
        skyBlue = f6;
    }
    GlStateManager.color(skyRed, skyGreen, skyBlue);
    Tessellator tessellator = Tessellator.getInstance();
    BufferBuilder renderer = tessellator.getBuffer();
    GlStateManager.depthMask(false);
    GlStateManager.enableFog();
    GlStateManager.color(skyRed, skyGreen, skyBlue);
    // @todo support VBO?
    // if (OpenGlHelper.useVbo()) {
    // skyVBO.bindBuffer();
    // GL11.glEnableClientState(GL11.GL_VERTEX_ARRAY);
    // GL11.glVertexPointer(3, GL11.GL_FLOAT, 12, 0L);
    // this.skyVBO.drawArrays(7);
    // this.skyVBO.unbindBuffer();
    // GL11.glDisableClientState(GL11.GL_VERTEX_ARRAY);
    // 
    // } else {
    GlStateManager.callList(glSkyList);
    // }
    GlStateManager.disableFog();
    GlStateManager.disableAlpha();
    GlStateManager.enableBlend();
    GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0);
    RenderHelper.disableStandardItemLighting();
    float[] sunsetColors = world.provider.calcSunriseSunsetColors(world.getCelestialAngle(partialTickTime), partialTickTime);
    if (sunsetColors != null) {
        GlStateManager.disableTexture2D();
        GlStateManager.shadeModel(7425);
        GlStateManager.pushMatrix();
        GlStateManager.rotate(90.0F, 1.0F, 0.0F, 0.0F);
        GlStateManager.rotate(MathHelper.sin(world.getCelestialAngleRadians(partialTickTime)) < 0.0F ? 180.0F : 0.0F, 0.0F, 0.0F, 1.0F);
        GlStateManager.rotate(90.0F, 0.0F, 0.0F, 1.0F);
        float f6 = sunsetColors[0];
        float f7 = sunsetColors[1];
        float f8 = sunsetColors[2];
        if (anaglyph) {
            float f9 = (f6 * 30.0F + f7 * 59.0F + f8 * 11.0F) / 100.0F;
            float f10 = (f6 * 30.0F + f7 * 70.0F) / 100.0F;
            float f11 = (f6 * 30.0F + f8 * 70.0F) / 100.0F;
            f6 = f9;
            f7 = f10;
            f8 = f11;
        }
        renderer.begin(GL11.GL_TRIANGLE_FAN, DefaultVertexFormats.POSITION_COLOR);
        renderer.pos(0.0D, 100.0D, 0.0D).color(f6, f7, f8, sunsetColors[3]).endVertex();
        for (int j = 0; j <= 16; ++j) {
            float f11 = j * (float) Math.PI * 2.0F / 16.0f;
            float f12 = MathHelper.sin(f11);
            float f13 = MathHelper.cos(f11);
            renderer.pos((f12 * 120.0F), (f13 * 120.0F), (-f13 * 40.0F * sunsetColors[3])).color(sunsetColors[0], sunsetColors[1], sunsetColors[2], 0.0F).endVertex();
        }
        tessellator.draw();
        GlStateManager.popMatrix();
        GlStateManager.shadeModel(GL11.GL_FLAT);
    }
    renderCelestialBodies(partialTickTime, provider.getDimensionInformation(), world, renderEngine, tessellator);
    GlStateManager.color(0.0F, 0.0F, 0.0F);
    double d0 = player.getPosition().getY() - world.getHorizon();
    if (d0 < 0.0D) {
        GlStateManager.pushMatrix();
        GlStateManager.translate(0.0F, 12.0F, 0.0F);
        // @todo
        // if (this.vboEnabled)
        // {
        // this.sky2VBO.bindBuffer();
        // GL11.glEnableClientState(GL11.GL_VERTEX_ARRAY);
        // GL11.glVertexPointer(3, GL11.GL_FLOAT, 12, 0L);
        // this.sky2VBO.drawArrays(7);
        // this.sky2VBO.unbindBuffer();
        // GL11.glDisableClientState(GL11.GL_VERTEX_ARRAY);
        // }
        // else
        // {
        GlStateManager.callList(glSkyList2);
        // GlStateManager.callList(this.glSkyList2);
        // }
        GlStateManager.popMatrix();
        float f8 = 1.0F;
        float f9 = -((float) (d0 + 65.0D));
        float f10 = -f8;
        renderer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_COLOR);
        renderer.pos((-f8), f9, f8).color(0, 0, 0, 255).endVertex();
        renderer.pos(f8, f9, f8).color(0, 0, 0, 255).endVertex();
        renderer.pos(f8, f10, f8).color(0, 0, 0, 255).endVertex();
        renderer.pos((-f8), f10, f8).color(0, 0, 0, 255).endVertex();
        renderer.pos((-f8), f10, (-f8)).color(0, 0, 0, 255).endVertex();
        renderer.pos(f8, f10, (-f8)).color(0, 0, 0, 255).endVertex();
        renderer.pos(f8, f9, (-f8)).color(0, 0, 0, 255).endVertex();
        renderer.pos((-f8), f9, (-f8)).color(0, 0, 0, 255).endVertex();
        renderer.pos(f8, f10, (-f8)).color(0, 0, 0, 255).endVertex();
        renderer.pos(f8, f10, f8).color(0, 0, 0, 255).endVertex();
        renderer.pos(f8, f9, f8).color(0, 0, 0, 255).endVertex();
        renderer.pos(f8, f9, (-f8)).color(0, 0, 0, 255).endVertex();
        renderer.pos((-f8), f9, (-f8)).color(0, 0, 0, 255).endVertex();
        renderer.pos((-f8), f9, f8).color(0, 0, 0, 255).endVertex();
        renderer.pos((-f8), f10, f8).color(0, 0, 0, 255).endVertex();
        renderer.pos((-f8), f10, (-f8)).color(0, 0, 0, 255).endVertex();
        renderer.pos((-f8), f10, (-f8)).color(0, 0, 0, 255).endVertex();
        renderer.pos((-f8), f10, f8).color(0, 0, 0, 255).endVertex();
        renderer.pos(f8, f10, f8).color(0, 0, 0, 255).endVertex();
        renderer.pos(f8, f10, (-f8)).color(0, 0, 0, 255).endVertex();
        tessellator.draw();
    }
    if (world.provider.isSkyColored()) {
        GlStateManager.color(skyRed * 0.2F + 0.04F, skyGreen * 0.2F + 0.04F, skyBlue * 0.6F + 0.1F);
    } else {
        GlStateManager.color(skyRed, skyGreen, skyBlue);
    }
    GlStateManager.pushMatrix();
    GlStateManager.translate(0.0F, -((float) (d0 - 16.0D)), 0.0F);
    GlStateManager.callList(glSkyList2);
    GlStateManager.popMatrix();
    GlStateManager.enableTexture2D();
    GlStateManager.depthMask(true);
}
Also used : TextureManager(net.minecraft.client.renderer.texture.TextureManager) EntityPlayerSP(net.minecraft.client.entity.EntityPlayerSP) WorldClient(net.minecraft.client.multiplayer.WorldClient) Vec3d(net.minecraft.util.math.Vec3d) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Aggregations

EntityPlayerSP (net.minecraft.client.entity.EntityPlayerSP)158 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)31 Minecraft (net.minecraft.client.Minecraft)29 ItemStack (net.minecraft.item.ItemStack)29 BlockPos (net.minecraft.util.math.BlockPos)27 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)23 Entity (net.minecraft.entity.Entity)21 EntityPlayer (net.minecraft.entity.player.EntityPlayer)13 TileEntity (net.minecraft.tileentity.TileEntity)13 WorldClient (net.minecraft.client.multiplayer.WorldClient)11 IBlockState (net.minecraft.block.state.IBlockState)10 Tessellator (net.minecraft.client.renderer.Tessellator)10 GCPlayerStatsClient (micdoodle8.mods.galacticraft.core.entities.player.GCPlayerStatsClient)8 ArrayList (java.util.ArrayList)6 Block (net.minecraft.block.Block)6 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)6 Vec3d (net.minecraft.util.math.Vec3d)6 World (net.minecraft.world.World)6 UUID (java.util.UUID)5 BufferBuilder (net.minecraft.client.renderer.BufferBuilder)5