mirror of
https://github.com/GTNewHorizons/Botania.git
synced 2026-11-18 03:15:07 +00:00
Split model paths for pylons
This commit is contained in:
1 parent
e2c7a8ec4b
commit
6c38e671d0
3 files changed
+108
-161
No files matched your search
@@ -1,21 +0,0 @@
|
||||
/**
|
||||
* This class was created by <Vazkii>. It's distributed as
|
||||
* part of the Botania Mod. Get the Source Code in github:
|
||||
* https://github.com/Vazkii/Botania
|
||||
*
|
||||
* Botania is Open Source and distributed under the
|
||||
* Botania License: http://botaniamod.net/license.php
|
||||
*
|
||||
* File Created @ [Apr 1, 2014, 6:23:24 PM (GMT)]
|
||||
*/
|
||||
package vazkii.botania.client.model;
|
||||
|
||||
import vazkii.botania.api.state.enums.PylonVariant;
|
||||
|
||||
public interface IPylonModel {
|
||||
|
||||
public void renderCrystal(PylonVariant variant);
|
||||
public void renderRing(PylonVariant variant);
|
||||
public void renderGems(PylonVariant variant);
|
||||
|
||||
}
|
||||
@@ -35,99 +35,54 @@ import org.lwjgl.opengl.GL11;
|
||||
import vazkii.botania.api.state.enums.PylonVariant;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
public class ModelPylon implements IPylonModel {
|
||||
public class ModelPylon {
|
||||
|
||||
private IBakedModel manaCrystal;
|
||||
private IBakedModel manaRingsAndPanes;
|
||||
private IBakedModel manaGems;
|
||||
private IBakedModel naturaCrystal;
|
||||
private IBakedModel naturaRingsAndPanes;
|
||||
private IBakedModel naturaGems;
|
||||
private IBakedModel gaiaCrystal;
|
||||
private IBakedModel gaiaRingsAndPanes;
|
||||
private IBakedModel gaiaGems;
|
||||
private IBakedModel crystal;
|
||||
private IBakedModel ringsAndPanes;
|
||||
private IBakedModel gems;
|
||||
|
||||
public ModelPylon() {
|
||||
public ModelPylon(ResourceLocation modelPath, ImmutableMap<String, String> textures) {
|
||||
try {
|
||||
// Load the OBJ
|
||||
OBJModel model = (OBJModel) OBJLoader.INSTANCE.loadModel(new ResourceLocation("botania:models/block/pylon.obj"));
|
||||
OBJModel model = (OBJModel) OBJLoader.INSTANCE.loadModel(modelPath);
|
||||
|
||||
// Apply the texture and flip the v's of the model
|
||||
IModel manaModel = ((OBJModel) model.retexture(ImmutableMap.of("#pylon", "botania:model/pylon"))).process(ImmutableMap.of("flip-v", "true"));
|
||||
IModel naturaModel = ((OBJModel) model.retexture(ImmutableMap.of("#pylon", "botania:model/pylon1"))).process(ImmutableMap.of("flip-v", "true"));
|
||||
IModel gaiaModel = ((OBJModel) model.retexture(ImmutableMap.of("#pylon", "botania:model/pylon2"))).process(ImmutableMap.of("flip-v", "true"));
|
||||
IModel processed = model.retexture(textures).process(ImmutableMap.of("flip-v", "true"));
|
||||
|
||||
// Hide necessary groups and bake
|
||||
VertexFormat format = Attributes.DEFAULT_BAKED_FORMAT;
|
||||
IModelState hideGroups = hideGroups(ImmutableList.of("Crystal_Ring", "Ring_Panel01", "Ring_Panel02", "Ring_Panel03", "Ring_Panel04",
|
||||
"Ring_Gem01", "Ring_Gem02", "Ring_Gem03", "Ring_Gem04"));
|
||||
manaCrystal = manaModel.bake(hideGroups, format, ModelLoader.defaultTextureGetter());
|
||||
naturaCrystal = naturaModel.bake(hideGroups, format, ModelLoader.defaultTextureGetter());
|
||||
gaiaCrystal = gaiaModel.bake(hideGroups, format, ModelLoader.defaultTextureGetter());
|
||||
crystal = processed.bake(hideGroups, format, ModelLoader.defaultTextureGetter());
|
||||
|
||||
hideGroups = hideGroups(ImmutableList.of("Crystal", "Ring_Gem01", "Ring_Gem02", "Ring_Gem03", "Ring_Gem04"));
|
||||
manaRingsAndPanes = manaModel.bake(hideGroups, format, ModelLoader.defaultTextureGetter());
|
||||
naturaRingsAndPanes = naturaModel.bake(hideGroups, format, ModelLoader.defaultTextureGetter());
|
||||
gaiaRingsAndPanes = gaiaModel.bake(hideGroups, format, ModelLoader.defaultTextureGetter());
|
||||
ringsAndPanes = processed.bake(hideGroups, format, ModelLoader.defaultTextureGetter());
|
||||
|
||||
hideGroups = hideGroups(ImmutableList.of("Crystal", "Crystal_Ring", "Ring_Panel01", "Ring_Panel02", "Ring_Panel03", "Ring_Panel04"));
|
||||
manaGems = manaModel.bake(hideGroups, format, ModelLoader.defaultTextureGetter());
|
||||
naturaGems = naturaModel.bake(hideGroups, format, ModelLoader.defaultTextureGetter());
|
||||
gaiaGems = gaiaModel.bake(hideGroups, format, ModelLoader.defaultTextureGetter());
|
||||
gems = processed.bake(hideGroups, format, ModelLoader.defaultTextureGetter());
|
||||
} catch(Exception e) {
|
||||
throw new ReportedException(new CrashReport("Error making pylon submodels for TESR!", e));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderCrystal(PylonVariant variant) {
|
||||
switch(variant) {
|
||||
case MANA:
|
||||
renderModel(manaCrystal);
|
||||
break;
|
||||
case NATURA:
|
||||
renderModel(naturaCrystal);
|
||||
break;
|
||||
case GAIA:
|
||||
renderModel(gaiaCrystal);
|
||||
break;
|
||||
}
|
||||
public void renderCrystal() {
|
||||
renderModel(crystal);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderRing(PylonVariant variant) {
|
||||
public void renderRing() {
|
||||
GlStateManager.disableLighting();
|
||||
switch(variant) {
|
||||
case MANA:
|
||||
renderModel(manaRingsAndPanes);
|
||||
break;
|
||||
case NATURA:
|
||||
renderModel(naturaRingsAndPanes);
|
||||
break;
|
||||
case GAIA:
|
||||
renderModel(gaiaRingsAndPanes);
|
||||
break;
|
||||
}
|
||||
renderModel(ringsAndPanes);
|
||||
GlStateManager.enableLighting();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderGems(PylonVariant variant) {
|
||||
public void renderGems() {
|
||||
GlStateManager.disableLighting();
|
||||
switch(variant) {
|
||||
case MANA:
|
||||
renderModel(manaGems);
|
||||
break;
|
||||
case NATURA:
|
||||
renderModel(naturaGems);
|
||||
break;
|
||||
case GAIA:
|
||||
renderModel(gaiaGems);
|
||||
break;
|
||||
}
|
||||
renderModel(gems);
|
||||
GlStateManager.enableLighting();
|
||||
}
|
||||
|
||||
@@ -144,10 +99,9 @@ public class ModelPylon implements IPylonModel {
|
||||
private IModelState hideGroups(List<String> groups) {
|
||||
return part -> {
|
||||
if (part.isPresent()) {
|
||||
List<String> parts = new ArrayList<>();
|
||||
Models.getParts(part.get()).forEachRemaining(parts::add);
|
||||
for (String s : parts) {
|
||||
if (groups.contains(s)) {
|
||||
Iterator<String> parts = Models.getParts(part.get());
|
||||
while (parts.hasNext()) {
|
||||
if (groups.contains(parts.next())) {
|
||||
// Hide it
|
||||
return Optional.of(TRSRTransformation.identity());
|
||||
}
|
||||
|
||||
@@ -2,14 +2,15 @@
|
||||
* This class was created by <Vazkii>. It's distributed as
|
||||
* part of the Botania Mod. Get the Source Code in github:
|
||||
* https://github.com/Vazkii/Botania
|
||||
*
|
||||
* <p>
|
||||
* Botania is Open Source and distributed under the
|
||||
* Botania License: http://botaniamod.net/license.php
|
||||
*
|
||||
* <p>
|
||||
* File Created @ [Feb 18, 2014, 10:18:36 PM (GMT)]
|
||||
*/
|
||||
package vazkii.botania.client.render.tile;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.client.renderer.OpenGlHelper;
|
||||
@@ -23,24 +24,22 @@ import vazkii.botania.client.core.handler.ClientTickHandler;
|
||||
import vazkii.botania.client.core.handler.MultiblockRenderHandler;
|
||||
import vazkii.botania.client.core.helper.ShaderHelper;
|
||||
import vazkii.botania.client.lib.LibResources;
|
||||
import vazkii.botania.client.model.IPylonModel;
|
||||
import vazkii.botania.client.model.ModelPylon;
|
||||
import vazkii.botania.common.block.ModBlocks;
|
||||
import vazkii.botania.common.block.tile.TilePylon;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.EnumMap;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
public class RenderTilePylon extends TileEntitySpecialRenderer<TilePylon> {
|
||||
|
||||
private static final ResourceLocation textureOld = new ResourceLocation(LibResources.MODEL_PYLON_OLD);
|
||||
private static final ResourceLocation textureGreenOld = new ResourceLocation(LibResources.MODEL_PYLON_GREEN_OLD);
|
||||
private static final ResourceLocation texturePinkOld = new ResourceLocation(LibResources.MODEL_PYLON_PINK_OLD);
|
||||
private static final ResourceLocation MANA_MODEL_PATH = new ResourceLocation("botania:models/block/pylon.obj");
|
||||
private static final ResourceLocation NATURA_MODEL_PATH = new ResourceLocation("botania:models/block/pylon.obj");
|
||||
private static final ResourceLocation GAIA_MODEL_PATH = new ResourceLocation("botania:models/block/pylon.obj");
|
||||
|
||||
public static boolean green = false;
|
||||
public static boolean pink = false;
|
||||
|
||||
private IPylonModel model;
|
||||
private Map<PylonVariant, ModelPylon> models = new EnumMap<>(PylonVariant.class);
|
||||
|
||||
@Override
|
||||
public void render(@Nonnull TilePylon pylon, double d0, double d1, double d2, float pticks, int digProgress, float unused) {
|
||||
@@ -48,83 +47,98 @@ public class RenderTilePylon extends TileEntitySpecialRenderer<TilePylon> {
|
||||
|| pylon.getWorld().getBlockState(pylon.getPos()).getBlock() != ModBlocks.pylon)
|
||||
return;
|
||||
|
||||
if(model == null)
|
||||
model = new ModelPylon();
|
||||
PylonVariant type = ModBlocks.pylon.getStateFromMeta(pylon.getBlockMetadata()).getValue(BotaniaStateProps.PYLON_VARIANT);
|
||||
ModelPylon model = models.computeIfAbsent(type, t -> {
|
||||
ResourceLocation modelPath;
|
||||
ImmutableMap<String, String> textures;
|
||||
|
||||
GlStateManager.pushMatrix();
|
||||
GlStateManager.enableRescaleNormal();
|
||||
GlStateManager.enableBlend();
|
||||
GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
|
||||
float a = MultiblockRenderHandler.rendering ? 0.6F : 1F;
|
||||
GlStateManager.color(1F, 1F, 1F, a);
|
||||
PylonVariant variant = null;
|
||||
if(pylon.getWorld() != null && pylon.getWorld().getBlockState(pylon.getPos()).getBlock() == ModBlocks.pylon) {
|
||||
variant = pylon.getWorld().getBlockState(pylon.getPos()).getValue(BotaniaStateProps.PYLON_VARIANT);
|
||||
green = variant == PylonVariant.NATURA;
|
||||
pink = variant == PylonVariant.GAIA;
|
||||
switch (t) {
|
||||
default:
|
||||
case MANA: {
|
||||
modelPath = MANA_MODEL_PATH;
|
||||
textures = ImmutableMap.of("#pylon", "botania:model/pylon");
|
||||
break;
|
||||
}
|
||||
case NATURA: {
|
||||
modelPath = NATURA_MODEL_PATH;
|
||||
textures = ImmutableMap.of("#pylon", "botania:model/pylon1");
|
||||
break;
|
||||
}
|
||||
case GAIA: {
|
||||
modelPath = GAIA_MODEL_PATH;
|
||||
textures = ImmutableMap.of("#pylon", "botania:model/pylon2");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Minecraft.getMinecraft().renderEngine.bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
|
||||
return new ModelPylon(modelPath, textures);
|
||||
});
|
||||
|
||||
double worldTime = pylon.getWorld() == null ? 0 : (double) (ClientTickHandler.ticksInGame + pticks);
|
||||
GlStateManager.pushMatrix();
|
||||
GlStateManager.enableRescaleNormal();
|
||||
GlStateManager.enableBlend();
|
||||
GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
|
||||
float a = MultiblockRenderHandler.rendering ? 0.6F : 1F;
|
||||
GlStateManager.color(1F, 1F, 1F, a);
|
||||
|
||||
if(pylon != null)
|
||||
worldTime += new Random(pylon.getPos().hashCode()).nextInt(360);
|
||||
Minecraft.getMinecraft().renderEngine.bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
|
||||
|
||||
GlStateManager.translate(d0 + 0.2 + (green ? -0.1 : 0), d1 + 0.05, d2 + 0.8 + (green ? 0.1 : 0));
|
||||
float scale = green ? 0.8F : 0.6F;
|
||||
GlStateManager.scale(scale, 0.6F, scale);
|
||||
double worldTime = (double) (ClientTickHandler.ticksInGame + pticks);
|
||||
|
||||
if(!green) {
|
||||
GlStateManager.pushMatrix();
|
||||
GlStateManager.translate(0.5F, 0F, -0.5F);
|
||||
GlStateManager.rotate((float) worldTime * 1.5F, 0F, 1F, 0F);
|
||||
GlStateManager.translate(-0.5F, 0F, 0.5F);
|
||||
worldTime += new Random(pylon.getPos().hashCode()).nextInt(360);
|
||||
|
||||
model.renderRing(variant);
|
||||
GlStateManager.translate(0D, Math.sin(worldTime / 20D) / 20 - 0.025, 0D);
|
||||
model.renderGems(variant);
|
||||
GlStateManager.popMatrix();
|
||||
}
|
||||
GlStateManager.translate(d0 + 0.2 + (type == PylonVariant.NATURA ? -0.1 : 0), d1 + 0.05, d2 + 0.8 + (type == PylonVariant.NATURA ? 0.1 : 0));
|
||||
float scale = type == PylonVariant.NATURA ? 0.8F : 0.6F;
|
||||
GlStateManager.scale(scale, 0.6F, scale);
|
||||
|
||||
if(type != PylonVariant.NATURA) {
|
||||
GlStateManager.pushMatrix();
|
||||
GlStateManager.translate(0D, Math.sin(worldTime / 20D) / 17.5, 0D);
|
||||
|
||||
GlStateManager.translate(0.5F, 0F, -0.5F);
|
||||
|
||||
GlStateManager.rotate((float) -worldTime, 0F, 1F, 0F);
|
||||
GlStateManager.rotate((float) worldTime * 1.5F, 0F, 1F, 0F);
|
||||
GlStateManager.translate(-0.5F, 0F, 0.5F);
|
||||
|
||||
|
||||
GlStateManager.disableCull();
|
||||
model.renderCrystal(variant);
|
||||
|
||||
GlStateManager.color(1F, 1F, 1F, a);
|
||||
if(!ShaderHelper.useShaders()) {
|
||||
int light = 15728880;
|
||||
int lightmapX = light % 65536;
|
||||
int lightmapY = light / 65536;
|
||||
OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, lightmapX, lightmapY);
|
||||
float alpha = (float) ((Math.sin(worldTime / 20D) / 2D + 0.5) / 2D);
|
||||
GlStateManager.color(1F, 1F, 1F, a * (alpha + 0.183F));
|
||||
}
|
||||
|
||||
GlStateManager.disableAlpha();
|
||||
GlStateManager.scale(1.1F, 1.1F, 1.1F);
|
||||
GlStateManager.translate(-0.05F, -0.1F, 0.05F);
|
||||
|
||||
ShaderHelper.useShader(ShaderHelper.pylonGlow);
|
||||
model.renderCrystal(variant);
|
||||
ShaderHelper.releaseShader();
|
||||
|
||||
GlStateManager.enableAlpha();
|
||||
GlStateManager.enableCull();
|
||||
model.renderRing();
|
||||
GlStateManager.translate(0D, Math.sin(worldTime / 20D) / 20 - 0.025, 0D);
|
||||
model.renderGems();
|
||||
GlStateManager.popMatrix();
|
||||
}
|
||||
|
||||
GlStateManager.disableBlend();
|
||||
GlStateManager.enableRescaleNormal();
|
||||
GlStateManager.popMatrix();
|
||||
GlStateManager.pushMatrix();
|
||||
GlStateManager.translate(0D, Math.sin(worldTime / 20D) / 17.5, 0D);
|
||||
|
||||
GlStateManager.translate(0.5F, 0F, -0.5F);
|
||||
|
||||
GlStateManager.rotate((float) -worldTime, 0F, 1F, 0F);
|
||||
GlStateManager.translate(-0.5F, 0F, 0.5F);
|
||||
|
||||
|
||||
GlStateManager.disableCull();
|
||||
model.renderCrystal();
|
||||
|
||||
GlStateManager.color(1F, 1F, 1F, a);
|
||||
if(!ShaderHelper.useShaders()) {
|
||||
int light = 15728880;
|
||||
int lightmapX = light % 65536;
|
||||
int lightmapY = light / 65536;
|
||||
OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, lightmapX, lightmapY);
|
||||
float alpha = (float) ((Math.sin(worldTime / 20D) / 2D + 0.5) / 2D);
|
||||
GlStateManager.color(1F, 1F, 1F, a * (alpha + 0.183F));
|
||||
}
|
||||
|
||||
GlStateManager.disableAlpha();
|
||||
GlStateManager.scale(1.1F, 1.1F, 1.1F);
|
||||
GlStateManager.translate(-0.05F, -0.1F, 0.05F);
|
||||
|
||||
ShaderHelper.useShader(ShaderHelper.pylonGlow);
|
||||
model.renderCrystal();
|
||||
ShaderHelper.releaseShader();
|
||||
|
||||
GlStateManager.enableAlpha();
|
||||
GlStateManager.enableCull();
|
||||
GlStateManager.popMatrix();
|
||||
|
||||
GlStateManager.disableBlend();
|
||||
GlStateManager.enableRescaleNormal();
|
||||
GlStateManager.popMatrix();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user