Search in sources :

Example 56 with EntityPlayerSP

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

the class CommandForWheeledRobotNavigationImplementation method install.

@Override
public void install(MissionInit missionInit) {
    // Create our movement hook, which allows us to override the Minecraft movement.
    this.overrideMovement = new MovementHook(Minecraft.getMinecraft().gameSettings);
    EntityPlayerSP player = Minecraft.getMinecraft().player;
    if (player != null) {
        // Insert it into the player, keeping a record of the original movement object
        // so we can restore it later.
        this.originalMovement = player.movementInput;
        player.movementInput = this.overrideMovement;
    }
    MinecraftForge.EVENT_BUS.register(this);
}
Also used : EntityPlayerSP(net.minecraft.client.entity.EntityPlayerSP)

Example 57 with EntityPlayerSP

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

the class CommandForWheeledRobotNavigationImplementation method init.

private void init() {
    EntityPlayerSP player = Minecraft.getMinecraft().player;
    this.mVelocity = 0;
    this.mTargetVelocity = 0;
    this.mTicksSinceLastVelocityChange = 0;
    this.mCameraPitch = (player != null) ? player.rotationPitch : 0;
    this.pitchScale = 0;
    this.mYaw = (player != null) ? player.rotationYaw : 0;
    this.yawScale = 0;
}
Also used : EntityPlayerSP(net.minecraft.client.entity.EntityPlayerSP)

Example 58 with EntityPlayerSP

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

the class CommandForWheeledRobotNavigationImplementation method updateYawAndPitch.

/**
 * Called to turn the robot / move the camera.
 */
public void updateYawAndPitch() {
    // Work out the time that has elapsed since we last updated the values.
    // (We need to do this because we can't guarantee that this method will be
    // called at a constant frequency.)
    long timeNow = System.currentTimeMillis();
    long deltaTime = timeNow - this.lastAngularUpdateTime;
    this.lastAngularUpdateTime = timeNow;
    // Work out how much the yaw and pitch should have changed in that time:
    double overclockScale = 50.0 / (double) TimeHelper.serverTickLength;
    double deltaYaw = this.yawScale * overclockScale * this.maxAngularVelocityDegreesPerSecond * (deltaTime / 1000.0);
    double deltaPitch = this.pitchScale * overclockScale * this.maxAngularVelocityDegreesPerSecond * (deltaTime / 1000.0);
    // And update them:
    mYaw += deltaYaw;
    mCameraPitch += deltaPitch;
    // Clamp to [-90, 90]
    mCameraPitch = (mCameraPitch < -90) ? -90 : (mCameraPitch > 90 ? 90 : mCameraPitch);
    // And update the player:
    EntityPlayerSP player = Minecraft.getMinecraft().player;
    if (player != null) {
        player.rotationPitch = this.mCameraPitch;
        player.rotationYaw = this.mYaw;
    }
}
Also used : EntityPlayerSP(net.minecraft.client.entity.EntityPlayerSP)

Example 59 with EntityPlayerSP

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

the class VideoHook method postRender.

/**
 * Called when the world has been rendered but not yet the GUI or player hand.
 *
 * @param event
 *            Contains information about the event (not used).
 */
