Search in sources :

Example 6 with IExtendedBlockState

use of net.minecraftforge.common.property.IExtendedBlockState in project ImmersiveEngineering by BluSunrize.

the class TileRenderSampleDrill method renderTileEntityAt.

@Override
public void renderTileEntityAt(TileEntitySampleDrill tile, double x, double y, double z, float partialTicks, int destroyStage) {
    if (tile.isDummy() || !tile.getWorld().isBlockLoaded(tile.getPos(), false))
        return;
    final BlockRendererDispatcher blockRenderer = Minecraft.getMinecraft().getBlockRendererDispatcher();
    IBlockState state = tile.getWorld().getBlockState(tile.getPos());
    BlockPos blockPos = tile.getPos();
    IBakedModel model = blockRenderer.getModelForState(state);
    //				.getModelFromBlockState(state, getWorld(), blockPos);
    if (state instanceof IExtendedBlockState)
        state = ((IExtendedBlockState) state).withProperty(Properties.AnimationProperty, new OBJState(Lists.newArrayList("drill"), true));
    Tessellator tessellator = Tessellator.getInstance();
    VertexBuffer worldRenderer = tessellator.getBuffer();
    bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
    RenderHelper.disableStandardItemLighting();
    GlStateManager.blendFunc(770, 771);
    GlStateManager.enableBlend();
    GlStateManager.disableCull();
    if (Minecraft.isAmbientOcclusionEnabled())
        GlStateManager.shadeModel(7425);
    else
        GlStateManager.shadeModel(7424);
    GlStateManager.pushMatrix();
    GlStateManager.translate(x + .5, y + .5, z + .5);
    //		float rot = 360*tile.rotation-(!tile.canTurn||tile.rotation==0||tile.rotation-tile.prevRotation<4?0:tile.facing.getAxis()==Axis.X?-f:f);
    //		GlStateManager.rotate(rot, 0,0,1);
    int max = IEConfig.Machines.coredrill_time;
    if (tile.process > 0 && tile.process < max) {
        GL11.glRotatef(((tile.process + partialTicks) * 22.5f) % 360f, 0, 1, 0);
        float push = tile.process / (float) max;
        if (tile.process > max / 2)
            push = 1 - push;
        GL11.glTranslated(0, -2.8f * push, 0);
    }
    worldRenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.BLOCK);
    worldRenderer.setTranslation(-.5 - blockPos.getX(), -.5 - blockPos.getY(), -.5 - blockPos.getZ());
    worldRenderer.color(255, 255, 255, 255);
    blockRenderer.getBlockModelRenderer().renderModel(tile.getWorld(), model, state, tile.getPos(), worldRenderer, true);
    worldRenderer.setTranslation(0.0D, 0.0D, 0.0D);
    tessellator.draw();
    GlStateManager.popMatrix();
    RenderHelper.enableStandardItemLighting();
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) IExtendedBlockState(net.minecraftforge.common.property.IExtendedBlockState) BlockPos(net.minecraft.util.math.BlockPos) IBakedModel(net.minecraft.client.renderer.block.model.IBakedModel) OBJState(net.minecraftforge.client.model.obj.OBJModel.OBJState)

Example 7 with IExtendedBlockState

use of net.minecraftforge.common.property.IExtendedBlockState in project ImmersiveEngineering by BluSunrize.

the class TileRenderBucketWheel method renderTileEntityAt.

