mirror of
https://github.com/GTNewHorizons/Botania.git
synced 2026-11-18 03:15:07 +00:00
Fix pylon item model (kind of)
This commit is contained in:
1 parent
443de41647
commit
3f41aa0943
11 files changed
+147
-202
No files matched your search
@@ -54,26 +54,6 @@ public final class MultiblockRenderHandler {
|
||||
public static BlockPos anchor;
|
||||
public static EnumFacing angle;
|
||||
|
||||
static {
|
||||
// todo 1.8.8 temporary shim, because cannot renderBlockBrightness directly, see MinecraftForge issue 2353
|
||||
IMultiblockRenderHook.renderHooks.put(ModBlocks.pylon, new IMultiblockRenderHook() {
|
||||
@Override
|
||||
public void renderBlockForMultiblock(IBlockAccess world, Multiblock mb, IBlockState state, MultiblockComponent comp) {
|
||||
// Steal itemstack model since it has the proper group visibilities configured
|
||||
ItemStack stack = new ItemStack(ModBlocks.pylon, 1, state.getBlock().getMetaFromState(state));
|
||||
IBakedModel model = Minecraft.getMinecraft().getRenderItem().getItemModelMesher().getItemModel(stack);
|
||||
GlStateManager.scale(0.65F, 0.65, 0.65F);
|
||||
GlStateManager.translate(0.5F, -0.75F, 0.5F);
|
||||
Minecraft.getMinecraft().getBlockRendererDispatcher().getBlockModelRenderer().renderModelBrightness(model, state, 1.0F, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean needsTranslate(IBlockState state) {
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void setMultiblock(MultiblockSet set) {
|
||||
currentMultiblock = set;
|
||||
anchor = null;
|
||||
|
||||
@@ -1,115 +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
|
||||
* <p>
|
||||
* Botania is Open Source and distributed under the
|
||||
* Botania License: http://botaniamod.net/license.php
|
||||
* <p>
|
||||
* File Created @ [Apr 1, 2014, 6:21:48 PM (GMT)]
|
||||
*/
|
||||
package vazkii.botania.client.model;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import net.minecraft.client.renderer.BufferBuilder;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.client.renderer.block.model.BakedQuad;
|
||||
import net.minecraft.client.renderer.block.model.IBakedModel;
|
||||
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
||||
import net.minecraft.client.renderer.vertex.VertexFormat;
|
||||
import net.minecraft.crash.CrashReport;
|
||||
import net.minecraft.util.ReportedException;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.client.model.Attributes;
|
||||
import net.minecraftforge.client.model.IModel;
|
||||
import net.minecraftforge.client.model.ModelLoader;
|
||||
import net.minecraftforge.client.model.obj.OBJLoader;
|
||||
import net.minecraftforge.client.model.obj.OBJModel;
|
||||
import net.minecraftforge.client.model.pipeline.LightUtil;
|
||||
import net.minecraftforge.common.model.IModelState;
|
||||
import net.minecraftforge.common.model.Models;
|
||||
import net.minecraftforge.common.model.TRSRTransformation;
|
||||
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 {
|
||||
|
||||
private IBakedModel crystal;
|
||||
private IBakedModel ringsAndPanes;
|
||||
private IBakedModel gems;
|
||||
|
||||
public ModelPylon(ResourceLocation modelPath, ImmutableMap<String, String> textures) {
|
||||
try {
|
||||
// Load the OBJ
|
||||
OBJModel model = (OBJModel) OBJLoader.INSTANCE.loadModel(modelPath);
|
||||
|
||||
// Apply the texture and flip the v's of the model
|
||||
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"));
|
||||
crystal = processed.bake(hideGroups, format, ModelLoader.defaultTextureGetter());
|
||||
|
||||
hideGroups = hideGroups(ImmutableList.of("Crystal", "Ring_Gem01", "Ring_Gem02", "Ring_Gem03", "Ring_Gem04"));
|
||||
ringsAndPanes = processed.bake(hideGroups, format, ModelLoader.defaultTextureGetter());
|
||||
|
||||
hideGroups = hideGroups(ImmutableList.of("Crystal", "Crystal_Ring", "Ring_Panel01", "Ring_Panel02", "Ring_Panel03", "Ring_Panel04"));
|
||||
gems = processed.bake(hideGroups, format, ModelLoader.defaultTextureGetter());
|
||||
} catch(Exception e) {
|
||||
throw new ReportedException(new CrashReport("Error making pylon submodels for TESR!", e));
|
||||
}
|
||||
}
|
||||
|
||||
public void renderCrystal() {
|
||||
renderModel(crystal);
|
||||
}
|
||||
|
||||
public void renderRing() {
|
||||
GlStateManager.disableLighting();
|
||||
renderModel(ringsAndPanes);
|
||||
GlStateManager.enableLighting();
|
||||
}
|
||||
|
||||
public void renderGems() {
|
||||
GlStateManager.disableLighting();
|
||||
renderModel(gems);
|
||||
GlStateManager.enableLighting();
|
||||
}
|
||||
|
||||
private void renderModel(IBakedModel model) {
|
||||
Tessellator tessellator = Tessellator.getInstance();
|
||||
BufferBuilder worldrenderer = tessellator.getBuffer();
|
||||
worldrenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.ITEM);
|
||||
|
||||
for(BakedQuad bakedquad : model.getQuads(null, null, 0))
|
||||
LightUtil.renderQuadColor(worldrenderer, bakedquad, -1);
|
||||
tessellator.draw();
|
||||
}
|
||||
|
||||
private IModelState hideGroups(List<String> groups) {
|
||||
return part -> {
|
||||
if (part.isPresent()) {
|
||||
Iterator<String> parts = Models.getParts(part.get());
|
||||
while (parts.hasNext()) {
|
||||
if (groups.contains(parts.next())) {
|
||||
// Hide it
|
||||
return Optional.of(TRSRTransformation.identity());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return Optional.empty();
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
@@ -29,7 +29,7 @@ import vazkii.botania.client.model.ModelPylonNatura;
|
||||
import vazkii.botania.common.block.ModBlocks;
|
||||
import vazkii.botania.common.block.tile.TilePylon;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Random;
|
||||
|
||||
public class RenderTilePylon extends TileEntitySpecialRenderer<TilePylon> {
|
||||
@@ -43,12 +43,14 @@ public class RenderTilePylon extends TileEntitySpecialRenderer<TilePylon> {
|
||||
private final ModelPylonGaia gaiaModel = new ModelPylonGaia();
|
||||
|
||||
@Override
|
||||
public void render(@Nonnull TilePylon pylon, double d0, double d1, double d2, float pticks, int digProgress, float unused) {
|
||||
if(!pylon.getWorld().isBlockLoaded(pylon.getPos(), false)
|
||||
|| pylon.getWorld().getBlockState(pylon.getPos()).getBlock() != ModBlocks.pylon)
|
||||
public void render(@Nullable TilePylon pylon, double d0, double d1, double d2, float pticks, int digProgress, float unused) {
|
||||
boolean renderingItem = pylon == null;
|
||||
|
||||
if(!renderingItem &&
|
||||
(!pylon.getWorld().isBlockLoaded(pylon.getPos(), false) || pylon.getWorld().getBlockState(pylon.getPos()).getBlock() != ModBlocks.pylon))
|
||||
return;
|
||||
|
||||
PylonVariant type = ModBlocks.pylon.getStateFromMeta(pylon.getBlockMetadata()).getValue(BotaniaStateProps.PYLON_VARIANT);
|
||||
PylonVariant type = renderingItem ? PylonVariant.MANA : ModBlocks.pylon.getStateFromMeta(pylon.getBlockMetadata()).getValue(BotaniaStateProps.PYLON_VARIANT); // todo get the type somehow....
|
||||
IPylonModel model;
|
||||
switch(type) {
|
||||
default:
|
||||
@@ -78,28 +80,30 @@ public class RenderTilePylon extends TileEntitySpecialRenderer<TilePylon> {
|
||||
|
||||
double worldTime = (double) (ClientTickHandler.ticksInGame + pticks);
|
||||
|
||||
worldTime += new Random(pylon.getPos().hashCode()).nextInt(360);
|
||||
worldTime += new Random(pylon == null ? 0 : pylon.getPos().hashCode()).nextInt(360);
|
||||
|
||||
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(0.5F, 0F, -0.5F);
|
||||
GlStateManager.pushMatrix();
|
||||
GlStateManager.translate(0.5F, 0F, -0.5F);
|
||||
if(!renderingItem)
|
||||
GlStateManager.rotate((float) worldTime * 1.5F, 0F, 1F, 0F);
|
||||
//GlStateManager.translate(-0.5F, 0F, 0.5F);
|
||||
//GlStateManager.translate(-0.5F, 0F, 0.5F);
|
||||
|
||||
model.renderRing();
|
||||
model.renderRing();
|
||||
if(!renderingItem)
|
||||
GlStateManager.translate(0D, Math.sin(worldTime / 20D) / 20 - 0.025, 0D);
|
||||
GlStateManager.popMatrix();
|
||||
}
|
||||
GlStateManager.popMatrix();
|
||||
|
||||
GlStateManager.pushMatrix();
|
||||
GlStateManager.translate(0D, Math.sin(worldTime / 20D) / 17.5, 0D);
|
||||
if(!renderingItem)
|
||||
GlStateManager.translate(0D, Math.sin(worldTime / 20D) / 17.5, 0D);
|
||||
|
||||
GlStateManager.translate(0.5F, 0F, -0.5F);
|
||||
GlStateManager.rotate((float) -worldTime, 0F, 1F, 0F);
|
||||
if(!renderingItem)
|
||||
GlStateManager.rotate((float) -worldTime, 0F, 1F, 0F);
|
||||
//GlStateManager.translate(-0.5F, 0F, 0.5F);
|
||||
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ import net.minecraft.block.state.BlockStateContainer;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.EnumBlockRenderType;
|
||||
@@ -24,6 +25,7 @@ import net.minecraft.util.math.AxisAlignedBB;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.client.ForgeHooksClient;
|
||||
import net.minecraftforge.fml.common.Optional;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
@@ -141,6 +143,10 @@ public class BlockPylon extends BlockMod implements ILexiconable, IInfusionStabi
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public void registerModels() {
|
||||
ModelHandler.registerBlockToState(this, PylonVariant.values().length);
|
||||
String[] names = { "mana", "natura", "gaia" };
|
||||
ModelHandler.registerCustomItemblock(this, names.length, i -> "pylon_" + names[i]);
|
||||
for(int i = 0; i < names.length; i++) {
|
||||
ForgeHooksClient.registerTESRItemStack(Item.getItemFromBlock(this), i, TilePylon.class);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user