use of net.minecraft.client.renderer.block.model.IBakedModel in project ImmersiveEngineering by BluSunrize.
the class ModelCoresample method getQuads.
@Override
public List<BakedQuad> getQuads(@Nullable IBlockState blockState, @Nullable EnumFacing side, long rand) {
if (bakedQuads == null) {
try {
bakedQuads = Collections.synchronizedSet(new LinkedHashSet<BakedQuad>());
float width = .25f;
float depth = .25f;
float wOff = (1 - width) / 2;
float dOff = (1 - depth) / 2;
int pixelLength = 0;
HashMap<TextureAtlasSprite, Integer> textureOre = new HashMap();
if (mineral != null && mineral.oreOutput != null) {
for (int i = 0; i < mineral.oreOutput.size(); i++) if (!mineral.oreOutput.get(i).isEmpty()) {
int weight = Math.max(2, Math.round(16 * mineral.recalculatedChances[i]));
Block b = Block.getBlockFromItem(mineral.oreOutput.get(i).getItem());
IBlockState state = b != null && b != Blocks.AIR ? b.getStateFromMeta(mineral.oreOutput.get(i).getMetadata()) : Blocks.STONE.getDefaultState();
IBakedModel model = Minecraft.getMinecraft().getBlockRendererDispatcher().getBlockModelShapes().getModelForState(state);
if (model != null && model.getParticleTexture() != null)
textureOre.put(model.getParticleTexture(), weight);
pixelLength += weight;
}
} else
pixelLength = 16;
TextureAtlasSprite textureStone = ClientUtils.getSprite(new ResourceLocation("blocks/stone"));
Vector2f[] stoneUVs = { new Vector2f(16 * wOff, 16 * dOff), new Vector2f(16 * wOff, 16 * (dOff + depth)), new Vector2f(16 * (wOff + width), 16 * (dOff + depth)), new Vector2f(16 * (wOff + width), 16 * dOff) };
putVertexData(new Vector3f(0, -1, 0), new Vector3f[] { new Vector3f(wOff, 0, dOff), new Vector3f(wOff + width, 0, dOff), new Vector3f(wOff + width, 0, dOff + depth), new Vector3f(wOff, 0, dOff + depth) }, stoneUVs, textureStone);
putVertexData(new Vector3f(0, 1, 0), new Vector3f[] { new Vector3f(wOff, 1, dOff), new Vector3f(wOff, 1, dOff + depth), new Vector3f(wOff + width, 1, dOff + depth), new Vector3f(wOff + width, 1, dOff) }, stoneUVs, textureStone);
if (textureOre.isEmpty()) {
Vector2f[][] uvs = new Vector2f[4][];
for (int j = 0; j < 4; j++) uvs[j] = new Vector2f[] { new Vector2f(j * 4, 0), new Vector2f(j * 4, 16), new Vector2f((j + 1) * 4, 16), new Vector2f((j + 1) * 4, 0) };
putVertexData(new Vector3f(0, 0, -1), new Vector3f[] { new Vector3f(wOff, 0, dOff), new Vector3f(wOff, 1, dOff), new Vector3f(wOff + width, 1, dOff), new Vector3f(wOff + width, 0, dOff) }, uvs[0], textureStone);
putVertexData(new Vector3f(0, 0, 1), new Vector3f[] { new Vector3f(wOff + width, 0, dOff + depth), new Vector3f(wOff + width, 1, dOff + depth), new Vector3f(wOff, 1, dOff + depth), new Vector3f(wOff, 0, dOff + depth) }, uvs[2], textureStone);
putVertexData(new Vector3f(-1, 0, 0), new Vector3f[] { new Vector3f(wOff, 0, dOff + depth), new Vector3f(wOff, 1, dOff + depth), new Vector3f(wOff, 1, dOff), new Vector3f(wOff, 0, dOff) }, uvs[3], textureStone);
putVertexData(new Vector3f(1, 0, 0), new Vector3f[] { new Vector3f(wOff + width, 0, dOff), new Vector3f(wOff + width, 1, dOff), new Vector3f(wOff + width, 1, dOff + depth), new Vector3f(wOff + width, 0, dOff + depth) }, uvs[1], textureStone);
} else {
float h = 0;
for (TextureAtlasSprite sprite : textureOre.keySet()) {
int weight = textureOre.get(sprite);
int v = weight > 8 ? 16 - weight : 8;
Vector2f[][] uvs = new Vector2f[4][];
for (int j = 0; j < 4; j++) uvs[j] = new Vector2f[] { new Vector2f(j * 4, v), new Vector2f(j * 4, v + weight), new Vector2f((j + 1) * 4, v + weight), new Vector2f((j + 1) * 4, v) };
float h1 = weight / (float) pixelLength;
putVertexData(new Vector3f(0, 0, -1), new Vector3f[] { new Vector3f(wOff, h, dOff), new Vector3f(wOff, h + h1, dOff), new Vector3f(wOff + width, h + h1, dOff), new Vector3f(wOff + width, h, dOff) }, uvs[0], sprite);
putVertexData(new Vector3f(0, 0, 1), new Vector3f[] { new Vector3f(wOff + width, h, dOff + depth), new Vector3f(wOff + width, h + h1, dOff + depth), new Vector3f(wOff, h + h1, dOff + depth), new Vector3f(wOff, h, dOff + depth) }, uvs[2], sprite);
putVertexData(new Vector3f(-1, 0, 0), new Vector3f[] { new Vector3f(wOff, h, dOff + depth), new Vector3f(wOff, h + h1, dOff + depth), new Vector3f(wOff, h + h1, dOff), new Vector3f(wOff, h, dOff) }, uvs[3], sprite);
putVertexData(new Vector3f(1, 0, 0), new Vector3f[] { new Vector3f(wOff + width, h, dOff), new Vector3f(wOff + width, h + h1, dOff), new Vector3f(wOff + width, h + h1, dOff + depth), new Vector3f(wOff + width, h, dOff + depth) }, uvs[1], sprite);
h += h1;
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
if (bakedQuads != null && !bakedQuads.isEmpty()) {
List<BakedQuad> quadList = Collections.synchronizedList(Lists.newArrayList(bakedQuads));
return quadList;
}
return emptyQuads;
}
use of net.minecraft.client.renderer.block.model.IBakedModel in project ImmersiveEngineering by BluSunrize.
the class ConnModelReal method getQuads.
@Nonnull
@Override
public List<BakedQuad> getQuads(@Nullable IBlockState state, @Nullable EnumFacing side, long rand) {
if (side == null && state instanceof IExtendedBlockState) {
IExtendedBlockState ext = (IExtendedBlockState) state;
Object[] additional = null;
if (ext.getUnlistedProperties().containsKey(IEProperties.TILEENTITY_PASSTHROUGH)) {
TileEntity te = ext.getValue(IEProperties.TILEENTITY_PASSTHROUGH);
if (te instanceof IEBlockInterfaces.ICacheData)
additional = ((IEBlockInterfaces.ICacheData) te).getCacheData();
}
int x = 0, z = 0;
if (ext.getUnlistedProperties().containsKey(IEProperties.CONNECTIONS)) {
Set<Connection> conns = ext.getValue(IEProperties.CONNECTIONS);
if (conns != null && conns.size() > 0) {
BlockPos tmp = conns.iterator().next().start;
x = (tmp.getX() % 16 + 16) % 16;
z = (tmp.getZ() % 16 + 16) % 16;
}
}
ExtBlockstateAdapter ad = new ExtBlockstateAdapter(ext, null, ExtBlockstateAdapter.ONLY_OBJ_CALLBACK, additional);
Pair<Byte, ExtBlockstateAdapter> key = new ImmutablePair<>((byte) ((x << 4) | z), ad);
try {
IBakedModel ret = cache.get(key, () -> new AssembledBakedModel(ext, textureAtlasSprite, base, layers));
return ret.getQuads(state, null, rand);
} catch (ExecutionException e) {
e.printStackTrace();
}
}
return getBaseQuads(MinecraftForgeClient.getRenderLayer(), state, side, rand);
}
use of net.minecraft.client.renderer.block.model.IBakedModel in project MorePlanets by SteveKunG.
the class OBJLoaderMP method getModelFromOBJ.
@SuppressWarnings("deprecation")
public static IBakedModel getModelFromOBJ(ResourceLocation modelLocation, List<String> visibleGroups, IModelState parentState) throws IOException {
IModel model = OBJLoaderMP.INSTANCE.loadModel(modelLocation);
Function<ResourceLocation, TextureAtlasSprite> spriteFunction = location -> Minecraft.getMinecraft().getTextureMapBlocks().getAtlasSprite(location.toString());
return model.bake(new OBJModel.OBJState(visibleGroups, false, parentState), DefaultVertexFormats.ITEM, spriteFunction);
}
use of net.minecraft.client.renderer.block.model.IBakedModel in project MorePlanets by SteveKunG.
the class ClientRendererUtils method renderModel.
public static void renderModel(IBlockState state) {
Minecraft mc = Minecraft.getMinecraft();
mc.renderEngine.bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
GlStateManager.rotate(90.0F, 0.0F, 1.0F, 0.0F);
int i = mc.getBlockColors().colorMultiplier(state, null, null, 0);
IBakedModel model = Minecraft.getMinecraft().getBlockRendererDispatcher().getBlockModelShapes().getModelForState(state);
if (EntityRenderer.anaglyphEnable) {
i = TextureUtil.anaglyphColor(i);
}
float f = (i >> 16 & 255) / 255.0F;
float f1 = (i >> 8 & 255) / 255.0F;
float f2 = (i & 255) / 255.0F;
ClientRendererUtils.renderModelBrightnessColor(state, model, 1.0F, f, f1, f2);
}
use of net.minecraft.client.renderer.block.model.IBakedModel in project MinecraftForge by MinecraftForge.
the class ItemModelMesherForge method rebuildCache.
public void rebuildCache() {
final ModelManager manager = this.getModelManager();
for (Map.Entry<Item, TIntObjectHashMap<ModelResourceLocation>> e : locations.entrySet()) {
TIntObjectHashMap<IBakedModel> mods = models.get(e.getKey());
if (mods != null) {
mods.clear();
} else {
mods = new TIntObjectHashMap<IBakedModel>();
models.put(e.getKey(), mods);
}
final TIntObjectHashMap<IBakedModel> map = mods;
e.getValue().forEachEntry(new TIntObjectProcedure<ModelResourceLocation>() {
@Override
public boolean execute(int meta, ModelResourceLocation location) {
map.put(meta, manager.getModel(location));
return true;
}
});
}
}
Aggregations