Bregor Posted August 11, 2013 Posted August 11, 2013 Hi, can someone give me a hint on how this could be accomplished: I want a block of my mod by default to be invisible - but it should show up if a specific tool is equipped by the player (active tool in the quick-bar, another item of my mod). As this should be an multiplayer compatible mod, the visibility toggle should only be on the client side (as only a player with the tool equipped should see the blocks). Thanks. Quote
Bregor Posted August 14, 2013 Author Posted August 14, 2013 If possible I would like to have a block without a corresponding tile entity, as there is no additional data required, the 4bit metadata are fine for me. So I experimented with normal blocks based on this tutorial http://www.minecraftforge.net/wiki/Multiple_Pass_Render_Blocks, but to my surprise the renderWorldBlock from the interface ISimpleBlockRenderingHandler is not called each frame but seems to be cached somehow. Is there a possibility to invalidate the state of a renderer on the client? So that the tool itself invalidates the renderer for the target block if it is equipped or unequipped by the player. The rendering code i used, it should render a bedrock block if the tool is equipped and an invisible block if not: public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId, RenderBlocks renderer) { //which render pass are we doing? if(ClientProxy.renderPass == 0) { EntityClientPlayerMP player = Minecraft.getMinecraft().thePlayer; ItemStack currentPlayerItemStack = player.getHeldItem(); if(currentPlayerItemStack.itemID == targetItemId) { renderer.renderStandardBlock(Block.bedrock, x, y, z); } } return true; } Quote
hydroflame Posted August 14, 2013 Posted August 14, 2013 my surprise the renderWorldBlock from the interface ISimpleBlockRenderingHandler is not called each frame but seems to be cached somehow. this is why i hate ISBRH, the only you CAN do to force a re-render is world.markBlockForUpdate(x, y, z) client side Quote how to debug 101:http://www.minecraftforge.net/wiki/Debug_101 -hydroflame, author of the forge revolution-
Bregor Posted August 15, 2013 Author Posted August 15, 2013 I now went down the TileEntitySpecialRenderer road, and it works quite well. Thanks a lot for the tip with the TileEntitySpecialRenderer. Just got one related question, if i want some sort of texture particle effect in my TileEntitySpecialRenderer, should i create it myself or is it possible to use something like EntityFX for it? If drawing it myself is the way to go, which time reference is best used to get a time base for the animation in the render method? And is there an easy way to get the camera vector to orient the texture perpendicular to the looking direction of the player? For reference if someone else may need it, this is how the toggling is done: @Override public void renderTileEntityAt(TileEntity tileentity, double x, double y, double z, float f) { EntityClientPlayerMP player = Minecraft.getMinecraft().thePlayer; ItemStack currentPlayerItemStack = player.getHeldItem(); if(currentPlayerItemStack == null || currentPlayerItemStack.itemID != requiredItemId) { return; } //Rendering code ... } Quote
hydroflame Posted August 15, 2013 Posted August 15, 2013 And is there an easy way to get the camera vector to orient the texture perpendicular to the looking direction of the player? "billboarding" is the word you are looking for heres how to do it (in minecraft, in an actual opengl program there are better way to do this): EntityPlayer p = Minecraft.getMinecraft().thePlayer; GL11.glRotated(-p.rotationYaw, 0, 1, 0); GL11.glRotated(p.rotationPitch, 1, 0, 0); i only did a small amount of research on particle but i can tell you this every particle are child class of Entity and they can only spawn in client world (as the server doesn't give a **** about particle and doesn't want to update+sync them) and they are spherically billboarded. i never tried to actually create a new EntityFX (a new particle), might be possible, might not be but what I personally did for one of my TESR (TileEntitySpecialRenderer) was to have an internal list of particle inside the TESR and render+update them inside the TESR. Might not be the best way but for my case it was good enough edit: btw the billboard "technique" i show earlier is fake billboarding, which is 99% of the minecraft case "good enough" true billboarding is a biiiiit more compilcated Quote how to debug 101:http://www.minecraftforge.net/wiki/Debug_101 -hydroflame, author of the forge revolution-
Bregor Posted August 15, 2013 Author Posted August 15, 2013 But how did you time the animation of the texture, is there a way to get the number of elapsed ticks or some other timebase? Quote
hydroflame Posted August 15, 2013 Posted August 15, 2013 But how did you time the animation of the texture can you give me your deffinition of that, because we could think 2 different stuff when we read that im thinking 3d texture or multiple texture that gets dispalyed one after the other how did I do it? well i personally like to use cyclic animation (the same thing over and over) since all i want is somethign that moves, i usually take the system and transform it into the matrix transform i want to apply it to hard to type but heres a real live example from my mod: //sorry about extremmelly shitty quality code that does that: import org.lwjgl.opengl.GL11; import com.hydroflame.mod.ForgeRevCommonProxy; import com.hydroflame.mod.TheMod; import net.minecraft.block.Block; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.OpenGlHelper; import net.minecraft.client.renderer.RenderBlocks; import net.minecraft.client.renderer.Tessellator; import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.ResourceLocation; import net.minecraft.world.IBlockAccess; import net.minecraftforge.client.model.AdvancedModelLoader; import net.minecraftforge.client.model.IModelCustom; import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler; public class RenderTeleporter extends TileEntitySpecialRenderer{ private IModelCustom teleporter; private ResourceLocation texture = new ResourceLocation(TheMod.modid, "/models/textures/teleporter.png"); private float[] pos; int displayList = -1; public RenderTeleporter(){ teleporter = AdvancedModelLoader.loadModel("/teleporter.obj"); pos = new float[30]; for(int i = 0; i < pos.length; i++){ pos[i] = (float) Math.random()*2; } } @Override public void renderTileEntityAt(TileEntity tileentity, double d0, double d1, double d2, float f) { //here for(int i =0; i < pos.length; i++){ } float size = 0.1f; Tessellator tess = Tessellator.instance; for(int i = 0; i < pos.length; i++){ pos[i]+=0.01f; if(pos[i] > 2){ pos[i] = 0; } } Minecraft.getMinecraft().renderEngine.func_110577_a(ForgeRevCommonProxy.portalParticle); GL11.glPushMatrix(); GL11.glTranslated(d0+0.5, d1+1, d2+0.5); for(int i = 0; i < pos.length; i++){ GL11.glRotated(360/pos.length, 0, 1, 0); GL11.glPushMatrix(); GL11.glTranslated(0, pos[i], 1); tess.startDrawingQuads(); tess.addVertexWithUV(-size, -size, 0, 0, 0); tess.addVertexWithUV(-size, size, 0, 0, 1); tess.addVertexWithUV(size, size, 0, 1, 1); tess.addVertexWithUV(size, -size, 0, 1, 0); tess.addVertexWithUV(-size, -size, 0, 0, 0); tess.addVertexWithUV(size, -size, 0, 1, 0); tess.addVertexWithUV(size, size, 0, 1, 1); tess.addVertexWithUV(-size, size, 0, 0, 1); tess.draw(); GL11.glPopMatrix(); } GL11.glPopMatrix(); GL11.glColor3f(1, 1, 1); Minecraft.getMinecraft().renderEngine.func_110577_a(texture); GL11.glPushMatrix(); GL11.glTranslated(d0+0.5, d1+1, d2+0.5); GL11.glScaled(1.3, 1.3, 1.3); Tessellator.instance.setColorOpaque_F(1, 1, 1); teleporter.renderAll(); Minecraft.getMinecraft().renderEngine.func_110577_a(ForgeRevCommonProxy.portalRune); GL11.glTranslated(0, 0.2, 0); GL11.glRotated(System.nanoTime()/100000000f, 0, 1, 0); tess.startDrawingQuads(); tess.addVertexWithUV(-0.5, 0, -0.5, 0, 0); tess.addVertexWithUV(-0.5, 0, 0.5, 0, 1); tess.addVertexWithUV(0.5, 0, 0.5, 1, 1); tess.addVertexWithUV(0.5, 0, -0.5, 1, 0); tess.draw(); GL11.glPopMatrix(); } } Quote how to debug 101:http://www.minecraftforge.net/wiki/Debug_101 -hydroflame, author of the forge revolution-
Bregor Posted August 15, 2013 Author Posted August 15, 2013 I was just thinking to complicated it seems, as the animation is only client side without synchronization needs, using System.nanoTime() is perfectly fine Quote
hydroflame Posted August 15, 2013 Posted August 15, 2013 just little warning, if you use System.nanoTime, ALL your block will be extremelly synchronized when i mean extremmelly, i mean like very very synchro (btw my code is synchonized but thats just because i did not have time to implement the synchro break to "break" this synchro you will need to use value that change from one block to another, the one i recommend using is x, y, z that is coviniently given to you by the method now we need to use those to differentiate one animation from the other imagine that all our animation are based on one factor lets say: float f = System.nanoTime()/1000000f; now that would mean everything is synchro, what would happen if we were to add somethign to differentiate them from one another: int loopFactor = 50; float f = System.nanoTime()/1000000f + (x%loopFactor)/attenuationFactor; and attenuationFactor im not sure what is a good value, to high will make it look weird, too low too basicly we introduced the x variable of the TE to make sure 2 TE with 2 different x will not be in synchronization, repeat for y and z to make sure that nothign is synchro ever of course this will only make the animation be at different "time" in their loop, but at least it looks nice now i know this isnt very clear, please ask if you want another explanation Quote how to debug 101:http://www.minecraftforge.net/wiki/Debug_101 -hydroflame, author of the forge revolution-
Bregor Posted August 15, 2013 Author Posted August 15, 2013 Got it working now, thanks to both of you. Quote
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.