Search in sources :

Example 21 with WorldClient

use of net.minecraft.client.multiplayer.WorldClient in project Almura by AlmuraDev.

the class IngameFarmersAlmanac method construct.

// TODO: Translation support
@SuppressWarnings("deprecation, unchecked")
@Override
public void construct() {
    guiscreenBackground = false;
    final BasicForm form = new BasicForm(this, formWidth, formHeight, formTitle);
    form.setClosable(false);
    final WorldClient world = this.client.world;
    final RayTraceResult omo = this.client.objectMouseOver;
    final BlockPos blockPos = omo.getBlockPos();
    final IBlockState blockState = getState(world, blockPos);
    final Block block = blockState.getBlock();
    // Block image
    final ItemStack pickStack = blockState.getBlock().getPickBlock(blockState, omo, this.client.world, omo.getBlockPos(), this.client.player);
    final UIImage blockImage = new UIImage(this, pickStack);
    blockImage.setPosition(leftPad / 2, 0, Anchor.LEFT | Anchor.TOP);
    form.add(blockImage);
    // Localized name
    final UILabel labelLocalizedName = new UILabel(this, block.getLocalizedName());
    labelLocalizedName.setFontOptions(FontColors.WHITE_FO);
    labelLocalizedName.setPosition(BasicScreen.getPaddedX(blockImage, 4), 0);
    form.add(labelLocalizedName);
    // Registry name
    final String registryName = block.getRegistryName() == null ? "unknown" : block.getRegistryName().toString();
    final UILabel labelRegistryName = new UILabel(this, registryName);
    labelRegistryName.setFontOptions(FontColors.GRAY_FO);
    labelRegistryName.setPosition(labelLocalizedName.getX(), BasicScreen.getPaddedY(labelLocalizedName, 2));
    form.add(labelRegistryName);
    // Property container
    this.propertyContainer = new BasicContainer<>(this);
    new UISlimScrollbar(this, this.propertyContainer, UIScrollBar.Type.VERTICAL).setAutoHide(true);
    this.propertyContainer.setBackgroundAlpha(35);
    this.propertyContainer.setPosition(0, BasicScreen.getPaddedY(labelRegistryName, 5), Anchor.TOP | Anchor.CENTER);
    this.propertyContainer.setBorder(FontColors.WHITE, 1, 185);
    form.add(this.propertyContainer);
    // Init this early so we can load stuff to it later.
    this.cropStatusLabel = new UILabel(this);
    // Get all displayed properties
    loadProperties(world, blockState, blockPos);
    // Adjust the size of the container to reach at most the specified max height
    this.propertyContainer.setSize(UIComponent.INHERITED, Math.min(propertyContainerMaxHeight, propertyContainer.getContentHeight() + 2));
    // Localized name
    if (this.growing) {
        this.cropStatusLabel.setText(TextFormatting.DARK_GREEN + "Growing...");
    } else if (this.canDie) {
        this.cropStatusLabel.setText(TextFormatting.RED + "Dying!");
    } else {
        this.cropStatusLabel.setText(TextFormatting.YELLOW + "Not Growing...");
    }
    if (this.readyForHarvest) {
        this.cropStatusLabel.setText(TextFormatting.GREEN + "Ready for Harvest!");
    }
    this.cropStatusLabel.setFontOptions(FontColors.WHITE_FO);
    this.cropStatusLabel.setPosition(1, -3, Anchor.BOTTOM | Anchor.LEFT);
    form.add(cropStatusLabel);
    final UIButton closeButton = new UIButtonBuilder(this).text("Close").anchor(Anchor.BOTTOM | Anchor.RIGHT).onClick(this::close).build("button.close");
    form.add(closeButton);
    // Adjust the size of the form to better fit content
    form.setSize(form.getContentWidth() + leftPad, form.getContentHeight() + closeButton.getHeight() + 10);
    // Readjust size for width because MalisisCore doesn't account for the scrollbar with UIComponent.INHERITED
    this.propertyContainer.setSize(propertyContainer.getWidth(), propertyContainer.getHeight());
    addToScreen(form);
    Mouse.setGrabbed(false);
}
Also used : UILabel(net.malisis.core.client.gui.component.decoration.UILabel) IBlockState(net.minecraft.block.state.IBlockState) UISlimScrollbar(net.malisis.core.client.gui.component.control.UISlimScrollbar) RayTraceResult(net.minecraft.util.math.RayTraceResult) WorldClient(net.minecraft.client.multiplayer.WorldClient) BasicForm(net.malisis.core.client.gui.component.container.BasicForm) UIButtonBuilder(net.malisis.core.client.gui.component.interaction.button.builder.UIButtonBuilder) UIButton(net.malisis.core.client.gui.component.interaction.UIButton) Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack) UIImage(net.malisis.core.client.gui.component.decoration.UIImage)