@Override
public void renderTileEntityAt(TileEntityBucketWheel tile, double x, double y, double z, float f, int destroyStage) {
    if (!tile.formed || !tile.getWorld().isBlockLoaded(tile.getPos(), false) || tile.isDummy())
        return;
    final BlockRendererDispatcher blockRenderer = Minecraft.getMinecraft().getBlockRendererDispatcher();
    IBlockState state = tile.getWorld().getBlockState(tile.getPos());
    if (state.getBlock() != IEContent.blockMetalMultiblock)
        return;
    if (model == null) {
        state = state.withProperty(IEProperties.DYNAMICRENDER, true);
        model = blockRenderer.getModelForState(state);
    }
    OBJState objState = null;
    HashMap<String, String> texMap = new HashMap<>();
    if (state instanceof IExtendedBlockState) {
        ArrayList<String> list = Lists.newArrayList("bucketWheel");
        synchronized (tile.digStacks) {
            for (int i = 0; i < tile.digStacks.length; i++) if (tile.digStacks[i] != null) {
                list.add("dig" + i);
                Block b = Block.getBlockFromItem(tile.digStacks[i].getItem());
                IBlockState digState = b != null ? b.getStateFromMeta(tile.digStacks[i].getMetadata()) : Blocks.STONE.getDefaultState();
                IBakedModel digModel = Minecraft.getMinecraft().getBlockRendererDispatcher().getBlockModelShapes().getModelForState(digState);
                if (digModel != null && digModel.getParticleTexture() != null)
                    texMap.put("dig" + i, digModel.getParticleTexture().getIconName());
            }
        }
        objState = new OBJState(list, true);
    }
    Tessellator tessellator = Tessellator.getInstance();
    GlStateManager.pushMatrix();
    GlStateManager.translate(x + .5, y + .5, z + .5);
    GlStateManager.blendFunc(770, 771);
    GlStateManager.enableBlend();
    GlStateManager.disableCull();
    EnumFacing facing = tile.facing;
    if (tile.mirrored) {
        GlStateManager.scale(facing.getAxis() == Axis.X ? -1 : 1, 1, facing.getAxis() == Axis.Z ? -1 : 1);
        GlStateManager.disableCull();
    }
    float dir = tile.facing == EnumFacing.SOUTH ? 90 : tile.facing == EnumFacing.NORTH ? -90 : tile.facing == EnumFacing.EAST ? 180 : 0;
    GlStateManager.rotate(dir, 0, 1, 0);
    float rot = tile.rotation + (float) (tile.active ? IEConfig.Machines.excavator_speed * f : 0);
    GlStateManager.rotate(rot, 1, 0, 0);
    RenderHelper.disableStandardItemLighting();
    Minecraft.getMinecraft().renderEngine.bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
    VertexBuffer worldRenderer = tessellator.getBuffer();
    worldRenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.BLOCK);
    worldRenderer.setTranslation(-.5, -.5, -.5);
    List<BakedQuad> quads;
    if (model instanceof IESmartObjModel)
        quads = ((IESmartObjModel) model).getQuads(state, null, 0, objState, texMap, true);
    else
        quads = model.getQuads(state, null, 0);
    ClientUtils.renderModelTESR(quads, worldRenderer, tile.getWorld().getCombinedLight(tile.getPos(), 0));
    worldRenderer.setTranslation(0, 0, 0);
    tessellator.draw();
    GlStateManager.popMatrix();
    RenderHelper.enableStandardItemLighting();
    GlStateManager.disableBlend();
    GlStateManager.enableCull();
    if (tile.mirrored) {
        GlStateManager.enableCull();
    }
}
Also used : BakedQuad(net.minecraft.client.renderer.block.model.BakedQuad) IBlockState(net.minecraft.block.state.IBlockState) HashMap(java.util.HashMap) EnumFacing(net.minecraft.util.EnumFacing) IExtendedBlockState(net.minecraftforge.common.property.IExtendedBlockState) IESmartObjModel(blusunrize.immersiveengineering.client.models.IESmartObjModel) Block(net.minecraft.block.Block) IBakedModel(net.minecraft.client.renderer.block.model.IBakedModel) OBJState(net.minecraftforge.client.model.obj.OBJModel.OBJState)

Example 8 with IExtendedBlockState

use of net.minecraftforge.common.property.IExtendedBlockState in project ImmersiveEngineering by BluSunrize.

the class IESmartObjModel method getQuads.

@Override
public List<BakedQuad> getQuads(IBlockState blockState, EnumFacing side, long rand) {
    OBJState objState = null;
    Map<String, String> tex = null;
    if (blockState instanceof IExtendedBlockState) {
        IExtendedBlockState ext = (IExtendedBlockState) blockState;
        if (ext.getUnlistedNames().contains(Properties.AnimationProperty)) {
            IModelState modState = ext.getValue(Properties.AnimationProperty);
            if (modState instanceof OBJState)
                objState = (OBJState) modState;
        }
        if (ext.getUnlistedNames().contains(IEProperties.OBJ_TEXTURE_REMAP))
            tex = ext.getValue(IEProperties.OBJ_TEXTURE_REMAP);
    }
    return getQuads(blockState, side, rand, objState, tex, false);
}
Also used : IExtendedBlockState(net.minecraftforge.common.property.IExtendedBlockState) IModelState(net.minecraftforge.common.model.IModelState)

