Search in sources :

Example 1 with StructureRenderer

use of mchorse.blockbuster_pack.morphs.structure.StructureRenderer in project blockbuster by mchorse.

the class ClientProxy method preLoad.

/**
 * Register mod items, blocks, tile entites and entities, load item,
 * block models and register entity renderer.
 */
@Override
public void preLoad(FMLPreInitializationEvent event) {
    super.preLoad(event);
    /* Items */
    this.registerItemModel(Blockbuster.playbackItem, Blockbuster.path("playback"));
    this.registerItemModel(Blockbuster.registerItem, Blockbuster.path("register"));
    this.registerItemModel(Blockbuster.actorConfigItem, Blockbuster.path("actor_config"));
    this.registerItemModel(Blockbuster.gunItem, Blockbuster.path("gun"));
    /* Blocks */
    this.registerItemModel(Blockbuster.directorBlock, Blockbuster.path("director"));
    final ModelResourceLocation modelStatic = new ModelResourceLocation(Blockbuster.path("model_static"), "inventory");
    final ModelResourceLocation model = new ModelResourceLocation(Blockbuster.path("model"), "inventory");
    /* Register model block's configurable render disable */
    Item item = Item.getItemFromBlock(Blockbuster.modelBlock);
    ModelBakery.registerItemVariants(item, model, modelStatic);
    ModelLoader.setCustomMeshDefinition(item, (stack) -> Blockbuster.modelBlockDisableItemRendering.get() ? modelStatic : model);
    Blockbuster.modelBlockItem.setTileEntityItemStackRenderer(new TileEntityModelItemStackRenderer());
    Blockbuster.gunItem.setTileEntityItemStackRenderer(new TileEntityGunItemStackRenderer());
    /* Entities */
    this.registerEntityRender(EntityActor.class, new RenderActor.FactoryActor());
    this.registerEntityRender(EntityGunProjectile.class, new RenderGunProjectile.FactoryGunProjectile());
    /* Tile entity */
    ClientRegistry.bindTileEntitySpecialRenderer(TileEntityModel.class, modelRenderer = new TileEntityModelRenderer());
    ClientRegistry.bindTileEntitySpecialRenderer(TileEntityDirector.class, new TileEntityDirectorRenderer());
    this.injectResourcePack(CommonProxy.configFile.getAbsolutePath());
    /* Structure morph */
    StructureMorph.STRUCTURES = new HashMap<String, StructureRenderer>();
    audio = new AudioLibrary(new File(CommonProxy.configFile, "audio"));
    skinsFolder = new File(configFile, "skins");
    skinsFolder.mkdirs();
}
Also used : AudioLibrary(mchorse.blockbuster.audio.AudioLibrary) RenderActor(mchorse.blockbuster.client.render.RenderActor) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) StructureRenderer(mchorse.blockbuster_pack.morphs.structure.StructureRenderer) TileEntityDirectorRenderer(mchorse.blockbuster.client.render.tileentity.TileEntityDirectorRenderer) Item(net.minecraft.item.Item) RenderGunProjectile(mchorse.blockbuster.client.render.RenderGunProjectile) TileEntityModelItemStackRenderer(mchorse.blockbuster.client.render.tileentity.TileEntityModelItemStackRenderer) TileEntityModelRenderer(mchorse.blockbuster.client.render.tileentity.TileEntityModelRenderer) TileEntityGunItemStackRenderer(mchorse.blockbuster.client.render.tileentity.TileEntityGunItemStackRenderer) File(java.io.File)

Example 2 with StructureRenderer

use of mchorse.blockbuster_pack.morphs.structure.StructureRenderer in project blockbuster by mchorse.

the class StructureMorph method render.

