Search in sources :

Example 91 with IExtendedBlockState

use of net.minecraftforge.common.property.IExtendedBlockState in project LogisticsPipes by RS485.

the class LogisticsNewPipeModel method bake.

@Override
@SideOnly(Side.CLIENT)
@Nonnull
public IBakedModel bake(@Nonnull IModelState state, @Nonnull VertexFormat format, @Nonnull Function<ResourceLocation, TextureAtlasSprite> bakedTextureGetter) {
    return new IBakedModel() {

        private ArrayList<BakedQuad> quads = null;

        @Override
        @SideOnly(Side.CLIENT)
        @Nonnull
        public List<BakedQuad> getQuads(@Nullable IBlockState blockstate, @Nullable EnumFacing side, long rand) {
            BlockRenderLayer layer = MinecraftForgeClient.getRenderLayer();
            ArrayList<BakedQuad> result;
            if (layer == BlockRenderLayer.CUTOUT || layer == null || blockstate == null) {
                result = getLPQuads(blockstate, side);
            } else {
                result = Lists.newArrayList();
            }
            addOtherQuads(result, blockstate, side, rand);
            return result;
        }

        private void addOtherQuads(@Nonnull List<BakedQuad> list, IBlockState blockstate, EnumFacing side, long rand) {
            if (blockstate != null) {
                SimpleServiceLocator.mcmpProxy.addQuads(list, blockstate, side, rand);
            }
        }

        private ArrayList<BakedQuad> getLPQuads(@Nullable IBlockState blockstate, @Nullable EnumFacing side) {
            if (blockstate != null) {
                if (side == null) {
                    IExtendedBlockState eState = (IExtendedBlockState) blockstate;
                    Cache<PipeRenderState.LocalCacheType, Object> objectCache = eState.getValue(LogisticsBlockGenericPipe.propertyCache);
                    if (objectCache != null) {
                        Object pipeQuads = objectCache.getIfPresent(PipeRenderState.LocalCacheType.QUADS);
                        if (pipeQuads instanceof Collection) {
                            // noinspection unchecked
                            return new ArrayList<>((Collection<? extends BakedQuad>) pipeQuads);
                        }
                    }
                    final ArrayList<BakedQuad> pipeQuads = LogisticsRenderPipe.secondRenderer.getQuadsFromRenderList(generatePipeRenderList(blockstate), format, true);
                    if (objectCache != null) {
                        objectCache.put(PipeRenderState.LocalCacheType.QUADS, new ArrayList<>(pipeQuads));
                    }
                    return pipeQuads;
                }
            } else {
                if (quads == null) {
                    quads = LogisticsRenderPipe.secondRenderer.getQuadsFromRenderList(generatePipeRenderList(), format, true);
                }
                return new ArrayList<>(quads);
            }
            return Lists.newArrayList();
        }

        @Override
        public boolean isAmbientOcclusion() {
            return false;
        }

        @Override
        public boolean isGui3d() {
            return true;
        }

        @Override
        public boolean isBuiltInRenderer() {
            return false;
        }

        @Override
        @Nonnull
        public TextureAtlasSprite getParticleTexture() {
            return BASE_TEXTURE_SPRITE;
        }

        @Override
        @Nonnull
        public ItemOverrideList getOverrides() {
            return ItemOverrideList.NONE;
        }

        @Override
        @Nonnull
        public org.apache.commons.lang3.tuple.Pair<? extends IBakedModel, Matrix4f> handlePerspective(@Nonnull ItemCameraTransforms.TransformType cameraTransformType) {
            return PerspectiveMapWrapper.handlePerspective(this, SimpleServiceLocator.cclProxy.getDefaultBlockState(), cameraTransformType);
        }
    };
}
Also used : BakedQuad(net.minecraft.client.renderer.block.model.BakedQuad) IBlockState(net.minecraft.block.state.IBlockState) Nonnull(javax.annotation.Nonnull) EnumFacing(net.minecraft.util.EnumFacing) ArrayList(java.util.ArrayList) Matrix4f(javax.vecmath.Matrix4f) IExtendedBlockState(net.minecraftforge.common.property.IExtendedBlockState) Collection(java.util.Collection) BlockRenderLayer(net.minecraft.util.BlockRenderLayer) ItemOverrideList(net.minecraft.client.renderer.block.model.ItemOverrideList) List(java.util.List) LPUVTransformationList(logisticspipes.proxy.object3d.operation.LPUVTransformationList) ArrayList(java.util.ArrayList) IBakedModel(net.minecraft.client.renderer.block.model.IBakedModel) Nullable(javax.annotation.Nullable) Nonnull(javax.annotation.Nonnull) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 92 with IExtendedBlockState

