Darth Posted September 2, 2018 Share Posted September 2, 2018 Hi gyus. I have really strange problem with model rendering. If you look at the model at the first angle - everything is fine, but if you look under the second... I use TESR for render model. All code u can find above: 1: Spoiler 2: Spoiler 3: Spoiler model: Spoiler eye.mtl eye.obj Code: Block: Spoiler package com.ancient.thaumicgadgets.blocks; import java.util.Random; import com.ancient.thaumicgadgets.init.ModBlocks; import com.ancient.thaumicgadgets.objects.machines.eye.TileEntityEye; import com.ancient.thaumicgadgets.util.Reference; import net.minecraft.block.BlockHorizontal; import net.minecraft.block.ITileEntityProvider; import net.minecraft.block.SoundType; import net.minecraft.block.material.Material; import net.minecraft.block.properties.IProperty; import net.minecraft.block.properties.PropertyDirection; import net.minecraft.block.state.BlockStateContainer; import net.minecraft.block.state.IBlockState; import net.minecraft.client.renderer.block.model.ModelResourceLocation; import net.minecraft.entity.EntityLivingBase; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.BlockRenderLayer; import net.minecraft.util.EnumBlockRenderType; import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumHand; import net.minecraft.util.Mirror; import net.minecraft.util.Rotation; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import net.minecraftforge.client.model.ModelLoader; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; public class BlockEye extends BlockBase implements ITileEntityProvider { private final String name; public BlockEye(String name) { super(name, Material.GLASS); this.name = name; setSoundType(SoundType.GLASS); setHardness(4f); setResistance(30f); setLightOpacity(0); setHarvestLevel("pickaxe", 0); } @Override public TileEntity createNewTileEntity(World worldIn, int meta) { return new TileEntityEye(); } @Override public Item getItemDropped(IBlockState state, Random rand, int fortune) { return Item.getItemFromBlock(ModBlocks.EYE); } @Override public ItemStack getItem(World worldIn, BlockPos pos, IBlockState state) { return new ItemStack(ModBlocks.EYE); } @Override public EnumBlockRenderType getRenderType(IBlockState state) { return EnumBlockRenderType.INVISIBLE; } @SideOnly(Side.CLIENT) public BlockRenderLayer getBlockLayer() { return BlockRenderLayer.CUTOUT; } @Override public boolean isOpaqueCube(IBlockState state) { return false; } @Override public boolean isFullCube(IBlockState state) { return false; } @Override public void registerModels() { ModelResourceLocation itemModel = new ModelResourceLocation(Reference.MOD_ID + ":" + this.name + ".obj"); ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(this), 0, itemModel); } } TileEntity: Spoiler package com.ancient.thaumicgadgets.objects.machines.eye; import net.minecraft.client.Minecraft; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.ITickable; import net.minecraft.util.math.Vec3d; public class TileEntityEye extends TileEntity implements ITickable { public Vec3d vec = Vec3d.ZERO; public TileEntityEye() { } @Override public void update() { if (world.isRemote) { EntityPlayer pl = Minecraft.getMinecraft().world.getClosestPlayer(this.pos.getX(), this.pos.getY(), this.pos.getZ(), 10, false); if (pl != null) { vec = new Vec3d(this.pos.getX() - pl.posX, this.pos.getY() - (pl.posY + (pl.height / 2)), this.pos.getZ() - pl.posZ).normalize(); } else { vec = Vec3d.ZERO; } } } } TESR: Spoiler package com.ancient.thaumicgadgets.objects.machines.eye; import com.ancient.thaumicgadgets.util.IFunctionLibrary; import com.ancient.thaumicgadgets.util.Reference; import net.minecraft.block.state.IBlockState; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.BlockRendererDispatcher; import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.RenderHelper; import net.minecraft.client.renderer.block.model.IBakedModel; import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; import net.minecraft.util.ResourceLocation; public class RenderEye extends TileEntitySpecialRenderer<TileEntityEye> { private float timer = 0f; private static final ResourceLocation modelLoc = new ResourceLocation(Reference.MOD_ID, "models/block/eye.obj"); private static final IBakedModel model = IFunctionLibrary.loadModel(modelLoc); @Override public void render(TileEntityEye te, double x, double y, double z, float partialTicks, int destroyStage, float alpha) { double teX = te.getPos().getX(); double teY = te.getPos().getY(); double teZ = te.getPos().getZ(); BlockRendererDispatcher brd = Minecraft.getMinecraft().getBlockRendererDispatcher(); GlStateManager.pushMatrix(); GlStateManager.color(1f, 1f, 1f, 1f); if (++timer > 7200) { timer = 0f; } GlStateManager.translate(x + 0.5d, y + (Math.sin(timer*0.05d)*0.1d) + 0.5d, z + 0.5d); GlStateManager.rotate((float) (te.vec.y * 180/Math.PI), 0, 1f, 0); GlStateManager.enableBlend(); IBlockState state = te.getWorld().getBlockState(te.getPos()); brd.getBlockModelRenderer().renderModelBrightness(model, state, 1.0f, false); GlStateManager.disableBlend(); GlStateManager.popMatrix(); } } Quote Link to comment Share on other sites More sharing options...
Animefan8888 Posted September 2, 2018 Share Posted September 2, 2018 13 minutes ago, Darth said: I use TESR for render model. All code u can find above: Is the model going to be animated? If not dont use a TESR use the normal model system, forge adds support for obj models. Quote VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect. Forge and vanilla BlockState generator. Link to comment Share on other sites More sharing options...
Darth Posted September 2, 2018 Author Share Posted September 2, 2018 (edited) Model must be animated, so without TESR it's impossible to make. I want this eye will always been rotated to the player, if u know another way to make this please say it. Edited September 2, 2018 by Darth Quote Link to comment Share on other sites More sharing options...
V0idWa1k3r Posted September 2, 2018 Share Posted September 2, 2018 3 hours ago, Darth said: GlStateManager.rotate((float) (te.vec.y * 180/Math.PI), 0, 1f, 0); This is not how vectors work. You need to get an angle between your vector and the default unitZ vector to get the rotation you need to apply around the Y axis. As for your direct issue - you must bind the TextureMap.LOCATION_BLOCKS_TEXTURE before rendering your TE otherwise the last bound texture is used. 1 Quote Link to comment Share on other sites More sharing options...
Cadiboo Posted September 2, 2018 Share Posted September 2, 2018 you should probably also te#getWorld#getTotalWorldTime() instead of your timer variable. If you need even more accuracy you can also add the partialTicks to the world time. You might want to take a look at https://github.com/Cadiboo/WIPTechAlpha/blob/fc508e4dd439603888ca2caf08c0b871372764d4/src/main/java/cadiboo/wiptech/client/ClientUtil.java#L776-L801 for the trigonometry and at https://github.com/Cadiboo/WIPTechAlpha/blob/fc508e4dd439603888ca2caf08c0b871372764d4/src/main/java/cadiboo/wiptech/client/ClientUtil.java#L247-L292 for my use of it Quote About Me Spoiler My Discord - Cadiboo#8887 My Website - Cadiboo.github.io My Mods - Cadiboo.github.io/projects My Tutorials - Cadiboo.github.io/tutorials Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support. When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible. Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme) Link to comment Share on other sites More sharing options...
Darth Posted September 4, 2018 Author Share Posted September 4, 2018 On 9/2/2018 at 4:54 PM, Cadiboo said: you should probably also te#getWorld#getTotalWorldTime() instead of your timer variable. If you need even more accuracy you can also add the partialTicks to the world time. You might want to take a look at https://github.com/Cadiboo/WIPTechAlpha/blob/fc508e4dd439603888ca2caf08c0b871372764d4/src/main/java/cadiboo/wiptech/client/ClientUtil.java#L776-L801 for the trigonometry and at https://github.com/Cadiboo/WIPTechAlpha/blob/fc508e4dd439603888ca2caf08c0b871372764d4/src/main/java/cadiboo/wiptech/client/ClientUtil.java#L247-L292 for my use of it Problem was with rendering, not with trigonometry, but thanks anyway. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.