Example 22 with WorldClient

use of net.minecraft.client.multiplayer.WorldClient 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 23 with WorldClient

use of net.minecraft.client.multiplayer.WorldClient 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)

Example 24 with WorldClient

use of net.minecraft.client.multiplayer.WorldClient in project GregTech by GregTechCE.

the class DebugRenderer method onRenderWorldLast.

@SubscribeEvent
public static void onRenderWorldLast(RenderWorldLastEvent event) {
    RenderGlobal context = event.getContext();
    float partialTicks = event.getPartialTicks();
    EntityPlayer player = Minecraft.getMinecraft().player;
    WorldClient world = Minecraft.getMinecraft().world;
    if (blockPosSet.size() == 0) {
        return;
    }
    double playerX = player.lastTickPosX + (player.posX - player.lastTickPosX) * partialTicks;
    double playerY = player.lastTickPosY + (player.posY - player.lastTickPosY) * partialTicks;
    double playerZ = player.lastTickPosZ + (player.posZ - player.lastTickPosZ) * partialTicks;
    GlStateManager.pushMatrix();
    GlStateManager.translate(-playerX, -playerY, -playerZ);
    GlStateManager.enableBlend();
    GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
    GlStateManager.disableTexture2D();
    GlStateManager.disableDepth();
    GlStateManager.glLineWidth(2.5F);
    {
        blockPosSet.forEach(blockPos -> {
            double distance = MathHelper.sqrt(player.getDistanceSqToCenter(blockPos));
            if (distance > 64F) {
                return;
            }
            AxisAlignedBB box = new AxisAlignedBB(blockPos.getX() + 0.25, blockPos.getY() + 0.25, blockPos.getZ() + 0.25, blockPos.getX() + 0.75, blockPos.getY() + 0.75, blockPos.getZ() + 0.75);
            RenderGlobal.drawSelectionBoundingBox(box, 0.0F, 1F, 0.0F, 0.5F);
            TileEntity tileEntity = world.getTileEntity(blockPos);
            if (tileEntity != null) {
                AxisAlignedBB axisAlignedBB = new AxisAlignedBB(blockPos.getX() + 0.25, blockPos.getY() + 0.25, blockPos.getZ() + 0.25, blockPos.getX() + 0.75, blockPos.getY() + 0.75, blockPos.getZ() + 0.75);
                RenderGlobal.drawSelectionBoundingBox(axisAlignedBB, 0.0F, 0.0F, 1F, 0.5F);
            // ((TileEntityCableEmitter) tileEntity).outgoingConnections.forEach(connectionInfo -> {
            // RenderGlobal.drawSelectionBoundingBox(new AxisAlignedBB(connectionInfo.receiverContainer.getPos()), 0.0F, 1F, 1F, 0.5F);
            // 
            // });
            }
        });
    }
    GlStateManager.enableDepth();
    GlStateManager.enableTexture2D();
    GlStateManager.disableBlend();
    GlStateManager.popMatrix();
}
Also used : BlockEvent(net.minecraftforge.event.world.BlockEvent) MetaBlocks(gregtech.common.blocks.MetaBlocks) RenderGlobal(net.minecraft.client.renderer.RenderGlobal) GlStateManager(net.minecraft.client.renderer.GlStateManager) AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) Set(java.util.Set) WorldClient(net.minecraft.client.multiplayer.WorldClient) BlockPos(net.minecraft.util.math.BlockPos) RenderWorldLastEvent(net.minecraftforge.client.event.RenderWorldLastEvent) HashSet(java.util.HashSet) Minecraft(net.minecraft.client.Minecraft) Side(net.minecraftforge.fml.relauncher.Side) EntityPlayer(net.minecraft.entity.player.EntityPlayer) MathHelper(net.minecraft.util.math.MathHelper) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent) TileEntity(net.minecraft.tileentity.TileEntity) Mod(net.minecraftforge.fml.common.Mod) SideOnly(net.minecraftforge.fml.relauncher.SideOnly) AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) TileEntity(net.minecraft.tileentity.TileEntity) EntityPlayer(net.minecraft.entity.player.EntityPlayer) WorldClient(net.minecraft.client.multiplayer.WorldClient) RenderGlobal(net.minecraft.client.renderer.RenderGlobal) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 25 with WorldClient

