mirror of
https://github.com/GTNewHorizons/Botania.git
synced 2026-11-22 21:19:46 +00:00
Pylon obj model possibly. item working, tile not so
This commit is contained in:
1 parent
33b423aaa1
commit
57e5a3d0ac
9 files changed
+187
-41
No files matched your search
@@ -13,18 +13,22 @@ import net.minecraft.item.Item;
|
||||
import net.minecraft.util.IStringSerializable;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.client.model.ModelLoader;
|
||||
import net.minecraftforge.client.model.obj.OBJLoader;
|
||||
import net.minecraftforge.fml.common.registry.GameData;
|
||||
import vazkii.botania.api.state.enums.AltGrassVariant;
|
||||
import vazkii.botania.api.state.enums.LivingRockVariant;
|
||||
import vazkii.botania.api.state.enums.LivingWoodVariant;
|
||||
import vazkii.botania.api.state.enums.PylonVariant;
|
||||
import vazkii.botania.api.state.enums.StorageVariant;
|
||||
import vazkii.botania.common.block.ModBlocks;
|
||||
import vazkii.botania.common.block.ModFluffBlocks;
|
||||
import vazkii.botania.common.block.decor.slabs.BlockModSlab;
|
||||
import vazkii.botania.common.item.ItemGaiaHead;
|
||||
import vazkii.botania.common.item.ModItems;
|
||||
import vazkii.botania.common.lib.LibMisc;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
public final class ModelHandler {
|
||||
|
||||
@@ -32,6 +36,8 @@ public final class ModelHandler {
|
||||
// In addition, many of the jsons currently use the vanilla format (simple and verified bug-free).
|
||||
// Once things settle down, we'll move to forge jsons, which will drastically cut down on the number of json files
|
||||
public static void registerModels() {
|
||||
OBJLoader.instance.addDomain(LibMisc.MOD_ID.toLowerCase(Locale.ROOT));
|
||||
|
||||
/** Custom statemappers **/
|
||||
registerStateMappers();
|
||||
|
||||
@@ -47,6 +53,7 @@ public final class ModelHandler {
|
||||
registerPanes();
|
||||
registerItemModel(ModBlocks.manaGlass);
|
||||
registerItemModel(ModBlocks.elfGlass);
|
||||
registerPylons();
|
||||
|
||||
/** Normal Items **/
|
||||
registerItemModel(ModItems.lexicon);
|
||||
@@ -200,6 +207,13 @@ public final class ModelHandler {
|
||||
|
||||
}
|
||||
|
||||
private static void registerPylons() {
|
||||
Item item = Item.getItemFromBlock(ModBlocks.pylon);
|
||||
ModelLoader.setCustomModelResourceLocation(item, 0, new ModelResourceLocation("botania:pylon", "variant=mana"));
|
||||
ModelLoader.setCustomModelResourceLocation(item, 1, new ModelResourceLocation("botania:pylon", "variant=natura"));
|
||||
ModelLoader.setCustomModelResourceLocation(item, 2, new ModelResourceLocation("botania:pylon", "variant=gaia"));
|
||||
}
|
||||
|
||||
private static void registerItemModel(Block b) {
|
||||
registerItemModel(Item.getItemFromBlock(b));
|
||||
}
|
||||
|
||||
@@ -10,10 +10,12 @@
|
||||
*/
|
||||
package vazkii.botania.client.model;
|
||||
|
||||
import vazkii.botania.api.state.enums.PylonVariant;
|
||||
|
||||
public interface IPylonModel {
|
||||
|
||||
public void renderCrystal();
|
||||
public void renderRing();
|
||||
public void renderGems();
|
||||
public void renderCrystal(PylonVariant variant);
|
||||
public void renderRing(PylonVariant variant);
|
||||
public void renderGems(PylonVariant variant);
|
||||
|
||||
}
|
||||
@@ -10,30 +10,133 @@
|
||||
*/
|
||||
package vazkii.botania.client.model;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Sets;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.client.renderer.WorldRenderer;
|
||||
import net.minecraft.client.renderer.block.model.BakedQuad;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.crash.CrashReport;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.ReportedException;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import vazkii.botania.client.lib.LibResources;
|
||||
import net.minecraftforge.client.model.Attributes;
|
||||
import net.minecraftforge.client.model.IFlexibleBakedModel;
|
||||
import net.minecraftforge.client.model.obj.OBJLoader;
|
||||
import net.minecraftforge.client.model.obj.OBJModel;
|
||||
import net.minecraftforge.client.model.pipeline.LightUtil;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import vazkii.botania.api.state.enums.PylonVariant;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class ModelPylon implements IPylonModel {
|
||||
|
||||
//private IModelCustom model;
|
||||
// todo 1.8 restore
|
||||
private IFlexibleBakedModel manaCrystal;
|
||||
private IFlexibleBakedModel manaRingsAndPanes;
|
||||
private IFlexibleBakedModel manaGems;
|
||||
|
||||
private IFlexibleBakedModel naturaCrystal;
|
||||
private IFlexibleBakedModel naturaRingsAndPanes;
|
||||
private IFlexibleBakedModel naturaGems;
|
||||
|
||||
private IFlexibleBakedModel gaiaCrystal;
|
||||
private IFlexibleBakedModel gaiaRingsAndPanes;
|
||||
private IFlexibleBakedModel gaiaGems;
|
||||
|
||||
private static final Function<ResourceLocation, TextureAtlasSprite> TEXTUREGETTER = new Function<ResourceLocation, TextureAtlasSprite>() {
|
||||
@Override
|
||||
public TextureAtlasSprite apply(ResourceLocation input) {
|
||||
return Minecraft.getMinecraft().getTextureMapBlocks().getAtlasSprite(input.toString());
|
||||
}
|
||||
};
|
||||
|
||||
private static final Set<String> GROUP_NAMES = ImmutableSet.of("Crystal", "CrystalRing", "Ring_Panel01", "Ring_Panel02",
|
||||
"Ring_Panel03", "Ring_Panel04", "Ring_Gem01", "Ring_Gem02", "Ring_Gem03", "Ring_Gem04");
|
||||
|
||||
public ModelPylon() {
|
||||
//model = AdvancedModelLoader.loadModel(new ResourceLocation(LibResources.OBJ_MODEL_PYLON));
|
||||
try {
|
||||
OBJModel model = ((OBJModel) OBJLoader.instance.loadModel(new ResourceLocation("botania:model/block/pylon.obj")));
|
||||
|
||||
OBJModel manaModel = ((OBJModel) model.retexture(ImmutableMap.of("#pylon", "botania:models/pylon")));
|
||||
OBJModel naturaModel = ((OBJModel) model.retexture(ImmutableMap.of("#pylon", "botania:models/pylon1")));
|
||||
OBJModel gaiaModel = ((OBJModel) model.retexture(ImmutableMap.of("#pylon", "botania:models/pylon2")));
|
||||
|
||||
// Turn off all except "Crystal"
|
||||
manaCrystal = manaModel.bake(new OBJModel.OBJState(ImmutableList.copyOf(Sets.difference(GROUP_NAMES, ImmutableSet.of("Crystal"))), false), Attributes.DEFAULT_BAKED_FORMAT, TEXTUREGETTER);
|
||||
naturaCrystal = naturaModel.bake(new OBJModel.OBJState(ImmutableList.copyOf(Sets.difference(GROUP_NAMES, ImmutableSet.of("Crystal"))), false), Attributes.DEFAULT_BAKED_FORMAT, TEXTUREGETTER);
|
||||
gaiaCrystal = gaiaModel.bake(new OBJModel.OBJState(ImmutableList.copyOf(Sets.difference(GROUP_NAMES, ImmutableSet.of("Crystal"))), false), Attributes.DEFAULT_BAKED_FORMAT, TEXTUREGETTER);
|
||||
|
||||
// Turn off all except "CrystalRing", and "Ring_Panel0x"
|
||||
manaRingsAndPanes = manaModel.bake(new OBJModel.OBJState(ImmutableList.copyOf(Sets.difference(GROUP_NAMES, ImmutableSet.of("CrystalRing", "Ring_Panel01", "Ring_Panel02", "Ring_Panel03", "Ring_Panel04"))), false), Attributes.DEFAULT_BAKED_FORMAT, TEXTUREGETTER);
|
||||
naturaRingsAndPanes = naturaModel.bake(new OBJModel.OBJState(ImmutableList.copyOf(Sets.difference(GROUP_NAMES, ImmutableSet.of("CrystalRing", "Ring_Panel01", "Ring_Panel02", "Ring_Panel03", "Ring_Panel04"))), false), Attributes.DEFAULT_BAKED_FORMAT, TEXTUREGETTER);
|
||||
gaiaRingsAndPanes = gaiaModel.bake(new OBJModel.OBJState(ImmutableList.copyOf(Sets.difference(GROUP_NAMES, ImmutableSet.of("CrystalRing", "Ring_Panel01", "Ring_Panel02", "Ring_Panel03", "Ring_Panel04"))), false), Attributes.DEFAULT_BAKED_FORMAT, TEXTUREGETTER);
|
||||
|
||||
// Turn off all except "Ring_Gem0x"
|
||||
manaGems = manaModel.bake(new OBJModel.OBJState(ImmutableList.copyOf(Sets.difference(GROUP_NAMES, ImmutableSet.of("Ring_Gem01", "Ring_Gem02", "Ring_Gem03", "Ring_Gem04"))), false), Attributes.DEFAULT_BAKED_FORMAT, TEXTUREGETTER);
|
||||
naturaGems = naturaModel.bake(new OBJModel.OBJState(ImmutableList.copyOf(Sets.difference(GROUP_NAMES, ImmutableSet.of("Ring_Gem01", "Ring_Gem02", "Ring_Gem03", "Ring_Gem04"))), false), Attributes.DEFAULT_BAKED_FORMAT, TEXTUREGETTER);
|
||||
gaiaGems = gaiaModel.bake(new OBJModel.OBJState(ImmutableList.copyOf(Sets.difference(GROUP_NAMES, ImmutableSet.of("Ring_Gem01", "Ring_Gem02", "Ring_Gem03", "Ring_Gem04"))), false), Attributes.DEFAULT_BAKED_FORMAT, TEXTUREGETTER);
|
||||
} catch (IOException e) {
|
||||
throw new ReportedException(new CrashReport("Error making pylon submodels for TESR!", e));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderCrystal() {
|
||||
//model.renderPart("Crystal");
|
||||
public void renderCrystal(PylonVariant variant) {
|
||||
switch (variant) {
|
||||
case MANA: renderModel(manaCrystal); break;
|
||||
case NATURA: renderModel(naturaCrystal); break;
|
||||
case GAIA: renderModel(gaiaCrystal); break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderRing() {
|
||||
//model.renderAllExcept("Crystal", "Ring_Gem01", "Ring_Gem02", "Ring_Gem03", "Ring_Gem04");
|
||||
public void renderRing(PylonVariant variant) {
|
||||
switch (variant) {
|
||||
case MANA: renderModel(manaRingsAndPanes); break;
|
||||
case NATURA: renderModel(naturaRingsAndPanes); break;
|
||||
case GAIA: renderModel(gaiaRingsAndPanes); break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderGems() {
|
||||
//for(int i = 1; i < 5; i++)
|
||||
//model.renderPart("Ring_Gem0" + i);
|
||||
public void renderGems(PylonVariant variant) {
|
||||
switch (variant) {
|
||||
case MANA: renderModel(manaGems); break;
|
||||
case NATURA: renderModel(naturaGems); break;
|
||||
case GAIA: renderModel(gaiaGems); break;
|
||||
}
|
||||
}
|
||||
|
||||
private void renderModel(IFlexibleBakedModel model)
|
||||
{
|
||||
renderModel(model, -1);
|
||||
}
|
||||
|
||||
private void renderModel(IFlexibleBakedModel model, int color)
|
||||
{
|
||||
Tessellator tessellator = Tessellator.getInstance();
|
||||
WorldRenderer worldrenderer = tessellator.getWorldRenderer();
|
||||
worldrenderer.begin(GL11.GL_QUADS, model.getFormat());
|
||||
|
||||
for (EnumFacing enumfacing : EnumFacing.values())
|
||||
{
|
||||
this.renderQuads(worldrenderer, model.getFaceQuads(enumfacing), color);
|
||||
}
|
||||
|
||||
this.renderQuads(worldrenderer, model.getGeneralQuads(), color);
|
||||
tessellator.draw();
|
||||
}
|
||||
|
||||
private void renderQuads(WorldRenderer renderer, List<BakedQuad> quads, int color)
|
||||
{
|
||||
for (BakedQuad bakedquad : quads)
|
||||
LightUtil.renderQuadColor(renderer, bakedquad, color);
|
||||
}
|
||||
}
|
||||
@@ -12,6 +12,7 @@ package vazkii.botania.client.model;
|
||||
|
||||
import net.minecraft.client.model.ModelBase;
|
||||
import net.minecraft.client.model.ModelRenderer;
|
||||
import vazkii.botania.api.state.enums.PylonVariant;
|
||||
|
||||
public class ModelPylonOld extends ModelBase implements IPylonModel {
|
||||
|
||||
@@ -119,7 +120,7 @@ public class ModelPylonOld extends ModelBase implements IPylonModel {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderCrystal() {
|
||||
public void renderCrystal(PylonVariant variant) {
|
||||
float f = 1F / 16F;
|
||||
crystal1.render(f);
|
||||
crystal2.render(f);
|
||||
@@ -132,7 +133,7 @@ public class ModelPylonOld extends ModelBase implements IPylonModel {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderRing() {
|
||||
public void renderRing(PylonVariant variant) {
|
||||
float f = 1F / 16F;
|
||||
outside1.render(f);
|
||||
outside2.render(f);
|
||||
@@ -151,7 +152,7 @@ public class ModelPylonOld extends ModelBase implements IPylonModel {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderGems() {
|
||||
public void renderGems(PylonVariant variant) {
|
||||
// NO-OP
|
||||
}
|
||||
|
||||
|
||||
@@ -15,13 +15,18 @@ import java.util.Random;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.client.renderer.OpenGlHelper;
|
||||
import net.minecraft.client.renderer.texture.TextureMap;
|
||||
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
import net.minecraftforge.client.event.ModelBakeEvent;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.lwjgl.opengl.GL12;
|
||||
|
||||
import vazkii.botania.api.state.BotaniaStateProps;
|
||||
import vazkii.botania.api.state.enums.PylonVariant;
|
||||
import vazkii.botania.client.core.handler.ClientTickHandler;
|
||||
import vazkii.botania.client.core.handler.MultiblockRenderHandler;
|
||||
import vazkii.botania.client.core.helper.ShaderHelper;
|
||||
@@ -57,14 +62,16 @@ public class RenderTilePylon extends TileEntitySpecialRenderer {
|
||||
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(tileentity.getWorld() != null) {
|
||||
green = tileentity.getBlockMetadata() == 1;
|
||||
pink = tileentity.getBlockMetadata() == 2;
|
||||
variant = ((PylonVariant) tileentity.getWorld().getBlockState(tileentity.getPos()).getValue(BotaniaStateProps.PYLON_VARIANT));
|
||||
green = variant == PylonVariant.NATURA;
|
||||
pink = variant == PylonVariant.GAIA;
|
||||
}
|
||||
|
||||
if(ConfigHandler.oldPylonModel)
|
||||
Minecraft.getMinecraft().renderEngine.bindTexture(pink ? texturePinkOld : green ? textureGreenOld : textureOld);
|
||||
else Minecraft.getMinecraft().renderEngine.bindTexture(pink ? texturePink : green ? textureGreen : texture);
|
||||
else Minecraft.getMinecraft().renderEngine.bindTexture(TextureMap.locationBlocksTexture);
|
||||
|
||||
double worldTime = tileentity.getWorld() == null ? 0 : (double) (ClientTickHandler.ticksInGame + pticks);
|
||||
|
||||
@@ -88,9 +95,9 @@ public class RenderTilePylon extends TileEntitySpecialRenderer {
|
||||
if(!ConfigHandler.oldPylonModel)
|
||||
GlStateManager.translate(-0.5F, 0F, 0.5F);
|
||||
|
||||
model.renderRing();
|
||||
model.renderRing(variant);
|
||||
GlStateManager.translate(0D, Math.sin(worldTime / 20D) / 20 - 0.025, 0D);
|
||||
model.renderGems();
|
||||
model.renderGems(variant);
|
||||
GlStateManager.popMatrix();
|
||||
}
|
||||
|
||||
@@ -106,7 +113,7 @@ public class RenderTilePylon extends TileEntitySpecialRenderer {
|
||||
|
||||
|
||||
GlStateManager.disableCull();
|
||||
model.renderCrystal();
|
||||
model.renderCrystal(variant);
|
||||
|
||||
GlStateManager.color(1F, 1F, 1F, a);
|
||||
if(!ShaderHelper.useShaders()) {
|
||||
@@ -125,7 +132,7 @@ public class RenderTilePylon extends TileEntitySpecialRenderer {
|
||||
else GlStateManager.translate(0F, -0.09F, 0F);
|
||||
|
||||
ShaderHelper.useShader(ShaderHelper.pylonGlow);
|
||||
model.renderCrystal();
|
||||
model.renderCrystal(variant);
|
||||
ShaderHelper.releaseShader();
|
||||
|
||||
GlStateManager.enableAlpha();
|
||||
|
||||
@@ -105,7 +105,7 @@ public class BlockPylon extends BlockModContainer implements ILexiconable, IInfu
|
||||
|
||||
@Override
|
||||
public int getRenderType() {
|
||||
return LibRenderIDs.idPylon;
|
||||
return 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in new issue
Block a user