use of net.minecraftforge.common.property.IExtendedBlockState in project Railcraft by Railcraft.

the class BlockRailcraftWall method getActualState.

@Override
public IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos) {
    boolean north = canConnectTo(worldIn, pos.north());
    boolean east = canConnectTo(worldIn, pos.east());
    boolean south = canConnectTo(worldIn, pos.south());
    boolean west = canConnectTo(worldIn, pos.west());
    boolean smooth = north && !east && south && !west || !north && east && !south && west;
    state = state.withProperty(UP, !smooth || !worldIn.isAirBlock(pos.up())).withProperty(NORTH, north).withProperty(EAST, east).withProperty(SOUTH, south).withProperty(WEST, west);
    IExtendedBlockState actState = (IExtendedBlockState) state;
    actState = actState.withProperty(Materials.MATERIAL_PROPERTY, MatTools.getMat(worldIn, pos));
    return actState;
}
Also used : IExtendedBlockState(net.minecraftforge.common.property.IExtendedBlockState)

Example 93 with IExtendedBlockState

use of net.minecraftforge.common.property.IExtendedBlockState in project TechReborn by TechReborn.

the class RenderFluidPipePart method getQuads.

@Override
public List<BakedQuad> getQuads(IBlockState blockState, EnumFacing side, long rand) {
    ArrayList<BakedQuad> list = new ArrayList<>();
    BlockFaceUV uv = new BlockFaceUV(new float[] { 0.0F, 0.0F, 16.0F, 16.0F }, 0);
    BlockPartFace face = new BlockPartFace(null, 0, "", uv);
    double thickness = MultipartFluidPipe.thickness;
    double lastThickness = 16 - thickness;
    IExtendedBlockState state = (IExtendedBlockState) blockState;
    if (side != null) {
        return Collections.emptyList();
    }
    boolean renderedConnection = false;
    if (state != null) {
        if (state.getValue(MultipartFluidPipe.UP)) {
            BakedModelUtils.addCubeToList(new Vecs3dCube(thickness, lastThickness, thickness, lastThickness, 16.0, lastThickness), list, face, ModelRotation.X0_Y0, texture, EnumFacing.UP, faceBakery);
            renderedConnection = true;
        }
        if (state.getValue(MultipartFluidPipe.DOWN)) {
            BakedModelUtils.addCubeToList(new Vecs3dCube(thickness, 0.0, thickness, lastThickness, thickness, lastThickness), list, face, ModelRotation.X0_Y0, texture, EnumFacing.DOWN, faceBakery);
            renderedConnection = true;
        }
        if (state.getValue(MultipartFluidPipe.NORTH)) {
            BakedModelUtils.addCubeToList(new Vecs3dCube(thickness, thickness, 0.0, lastThickness, lastThickness, lastThickness), list, face, ModelRotation.X0_Y0, texture, EnumFacing.NORTH, faceBakery);
            renderedConnection = true;
        }
        if (state.getValue(MultipartFluidPipe.SOUTH)) {
            BakedModelUtils.addCubeToList(new Vecs3dCube(thickness, thickness, thickness, lastThickness, lastThickness, 16.0), list, face, ModelRotation.X0_Y0, texture, EnumFacing.SOUTH, faceBakery);
            renderedConnection = false;
        }
        if (state.getValue(MultipartFluidPipe.EAST)) {
            BakedModelUtils.addCubeToList(new Vecs3dCube(thickness, thickness, thickness, 16, lastThickness, lastThickness), list, face, ModelRotation.X0_Y0, texture, EnumFacing.EAST, faceBakery);
            renderedConnection = false;
        }
        if (state.getValue(MultipartFluidPipe.WEST)) {
            BakedModelUtils.addCubeToList(new Vecs3dCube(0.0, thickness, thickness, thickness, lastThickness, lastThickness), list, face, ModelRotation.X0_Y0, texture, EnumFacing.WEST, faceBakery);
            renderedConnection = true;
        }
        if (!renderedConnection) {
            BakedModelUtils.addCubeToList(new Vecs3dCube(thickness, thickness, thickness, lastThickness, lastThickness, lastThickness), list, face, ModelRotation.X0_Y0, texture, null, faceBakery);
        }
    }
    return list;
}
Also used : Vecs3dCube(reborncore.common.misc.vecmath.Vecs3dCube) IExtendedBlockState(net.minecraftforge.common.property.IExtendedBlockState) ArrayList(java.util.ArrayList)

