use of net.minecraft.client.renderer.block.model.ItemOverrideList in project Tropicraft by Tropicraft.
the class ClientProxy method onModelBake.
@SubscribeEvent
public void onModelBake(ModelBakeEvent event) {
for (Entry<String, String[]> e : blockVariants.entrySet()) {
for (String variant : e.getValue()) {
ModelResourceLocation loc = new ModelResourceLocation(Info.MODID + ":" + e.getKey(), variant);
IModel model = ModelLoaderRegistry.getModelOrLogError(loc, "Could not load arbitrary block variant " + variant + " for block " + e.getKey());
event.getModelRegistry().putObject(loc, model.bake(model.getDefaultState(), DefaultVertexFormats.ITEM, ModelLoader.defaultTextureGetter()));
}
}
try {
IModel waterTop = ModelLoaderRegistry.getModel(new ResourceLocation("tropicraft:block/tropics_water_top"));
final IBakedModel waterTopBaked = waterTop.bake(waterTop.getDefaultState(), DefaultVertexFormats.ITEM, ModelLoader.defaultTextureGetter());
Block[] fences = new Block[] { BlockRegistry.bambooFence, BlockRegistry.chunkFence, BlockRegistry.mahoganyFence, BlockRegistry.palmFence, BlockRegistry.thatchFence };
for (Block block : fences) {
ModelResourceLocation loc = new ModelResourceLocation(block.getRegistryName(), "normal");
final IBakedModel fenceModel = event.getModelRegistry().getObject(loc);
event.getModelRegistry().putObject(loc, new IBakedModel() {
@Override
@Nonnull
public List<BakedQuad> getQuads(@Nullable IBlockState state, @Nullable EnumFacing side, long rand) {
BlockRenderLayer layer = MinecraftForgeClient.getRenderLayer();
if (layer == null || layer == BlockRenderLayer.SOLID) {
return fenceModel.getQuads(state, side, rand);
} else if (layer == BlockRenderLayer.TRANSLUCENT && state.getValue(BlockTropicraftFence.WATER) == WaterState.SURFACE) {
return waterTopBaked.getQuads(state, side, rand);
}
return Collections.emptyList();
}
@Override
public boolean isGui3d() {
return true;
}
@Override
public boolean isBuiltInRenderer() {
return false;
}
@Override
public boolean isAmbientOcclusion() {
return true;
}
@Override
@Nonnull
public TextureAtlasSprite getParticleTexture() {
return fenceModel.getParticleTexture();
}
@Override
@Nonnull
public ItemOverrideList getOverrides() {
return fenceModel.getOverrides();
}
});
}
} catch (Exception e1) {
e1.printStackTrace();
}
}
use of net.minecraft.client.renderer.block.model.ItemOverrideList in project FoamFix by asiekierka.
the class FoamyItemLayerModel method bakeStatic.
public static IBakedModel bakeStatic(ItemLayerModel parent, final IModelState state, final VertexFormat format, final Function<ResourceLocation, TextureAtlasSprite> bakedTextureGetter) {
ImmutableMap<ItemCameraTransforms.TransformType, TRSRTransformation> map = PerspectiveMapWrapper.getTransforms(state);
TRSRTransformation guiTransform = map.get(ItemCameraTransforms.TransformType.GUI);
ImmutableList.Builder<BakedQuad> builder = ImmutableList.builder();
Optional<TRSRTransformation> transform = state.apply(Optional.empty());
List<ResourceLocation> textures = (List<ResourceLocation>) parent.getTextures();
ImmutableList.Builder<TextureAtlasSprite> textureAtlas = new ImmutableList.Builder<>();
TextureAtlasSprite particle = bakedTextureGetter.apply(textures.isEmpty() ? MISSINGNO : textures.get(0));
ItemOverrideList list;
try {
list = (ItemOverrideList) OVERRIDES_GET.invokeExact(parent);
} catch (Throwable t) {
throw new RuntimeException(t);
}
if (guiTransform != null && !guiTransform.isIdentity()) {
// Have only 3D model
return new Static3DItemModel(map, format, particle, list, textureAtlas.build(), transform);
} else {
if (BUILD_QUAD != null) {
// Fast route!
for (int i = 0; i < textures.size(); i++) {
TextureAtlasSprite sprite = bakedTextureGetter.apply(textures.get(i));
textureAtlas.add(sprite);
try {
builder.add((BakedQuad) BUILD_QUAD.invokeExact(format, transform, EnumFacing.SOUTH, sprite, i, 0f, 0f, 8.5f / 16f, (float) sprite.getMinU(), (float) sprite.getMaxV(), 1f, 0f, 8.5f / 16f, (float) sprite.getMaxU(), (float) sprite.getMaxV(), 1f, 1f, 8.5f / 16f, (float) sprite.getMaxU(), (float) sprite.getMinV(), 0f, 1f, 8.5f / 16f, (float) sprite.getMinU(), (float) sprite.getMinV()));
} catch (Throwable t) {
throw new RuntimeException(t);
}
}
} else {
// Slow fallback route :-(
for (int i = 0; i < textures.size(); i++) {
TextureAtlasSprite sprite = bakedTextureGetter.apply(textures.get(i));
for (BakedQuad quad : ItemLayerModel.getQuadsForSprite(i, sprite, format, transform)) {
if (quad.getFace() == EnumFacing.SOUTH)
builder.add(quad);
}
}
}
// This returns otherModel because the 3D model is default
return new DynamicItemModel(builder.build(), particle, map, list, textureAtlas.build(), format, transform).otherModel;
}
}
use of net.minecraft.client.renderer.block.model.ItemOverrideList in project Random-Things by lumien231.
the class ModelCustomWorkbench method getOverrides.
@Override
public ItemOverrideList getOverrides() {
return new ItemOverrideList(new ArrayList<ItemOverride>()) {
@Override
public IBakedModel handleItemState(IBakedModel originalModel, ItemStack stack, World world, EntityLivingBase entity) {
checkDefault();
NBTTagCompound compound;
String woodName;
int meta;
if ((compound = stack.getTagCompound()) != null) {
woodName = compound.getString("woodName");
meta = compound.getInteger("woodMeta");
} else {
woodName = "minecraft:planks";
meta = 0;
}
Block woodBlock = Block.getBlockFromName(woodName);
if (woodBlock == null) {
woodBlock = Blocks.PLANKS;
meta = 0;
}
IBlockState woodState = woodBlock.getStateFromMeta(meta);
if (woodState == null) {
return defaultModel;
}
if (modelCache.containsKey(woodState)) {
return modelCache.get(woodState);
} else {
modelCache.put(woodState, new ModelCubeOverlay(RenderUtils.getQuadFaceMapFromState(woodState), overlays, Minecraft.getMinecraft().getBlockRendererDispatcher().getModelForState(Blocks.PLANKS.getDefaultState()).getParticleTexture(), true));
return modelCache.get(woodState);
}
}
};
}
use of net.minecraft.client.renderer.block.model.ItemOverrideList 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);
}
};
}
Aggregations