use of net.minecraft.client.multiplayer.WorldClient in project Galacticraft by micdoodle8.

the class TickHandlerClientVenus method onClientTick.

@SideOnly(Side.CLIENT)
@SubscribeEvent
public void onClientTick(TickEvent.ClientTickEvent event) {
    final Minecraft minecraft = FMLClientHandler.instance().getClient();
    final WorldClient world = minecraft.theWorld;
    if (world != null) {
        if (world.provider instanceof WorldProviderVenus) {
            if (world.provider.getSkyRenderer() == null) {
                world.provider.setSkyRenderer(new SkyProviderVenus((IGalacticraftWorldProvider) world.provider));
            }
            if (world.provider.getCloudRenderer() == null) {
                world.provider.setCloudRenderer(new CloudRenderer());
            }
        }
    }
}
Also used : IGalacticraftWorldProvider(micdoodle8.mods.galacticraft.api.world.IGalacticraftWorldProvider) CloudRenderer(micdoodle8.mods.galacticraft.core.client.CloudRenderer) Minecraft(net.minecraft.client.Minecraft) WorldClient(net.minecraft.client.multiplayer.WorldClient) WorldProviderVenus(micdoodle8.mods.galacticraft.planets.venus.dimension.WorldProviderVenus) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Aggregations

WorldClient (net.minecraft.client.multiplayer.WorldClient)39 Minecraft (net.minecraft.client.Minecraft)19 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)12 EntityPlayerSP (net.minecraft.client.entity.EntityPlayerSP)10 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)10 Entity (net.minecraft.entity.Entity)9 EntityPlayer (net.minecraft.entity.player.EntityPlayer)8 BlockPos (net.minecraft.util.math.BlockPos)7 Block (net.minecraft.block.Block)6 IBlockState (net.minecraft.block.state.IBlockState)6 IGalacticraftWorldProvider (micdoodle8.mods.galacticraft.api.world.IGalacticraftWorldProvider)4 IRenderHandler (net.minecraftforge.client.IRenderHandler)4 BlockVec3 (micdoodle8.mods.galacticraft.api.vector.BlockVec3)3 ItemStack (net.minecraft.item.ItemStack)3 TileEntity (net.minecraft.tileentity.TileEntity)3 BlockPos (net.minecraft.util.BlockPos)3 Function (com.google.common.base.Function)2 Random (java.util.Random)2 GuiCelestialSelection (micdoodle8.mods.galacticraft.core.client.gui.screen.GuiCelestialSelection)2 WorldProviderSpaceStation (micdoodle8.mods.galacticraft.core.dimension.WorldProviderSpaceStation)2