Example 9 with IExtendedBlockState

use of net.minecraftforge.common.property.IExtendedBlockState in project ImmersiveEngineering by BluSunrize.

the class IESmartObjModel method getQuads.

public List<BakedQuad> getQuads(IBlockState blockState, EnumFacing side, long rand, OBJState objstate, Map<String, String> tex, boolean addAnimationAndTex) {
    texReplace = tex;
    this.tempState = blockState;
    if (blockState instanceof IExtendedBlockState) {
        IExtendedBlockState exState = (IExtendedBlockState) blockState;
        ExtBlockstateAdapter adapter;
        if (objstate != null) {
            if (objstate.parent == null || objstate.parent == TRSRTransformation.identity())
                objstate.parent = this.getState();
            if (objstate.getVisibilityMap().containsKey(Group.ALL) || objstate.getVisibilityMap().containsKey(Group.ALL_EXCEPT))
                this.updateStateVisibilityMap(objstate);
        }
        if (addAnimationAndTex)
            adapter = new ExtBlockstateAdapter(exState, MinecraftForgeClient.getRenderLayer(), ExtBlockstateAdapter.CONNS_OBJ_CALLBACK, new Object[] { objstate, tex });
        else
            adapter = new ExtBlockstateAdapter(exState, MinecraftForgeClient.getRenderLayer(), ExtBlockstateAdapter.CONNS_OBJ_CALLBACK);
        if (!modelCache.containsKey(adapter)) {
            IESmartObjModel model = null;
            if (objstate != null)
                model = new IESmartObjModel(baseModel, getModel(), objstate, getFormat(), getTextures(), transformationMap);
            if (model == null)
                model = new IESmartObjModel(baseModel, getModel(), this.getState(), getFormat(), getTextures(), transformationMap);
            model.tempState = blockState;
            model.texReplace = tex;
            modelCache.put(adapter, model.buildQuads());
        }
        return Collections.synchronizedList(Lists.newArrayList(modelCache.get(adapter)));
    }
    if (bakedQuads == null)
        bakedQuads = buildQuads();
    List<BakedQuad> quadList = Collections.synchronizedList(Lists.newArrayList(bakedQuads));
    return quadList;
}
Also used : BakedQuad(net.minecraft.client.renderer.block.model.BakedQuad) UnpackedBakedQuad(net.minecraftforge.client.model.pipeline.UnpackedBakedQuad) ExtBlockstateAdapter(blusunrize.immersiveengineering.client.models.smart.ConnModelReal.ExtBlockstateAdapter) IExtendedBlockState(net.minecraftforge.common.property.IExtendedBlockState)

Example 10 with IExtendedBlockState

use of net.minecraftforge.common.property.IExtendedBlockState in project ImmersiveEngineering by BluSunrize.

the class ModelConveyor method getQuads.