Example 94 with IExtendedBlockState

use of net.minecraftforge.common.property.IExtendedBlockState in project TechReborn by TechReborn.

the class RenderCablePart method getQuads.

@Override
public List<BakedQuad> getQuads(IBlockState blockState, EnumFacing side, long rand) {
    type = blockState.getValue(CableMultipart.TYPE);
    texture = Minecraft.getMinecraft().getTextureMapBlocks().getAtlasSprite(type.textureName);
    ArrayList<BakedQuad> list = new ArrayList<>();
    BlockFaceUV uv = new BlockFaceUV(new float[] { 0.0F, 0.0F, 16.0F, 16.0F }, 0);
    BlockPartFace face = new BlockPartFace(null, 0, "", uv);
    double thickness = type.cableThickness;
    double lastThickness = 16 - thickness;
    IExtendedBlockState state = (IExtendedBlockState) blockState;
    if (side != null) {
        return Collections.emptyList();
    }
    BakedModelUtils.addCubeToList(new Vecs3dCube(thickness, thickness, thickness, lastThickness, lastThickness, lastThickness), list, face, ModelRotation.X0_Y0, texture, null, faceBakery);
    if (state != null) {
        if (state.getValue(CableMultipart.UP)) {
            BakedModelUtils.addCubeToList(new Vecs3dCube(thickness, lastThickness, thickness, lastThickness, 16.0, lastThickness), list, face, ModelRotation.X0_Y0, texture, EnumFacing.UP, faceBakery);
        }
        if (state.getValue(CableMultipart.DOWN)) {
            BakedModelUtils.addCubeToList(new Vecs3dCube(thickness, 0.0, thickness, lastThickness, thickness, lastThickness), list, face, ModelRotation.X0_Y0, texture, EnumFacing.DOWN, faceBakery);
        }
        if (state.getValue(CableMultipart.NORTH)) {
            BakedModelUtils.addCubeToList(new Vecs3dCube(0.0, thickness, thickness, thickness, lastThickness, lastThickness), list, face, ModelRotation.X0_Y90, texture, EnumFacing.NORTH, faceBakery);
        }
        if (state.getValue(CableMultipart.SOUTH)) {
            BakedModelUtils.addCubeToList(new Vecs3dCube(0.0, thickness, thickness, thickness, lastThickness, lastThickness), list, face, ModelRotation.X0_Y270, texture, EnumFacing.SOUTH, faceBakery);
        }
        if (state.getValue(CableMultipart.EAST)) {
            BakedModelUtils.addCubeToList(new Vecs3dCube(lastThickness, thickness, thickness, 16.0, lastThickness, lastThickness), list, face, ModelRotation.X0_Y0, texture, EnumFacing.EAST, faceBakery);
        }
        if (state.getValue(CableMultipart.WEST)) {
            BakedModelUtils.addCubeToList(new Vecs3dCube(0.0, thickness, thickness, thickness, lastThickness, lastThickness), list, face, ModelRotation.X0_Y0, texture, EnumFacing.WEST, faceBakery);
        }
    }
    return list;
}
Also used : Vecs3dCube(reborncore.common.misc.vecmath.Vecs3dCube) IExtendedBlockState(net.minecraftforge.common.property.IExtendedBlockState) ArrayList(java.util.ArrayList)

Example 95 with IExtendedBlockState

use of net.minecraftforge.common.property.IExtendedBlockState in project Immersive-Tech by FerroO2000.

the class BlockITTileProvider method getExtendedState.

