Jump to content

Flayr

Members
  • Posts

    22
  • Joined

  • Last visited

Everything posted by Flayr

  1. Okay I don't think I was very clear. Here is my renderer file. package flayr.lensoftruth.tileentities; import i.will.skip.the.imports public class InvisibleBlockRenderer extends TileEntitySpecialRenderer{ @SideOnly(Side.CLIENT) public void renderTileEntityAt(TileEntity tileentity, double x, double y, double z, float f) { ItemStack heldItem = Minecraft.getMinecraft().thePlayer.getHeldItem(); ItemStack lens = new ItemStack(LensOfTruth.truthLens); if (heldItem != null && ItemStack.areItemStacksEqual(heldItem, lens)) { ResourceLocation rl = new ResourceLocation("lensoftruth:textures/blocks/invisibleBlock.png"); Minecraft.getMinecraft().renderEngine.bindTexture(rl); Tessellator tessellator = Tessellator.instance; GL11.glPushMatrix(); GL11.glTranslated(x, y, z); GL11.glNormal3f(0.0F, 10.0F, 0.0F); // Rendering Code GL11.glPopMatrix(); } } } I have already made a version that used tessalator to individually render all six sides when truthLens is held, however the result looks strange(textures glitch a bit on movement) and it also does not seem like the overall best option. Is there a way to access the regular block rendering code instead?
  2. How do you render a normal looking block within a custom renderer? The renderer changes depending on different factors but sometimes it should look like a regular block, how do I do this without just drawing 6 separate squares with tessalator (it doesn't look right when you do that).
  3. oops! This time I'll type it into my code and make sure it compiles!.... if (Minecraft.getMinecraft().thePlayer.getHeldItem().getItem().itemID == myLightStaffID) { // staff is held so render it } -TGG Okay so if I spawn in lightInv it is invisible and in I make lightInv with the staff it is visible, but whenever I change equip or unequipped the staff respectively it crashes. package flayr.magiclights.tileentities; import java.util.List; import org.lwjgl.opengl.GL11; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import flayr.magiclights.MagicLights; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.Tessellator; import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.AxisAlignedBB; import net.minecraft.util.MovingObjectPosition; import net.minecraft.util.ResourceLocation; import net.minecraft.util.Vec3; import net.minecraft.world.World; public class LightInvRenderer extends TileEntitySpecialRenderer{ @SideOnly(Side.CLIENT) public void renderTileEntityAt(TileEntity tileentity, double x, double y, double z, float f) { if (Minecraft.getMinecraft().thePlayer.getHeldItem().getItem().itemID == MagicLights.lightStaff.itemID) { ResourceLocation rl = new ResourceLocation("magiclights:textures/blocks/lightInv.png"); Minecraft.getMinecraft().renderEngine.bindTexture(rl); Tessellator tessellator = Tessellator.instance; GL11.glPushMatrix(); GL11.glTranslated(x+0.5, y+0.5, z+0.5); GL11.glNormal3f(0.0F, 10.0F, 0.0F); GL11.glRotatef(-this.tileEntityRenderer.playerYaw, 0.0F, 1.0F, 0.0F); GL11.glRotatef(this.tileEntityRenderer.playerPitch, 1.0F, 0.0F, 0.0F); tessellator.startDrawingQuads(); tessellator.addVertexWithUV(-0.5, 0.5, 0, 1, 0); tessellator.addVertexWithUV(0.5, 0.5, 0, 1, 1); tessellator.addVertexWithUV(-0.5, -0.5, 0, 0, 0); tessellator.addVertexWithUV(0.5, -0.5, 0, 0, 1); tessellator.addVertexWithUV(0.5, -0.5, 0, 1, 0); tessellator.addVertexWithUV(-0.5, -0.5, 0, 0, 0); tessellator.addVertexWithUV(0.5, 0.5, 0, 1, 1); tessellator.addVertexWithUV(-0.5, 0.5, 0, 0, 1); tessellator.draw(); GL11.glPopMatrix(); } } }
  4. That doesnt work, thePlayer does not exist in Minecraft, the problem I have is how to refer to the correct player from within the renderer code. Do you know how to do that?
  5. Thanks for the response, at this point I was already planning on making it check weather the player is holding the staff in the EntityRenderer but I could not find a way to implement the code I used in the block class (it needs the world object as an input to check for players holding the staff). Do you have any ideas for the actual code that I could put in LightRenderer.java that checks if the player is holding the staff?
  6. Sorry, have not been on the forums lately so this response is a bit late. First, here is the GitHub for my sourcecode: https://github.com/TheJawrey/Magic-Lights/ Basically, what the mod does so far is add a single item, Staff of Light(lightStaff in the code) that on right click creates the block Light. The block light can be walked through, seen through and is also not editable without holding the Staff of Light, the object Light also creates a tile entity TileEntityLight that renderers a 2D object witch rotates to face the player. What I need to do is make it so that when you are holding the staff the rendered objects are visible and when the staff is not held they are invisible, basically acting like air that makes light.
  7. AxisAlignedBB aabb = AxisAlignedBB.getAABBPool().getAABB(x-4, y-4, z-4, x+4, y+4, z+4); List w = par1World.getEntitiesWithinAABB(EntityPlayer.class, aabb); if(w.size() > 0) { //at least one player in range EntityPlayer player; for(int i = 0; i < w.size() { player = (EntityPlayer) w.get(i); ItemStack stack = player.getHeldItem(); ItemStack stack2 = new ItemStack(MagicLights.lightStaff); if(ItemStack.areItemStacksEqual(stack, stack2)){ So I wrote code that did change the TileEntity but it was kind of glitchy, I could go back to that but it seems like it would be better to put the code in the Renderer. How would I implement it in the renderer? The only problem is that there is no world object parameter in the renderer method, how would I change this code to work with entities instead of blocks?
  8. You haven't actually used a TileEntity have you? When you (the modder) creates one, you don't have block coordinates. You only have the world: @Override public TileEntity createNewTileEntity(World world) { return new MyTileEntity(); } Vanilla code handles the rest. That is the problem I have, how would i best do the same thing I did with the MovingObjectPosition collisionRayTrace method in a CreateNewTileEntity method because it only has the parameter world.
  9. EDIT: This was solved earlier but then I ran into a problem that stems from this one. So the block that needed to be unelectable when a certain item was held also needs to change what type of tile entity is spawned when this item is held. The problem is that that method does not have x, y and z as parameters so I cannot use the same code. How would I do this? Also, if it would be easier to put the detecting in the renderer to change the texture that would work too. The current code for the original method: @Override public MovingObjectPosition collisionRayTrace(World par1World, int x, int y, int z, Vec3 par5Vec3, Vec3 par6Vec3) { AxisAlignedBB aabb = AxisAlignedBB.getAABBPool().getAABB(x-4, y-4, z-4, x+4, y+4, z+4); List w = par1World.getEntitiesWithinAABB(EntityPlayer.class, aabb); if(w.size() > 0) { //at least one player in range EntityPlayer player; for(int i = 0; i < w.size() { player = (EntityPlayer) w.get(i); ItemStack stack = player.getHeldItem(); ItemStack stack2 = new ItemStack(MagicLights.lightStaff); if(ItemStack.areItemStacksEqual(stack, stack2)){ return super.collisionRayTrace(par1World, x, y, z, par5Vec3, par6Vec3); }else{return null;} } return null; }else{return null;} }
  10. I don't want to store any data I just need to get the coordinates of the block for use in methods, here is an example that would require the x coordinate of the block: public TileEntity createNewTileEntity(World par1world){ if(x>0){ return new TileEntityExample(); }else{ return new TileEntityExample2(); }
  11. I cannot believe that I have to post this, but I can't seem to find the answer by looking through the source. How do I get the coordinates of a block inside it's class as variables that I can use outside of a method that has x y and z as parameters.
  12. It works now, thank you very much for the help!
  13. Well, it is error free now but when I run minecraft i cannot select the block regardless of weather I am holding the staff or not. Here is my current code. @Override public MovingObjectPosition collisionRayTrace(World par1World, int x, int y, int z, Vec3 par5Vec3, Vec3 par6Vec3) { AxisAlignedBB aabb = AxisAlignedBB.getAABBPool().getAABB(x-4, y-4, z-4, x+4, y+4, z+4); List w = par1World.getEntitiesWithinAABB(EntityPlayer.class, aabb); if(w.size() > 0) { //at least one player in range EntityPlayer player; for(int i = 0; i < w.size() { player = (EntityPlayer) w.get(i); if(player.getHeldItem() == new ItemStack(MagicLights.lightStaff)){ return super.collisionRayTrace(par1World, x, y, z, par5Vec3, par6Vec3); }else{return null;} } return null; }else{return null;} }
  14. Here is the method that i am working on: @Override public MovingObjectPosition collisionRayTrace(World par1World, int x, int y, int z, Vec3 par5Vec3, Vec3 par6Vec3) { AxisAlignedBB aabb = AxisAlignedBB.getAABBPool().getAABB(x-4, y-4, z-4, x+4, y+4, z+4); List w = par1World.getEntitiesWithinAABB(EntityPlayer.class, aabb); if(w.size() > 0) { //at least one player in range EntityPlayer player; for(int i = 0; i < w.size(); i++) { [b] player = w.get(i);[/b] } if(player.getHeldItem() == new ItemStack(MagicLights.lightStaff)){ return null; }else{return super.collisionRayTrace(par1World, x, y, z, par5Vec3, par6Vec3);} }else{return super.collisionRayTrace(par1World, x, y, z, par5Vec3, par6Vec3);} } First, is this correct, second I am getting an error on the line "player = w.get(i);"
  15. I was actually having trouble with both things, although checking the players held item was a bigger one. The return statement works perfectly find, but I cannot seem to get it to read the closest player's held item. Could you explain in a bit more what the implementation of this code would be?
  16. EDIT: Thanks for all the help and support, I got everything in my mod working now and am going to release it after some testing. My goal is to create a block that cannot be interacted with at all unless you are holding a specific item. I already have this in my Block class: @Override public MovingObjectPosition collisionRayTrace(World par1World, int par2, int par3, int par4, Vec3 par5Vec3, Vec3 par6Vec3) { return null; } What I cant figure out is how to make it so that it only returns null when a certain item is held but returns how it normally would otherwise. The biggest problem is that if i do make a basic if statement that will be true to test it I don't know what to return to make it normal. (because I already used @Override).
  17. I have been trying for a while and cannot find a good way to do this. How do I make a block that your cursor just goes through allowing you to destroy the block behind it and not destroy it (just like how you cant click on water, but can still build underwater). Thanks in advance.
  18. All of my classes are on my GitHub: https://github.com/TheJawrey/Magic-Lights For the Light Class: https://github.com/TheJawrey/Magic-Lights/blob/master/src/minecraft/flayr/magiclights/Light.java
  19. Okay, so I used some of your changes and got it to render the entity, the problem is that this happens. http://i1299.photobucket.com/albums/ag79/jackawrey/2013-10-06_170243_zpsd5a7b341.png[/img] I think the problem is just the custom renderer file. Let me know if there is anything wrong with it. package flayr.magiclights.tileentities; import org.lwjgl.opengl.GL11; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.Tessellator; import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.ResourceLocation; public class LightRenderer extends TileEntitySpecialRenderer{ public void renderTileEntityAt(TileEntity tileentity, double x, double y, double z, float f) { float f1 = 1.6F; float f2 = 0.01666667F * f1; GL11.glPushMatrix(); GL11.glTranslatef((float)x, (float)y, (float)z); GL11.glTranslated(0.5, 0.5, 0.5); GL11.glNormal3f(0.0F, 1.0F, 0.0F); GL11.glRotatef(-this.tileEntityRenderer.playerYaw, 0.0F, 1.0F, 0.0F); GL11.glRotatef(this.tileEntityRenderer.playerPitch, 1.0F, 0.0F, 0.0F); GL11.glScalef(-f2, -f2, f2); GL11.glDisable(2896); GL11.glDepthMask(false); GL11.glDisable(2929); GL11.glEnable(3042); GL11.glBlendFunc(770, 771); Tessellator tessellator = Tessellator.instance; byte byte0 = 0; GL11.glDisable(3553); tessellator.disableColor(); tessellator.startDrawingQuads(); int j = 3; tessellator.setColorRGBA_F(1F, 1F, 1F, 1F); ResourceLocation rl = new ResourceLocation("assets:magiclights/textures/blocks/light.png"); Minecraft.getMinecraft().renderEngine.bindTexture(rl); tessellator.addVertex(-j - 1, -1 + byte0, 0.0D); tessellator.addVertex(-j - 1, 8 + byte0, 0.0D); tessellator.addVertex(j + 1, 8 + byte0, 0.0D); tessellator.addVertex(j + 1, -1 + byte0, 0.0D); tessellator.draw(); GL11.glPopMatrix(); } } If you want to see the rest of the source here it is: https://github.com/TheJawrey/Magic-Lights. Edit: How should I link to the file? It is located in /forge/mcp/src/minecraft/assets/magiclights/light.png.
  20. Okay, it is still not working, here is my code. MagicLights package flayr.magiclights; // This Import list will grow longer with each additional tutorial. // It's not pruned between full class postings, unlike other tutorial code. import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraftforge.common.Configuration; import net.minecraftforge.common.MinecraftForge; import cpw.mods.fml.common.Mod; import cpw.mods.fml.common.Mod.EventHandler; import cpw.mods.fml.common.Mod.Init; import cpw.mods.fml.common.Mod.Instance; import cpw.mods.fml.common.Mod.PostInit; import cpw.mods.fml.common.Mod.PreInit; import cpw.mods.fml.common.SidedProxy; import cpw.mods.fml.common.event.FMLInitializationEvent; import cpw.mods.fml.common.event.FMLPostInitializationEvent; import cpw.mods.fml.common.event.FMLPreInitializationEvent; import cpw.mods.fml.common.network.NetworkMod; import cpw.mods.fml.common.registry.GameRegistry; import cpw.mods.fml.common.registry.LanguageRegistry; @Mod(modid = MagicLights.MOD_ID, name = MagicLights.MOD_NAME, version = MagicLights.MOD_VERSION) @NetworkMod(clientSideRequired = true, serverSideRequired = false) public class MagicLights { public static final String MOD_ID = "MagicLights"; static final String MOD_NAME = "Magic Lights"; static final String MOD_VERSION = "1.0.3"; static final String SOURCE_PATH = "flayr.magiclights."; private static int lightStaffID; private static int lightID; public static Item lightStaff; public static Block light; public static CreativeTabs tabMagicLights = new CreativeTabs("tabMagicLights"){ public ItemStack getIconItemStack(){ return new ItemStack(lightStaff); } }; @Mod.Instance("MOD_ID") public static MagicLights instance; @SidedProxy(clientSide="flayr.magiclights.client.ClientProxy", serverSide="flayr.magiclights.CommonProxy") public static CommonProxy proxy; @EventHandler public void preInit(FMLPreInitializationEvent event) { Configuration config = new Configuration(event.getSuggestedConfigurationFile()); config.load(); lightID = config.getBlock("light", 672).getInt(); lightStaffID = config.getItem("lightStaff", 2527).getInt(); config.save(); } @EventHandler public void load(FMLInitializationEvent event) { lightStaff = new LightStaff(lightStaffID); light = new Light(lightID, Material.rock) .setHardness(0.0F).setLightValue(1.0f).setUnlocalizedName("lightStaffBlock").setCreativeTab(MagicLights.tabMagicLights); ItemStack starStack = new ItemStack(Item.netherStar); ItemStack stickStack = new ItemStack(Item.stick); ItemStack goldStack = new ItemStack(Item.ingotGold); GameRegistry.addRecipe(new ItemStack(lightStaff, 4), "gng", " s ", " s ", 'n', starStack, 's', stickStack, 'g', goldStack); LanguageRegistry.addName(lightStaff, "Staff of Light"); LanguageRegistry.addName(light, "Light"); LanguageRegistry.instance().addStringLocalization("itemGroup.tabMagicLights", "en_US", MOD_NAME); GameRegistry.registerBlock(light, "light"); GameRegistry.registerTileEntity(flayr.magiclights.tileentities.TileEntityLight.class, "lightTileEntity"); } @Mod.EventHandler public void postInit(FMLPostInitializationEvent event) { // Stub Method } } ClientProxy package flayr.magiclights.client; import cpw.mods.fml.client.registry.ClientRegistry; import flayr.magiclights.CommonProxy; import net.minecraftforge.client.MinecraftForgeClient; public class ClientProxy extends CommonProxy { @Override public void registerRenderers() { ClientRegistry.bindTileEntitySpecialRenderer(flayr.magiclights.tileentities.TileEntityLight.class, new flayr.magiclights.tileentities.LightRenderer()); } } Light package flayr.magiclights; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import flayr.magiclights.tileentities.TileEntityLight; import net.minecraft.block.BlockContainer; import net.minecraft.block.material.Material; import net.minecraft.client.renderer.texture.IconRegister; import net.minecraft.tileentity.TileEntity; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; public class Light extends BlockContainer { public Light (int id, Material material) { super(id, material); } @Override @SideOnly(Side.CLIENT) public boolean shouldSideBeRendered(IBlockAccess iblockaccess, int i, int j, int k, int l) { return false; } public boolean isOpaqueCube() { return false;} @Override public TileEntity createNewTileEntity(World world) { // TODO Auto-generated method stub return new TileEntityLight(); } } TileEntityLight LightRenderer package flayr.magiclights.tileentities; import net.minecraft.client.Minecraft; import net.minecraft.client.entity.AbstractClientPlayer; import net.minecraft.client.renderer.Tessellator; import net.minecraft.client.renderer.entity.RenderManager; import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.ChatMessageComponent; import net.minecraft.util.ChunkCoordinates; import net.minecraft.util.ResourceLocation; import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL12; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; @SideOnly(Side.CLIENT) public class LightRenderer extends TileEntitySpecialRenderer { @Override public void renderTileEntityAt(TileEntity entity, double d, double d1, double d2, float par8) { renderTileEntityAt((TileEntityLight)entity, d, d1, d2, par8); float f1 = 1.6F; float f2 = 0.01666667F * f1; GL11.glPushMatrix(); GL11.glTranslatef((float)d, (float)d1, (float)d2); GL11.glNormal3f(0.0F, 1.0F, 0.0F); GL11.glRotatef(-this.tileEntityRenderer.playerYaw, 0.0F, 1.0F, 0.0F); GL11.glRotatef(this.tileEntityRenderer.playerPitch, 1.0F, 0.0F, 0.0F); GL11.glScalef(-f2, -f2, f2); GL11.glDisable(2896); GL11.glDepthMask(false); GL11.glDisable(2929); GL11.glEnable(3042); GL11.glBlendFunc(770, 771); Tessellator tessellator = Tessellator.instance; byte byte0 = 0; GL11.glDisable(3553); tessellator.disableColor(); tessellator.startDrawingQuads(); int j = 16;//set width of plane here tessellator.setColorRGBA_F(0.0F, 0.0F, 0.0F, 1F); ResourceLocation rl = new ResourceLocation("artifacts:textures/blocks/light"); Minecraft.getMinecraft().renderEngine.bindTexture(rl); tessellator.addVertex(-j - 1, -1 + byte0, 0.0D); tessellator.addVertex(-j - 1, 8 + byte0, 0.0D); tessellator.addVertex(j + 1, 8 + byte0, 0.0D); tessellator.addVertex(j + 1, -1 + byte0, 0.0D); tessellator.draw(); GL11.glPopMatrix(); } package flayr.magiclights.tileentities; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.network.INetworkManager; import net.minecraft.network.packet.Packet; import net.minecraft.network.packet.Packet132TileEntityData; import net.minecraft.tileentity.TileEntity; public class TileEntityLight extends TileEntity { public void writeToNBT(NBTTagCompound nbt) { super.writeToNBT(nbt); } public void readFromNBT(NBTTagCompound nbt) { super.readFromNBT(nbt); } public Packet getDescriptionPacket() { NBTTagCompound nbtTag = new NBTTagCompound(); this.writeToNBT(nbtTag); return new Packet132TileEntityData(this.xCoord, this.yCoord, this.zCoord, 1, nbtTag); } public void onDataPacket(INetworkManager net, Packet132TileEntityData packet) { readFromNBT(packet.data); } } } Any ideas what I am doing wrong? Sorry for being such a bother, I am relatively new to forge modding and have not worked with custom renders yet.
  21. How would I implement this and how do I specify the texture? Thanks in advance.
  22. EDIT: I actually figured out the solutions to my problems on my own, thanks for all the help though! Okay, so I have been trying to find a way to do this for a while now, but I just can't figure it out. I am trying to make a floating sphere block and to do it I want to make a 2d texture that always appears to face the player (like all of the round enemies in super Mario 64). Is there any possible way to do this, and if so how is it done? Also I want to make it a block, not an entity. Edit: I was having so much trouble with the suggested rendering code I just decided to write my own. After writing and debugging it I ran into two different problems. Here is the code to keep in mind while reading them: package flayr.magiclights.tileentities; import org.lwjgl.opengl.GL11; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.Tessellator; import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.ResourceLocation; public class LightRenderer extends TileEntitySpecialRenderer{ public void renderTileEntityAt(TileEntity tileentity, double x, double y, double z, float f) { ResourceLocation rl = new ResourceLocation("minecraft:assets/magiclights/textures/blocks/light.png"); Minecraft.getMinecraft().renderEngine.bindTexture(rl); Tessellator tessellator = Tessellator.instance; GL11.glPushMatrix(); GL11.glTranslated(x+0.5, y+0.5, z+0.5);//+1 so that our "drawing" appears 1 block over our block (to get a better view) GL11.glNormal3f(0.0F, 1.0F, 0.0F); GL11.glRotatef(-this.tileEntityRenderer.playerYaw, 0.0F, 1.0F, 0.0F); GL11.glRotatef(this.tileEntityRenderer.playerPitch, 1.0F, 0.0F, 0.0F); tessellator.startDrawingQuads(); tessellator.addVertex(-0.5, 0.5, 0); tessellator.addVertex(0.5, 0.5, 0); tessellator.addVertex(-0.5, -0.5, 0); tessellator.addVertex(0.5, -0.5, 0); tessellator.addVertex(0.5, -0.5, 0); tessellator.addVertex(-0.5, -0.5, 0); tessellator.addVertex(0.5, 0.5, 0); tessellator.addVertex(-0.5, 0.5, 0); tessellator.draw(); GL11.glPopMatrix(); } } !. In order to render a square with its center as the origin (so I could rotate the square within the block) I had to make two triangles that formed a square (you will see this in the code). I was wondering if anyone had a better way of doing this. 2. I cannot get the proper texture for the drawn object (my texture is located in /forge/mcp/src/minecraft/assets/textures/blocks/light.png), how am I supposed to bind the texture because my current method has failed.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.