@SubscribeEvent
public void postRender(RenderWorldLastEvent event) {
    // Check that the video producer and frame type match - eg if this is a colourmap frame, then
    // only the colourmap videoproducer needs to do anything.
    boolean colourmapFrame = TextureHelper.colourmapFrame;
    boolean colourmapVideoProducer = this.videoProducer.getVideoType() == VideoType.COLOUR_MAP;
    if (colourmapFrame != colourmapVideoProducer)
        return;
    EntityPlayerSP player = Minecraft.getMinecraft().player;
    float x = (float) (player.lastTickPosX + (player.posX - player.lastTickPosX) * event.getPartialTicks());
    float y = (float) (player.lastTickPosY + (player.posY - player.lastTickPosY) * event.getPartialTicks());
    float z = (float) (player.lastTickPosZ + (player.posZ - player.lastTickPosZ) * event.getPartialTicks());
    float yaw = player.prevRotationYaw + (player.rotationYaw - player.prevRotationYaw) * event.getPartialTicks();
    float pitch = player.prevRotationPitch + (player.rotationPitch - player.prevRotationPitch) * event.getPartialTicks();
    long time_before_ns = System.nanoTime();
    if (observer != null)
        observer.frameProduced();
    if (time_before_ns < retry_time_ns)
        return;
    boolean success = false;
    long time_after_render_ns;
    try {
        int size = this.videoProducer.getRequiredBufferSize();
        if (AddressHelper.getMissionControlPort() == 0) {
            success = true;
            if (envServer != null) {
                // Write the obs data into a newly allocated buffer:
                byte[] data = new byte[size];
                this.buffer.clear();
                this.videoProducer.getFrame(this.missionInit, this.buffer);
                // Avoiding copy not simple as data is kept & written to a stream later.
                this.buffer.get(data);
                time_after_render_ns = System.nanoTime();
                envServer.addFrame(data);
            } else {
                time_after_render_ns = System.nanoTime();
            }
        } else {
            // Get buffer ready for writing to:
            this.buffer.clear();
            this.headerbuffer.clear();
            // Write the pos data:
            this.headerbuffer.putFloat(x);
            this.headerbuffer.putFloat(y);
            this.headerbuffer.putFloat(z);
            this.headerbuffer.putFloat(yaw);
            this.headerbuffer.putFloat(pitch);
            // Write the frame data:
            this.videoProducer.getFrame(this.missionInit, this.buffer);
            // The buffer gets flipped by getFrame(), but we need to flip our header buffer ourselves:
            this.headerbuffer.flip();
            ByteBuffer[] buffers = { this.headerbuffer, this.buffer };
            time_after_render_ns = System.nanoTime();
            success = this.connection.sendTCPBytes(buffers, size + POS_HEADER_SIZE);
        }
        long time_after_ns = System.nanoTime();
        float ms_send = (time_after_ns - time_after_render_ns) / 1000000.0f;
        float ms_render = (time_after_render_ns - time_before_ns) / 1000000.0f;
        if (success) {
            // Reset count of failed sends.
            this.failedTCPSendCount = 0;
            this.timeOfLastFrame = System.currentTimeMillis();
            if (this.timeOfFirstFrame == 0)
                this.timeOfFirstFrame = this.timeOfLastFrame;
            this.framesSent++;
        // System.out.format("Total: %.2fms; collecting took %.2fms; sending %d bytes took %.2fms\n", ms_send + ms_render, ms_render, size, ms_send);
        // System.out.println("Collect: " + ms_render + "; Send: " + ms_send);
        }
    } catch (Exception e) {
        System.out.format(e.getMessage());
    }
    if (!success) {
        System.out.format("Failed to send frame - will retry in %d seconds\n", RETRY_GAP_NS / 1000000000L);
        retry_time_ns = time_before_ns + RETRY_GAP_NS;
        this.failedTCPSendCount++;
    }
}
Also used : EntityPlayerSP(net.minecraft.client.entity.EntityPlayerSP) ByteBuffer(java.nio.ByteBuffer) LWJGLException(org.lwjgl.LWJGLException) InvocationTargetException(java.lang.reflect.InvocationTargetException) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 60 with EntityPlayerSP

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

the class ObservationFromDiscreteCellImplementation method writeObservationsToJSON.

@Override
public void writeObservationsToJSON(JsonObject json, MissionInit missionInit) {
    // Return a string that is unique for every cell on the x/z plane (ignores y)
    EntityPlayerSP player = Minecraft.getMinecraft().player;
    // getPosition() rounds to int.
    int x = player.getPosition().getX();
    int z = player.getPosition().getZ();
    json.addProperty("cell", "(" + x + "," + z + ")");
}
Also used : EntityPlayerSP(net.minecraft.client.entity.EntityPlayerSP)

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