Search in sources :

Example 1 with IModelState

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

the class AnimationTESR method renderTileEntityFast.

public void renderTileEntityFast(@Nonnull T te, double x, double y, double z, float partialTick, int breakStage, @Nonnull VertexBuffer renderer) {
    if (!te.hasCapability(CapabilityAnimation.ANIMATION_CAPABILITY, null)) {
        return;
    }
    if (blockRenderer == null)
        blockRenderer = Minecraft.getMinecraft().getBlockRendererDispatcher();
    BlockPos pos = te.getPos();
    IBlockAccess world = MinecraftForgeClient.getRegionRenderCache(te.getWorld(), pos);
    IBlockState state = world.getBlockState(pos);
    if (state.getPropertyKeys().contains(Properties.StaticProperty)) {
        state = state.withProperty(Properties.StaticProperty, false);
    }
    if (state instanceof IExtendedBlockState) {
        IExtendedBlockState exState = (IExtendedBlockState) state;
        if (exState.getUnlistedNames().contains(Properties.AnimationProperty)) {
            float time = Animation.getWorldTime(getWorld(), partialTick);
            IAnimationStateMachine capability = te.getCapability(CapabilityAnimation.ANIMATION_CAPABILITY, null);
            if (capability != null) {
                Pair<IModelState, Iterable<Event>> pair = capability.apply(time);
                handleEvents(te, time, pair.getRight());
                // TODO: caching?
                IBakedModel model = blockRenderer.getBlockModelShapes().getModelForState(exState.getClean());
                exState = exState.withProperty(Properties.AnimationProperty, pair.getLeft());
                renderer.setTranslation(x - pos.getX(), y - pos.getY(), z - pos.getZ());
                blockRenderer.getBlockModelRenderer().renderModel(world, model, exState, pos, renderer, false);
            }
        }
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) IExtendedBlockState(net.minecraftforge.common.property.IExtendedBlockState) IBlockAccess(net.minecraft.world.IBlockAccess) IModelState(net.minecraftforge.common.model.IModelState) BlockPos(net.minecraft.util.math.BlockPos) IBakedModel(net.minecraft.client.renderer.block.model.IBakedModel) IAnimationStateMachine(net.minecraftforge.common.model.animation.IAnimationStateMachine)

Example 2 with IModelState

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

the class RendererGate method bake.

@Override
public IBakedModel bake(PartGate gate, boolean isItem, BlockRenderLayer blockRenderLayer) {
    SimpleBakedModel result = new SimpleBakedModel(this);
    ModelStateComposition transform = new ModelStateComposition(new TRSRTransformation(ROTATIONS_SIDE[gate.getSide().ordinal()]), new TRSRTransformation(ROTATIONS_TOP[gate.getTop().ordinal()]));
    if (gate.mirrored) {
        transform = new ModelStateComposition(transform, new TRSRTransformation(null, null, new Vector3f(-1.0f, 1.0f, 1.0f), null));
    }
    GateLogic logic = gate.logic;
    GateRenderDefinitions.Definition definition = GateRenderDefinitions.INSTANCE.getGateDefinition(SimpleLogicGates.getId(logic));
    if (definition == null) {
        result.addModel(ModelLoaderRegistry.getMissingModel().bake(transform, DefaultVertexFormats.BLOCK, ModelLoader.defaultTextureGetter()));
        return result;
    }
    GateRenderDefinitions.BaseDefinition base = GateRenderDefinitions.INSTANCE.base;
    IModel model = definition.getModel(gate.getModelName());
    if (model != null) {
        result.addModel(model.bake(transform, DefaultVertexFormats.BLOCK, ModelLoader.defaultTextureGetter()));
    }
    IModel layerModel = definition.getModel("layer");
    int i = 0;
    for (GateRenderDefinitions.Layer layer : definition.layers) {
        GateLogic.State state = gate.logic.getLayerState(i++);
        if (state == GateLogic.State.NO_RENDER) {
            continue;
        }
        IModelState layerTransform = transform;
        if (layer.height != 0) {
            layerTransform = new ModelStateComposition(new TRSRTransformation(new Vector3f(0, (float) layer.height / 16f, 0), null, null, null), transform);
        }
        if ("color".equals(layer.type) && layer.texture != null) {
            model = layerModels.get(layer.texture);
            if (model == null) {
                model = layerModel.retexture(ImmutableMap.of("layer", layer.texture));
                layerModels.put(layer.texture, model);
            }
            IBakedModel bakedModel = model.bake(layerTransform, DefaultVertexFormats.BLOCK, ModelLoader.defaultTextureGetter());
            int color = state == GateLogic.State.ON ? base.colorMul.get("on") : (state == GateLogic.State.OFF ? base.colorMul.get("off") : base.colorMul.get("disabled"));
            result.addModel(ModelTransformer.transform(bakedModel, SimpleLogicGates.blockGate.getDefaultState(), 0, ((quad, element, data) -> {
                if (element.getUsage() == VertexFormatElement.EnumUsage.COLOR) {
                    return new float[] { ((color) & 0xFF) / 255.0f, ((color >> 8) & 0xFF) / 255.0f, ((color >> 16) & 0xFF) / 255.0f, 1 };
                } else {
                    return data;
                }
            })));
        } else if ("map".equals(layer.type) && layer.textures != null) {
            String texture = layer.textures.get(state.name().toLowerCase(Locale.ENGLISH));
            if (texture == null) {
                texture = layer.textures.get("off");
                if (texture == null) {
                    texture = layer.textures.get("disabled");
                }
            }
            if (texture != null) {
                model = layerModels.get(texture);
                if (model == null) {
                    model = layerModel.retexture(ImmutableMap.of("layer", texture));
                    layerModels.put(texture, model);
                }
                result.addModel(model.bake(layerTransform, DefaultVertexFormats.BLOCK, ModelLoader.defaultTextureGetter()));
            }
        }
    }
    Set<EnumFacing> invertedSides = EnumSet.noneOf(EnumFacing.class);
    i = 0;
    for (GateRenderDefinitions.Torch torch : definition.torches) {
        GateLogic.State state = gate.logic.getTorchState(i++);
        if (state == GateLogic.State.NO_RENDER) {
            continue;
        }
        if (torch.inverter != null) {
            EnumFacing inverter = EnumFacing.byName(torch.inverter);
            if (gate.logic.isSideInverted(inverter)) {
                invertedSides.add(inverter);
            } else {
                continue;
            }
        }
        result.addModel(definition.getModel(state == GateLogic.State.ON ? (torch.model_on == null ? "torch_on" : torch.model_on) : (torch.model_off == null ? "torch_off" : torch.model_off)).bake(new ModelStateComposition(transform, new TRSRTransformation(new Vector3f((torch.pos[0] - 7.5f) / 16.0f, 0f, (torch.pos[1] - 7.5f) / 16.0f), null, null, null)), DefaultVertexFormats.BLOCK, ModelLoader.defaultTextureGetter()));
    }
    for (EnumFacing facing : EnumFacing.HORIZONTALS) {
        if (gate.logic.isSideInverted(facing) && !invertedSides.contains(facing)) {
            result.addModel(definition.getModel(gate.getInverterState(facing) ? "torch_on" : "torch_off").bake(new ModelStateComposition(transform, new TRSRTransformation(new Vector3f(((facing.getFrontOffsetX() * 6.9875f)) / 16.0f, 0f, ((facing.getFrontOffsetZ() * 6.9875f)) / 16.0f), null, null, null)), DefaultVertexFormats.BLOCK, ModelLoader.defaultTextureGetter()));
        }
    }
    return result;
}
Also used : TRSRTransformation(net.minecraftforge.common.model.TRSRTransformation) IModel(net.minecraftforge.client.model.IModel) EnumFacing(net.minecraft.util.EnumFacing) IModelState(net.minecraftforge.common.model.IModelState) SimpleBakedModel(pl.asie.charset.lib.render.model.SimpleBakedModel) GateLogic(pl.asie.simplelogic.gates.logic.GateLogic) ModelStateComposition(net.minecraftforge.client.model.ModelStateComposition) Vector3f(javax.vecmath.Vector3f) IBakedModel(net.minecraft.client.renderer.block.model.IBakedModel)

Example 3 with IModelState

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

the class ModelButterflyItem method bakeModel.

private IBakedModel bakeModel(IAlleleButterflySpecies species, float size) {
    ImmutableMap<String, String> textures = ImmutableMap.of("butterfly", species.getItemTexture());
    if (modelButterfly == null) {
        try {
            modelButterfly = ModelLoaderRegistry.getModel(new ResourceLocation(Constants.MOD_ID, "item/butterfly_ge"));
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
    IModel model = modelButterfly.retexture(textures);
    IBakedModel bakedModel = model.bake(ModelRotation.X0_Y0, DefaultVertexFormats.ITEM, DefaultTextureGetter.INSTANCE);
    float scale = 1F / 16F;
    IModelState state = ModelUtil.loadModelState(new ResourceLocation(Constants.MOD_ID, "models/item/butterfly_ge"));
    state = new ModelStateComposition(state, new SimpleModelState(getTransformations(size)));
    return new PerspectiveMapWrapper(new TRSRBakedModel(bakedModel, -0.03125F, 0.25F - size * 0.37F, -0.03125F + size * scale, size * 1.4F), state);
}
Also used : IModel(net.minecraftforge.client.model.IModel) SimpleModelState(net.minecraftforge.client.model.SimpleModelState) TRSRBakedModel(forestry.core.models.TRSRBakedModel) IModelState(net.minecraftforge.common.model.IModelState) PerspectiveMapWrapper(net.minecraftforge.client.model.PerspectiveMapWrapper) ModelStateComposition(net.minecraftforge.client.model.ModelStateComposition) ResourceLocation(net.minecraft.util.ResourceLocation) IBakedModel(net.minecraft.client.renderer.block.model.IBakedModel)

Example 4 with IModelState

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

the class ModelGreenhouseWindow method bakeBlock.

@Override
protected IBakedModel bakeBlock(BlockGreenhouseWindow block, Key key, boolean inventory) {
    ImmutableMap.Builder<String, String> textures = ImmutableMap.builder();
    String texture = GreenhouseManager.helper.getGlassTexture(key.glassName);
    textures.put("texture", texture);
    textures.put("particle", texture);
    IModel model = null;
    IModelState state = null;
    String stateName = "forestry:models/item/greenhouse_window";
    String modelName = "forestry:block/greenhouse_window_";
    if (block.isRoofWindow()) {
        stateName += "_up";
        modelName += "up_";
    }
    modelName += key.isOpen ? "open" : "closed";
    try {
        model = ModelLoaderRegistry.getModel(new ResourceLocation(modelName));
        state = ModelUtil.loadModelState(new ResourceLocation(stateName));
    } catch (Exception e) {
        Throwables.propagate(e);
    }
    if (model == null || state == null) {
        throw new IllegalArgumentException("Could not bake greenhouse window model");
    }
    EnumFacing facing = key.facing;
    if (facing == EnumFacing.EAST) {
        state = new ModelStateComposition(state, ModelRotation.X0_Y270);
    } else if (facing == EnumFacing.WEST) {
        state = new ModelStateComposition(state, ModelRotation.X0_Y90);
    } else if (facing == EnumFacing.NORTH) {
        state = new ModelStateComposition(state, ModelRotation.X0_Y180);
    }
    IModel retexturedModel = model.retexture(textures.build());
    return retexturedModel.bake(state, key.inventory ? DefaultVertexFormats.ITEM : DefaultVertexFormats.BLOCK, DefaultTextureGetter.INSTANCE);
}
Also used : ModelStateComposition(net.minecraftforge.client.model.ModelStateComposition) IModel(net.minecraftforge.client.model.IModel) ResourceLocation(net.minecraft.util.ResourceLocation) EnumFacing(net.minecraft.util.EnumFacing) IModelState(net.minecraftforge.common.model.IModelState) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 5 with IModelState

use of net.minecraftforge.common.model.IModelState in project Solar by ArekkuusuJerii.

the class PhenomenaRenderer method renderTileEntityFast.

@Override
public void renderTileEntityFast(@Nonnull TilePhenomena phenomena, double x, double y, double z, float partialTick, int breakStage, float partial, @Nullable BufferBuilder renderer) {
    if (blockRenderer == null)
        blockRenderer = Minecraft.getMinecraft().getBlockRendererDispatcher();
    BlockPos pos = phenomena.getPos();
    IBlockAccess world = MinecraftForgeClient.getRegionRenderCache(phenomena.getWorld(), pos);
    IBlockState state = getState(phenomena, world, pos);
    if (state instanceof IExtendedBlockState) {
        IExtendedBlockState extendedState = (IExtendedBlockState) state;
        if (extendedState.getUnlistedNames().contains(Properties.AnimationProperty)) {
            // Using tile timer instead of world time.
            float time = ((20 - phenomena.timer)) / 20F;
            IAnimationStateMachine capability = phenomena.getCapability(CapabilityAnimation.ANIMATION_CAPABILITY, null);
            if (capability != null) {
                Pair<IModelState, Iterable<Event>> pair = capability.apply(time);
                extendedState = extendedState.withProperty(Properties.AnimationProperty, pair.getLeft());
                IBakedModel model = getModel(state);
                assert renderer != null;
                renderer.setTranslation(x - pos.getX(), y - pos.getY(), z - pos.getZ());
                blockRenderer.getBlockModelRenderer().renderModel(world, model, extendedState, pos, renderer, false);
            }
        }
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) IExtendedBlockState(net.minecraftforge.common.property.IExtendedBlockState) IBlockAccess(net.minecraft.world.IBlockAccess) IModelState(net.minecraftforge.common.model.IModelState) BlockPos(net.minecraft.util.math.BlockPos) IBakedModel(net.minecraft.client.renderer.block.model.IBakedModel) IAnimationStateMachine(net.minecraftforge.common.model.animation.IAnimationStateMachine)

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