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();
}
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();
}
}
}
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();
}
});
}
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);
}
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);
}
Aggregations