Search in sources :

Example 11 with IModelState

use of net.minecraftforge.common.model.IModelState in project MinecraftForge by MinecraftForge.

the class FancyMissingModel method bake.

@Override
public IBakedModel bake(IModelState state, VertexFormat format, Function<ResourceLocation, TextureAtlasSprite> bakedTextureGetter) {
    IBakedModel bigMissing = missingModel.bake(state, format, bakedTextureGetter);
    IModelState smallState = new ModelStateComposition(state, smallTransformation);
    IBakedModel smallMissing = missingModel.bake(smallState, format, bakedTextureGetter);
    return new BakedModel(bigMissing, smallMissing, fontCache.getUnchecked(format), message, bakedTextureGetter.apply(font2));
}
Also used : IBakedModel(net.minecraft.client.renderer.block.model.IBakedModel) IModelState(net.minecraftforge.common.model.IModelState) IBakedModel(net.minecraft.client.renderer.block.model.IBakedModel)

Example 12 with IModelState

use of net.minecraftforge.common.model.IModelState in project MinecraftForge by MinecraftForge.

the class AnimationStateMachine method apply.

public Pair<IModelState, Iterable<Event>> apply(float time) {
    if (lastPollTime == Float.NEGATIVE_INFINITY) {
        lastPollTime = time;
    }
    Pair<IModelState, Iterable<Event>> pair = clipCache.getUnchecked(Triple.of(currentState, lastPollTime, time));
    lastPollTime = time;
    boolean shouldFilter = false;
    if (shouldHandleSpecialEvents) {
        for (Event event : ImmutableList.copyOf(pair.getRight()).reverse()) {
            if (event.event().startsWith("!")) {
                shouldFilter = true;
                if (event.event().startsWith("!transition:")) {
                    String newState = event.event().substring("!transition:".length());
                    transition(newState);
                } else {
                    System.out.println("Unknown special event \"" + event.event() + "\", ignoring");
                }
            }
        }
    }
    if (!shouldFilter) {
        return pair;
    }
    return Pair.of(pair.getLeft(), Iterables.filter(pair.getRight(), new Predicate<Event>() {

        public boolean apply(Event event) {
            return !event.event().startsWith("!");
        }
    }));
}
Also used : IModelState(net.minecraftforge.common.model.IModelState) Event(net.minecraftforge.common.animation.Event) Predicate(com.google.common.base.Predicate)

Example 13 with IModelState

use of net.minecraftforge.common.model.IModelState in project Charset by CharsetMC.

the class ProxyClient method onModelBake.

@SubscribeEvent
public void onModelBake(ModelBakeEvent event) {
    IBakedModel origModel = event.getModelRegistry().getObject(bmLoc);
    ModelCompressionCrafter result = new ModelCompressionCrafter(origModel);
    event.getModelRegistry().putObject(bmLoc, result);
    ProgressManager.ProgressBar bar = ProgressManager.push("Compression Crafter", 6 + (4 * 12));
    IModel modelRod = RenderUtils.getModel(new ResourceLocation("charset:block/compression_crafter_rod"));
    for (EnumFacing side : EnumFacing.VALUES) {
        bar.step("rod " + side.name());
        rodModels[side.ordinal()] = modelRod.bake(ROTATIONS[side.ordinal()], DefaultVertexFormats.ITEM, ModelLoader.defaultTextureGetter());
    }
    IModel model = RenderUtils.getModel(new ResourceLocation("charset:block/compression_crafter_block"));
    IBlockState defState = CharsetCraftingCompression.blockCompressionCrafter.getDefaultState();
    for (int i = 0; i < 4; i++) {
        IModel retexModel = model.retexture(ImmutableMap.of("top", "charset:blocks/compact/compact_inner#" + i, "bottom", "charset:blocks/compact/compact_bottom#" + i, "side_x", "charset:blocks/compact/compact_side#" + i, "side_z", "charset:blocks/compact/compact_side#" + i));
        for (int k = 0; k < 12; k++) {
            bar.step("crafter " + (i * 4 + k + 1) + "/48");
            if (i == 0 && k >= 6) {
                for (EnumFacing side : EnumFacing.VALUES) {
                    result.quads[k][side.ordinal()][i] = result.quads[k - 6][side.ordinal()][i];
                }
                continue;
            }
            EnumFacing facing = EnumFacing.getFront(k % 6);
            IModelState modelState = ROTATIONS[k % 6];
            if (k >= 6) {
                modelState = new ModelStateComposition(modelState, ModelRotation.X0_Y90);
            }
            IBakedModel bakedModel = retexModel.bake(modelState, DefaultVertexFormats.ITEM, ModelLoader.defaultTextureGetter());
            for (EnumFacing side : EnumFacing.VALUES) {
                List<BakedQuad> list = bakedModel.getQuads(defState, side, 0);
                int j = i;
                if ((facing == EnumFacing.DOWN && (side == EnumFacing.SOUTH || side == EnumFacing.WEST)) || (facing == EnumFacing.UP && (side == EnumFacing.NORTH || side == EnumFacing.EAST)) || ((facing == EnumFacing.SOUTH || facing == EnumFacing.WEST) && (side.getAxis() == EnumFacing.Axis.Y || (side.getAxis() == facing.getAxis() && k < 8))) || (facing == EnumFacing.DOWN && side == EnumFacing.UP && k >= 6) || (facing.getAxis() != EnumFacing.Axis.Y && k >= 8 && side == facing.rotateY())) {
                    if (j == 1)
                        j = 2;
                    else if (j == 2)
                        j = 1;
                }
                result.quads[k][side.ordinal()][j] = list.get(0);
            }
        }
    }
    ProgressManager.pop(bar);
}
Also used : BakedQuad(net.minecraft.client.renderer.block.model.BakedQuad) IModel(net.minecraftforge.client.model.IModel) IBlockState(net.minecraft.block.state.IBlockState) EnumFacing(net.minecraft.util.EnumFacing) IModelState(net.minecraftforge.common.model.IModelState) ModelStateComposition(net.minecraftforge.client.model.ModelStateComposition) ProgressManager(net.minecraftforge.fml.common.ProgressManager) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) ResourceLocation(net.minecraft.util.ResourceLocation) IBakedModel(net.minecraft.client.renderer.block.model.IBakedModel) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 14 with IModelState

