net.minecraftforge.client.ForgeHooksClient Java Examples

The following examples show how to use net.minecraftforge.client.ForgeHooksClient. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RenderUtils.java    From CodeChickenLib with GNU Lesser General Public License v2.1 6 votes vote down vote up
public static void renderFluidCuboid(CCRenderState ccrs, Matrix4 mat, RenderType renderType, IRenderTypeBuffer getter, FluidStack stack, Cuboid6 bound, double capacity, double res) {
    if (stack.isEmpty()) {
        return;
    }
    int alpha = 255;
    FluidAttributes attributes = stack.getFluid().getAttributes();
    if (attributes.isGaseous(stack)) {
        alpha = (int) (Math.pow(capacity, 0.4) * 255);
    } else {
        bound.max.y = bound.min.y + (bound.max.y - bound.min.y) * capacity;
    }
    Material material = ForgeHooksClient.getBlockMaterial(attributes.getStillTexture(stack));
    ccrs.bind(renderType, getter);
    ccrs.baseColour = attributes.getColor(stack) << 8 | alpha;
    makeFluidModel(bound, material.getSprite(), res).render(ccrs, mat);
}
 
Example #2
Source File: ClientProxy.java    From BetterChests with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void init() {
	new ClientEventListener();
	ClientRegistry.bindTileEntitySpecialRenderer(TileEntityBChest.class, TESRBChest.INSTANCE);
	ClientRegistry.bindTileEntitySpecialRenderer(TileEntityBBarrel.class, TESRBBarrel.INSTANCE);
	ClientRegistry.bindTileEntitySpecialRenderer(TileEntityBTank.class, TESRBTank.INSTANCE);
	ForgeHooksClient.registerTESRItemStack(Item.getItemFromBlock(BlocksItemsBetterChests.betterchest), 0, TileEntityBChest.class);

	TickRegistry.CLIENT.addContinuousCallback(() -> {
		if (!pressed && keyBind.isPressed() && Minecraft.getMinecraft().world != null) {
			//Open bag
			int idx = InvUtil.findInInvInternal(Minecraft.getMinecraft().player.inventory, null, stack -> stack.getItem() instanceof ItemBBag);
			if (idx != -1) {
				BetterChests.instance.ph.sendPacketToPlayers(new PacketOpenBag(idx));
			}
		}
		pressed = keyBind.isPressed();
	});
	ClientRegistry.registerKeyBinding(keyBind);
}
 
Example #3
Source File: EntityPlayerSPPatch.java    From seppuku with GNU General Public License v3.0 5 votes vote down vote up
/**
 * This is where minecraft slows you down while your hand is active
 *
 * @param methodNode
 * @param env
 */
@MethodPatch(
        mcpName = "onLivingUpdate",
        notchName = "n",
        mcpDesc = "()V")
public void onLivingUpdate(MethodNode methodNode, PatchManager.Environment env) {
    final AbstractInsnNode target = ASMUtil.findMethodInsn(methodNode, INVOKESTATIC, Type.getInternalName(ForgeHooksClient.class), "onInputUpdate", env == PatchManager.Environment.IDE ? "(Lnet/minecraft/entity/player/EntityPlayer;Lnet/minecraft/util/MovementInput;)V" : "(Laed;Lbub;)V");

    if (target != null) {
        methodNode.instructions.insert(target, new MethodInsnNode(INVOKESTATIC, Type.getInternalName(this.getClass()), "onLivingUpdateHook", "()V", false));
    }
}
 
Example #4
Source File: ArmorRenderHooks.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static void renderArmorLayer(LayerArmorBase<ModelBase> layer, EntityLivingBase entity, float limbSwing, float limbSwingAmount, float partialTicks, float ageInTicks, float netHeadYaw, float headPitch, float scale, EntityEquipmentSlot slotIn) {
    ItemStack itemStack = entity.getItemStackFromSlot(slotIn);

    if (isArmorItem(itemStack, slotIn)) {
        IArmorItem armorItem = (IArmorItem) itemStack.getItem();
        ModelBase armorModel = layer.getModelFromSlot(slotIn);
        if (armorModel instanceof ModelBiped) {
            armorModel = ForgeHooksClient.getArmorModel(entity, itemStack, slotIn, (ModelBiped) armorModel);
        }
        armorModel.setModelAttributes(layer.renderer.getMainModel());
        armorModel.setLivingAnimations(entity, limbSwing, limbSwingAmount, partialTicks);
        layer.setModelSlotVisible(armorModel, slotIn);

        GlStateManager.enableBlend();
        GlStateManager.blendFunc(SourceFactor.ONE, DestFactor.ONE_MINUS_SRC_ALPHA);

        int layers = armorItem.getArmorLayersAmount(itemStack);
        for (int layerIndex = 0; layerIndex < layers; layerIndex++) {
            int i = armorItem.getArmorLayerColor(itemStack, layerIndex);
            float f = (float) (i >> 16 & 255) / 255.0F;
            float f1 = (float) (i >> 8 & 255) / 255.0F;
            float f2 = (float) (i & 255) / 255.0F;
            GlStateManager.color(f, f1, f2, 1.0f);
            String type = layerIndex == 0 ? null : "layer_" + layerIndex;
            layer.renderer.bindTexture(getArmorTexture(entity, itemStack, slotIn, type));
            armorModel.render(entity, limbSwing, limbSwingAmount, ageInTicks, netHeadYaw, headPitch, scale);
        }
        if (itemStack.hasEffect()) {
            LayerArmorBase.renderEnchantedGlint(layer.renderer, entity, armorModel, limbSwing, limbSwingAmount, partialTicks, ageInTicks, netHeadYaw, headPitch, scale);
        }
    }
}
 