@Override
@SideOnly(Side.CLIENT)
public void render(EntityLivingBase entity, double x, double y, double z, float entityYaw, float partialTicks) {
    StructureRenderer renderer = STRUCTURES.get(this.structure);
    if (renderer != null) {
        if (renderer.status != StructureStatus.LOADED) {
            if (renderer.status == StructureStatus.UNLOADED) {
                renderer.status = StructureStatus.LOADING;
                Dispatcher.sendToServer(new PacketStructureRequest(this.structure));
            }
            return;
        }
        float lastX = OpenGlHelper.lastBrightnessX;
        float lastY = OpenGlHelper.lastBrightnessY;
        if (GuiModelRenderer.isRendering() && !this.lighting) {
            Minecraft.getMinecraft().entityRenderer.enableLightmap();
        }
        Minecraft.getMinecraft().renderEngine.bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
        /* These states are important to enable */
        GlStateManager.pushMatrix();
        GlStateManager.enableRescaleNormal();
        GlStateManager.translate(x, y, z);
        ModelTransform transform = this.pose;
        float anchorX = this.anchorX;
        float anchorY = this.anchorY;
        float anchorZ = this.anchorZ;
        if (this.animation.isInProgress()) {
            transform = new ModelTransform();
            transform.copy(this.pose);
            this.animation.apply(transform, partialTicks);
            if (this.animation.lastAnchorX != null) {
                float factor = this.animation.getFactor(partialTicks);
                anchorX = this.animation.interp.interpolate(this.animation.lastAnchorX, anchorX, factor);
                anchorY = this.animation.interp.interpolate(this.animation.lastAnchorY, anchorY, factor);
                anchorZ = this.animation.interp.interpolate(this.animation.lastAnchorZ, anchorZ, factor);
            }
        }
        transform.transform();
        GlStateManager.translate(anchorX, anchorY, anchorZ);
        RenderHelper.disableStandardItemLighting();
        GlStateManager.shadeModel(GL11.GL_SMOOTH);
        GlStateManager.enableAlpha();
        GlStateManager.enableBlend();
        GlStateManager.blendFunc(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA);
        renderer.render(this);
        GlStateManager.disableBlend();
        GlStateManager.disableAlpha();
        GlStateManager.shadeModel(GL11.GL_FLAT);
        GlStateManager.enableLighting();
        GlStateManager.enableLight(0);
        GlStateManager.enableLight(1);
        GlStateManager.enableColorMaterial();
        GL11.glColor4f(1, 1, 1, 1);
        renderer.renderTEs(this);
        GlStateManager.popMatrix();
        OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, lastX, lastY);
        if (GuiModelRenderer.isRendering() && !this.lighting) {
            Minecraft.getMinecraft().entityRenderer.disableLightmap();
        }
    }
}
Also used : ModelTransform(mchorse.blockbuster.api.ModelTransform) PacketStructureRequest(mchorse.blockbuster.network.common.structure.PacketStructureRequest) StructureRenderer(mchorse.blockbuster_pack.morphs.structure.StructureRenderer) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 3 with StructureRenderer

use of mchorse.blockbuster_pack.morphs.structure.StructureRenderer in project blockbuster by mchorse.

the class ClientHandlerStructure method run.

@Override
@SideOnly(Side.CLIENT)
public void run(EntityPlayerSP player, PacketStructure message) {
    Minecraft.getMinecraft().addScheduledTask(() -> {
        try {
            /* Remove the structure if null was sent */
            if (message.tag == null) {
                StructureRenderer renderer = StructureMorph.STRUCTURES.get(message.name);
                if (renderer != null) {
                    renderer.delete();
                }
                return;
            }
            /* Finally clean the old one, if there was, and fill the structure */
            StructureRenderer renderer = createListFromTemplate(message);
            StructureRenderer old = StructureMorph.STRUCTURES.remove(message.name);
            if (old != null) {
                old.delete();
            }
            StructureMorph.STRUCTURES.put(message.name, renderer);
        } catch (Exception e) {
            e.printStackTrace();
        }
    });
}
Also used : StructureRenderer(mchorse.blockbuster_pack.morphs.structure.StructureRenderer) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 4 with StructureRenderer

use of mchorse.blockbuster_pack.morphs.structure.StructureRenderer in project blockbuster by mchorse.

the class ClientHandlerStructure method createListFromTemplate.

/**
 * This method creates a renderable display list which allows
 * rendering fully baked into a display list.
 *
 * This was harder than I thought...
 */