use of net.minecraftforge.common.model.IModelState in project Charset by CharsetMC.

the class ModelShelf method bake.

@Override
public IBakedModel bake(ShelfCacheInfo info, boolean isItem, BlockRenderLayer layer) {
    IModel retexturedModel = (shelfModel.retexture(ImmutableMap.of("plank", info.plank.getIconName()))).uvlock(false);
    IModelState state = ModelRotation.getModelRotation(0, (int) info.facing.getHorizontalAngle());
    if (info.back) {
        state = new ModelStateComposition(state, STATE_BACK);
    }
    return new WrappedBakedModel(retexturedModel.bake(state, DefaultVertexFormats.BLOCK, ModelLoader.defaultTextureGetter()), info.plank).addDefaultBlockTransforms();
}
Also used : ModelStateComposition(net.minecraftforge.client.model.ModelStateComposition) IModel(net.minecraftforge.client.model.IModel) IModelState(net.minecraftforge.common.model.IModelState) WrappedBakedModel(pl.asie.charset.lib.render.model.WrappedBakedModel)

Example 15 with IModelState

use of net.minecraftforge.common.model.IModelState in project Charset by CharsetMC.

the class BarrelModel method bake.

@Override
public IBakedModel bake(BarrelCacheInfo info, boolean isItem, BlockRenderLayer layer) {
    TextureAtlasSprite log = info.log;
    TextureAtlasSprite plank = info.plank;
    TextureAtlasSprite top = info.isMetal ? this.top_metal : this.top;
    TextureAtlasSprite front = this.front;
    TextureAtlasSprite side = this.side;
    if (info.upgrades.contains(BarrelUpgrade.STICKY)) {
        side = this.side_sticky;
        front = info.upgrades.contains(BarrelUpgrade.SILKY) ? this.front_silky_sticky : this.front_sticky;
    } else if (info.upgrades.contains(BarrelUpgrade.SILKY)) {
        front = this.front_silky;
    }
    ImmutableMap.Builder<String, String> textures = new ImmutableMap.Builder<>();
    if (isItem || layer == BlockRenderLayer.SOLID) {
        textures.put("log", log.getIconName());
        textures.put("plank", plank.getIconName());
    } else {
        textures.put("#log", "");
        textures.put("log", "");
        textures.put("#plank", "");
        textures.put("plank", "");
    }
    if (isItem || layer == BlockRenderLayer.TRANSLUCENT) {
        if (info.upgrades.contains(BarrelUpgrade.HOPPING)) {
            top = this.top_hopping;
            textures.put("hopping", side_hopping.getIconName());
        } else {
            textures.put("#hopping", "");
            textures.put("hopping", "");
        }
        textures.put("top", top.getIconName());
        textures.put("front", front.getIconName());
        textures.put("side", side.getIconName());
    } else {
        textures.put("#top", "");
        textures.put("top", "");
        textures.put("#front", "");
        textures.put("front", "");
        textures.put("#side", "");
        textures.put("side", "");
        textures.put("#hopping", "");
        textures.put("hopping", "");
    }
    IModelState state = info.orientation.toTransformation();
    IModel retexture = template.retexture(textures.build());
    return new WrappedBakedModel(retexture.bake(state, DefaultVertexFormats.BLOCK, ModelLoader.defaultTextureGetter()), log).addDefaultBlockTransforms();
}
Also used : IModel(net.minecraftforge.client.model.IModel) TextureAtlasSprite(net.minecraft.client.renderer.texture.TextureAtlasSprite) IModelState(net.minecraftforge.common.model.IModelState) WrappedBakedModel(pl.asie.charset.lib.render.model.WrappedBakedModel) ImmutableMap(com.google.common.collect.ImmutableMap)

Aggregations

IModelState (net.minecraftforge.common.model.IModelState)18 IBakedModel (net.minecraft.client.renderer.block.model.IBakedModel)11 IModel (net.minecraftforge.client.model.IModel)10 ResourceLocation (net.minecraft.util.ResourceLocation)6 EnumFacing (net.minecraft.util.EnumFacing)5 ModelStateComposition (net.minecraftforge.client.model.ModelStateComposition)5 ImmutableMap (com.google.common.collect.ImmutableMap)4 IBlockState (net.minecraft.block.state.IBlockState)4 BlockPos (net.minecraft.util.math.BlockPos)4 BakedQuad (net.minecraft.client.renderer.block.model.BakedQuad)3 TextureAtlasSprite (net.minecraft.client.renderer.texture.TextureAtlasSprite)3 IExtendedBlockState (net.minecraftforge.common.property.IExtendedBlockState)3 IBlockAccess (net.minecraft.world.IBlockAccess)2 TRSRTransformation (net.minecraftforge.common.model.TRSRTransformation)2 IAnimationStateMachine (net.minecraftforge.common.model.animation.IAnimationStateMachine)2 WrappedBakedModel (pl.asie.charset.lib.render.model.WrappedBakedModel)2 Function (com.google.common.base.Function)1 Predicate (com.google.common.base.Predicate)1 CacheBuilder (com.google.common.cache.CacheBuilder)1 Lists (com.google.common.collect.Lists)1