@Override
public List<BakedQuad> getQuads(@Nullable IBlockState blockState, @Nullable EnumFacing side, long rand) {
    TileEntity tile = null;
    String key = "default";
    EnumFacing facing = EnumFacing.NORTH;
    if (blockState == null)
        key = conveyor != null ? ConveyorHandler.reverseClassRegistry.get(conveyor.getClass()).toString() : "immersiveengineering:conveyor";
    else {
        facing = blockState.getValue(IEProperties.FACING_ALL);
        if (blockState instanceof IExtendedBlockState) {
            IExtendedBlockState exState = (IExtendedBlockState) blockState;
            if (exState.getUnlistedNames().contains(BlockConveyor.ICONEYOR_PASSTHROUGH))
                conveyor = ((IExtendedBlockState) blockState).getValue(BlockConveyor.ICONEYOR_PASSTHROUGH);
            if (exState.getUnlistedNames().contains(IEProperties.TILEENTITY_PASSTHROUGH))
                tile = ((IExtendedBlockState) blockState).getValue(IEProperties.TILEENTITY_PASSTHROUGH);
            if (conveyor != null && tile != null)
                key = conveyor.getModelCacheKey(tile, facing);
        }
    }
    List<BakedQuad> cachedQuads = modelCache.get(key);
    if (cachedQuads != null)
        return Collections.synchronizedList(Lists.newArrayList(cachedQuads));
    else {
        cachedQuads = Collections.synchronizedList(Lists.newArrayList());
        Matrix4f facingMatrix = TRSRTransformation.getMatrix(facing);
        if (conveyor != null)
            facingMatrix = conveyor.modifyBaseRotationMatrix(facingMatrix, tile, facing);
        Matrix4 matrix = new Matrix4(facingMatrix);
        ConveyorDirection conDir = conveyor != null ? conveyor.getConveyorDirection() : ConveyorDirection.HORIZONTAL;
        boolean[] walls = conveyor != null && tile != null ? new boolean[] { conveyor.renderWall(tile, facing, 0), conveyor.renderWall(tile, facing, 1) } : new boolean[] { true, true };
        TextureAtlasSprite tex_conveyor = ClientUtils.mc().getTextureMapBlocks().getMissingSprite();
        TextureAtlasSprite tex_conveyor_colour = null;
        int colourStripes = -1;
        if (conveyor != null) {
            tex_conveyor = ClientUtils.getSprite(tile != null ? (conveyor.isActive(tile) ? conveyor.getActiveTexture() : conveyor.getInactiveTexture()) : conveyor.getActiveTexture());
            if ((colourStripes = conveyor.getDyeColour()) >= 0)
                tex_conveyor_colour = ClientUtils.getSprite(conveyor.getColouredStripesTexture());
        }
        cachedQuads.addAll(getBaseConveyor(facing, 1, matrix, conDir, tex_conveyor, walls, new boolean[] { true, true }, tex_conveyor_colour, colourStripes));
        if (conveyor != null)
            cachedQuads = conveyor.modifyQuads(cachedQuads, tile, facing);
        modelCache.put(key, cachedQuads);
        return Collections.synchronizedList(Lists.newArrayList(cachedQuads));
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) BakedQuad(net.minecraft.client.renderer.block.model.BakedQuad) Matrix4f(javax.vecmath.Matrix4f) IExtendedBlockState(net.minecraftforge.common.property.IExtendedBlockState) TextureAtlasSprite(net.minecraft.client.renderer.texture.TextureAtlasSprite) EnumFacing(net.minecraft.util.EnumFacing) ConveyorDirection(blusunrize.immersiveengineering.api.tool.ConveyorHandler.ConveyorDirection) Matrix4(blusunrize.immersiveengineering.common.util.chickenbones.Matrix4)

Aggregations

IExtendedBlockState (net.minecraftforge.common.property.IExtendedBlockState)29 IBlockState (net.minecraft.block.state.IBlockState)8 IBakedModel (net.minecraft.client.renderer.block.model.IBakedModel)8 OBJState (net.minecraftforge.client.model.obj.OBJModel.OBJState)8 TileEntity (net.minecraft.tileentity.TileEntity)6 EnumFacing (net.minecraft.util.EnumFacing)6 BakedQuad (net.minecraft.client.renderer.block.model.BakedQuad)5 BlockPos (net.minecraft.util.math.BlockPos)5 TileEntityImmersiveConnectable (blusunrize.immersiveengineering.api.energy.wires.TileEntityImmersiveConnectable)4 TextureAtlasSprite (net.minecraft.client.renderer.texture.TextureAtlasSprite)4 CustomWoodType (com.infinityraider.agricraft.utility.CustomWoodType)2 SidedConnection (com.infinityraider.infinitylib.block.blockstate.SidedConnection)2 UnpackedBakedQuad (net.minecraftforge.client.model.pipeline.UnpackedBakedQuad)2 IModelState (net.minecraftforge.common.model.IModelState)2 ComparableItemStack (blusunrize.immersiveengineering.api.ComparableItemStack)1 SideConfig (blusunrize.immersiveengineering.api.IEEnums.SideConfig)1 Connection (blusunrize.immersiveengineering.api.energy.wires.ImmersiveNetHandler.Connection)1 ShaderWrapper (blusunrize.immersiveengineering.api.shader.CapabilityShader.ShaderWrapper)1 IShaderItem (blusunrize.immersiveengineering.api.shader.IShaderItem)1 ShaderCase (blusunrize.immersiveengineering.api.shader.ShaderCase)1