@Override
public IBlockState getExtendedState(IBlockState state, IBlockAccess world, BlockPos pos) {
    state = super.getExtendedState(state, world, pos);
    if (state instanceof IExtendedBlockState) {
        IExtendedBlockState extended = (IExtendedBlockState) state;
        TileEntity te = world.getTileEntity(pos);
        if (te != null) {
            if (te instanceof IConfigurableSides)
                for (int i = 0; i < 6; i++) if (extended.getUnlistedNames().contains(IEProperties.SIDECONFIG[i]))
                    extended = extended.withProperty(IEProperties.SIDECONFIG[i], ((IConfigurableSides) te).getSideConfig(i));
            if (te instanceof IAdvancedHasObjProperty)
                extended = extended.withProperty(Properties.AnimationProperty, ((IAdvancedHasObjProperty) te).getOBJState());
            else if (te instanceof IHasObjProperty)
                extended = extended.withProperty(Properties.AnimationProperty, new OBJState(((IHasObjProperty) te).compileDisplayList(), true));
            if (te instanceof IDynamicTexture)
                extended = extended.withProperty(IEProperties.OBJ_TEXTURE_REMAP, ((IDynamicTexture) te).getTextureReplacements());
            if (te instanceof IOBJModelCallback)
                extended = extended.withProperty(IOBJModelCallback.PROPERTY, (IOBJModelCallback) te);
            if (te.hasCapability(CapabilityShader.SHADER_CAPABILITY, null))
                extended = extended.withProperty(CapabilityShader.BLOCKSTATE_PROPERTY, te.getCapability(CapabilityShader.SHADER_CAPABILITY, null));
            if (te instanceof IPropertyPassthrough && ((IExtendedBlockState) state).getUnlistedNames().contains(IEProperties.TILEENTITY_PASSTHROUGH))
                extended = extended.withProperty(IEProperties.TILEENTITY_PASSTHROUGH, te);
            if (te instanceof TileEntityImmersiveConnectable && ((IExtendedBlockState) state).getUnlistedNames().contains(IEProperties.CONNECTIONS))
                extended = extended.withProperty(IEProperties.CONNECTIONS, ((TileEntityImmersiveConnectable) te).genConnBlockstate());
        }
        state = extended;
    }
    return state;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileEntityImmersiveConnectable(blusunrize.immersiveengineering.api.energy.wires.TileEntityImmersiveConnectable) IDynamicTexture(blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IDynamicTexture) IPropertyPassthrough(blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IPropertyPassthrough) IOBJModelCallback(blusunrize.immersiveengineering.client.models.IOBJModelCallback) IExtendedBlockState(net.minecraftforge.common.property.IExtendedBlockState) IAdvancedHasObjProperty(blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IAdvancedHasObjProperty) IHasObjProperty(blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IHasObjProperty) IConfigurableSides(blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IConfigurableSides) OBJState(net.minecraftforge.client.model.obj.OBJModel.OBJState)

Aggregations

IExtendedBlockState (net.minecraftforge.common.property.IExtendedBlockState)96 IBlockState (net.minecraft.block.state.IBlockState)27 BlockPos (net.minecraft.util.math.BlockPos)24 IBakedModel (net.minecraft.client.renderer.block.model.IBakedModel)17 EnumFacing (net.minecraft.util.EnumFacing)17 OBJState (net.minecraftforge.client.model.obj.OBJModel.OBJState)17 TileEntity (net.minecraft.tileentity.TileEntity)16 BakedQuad (net.minecraft.client.renderer.block.model.BakedQuad)14 ArrayList (java.util.ArrayList)13 IBlockAccess (net.minecraft.world.IBlockAccess)13 UnlistedBlockPos (forestry.core.blocks.properties.UnlistedBlockPos)10 TileEntityImmersiveConnectable (blusunrize.immersiveengineering.api.energy.wires.TileEntityImmersiveConnectable)7 TextureAtlasSprite (net.minecraft.client.renderer.texture.TextureAtlasSprite)7 Block (net.minecraft.block.Block)6 ItemStack (net.minecraft.item.ItemStack)6 Nonnull (javax.annotation.Nonnull)4 ResourceLocation (net.minecraft.util.ResourceLocation)4 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)4 Minecraft (net.minecraft.client.Minecraft)3 Vec3d (net.minecraft.util.math.Vec3d)3