Example #5
Source File: CoverFacade.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void renderCover(CCRenderState renderState, Matrix4 translation, IVertexOperation[] pipeline, Cuboid6 plateBox, BlockRenderLayer layer) {
    BlockRenderLayer oldLayer = MinecraftForgeClient.getRenderLayer();
    ForgeHooksClient.setRenderLayer(layer);
    FacadeRenderer.renderBlockCover(renderState, translation, coverHolder.getWorld(), coverHolder.getPos(), attachedSide.getIndex(), facadeState, plateBox);
    ForgeHooksClient.setRenderLayer(oldLayer);
}
 
Example #6
Source File: CCRenderItem.java    From CodeChickenLib with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void renderItem(ItemStack stack, ItemCameraTransforms.TransformType transformType, boolean leftHand, MatrixStack mStack, IRenderTypeBuffer getter, int packedLight, int packedOverlay, IBakedModel modelIn) {
    if (modelIn instanceof IItemRenderer) {
        mStack.push();
        IBakedModel handled = ForgeHooksClient.handleCameraTransforms(mStack, modelIn, transformType, leftHand);
        mStack.translate(-0.5D, -0.5D, -0.5D);
        //If anyone doesnt return an IItemRenderer from here, your doing it wrong.
        ((IItemRenderer) handled).renderItem(stack, transformType, mStack, getter, packedLight, packedOverlay);
        mStack.pop();
    }
    super.renderItem(stack, transformType, leftHand, mStack, getter, packedLight, packedOverlay, modelIn);
}
 
Example #7
Source File: RocketEventHandler.java    From AdvancedRocketry with MIT License 5 votes vote down vote up
@SubscribeEvent
public void onRocketDeorbit(RocketEvent.RocketDeOrbitingEvent event) {
	if(event.world.isRemote) {
		prepareOrbitalMap(event);

		//Sky blend color gets stuck and doesnt update unless a new X/Z coord is passed
		//So fix that...
		ForgeHooksClient.getSkyBlendColour(event.world, event.getEntity().getPosition());

		if(Configuration.planetSkyOverride && !(event.world.provider instanceof IPlanetaryProvider)) {
			prevRenderHanlder = event.world.provider.getSkyRenderer();
			event.world.provider.setSkyRenderer(new RenderPlanetarySky());
		}
	}
}
 
Example #8
Source File: WorldSceneRenderer.java    From GregTech with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Renders scene on given coordinates with given width and height, and RGB background color
 * Note that this will ignore any transformations applied currently to projection/view matrix,
 * so specified coordinates are scaled MC gui coordinates.
 * It will return matrices of projection and view in previous state after rendering
 */