@SideOnly(Side.CLIENT)
private StructureRenderer createListFromTemplate(PacketStructure message) {
    Profiler profiler = new Profiler();
    Template template = new Template();
    PlacementSettings placement = new PlacementSettings();
    WorldSettings settings = new WorldSettings(0, GameType.CREATIVE, true, false, WorldType.DEFAULT);
    WorldInfo info = new WorldInfo(settings, message.name);
    WorldProvider provider = new WorldProviderSurface();
    FakeWorld world = new FakeWorld(null, info, provider, profiler, true);
    provider.setWorld(world);
    template.read(message.tag);
    BlockPos origin = new BlockPos(1, 1, 1);
    int w = template.getSize().getX();
    int d = template.getSize().getZ();
    for (int x = 0, cx = (w + 2) / 16 + 1; x < cx; x++) {
        for (int z = 0, cz = (d + 2) / 16 + 1; z < cz; z++) {
            ((ChunkProviderClient) world.getChunkProvider()).loadChunk(x, z);
        }
    }
    template.addBlocksToWorld(world, origin, placement);
    return new StructureRenderer(template.getSize(), world);
}
Also used : ChunkProviderClient(net.minecraft.client.multiplayer.ChunkProviderClient) WorldProviderSurface(net.minecraft.world.WorldProviderSurface) Profiler(net.minecraft.profiler.Profiler) WorldProvider(net.minecraft.world.WorldProvider) WorldInfo(net.minecraft.world.storage.WorldInfo) BlockPos(net.minecraft.util.math.BlockPos) StructureRenderer(mchorse.blockbuster_pack.morphs.structure.StructureRenderer) PlacementSettings(net.minecraft.world.gen.structure.template.PlacementSettings) WorldSettings(net.minecraft.world.WorldSettings) Template(net.minecraft.world.gen.structure.template.Template) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 5 with StructureRenderer

use of mchorse.blockbuster_pack.morphs.structure.StructureRenderer in project blockbuster by mchorse.

the class ClientHandlerStructureList method run.

@Override
@SideOnly(Side.CLIENT)
public void run(EntityPlayerSP player, PacketStructureList message) {
    for (String str : message.structures) {
        StructureRenderer renderer = StructureMorph.STRUCTURES.get(str);
        if (renderer == null) {
            renderer = new StructureRenderer();
            StructureMorph.STRUCTURES.put(str, renderer);
        }
    }
    Blockbuster.proxy.factory.section.addStructures(message.structures);
}
Also used : StructureRenderer(mchorse.blockbuster_pack.morphs.structure.StructureRenderer) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Aggregations

StructureRenderer (mchorse.blockbuster_pack.morphs.structure.StructureRenderer)6 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)5 PacketStructureRequest (mchorse.blockbuster.network.common.structure.PacketStructureRequest)2 File (java.io.File)1 ModelTransform (mchorse.blockbuster.api.ModelTransform)1 AudioLibrary (mchorse.blockbuster.audio.AudioLibrary)1 RenderActor (mchorse.blockbuster.client.render.RenderActor)1 RenderGunProjectile (mchorse.blockbuster.client.render.RenderGunProjectile)1 TileEntityDirectorRenderer (mchorse.blockbuster.client.render.tileentity.TileEntityDirectorRenderer)1 TileEntityGunItemStackRenderer (mchorse.blockbuster.client.render.tileentity.TileEntityGunItemStackRenderer)1 TileEntityModelItemStackRenderer (mchorse.blockbuster.client.render.tileentity.TileEntityModelItemStackRenderer)1 TileEntityModelRenderer (mchorse.blockbuster.client.render.tileentity.TileEntityModelRenderer)1 ChunkProviderClient (net.minecraft.client.multiplayer.ChunkProviderClient)1 ModelResourceLocation (net.minecraft.client.renderer.block.model.ModelResourceLocation)1 Item (net.minecraft.item.Item)1 Profiler (net.minecraft.profiler.Profiler)1 BlockPos (net.minecraft.util.math.BlockPos)1 WorldProvider (net.minecraft.world.WorldProvider)1 WorldProviderSurface (net.minecraft.world.WorldProviderSurface)1 WorldSettings (net.minecraft.world.WorldSettings)1