public void render(int x, int y, int width, int height, int backgroundColor) {
    Vec2f mousePosition = setupCamera(x, y, width, height, backgroundColor);
    if (renderCallback != null) {
        renderCallback.preRenderScene(this);
    }
    Minecraft minecraft = Minecraft.getMinecraft();
    minecraft.renderEngine.bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
    BlockRendererDispatcher dispatcher = minecraft.getBlockRendererDispatcher();
    BlockRenderLayer oldRenderLayer = MinecraftForgeClient.getRenderLayer();
    Tessellator tessellator = Tessellator.getInstance();
    BufferBuilder bufferBuilder = tessellator.getBuffer();

    bufferBuilder.begin(GL11.GL_QUADS, DefaultVertexFormats.BLOCK);
    for (BlockPos pos : renderedBlocks) {
        if (renderFilter != null && !renderFilter.test(pos))
            continue; //do not render if position is skipped
        IBlockState blockState = world.getBlockState(pos);
        for(BlockRenderLayer renderLayer : BlockRenderLayer.values()) {
            if (!blockState.getBlock().canRenderInLayer(blockState, renderLayer)) continue;
            ForgeHooksClient.setRenderLayer(renderLayer);
            dispatcher.renderBlock(blockState, pos, world, bufferBuilder);
        }
    }
    tessellator.draw();
    ForgeHooksClient.setRenderLayer(oldRenderLayer);

    if (mousePosition != null) {
        this.lastHitBlock = handleMouseHit(mousePosition);
    } else {
        this.lastHitBlock = null;
    }

    if (lastHitBlock != null) {
        GlStateManager.disableTexture2D();
        CCRenderState renderState = CCRenderState.instance();
        renderState.startDrawing(GL11.GL_QUADS, DefaultVertexFormats.POSITION_COLOR, tessellator.getBuffer());
        ColourMultiplier multiplier = new ColourMultiplier(0);
        renderState.setPipeline(new Translation(lastHitBlock), multiplier);
        BlockFace blockFace = new BlockFace();
        renderState.setModel(blockFace);
        for (EnumFacing renderSide : EnumFacing.VALUES) {
            float diffuse = LightUtil.diffuseLight(renderSide);
            int color = (int) (255 * diffuse);
            multiplier.colour = RenderUtil.packColor(color, color, color, 100);
            blockFace.loadCuboidFace(Cuboid6.full, renderSide.getIndex());
            renderState.render();
        }
        renderState.draw();
        GlStateManager.enableTexture2D();
    }

    resetCamera();
}
 
Example #9
Source File: ArmorRenderHooks.java    From GregTech with GNU Lesser General Public License v3.0 4 votes vote down vote up
private static ResourceLocation getArmorTexture(EntityLivingBase entity, ItemStack itemStack, EntityEquipmentSlot slot, String type) {
    ResourceLocation registryName = itemStack.getItem().getRegistryName();
    String s1 = String.format("%s:textures/models/armor/%s_layer_%d%s.png", registryName.getResourceDomain(), registryName.getResourcePath(),
        (isLegSlot(slot) ? 2 : 1), type == null ? "" : String.format("_%s", type));
    return new ResourceLocation(ForgeHooksClient.getArmorTexture(entity, itemStack, s1, slot, type));
}
 
Example #10
Source File: RenderUtils.java    From Wizardry with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Will render an itemstack with opacity support properly. Minecraft does not normally support this so we
 * reimplemented all the itemstack rendering code.
 */
public static void renderItemStackWithOpacity(ItemStack stack, float opacity, @Nullable Runnable preDrawRunnable) {
	RenderHelper.enableGUIStandardItemLighting();
	GlStateManager.enableRescaleNormal();
	GlStateManager.enableTexture2D();

	GlStateManager.scale(2, 2, 2);

	if (preDrawRunnable != null) preDrawRunnable.run();

	GlStateManager.color(1f, 1f, 1f, opacity);

	IBakedModel model = Minecraft.getMinecraft().getRenderItem().getItemModelWithOverrides(stack, null, Minecraft.getMinecraft().player);

	GlStateManager.pushMatrix();
	Minecraft.getMinecraft().getTextureManager().bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
	Minecraft.getMinecraft().getTextureManager().getTexture(TextureMap.LOCATION_BLOCKS_TEXTURE).setBlurMipmap(false, false);
	GlStateManager.enableRescaleNormal();
	GlStateManager.enableAlpha();
	GlStateManager.alphaFunc(516, 0.1F);
	GlStateManager.enableBlend();
	GlStateManager.blendFunc(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA);

	GlStateManager.translate(8.0F, 8.0F, 0.0F);
	GlStateManager.scale(1.0F, -1.0F, 1.0F);
	GlStateManager.scale(16.0F, 16.0F, 16.0F);

	if (model.isGui3d()) GlStateManager.enableLighting();
	else GlStateManager.disableLighting();

	ForgeHooksClient.handleCameraTransforms(model, ItemCameraTransforms.TransformType.GUI, false);

	if (!stack.isEmpty()) {
		GlStateManager.pushMatrix();
		GlStateManager.translate(-0.5F, -0.5F, -0.5F);

		if (model.isBuiltInRenderer()) {
			GlStateManager.enableRescaleNormal();
			stack.getItem().getTileEntityItemStackRenderer().renderByItem(stack);
		} else {
			renderModel(model, 0xFFFFFF | (((int) (opacity * 255)) << 24), stack);

			if (stack.hasEffect()) {
				renderEffect(model);
			}
		}

		GlStateManager.translate(0.5F, 0.5F, 0.5F);
		GlStateManager.popMatrix();
	}

	GlStateManager.translate(-8.0F, -8.0F, -0.0F);
	GlStateManager.scale(1 / 16.0F, 1 / 16.0F, 1 / 16.0F);
	GlStateManager.scale(1 / 2.0, 1 / 2.0, 1 / 2.0);

	GlStateManager.disableAlpha();
	GlStateManager.disableRescaleNormal();
	GlStateManager.disableLighting();
	GlStateManager.popMatrix();

	Minecraft.getMinecraft().getTextureManager().bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
	Minecraft.getMinecraft().getTextureManager().getTexture(TextureMap.LOCATION_BLOCKS_TEXTURE).restoreLastBlurMipmap();
	GlStateManager.disableRescaleNormal();
	RenderHelper.disableStandardItemLighting();
}
 
Example #11
Source File: PhysRenderChunk.java    From Valkyrien-Skies with Apache License 2.0 4 votes vote down vote up
private void updateList(BlockRenderLayer layerToUpdate) {
    if (parent.toRender.getShipRenderer() == null) {
        return;
    }
    BlockPos offsetPos = parent.toRender.getShipRenderer().offsetPos;
    if (offsetPos == null) {
        return;
    }
    Tessellator tessellator = Tessellator.getInstance();
    BufferBuilder worldrenderer = tessellator.getBuffer();
    worldrenderer.begin(7, DefaultVertexFormats.BLOCK);
    worldrenderer.setTranslation(-offsetPos.getX(), -offsetPos.getY(), -offsetPos.getZ());
    GL11.glPushMatrix();
    switch (layerToUpdate) {
        case CUTOUT:
            GLAllocation.deleteDisplayLists(glCallListCutout);
            GL11.glNewList(glCallListCutout, GL11.GL_COMPILE);
            break;
        case CUTOUT_MIPPED:
            GLAllocation.deleteDisplayLists(glCallListCutoutMipped);
            GL11.glNewList(glCallListCutoutMipped, GL11.GL_COMPILE);
            break;
        case SOLID:
            GLAllocation.deleteDisplayLists(glCallListSolid);
            GL11.glNewList(glCallListSolid, GL11.GL_COMPILE);
            break;
        case TRANSLUCENT:
            GLAllocation.deleteDisplayLists(glCallListTranslucent);
            GL11.glNewList(glCallListTranslucent, GL11.GL_COMPILE);
            break;
        default:
            break;
    }

    GlStateManager.pushMatrix();
    // worldrenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.BLOCK);
    IBlockState iblockstate;

    BlockRenderLayer oldLayer = MinecraftForgeClient.getRenderLayer();
    ForgeHooksClient.setRenderLayer(layerToUpdate);
    MutableBlockPos pos = new MutableBlockPos();
    for (int x = chunkToRender.x * 16; x < chunkToRender.x * 16 + 16; x++) {
        for (int z = chunkToRender.z * 16; z < chunkToRender.z * 16 + 16; z++) {
            for (int y = yMin; y <= yMax; y++) {
                pos.setPos(x, y, z);
                iblockstate = chunkToRender.getBlockState(pos);
                try {
                    if (iblockstate.getBlock()
                            .canRenderInLayer(iblockstate, layerToUpdate)) {
                        Minecraft.getMinecraft().getBlockRendererDispatcher()
                                .renderBlock(iblockstate, pos, chunkToRender.world,
                                        worldrenderer);
                    }
                } catch (NullPointerException e) {
                    System.out.println(
                            "Something was null! LValkyrienSkiesBase/render/PhysRenderChunk#updateList");
                }
            }
        }
    }
    tessellator.draw();
    // worldrenderer.finishDrawing();
    ForgeHooksClient.setRenderLayer(oldLayer);
    GlStateManager.popMatrix();
    GL11.glEndList();
    GL11.glPopMatrix();
    worldrenderer.setTranslation(0, 0, 0);

    switch (layerToUpdate) {
        case CUTOUT:
            needsCutoutUpdate = false;
            break;
        case CUTOUT_MIPPED:
            needsCutoutMippedUpdate = false;
            break;
        case SOLID:
            needsSolidUpdate = false;
            break;
        case TRANSLUCENT:
            needsTranslucentUpdate = false;
            break;
        default:
            break;
    }
}
 
Example #12
Source File: BlockMultiLayerBase.java    From Chisel-2 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public boolean canRenderInPass(int pass) {
	ForgeHooksClient.setRenderPass(pass);
	return pass == 1 || pass == 0;
}