Jump to content

Meoco

Forge Modder
  • Posts

    56
  • Joined

  • Last visited

Converted

  • Gender
    Undisclosed

Meoco's Achievements

Stone Miner

Stone Miner (3/8)

2

Reputation

  1. Hello everyone! I am attempting to revive an old mod that I abandoned development on many years ago and have run into an issue. When setting the BlockBehaviour Properties whilst initializing my custom block, I haven't found a way to turn of physical collision but keep occlusion (the "noCollission" method turns off collision and occlusion for some reason). For reference, this is a block that is using a semitransparent texture and is intended to be a block of concentrated darkness. It is a full block with a normal model, but because it is darkness, it is intended to block light. I tried extending the Properties class to make my own method to no avail, is there something I'm missing? Screenshot showing light getting through: tl;dr; How do I disable collision but keep occlusion for a block?
  2. I've tried doing something like that, but as soon as it hits another block, it turns back from entity to block, and I couldn't figure out how to disable the falling... so would I need to create my own entity based on EntityFallingSand, and use that?
  3. Hello! I'm trying to create a block that "absorbs" blocks around it, and I'd like the blocks to visually fly through the air to meet my block. I know iChun uses this effect with the portal gun mod, but it's not open source. long story short, how would I recreate that effect?
  4. Ok, found a couple of problems here, unfortunately... for one, because the animation is handled by the renderer, pausing the game allows the animation code to continue, which is unwanted. Also, I'm still struggling trying to figure out how to smoothly stop the animation, even after your suggestions, TGG. As far as code goes, we'll just say it's the same (I've added a few lines here or there to try and figure out the stopping, but to no avail).
  5. Well, TGG, I tried your idea, and it did not work. I did, however, get it to work by an alternate means. My guess is that the animationOffset variable was being reset in the time between onBlockActivated, and the pump method. This is how I got it to work. Renderer: public class TileEntityExtractorRender extends TileEntitySpecialRenderer { private final ModelExtractor model; public static final ResourceLocation Extractor = new ResourceLocation( Reference.MOD_ID.toLowerCase(), "/textures/models/ModelExtractor.png"); static boolean running = false; public TileEntityExtractorRender() { this.model = new ModelExtractor(); } private void adjustRotatePivotViaMeta(World world, int x, int y, int z) { int meta = world.getBlockMetadata(x, y, z); GL11.glPushMatrix(); GL11.glRotatef(meta * (-90), 0.0F, 0.0F, 1.0F); GL11.glPopMatrix(); } @Override public void renderTileEntityAt(TileEntity te, double x, double y, double z, float scale) { GL11.glPushMatrix(); GL11.glTranslatef((float) x + 0.5F, (float) y + 1.5F, (float) z + 0.5F); Minecraft.getMinecraft().renderEngine.func_110577_a(Extractor); GL11.glPushMatrix(); GL11.glRotatef(180F, 0.0F, 0.0F, 1.0F); TileEntityExtractor tile = (TileEntityExtractor) te; GL11.glRotatef(te.blockMetadata * 90, 0.0F, 1.0F, 0.0F); if(tile.blockMetadata > 3){ if(tile.flag){ tile.animationOffset = System.currentTimeMillis() * -1; tile.flag = false; } this.model.pump(tile.animationOffset); } else{ this.model.slider1.offsetY = 0; this.model.slider2.offsetY = 0; tile.flag = true; } this.model.render((Entity) null, 0.0F, 0.0F, -0.1F, 0.0F, 0.0F, 0.0625F); GL11.glPopMatrix(); GL11.glPopMatrix(); } private void adjustLightFixture(World world, int i, int j, int k, Block block) { Tessellator tess = Tessellator.instance; float brightness = block.getBlockBrightness(world, i, j, k); int skyLight = world.getLightBrightnessForSkyBlocks(i, j, k, 0); int modulousModifier = skyLight % 65536; int divModifier = skyLight / 65536; tess.setColorOpaque_F(brightness, brightness, brightness); OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit,(float) modulousModifier, divModifier); } } Model: public class ModelExtractor extends ModelBase { ModelRenderer top; ModelRenderer bottom; ModelRenderer wall1; ModelRenderer wall2; ModelRenderer wall3; ModelRenderer wall4; ModelRenderer funnel; ModelRenderer beam; public static ModelRenderer slider1; public static ModelRenderer slider2; ModelRenderer output0; ModelRenderer output1; ModelRenderer output2; ModelRenderer output3; ModelRenderer output4; ModelRenderer base1; ModelRenderer base2; ModelRenderer base3; ModelRenderer base4; public ModelExtractor() { textureWidth = 64; textureHeight = 128; top = new ModelRenderer(this, 0, 0); top.addBox(-8F, 0F, -8F, 16, 1, 16); top.setRotationPoint(0F, 8F, 0F); top.setTextureSize(64, 128); top.mirror = true; setRotation(top, 0F, 0F, 0F); bottom = new ModelRenderer(this, 0, 0); bottom.addBox(-8F, 0F, -8F, 16, 1, 16); bottom.setRotationPoint(0F, 23F, 0F); bottom.setTextureSize(64, 128); bottom.mirror = true; setRotation(bottom, 0F, 0F, 0F); wall1 = new ModelRenderer(this, 0, 17); wall1.addBox(-8F, -1F, 0F, 18, 3, 1); wall1.setRotationPoint(-1F, 7F, -9F); wall1.setTextureSize(64, 128); wall1.mirror = true; setRotation(wall1, 0F, 0F, 0F); wall2 = new ModelRenderer(this, 0, 21); wall2.addBox(17F, -1F, -8F, 1, 3, 16); wall2.setRotationPoint(-9F, 7F, 0F); wall2.setTextureSize(64, 128); wall2.mirror = true; setRotation(wall2, 0F, 0F, 0F); wall3 = new ModelRenderer(this, 0, 17); wall3.addBox(-8F, -1F, 0F, 18, 3, 1); wall3.setRotationPoint(-1F, 7F, 8F); wall3.setTextureSize(64, 128); wall3.mirror = true; setRotation(wall3, 0F, 0F, 0F); wall4 = new ModelRenderer(this, 0, 21); wall4.addBox(0F, -1F, -8F, 1, 3, 16); wall4.setRotationPoint(-9F, 7F, 0F); wall4.setTextureSize(64, 128); wall4.mirror = true; setRotation(wall4, 0F, 0F, 0F); funnel = new ModelRenderer(this, 0, 59); funnel.addBox(-5F, -1F, -5F, 10, 2, 10); funnel.setRotationPoint(0F, 10F, 0F); funnel.setTextureSize(64, 128); funnel.mirror = true; setRotation(funnel, 0F, 0F, 0F); beam = new ModelRenderer(this, 0, 40); beam.addBox(-3F, -1F, -3F, 6, 13, 6); beam.setRotationPoint(0F, 11F, 0F); beam.setTextureSize(64, 128); beam.mirror = true; setRotation(beam, 0F, 0F, 0F); slider1 = new ModelRenderer(this, 0, 71); slider1.addBox(1F, -2F, -4F, 4, 4, ; slider1.setRotationPoint(0F, 21F, 0F); slider1.setTextureSize(64, 128); slider1.mirror = true; setRotation(slider1, 0F, 0F, 0F); slider2 = new ModelRenderer(this, 24, 71); slider2.addBox(-5F, -2F, -4F, 4, 4, ; slider2.setRotationPoint(0F, 21F, 0F); slider2.setTextureSize(64, 128); slider2.mirror = true; setRotation(slider2, 0F, 0F, 0F); output0 = new ModelRenderer(this, 0, 89); output0.addBox(-1F, -1F, 0F, 2, 2, 1); output0.setRotationPoint(0F, 16F, -4F); output0.setTextureSize(64, 128); output0.mirror = true; setRotation(output0, 0F, 0F, 0F); output1 = new ModelRenderer(this, 0, 83); output1.addBox(-3F, -3F, -1F, 6, 2, 4); output1.setRotationPoint(0F, 20F, -7F); output1.setTextureSize(64, 128); output1.mirror = true; setRotation(output1, 0F, 0F, 0F); output2 = new ModelRenderer(this, 0, 83); output2.addBox(-3F, -3F, -1F, 6, 2, 4); output2.setRotationPoint(0F, 16F, -7F); output2.setTextureSize(64, 128); output2.mirror = true; setRotation(output2, 0F, 0F, 0F); output3 = new ModelRenderer(this, 0, 92); output3.addBox(-3F, -3F, -1F, 2, 2, 4); output3.setRotationPoint(4F, 18F, -7F); output3.setTextureSize(64, 128); output3.mirror = true; setRotation(output3, 0F, 0F, 0F); output4 = new ModelRenderer(this, 0, 92); output4.addBox(-3F, -3F, -1F, 2, 2, 4); output4.setRotationPoint(0F, 18F, -7F); output4.setTextureSize(64, 128); output4.mirror = true; setRotation(output4, 0F, 0F, 0F); base1 = new ModelRenderer(this, 0, 102); base1.addBox(0F, 0F, -8F, 2, 1, 14); base1.setRotationPoint(5F, 22F, 1F); base1.setTextureSize(64, 128); base1.mirror = true; setRotation(base1, 0F, 0F, 0F); base2 = new ModelRenderer(this, 0, 102); base2.addBox(0F, 0F, -8F, 2, 1, 14); base2.setRotationPoint(-7F, 22F, 1F); base2.setTextureSize(64, 128); base2.mirror = true; setRotation(base2, 0F, 0F, 0F); base3 = new ModelRenderer(this, 0, 98); base3.addBox(0F, 0F, -8F, 10, 1, 3); base3.setRotationPoint(-5F, 22F, 12F); base3.setTextureSize(64, 128); base3.mirror = true; setRotation(base3, 0F, 0F, 0F); base4 = new ModelRenderer(this, 0, 98); base4.addBox(0F, 0F, -7F, 10, 1, 3); base4.setRotationPoint(-5F, 22F, 0F); base4.setTextureSize(64, 128); base4.mirror = true; setRotation(base4, 0F, 0F, 0F); } public void render(Entity entity, float f, float f1, float f2, float f3, float f4, float f5) { super.render(entity, f, f1, f2, f3, f4, f5); setRotationAngles(f, f1, f2, f3, f4, f5, entity); top.render(f5); bottom.render(f5); wall1.render(f5); wall2.render(f5); wall3.render(f5); wall4.render(f5); funnel.render(f5); beam.render(f5); slider1.render(f5); slider2.render(f5); output0.render(f5); output1.render(f5); output2.render(f5); output3.render(f5); output4.render(f5); base1.render(f5); base2.render(f5); base3.render(f5); base4.render(f5); } private void setRotation(ModelRenderer model, float x, float y, float z) { model.rotateAngleX = x; model.rotateAngleY = y; model.rotateAngleZ = z; } public void setRotationAngles(float f, float f1, float f2, float f3, float f4, float f5, Entity entity) { super.setRotationAngles(f, f1, f2, f3, f4, f5, entity); } public void pump(long animationOffset){ final long CYCLE_TIME_IN_MS = 3000; final long HALF_CYCLE_TIME_IN_MS = CYCLE_TIME_IN_MS / 2; final float START_SLIDER_POS = 0.0F; final float MID_CYCLE_SLIDER_POS = -0.5F; long time = (System.currentTimeMillis() + animationOffset) % CYCLE_TIME_IN_MS; if (time < HALF_CYCLE_TIME_IN_MS) { slider1.offsetY = START_SLIDER_POS + (time / (float)HALF_CYCLE_TIME_IN_MS) * (MID_CYCLE_SLIDER_POS - START_SLIDER_POS); } else { time -= HALF_CYCLE_TIME_IN_MS; slider1.offsetY = MID_CYCLE_SLIDER_POS + (time / (float)HALF_CYCLE_TIME_IN_MS) * (START_SLIDER_POS - MID_CYCLE_SLIDER_POS); } slider2.offsetY = slider1.offsetY; } } Block: public class BlockExtractor extends Block { public BlockExtractor(int par1, Material par2Material) { super(par1, par2Material); this.setHardness(10); this.setCreativeTab(BlockTab.blockTab); this.setUnlocalizedName("Extractor"); } @Override public boolean canConnectRedstone(IBlockAccess world, int x, int y, int z, int side) { return true; } @Override public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entity, ItemStack stack) { if (entity == null) { return; } TileEntityExtractor tile = (TileEntityExtractor) world.getBlockTileEntity(x, y, z); if(!world.isRemote){ world.setBlockMetadataWithNotify(x, y, z, MathHelper.floor_double((double)(entity.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3, 3); } } @Override @SideOnly(Side.CLIENT) public void registerIcons(IconRegister iconRegister) { blockIcon = iconRegister.registerIcon(Methods.textureName(this .getUnlocalizedName())); } @Override public boolean hasTileEntity(int metadata) { return true; } @Override public boolean renderAsNormalBlock() { return false; } @Override public boolean isOpaqueCube() { return false; } @Override public TileEntity createTileEntity(World world, int metadata) { return new TileEntityExtractor(); } @Override public int getRenderType() { return -1; } @Override public void setBlockBoundsBasedOnState(IBlockAccess par1IBlockAccess, int par2, int par3, int par4) { this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F); } public boolean onBlockActivated(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9) { if(!par1World.isRemote){ if(par5EntityPlayer.getCurrentEquippedItem() == null){ int meta = par1World.getBlockMetadata(par2, par3, par4); if(meta < 4){ meta += 4; } else{ meta -= 4; } par1World.setBlockMetadataWithNotify(par2, par3, par4, meta, 3); } } return false; } public static void extract(World world, int x, int y, int z){ double posx = 0; double posz = 0; double velx = 0; double velz = 0; if(!world.isRemote){ switch(world.getBlockMetadata(x, y, z)){ case 0: { posx = x + 0.5; posz = z - 0.6; velz = -1; velx = 0; }; break; case 1: { posx = x + 1.5; posz = z + 0.5; velx = 1; velz = 0; }; break; case 2: { posx = x + 0.5; posz = z + 1.5; velz = 1; velx = 0; } break; case 3: { posx = x - 0.6; posz = z + 0.5; velx = -1; velz = 0; } break; } } ItemStack LightStack = new ItemStack(Items.ItemLightBall, 1); EntityItem LightItem = new EntityItem(world, posx, y + 0.5, posz, LightStack); LightItem.motionX = velx; LightItem.motionY = 0; LightItem.motionZ = velz; ItemStack DarkStack = new ItemStack(Items.ItemDarkBall, 1); EntityItem DarkItem = new EntityItem(world, posx, y + 0.5, posz, DarkStack); DarkItem.motionX = velx; DarkItem.motionY = 0; DarkItem.motionZ = velz; int ID = world.getBlockId(x, y + 1, z); if(!world.isRemote){ if(ID == IDRef.LIGHT_WOOD_ID){ world.setBlockToAir(x, y + 1, z); world.spawnEntityInWorld(LightItem); } if(ID == IDRef.DARK_LEAF_ID){ world.setBlockToAir(x, y + 1, z); world.spawnEntityInWorld(DarkItem); } } } } TileEntity: public class TileEntityExtractor extends TileEntity{ public TileEntityExtractor(){ animationOffset = System.nanoTime() % 400000; flag = true; } public long animationOffset; public boolean flag; } By making the change to the offset in the same method, I knew it would make the change happen directly before the animation, and it worked! Now the only problem I'm having is stopping it. I'd like for the sliders to gracefully slide back to 0 when it's turned off, and so far, I've only managed to make it instantly jump.
  6. Huzzah!!! Thank you SO much, everyone. It's working perfectly now (apart from the item instance spazzing out, but I'm certain I can handle that. )!! Btw, I'll be adding your names to the "special thanks" section of the mod info, so you get the credit you deserve for your invaluable help! EDIT: Actually, I have ONE more question! I'm making this animation toggle-able on right-click, which is working just fine, but the problem is that due to the animation being set via the time, when the animation starts, it jumps to whatever time value the tile entity has and starts from there. At the moment, I'm adding 4 to the block's metadata on right click (or subtracting 4 if it's 4 or above). The animation will only run on extractors with a metadata higher than 3, so all the basic rotations do not animate until right clicked. I've also set the yOffset of both sliders to 0 if the metadata is less than 4... long story short, how do I smooth out the animation's start? in the block: public boolean onBlockActivated(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9) { if(!par1World.isRemote){ if(par5EntityPlayer.getCurrentEquippedItem() == null){ int meta = par1World.getBlockMetadata(par2, par3, par4); if(meta < 4){ meta += 4; } else{ meta -= 4; } par1World.setBlockMetadataWithNotify(par2, par3, par4, meta, 3); } } return false; } in the model: public void pump(long animationOffset){ final long CYCLE_TIME_IN_MS = 2000; final long HALF_CYCLE_TIME_IN_MS = CYCLE_TIME_IN_MS / 2; final float START_SLIDER_POS = 0.0F; final float MID_CYCLE_SLIDER_POS = -0.5F; long time = (System.currentTimeMillis() + animationOffset) % CYCLE_TIME_IN_MS; if (time < HALF_CYCLE_TIME_IN_MS) { slider1.offsetY = START_SLIDER_POS + (time / (float)HALF_CYCLE_TIME_IN_MS) * (MID_CYCLE_SLIDER_POS - START_SLIDER_POS); } else { time -= HALF_CYCLE_TIME_IN_MS; slider1.offsetY = MID_CYCLE_SLIDER_POS + (time / (float)HALF_CYCLE_TIME_IN_MS) * (START_SLIDER_POS - MID_CYCLE_SLIDER_POS); } slider2.offsetY = slider1.offsetY; } in the renderer: public void renderTileEntityAt(TileEntity te, double x, double y, double z, float scale) { GL11.glPushMatrix(); GL11.glTranslatef((float) x + 0.5F, (float) y + 1.5F, (float) z + 0.5F); Minecraft.getMinecraft().renderEngine.func_110577_a(Extractor); GL11.glPushMatrix(); GL11.glRotatef(180F, 0.0F, 0.0F, 1.0F); TileEntityExtractor tile = (TileEntityExtractor) te; GL11.glRotatef(te.blockMetadata * 90, 0.0F, 1.0F, 0.0F); if(tile.blockMetadata > 3){ this.model.pump(tile.animationOffset); } else{ this.model.slider1.offsetY = 0; this.model.slider2.offsetY = 0; } this.model.render((Entity) null, 0.0F, 0.0F, -0.1F, 0.0F, 0.0F, 0.0625F); GL11.glPopMatrix(); GL11.glPopMatrix(); }
  7. Well, all of the extractors are animating independently now, but it just jumps from the bottom to the top, and back, no smooth motion. So I'll try and figure out how to fix that, but other than that, it's working fine!
  8. The long variable came from TheGreyGhost's suggestion. Model public class ModelExtractor extends ModelBase { ModelRenderer top; ModelRenderer bottom; ModelRenderer wall1; ModelRenderer wall2; ModelRenderer wall3; ModelRenderer wall4; ModelRenderer funnel; ModelRenderer beam; ModelRenderer slider1; ModelRenderer slider2; ModelRenderer output0; ModelRenderer output1; ModelRenderer output2; ModelRenderer output3; ModelRenderer output4; ModelRenderer base1; ModelRenderer base2; ModelRenderer base3; ModelRenderer base4; public ModelExtractor() { textureWidth = 64; textureHeight = 128; top = new ModelRenderer(this, 0, 0); top.addBox(-8F, 0F, -8F, 16, 1, 16); top.setRotationPoint(0F, 8F, 0F); top.setTextureSize(64, 128); top.mirror = true; setRotation(top, 0F, 0F, 0F); bottom = new ModelRenderer(this, 0, 0); bottom.addBox(-8F, 0F, -8F, 16, 1, 16); bottom.setRotationPoint(0F, 23F, 0F); bottom.setTextureSize(64, 128); bottom.mirror = true; setRotation(bottom, 0F, 0F, 0F); wall1 = new ModelRenderer(this, 0, 17); wall1.addBox(-8F, -1F, 0F, 18, 3, 1); wall1.setRotationPoint(-1F, 7F, -9F); wall1.setTextureSize(64, 128); wall1.mirror = true; setRotation(wall1, 0F, 0F, 0F); wall2 = new ModelRenderer(this, 0, 21); wall2.addBox(17F, -1F, -8F, 1, 3, 16); wall2.setRotationPoint(-9F, 7F, 0F); wall2.setTextureSize(64, 128); wall2.mirror = true; setRotation(wall2, 0F, 0F, 0F); wall3 = new ModelRenderer(this, 0, 17); wall3.addBox(-8F, -1F, 0F, 18, 3, 1); wall3.setRotationPoint(-1F, 7F, 8F); wall3.setTextureSize(64, 128); wall3.mirror = true; setRotation(wall3, 0F, 0F, 0F); wall4 = new ModelRenderer(this, 0, 21); wall4.addBox(0F, -1F, -8F, 1, 3, 16); wall4.setRotationPoint(-9F, 7F, 0F); wall4.setTextureSize(64, 128); wall4.mirror = true; setRotation(wall4, 0F, 0F, 0F); funnel = new ModelRenderer(this, 0, 59); funnel.addBox(-5F, -1F, -5F, 10, 2, 10); funnel.setRotationPoint(0F, 10F, 0F); funnel.setTextureSize(64, 128); funnel.mirror = true; setRotation(funnel, 0F, 0F, 0F); beam = new ModelRenderer(this, 0, 40); beam.addBox(-3F, -1F, -3F, 6, 13, 6); beam.setRotationPoint(0F, 11F, 0F); beam.setTextureSize(64, 128); beam.mirror = true; setRotation(beam, 0F, 0F, 0F); slider1 = new ModelRenderer(this, 0, 71); slider1.addBox(1F, -2F, -4F, 4, 4, ; slider1.setRotationPoint(0F, 21F, 0F); slider1.setTextureSize(64, 128); slider1.mirror = true; setRotation(slider1, 0F, 0F, 0F); slider2 = new ModelRenderer(this, 24, 71); slider2.addBox(-5F, -2F, -4F, 4, 4, ; slider2.setRotationPoint(0F, 21F, 0F); slider2.setTextureSize(64, 128); slider2.mirror = true; setRotation(slider2, 0F, 0F, 0F); output0 = new ModelRenderer(this, 0, 89); output0.addBox(-1F, -1F, 0F, 2, 2, 1); output0.setRotationPoint(0F, 16F, -4F); output0.setTextureSize(64, 128); output0.mirror = true; setRotation(output0, 0F, 0F, 0F); output1 = new ModelRenderer(this, 0, 83); output1.addBox(-3F, -3F, -1F, 6, 2, 4); output1.setRotationPoint(0F, 20F, -7F); output1.setTextureSize(64, 128); output1.mirror = true; setRotation(output1, 0F, 0F, 0F); output2 = new ModelRenderer(this, 0, 83); output2.addBox(-3F, -3F, -1F, 6, 2, 4); output2.setRotationPoint(0F, 16F, -7F); output2.setTextureSize(64, 128); output2.mirror = true; setRotation(output2, 0F, 0F, 0F); output3 = new ModelRenderer(this, 0, 92); output3.addBox(-3F, -3F, -1F, 2, 2, 4); output3.setRotationPoint(4F, 18F, -7F); output3.setTextureSize(64, 128); output3.mirror = true; setRotation(output3, 0F, 0F, 0F); output4 = new ModelRenderer(this, 0, 92); output4.addBox(-3F, -3F, -1F, 2, 2, 4); output4.setRotationPoint(0F, 18F, -7F); output4.setTextureSize(64, 128); output4.mirror = true; setRotation(output4, 0F, 0F, 0F); base1 = new ModelRenderer(this, 0, 102); base1.addBox(0F, 0F, -8F, 2, 1, 14); base1.setRotationPoint(5F, 22F, 1F); base1.setTextureSize(64, 128); base1.mirror = true; setRotation(base1, 0F, 0F, 0F); base2 = new ModelRenderer(this, 0, 102); base2.addBox(0F, 0F, -8F, 2, 1, 14); base2.setRotationPoint(-7F, 22F, 1F); base2.setTextureSize(64, 128); base2.mirror = true; setRotation(base2, 0F, 0F, 0F); base3 = new ModelRenderer(this, 0, 98); base3.addBox(0F, 0F, -8F, 10, 1, 3); base3.setRotationPoint(-5F, 22F, 12F); base3.setTextureSize(64, 128); base3.mirror = true; setRotation(base3, 0F, 0F, 0F); base4 = new ModelRenderer(this, 0, 98); base4.addBox(0F, 0F, -7F, 10, 1, 3); base4.setRotationPoint(-5F, 22F, 0F); base4.setTextureSize(64, 128); base4.mirror = true; setRotation(base4, 0F, 0F, 0F); } public void render(Entity entity, float f, float f1, float f2, float f3, float f4, float f5) { super.render(entity, f, f1, f2, f3, f4, f5); setRotationAngles(f, f1, f2, f3, f4, f5, entity); top.render(f5); bottom.render(f5); wall1.render(f5); wall2.render(f5); wall3.render(f5); wall4.render(f5); funnel.render(f5); beam.render(f5); slider1.render(f5); slider2.render(f5); output0.render(f5); output1.render(f5); output2.render(f5); output3.render(f5); output4.render(f5); base1.render(f5); base2.render(f5); base3.render(f5); base4.render(f5); } private void setRotation(ModelRenderer model, float x, float y, float z) { model.rotateAngleX = x; model.rotateAngleY = y; model.rotateAngleZ = z; } public void setRotationAngles(float f, float f1, float f2, float f3, float f4, float f5, Entity entity) { super.setRotationAngles(f, f1, f2, f3, f4, f5, entity); } static boolean down = false; public void pump(long animationOffset){ long time = ((System.currentTimeMillis() + animationOffset) % 40000L) * -1; slider1.offsetY = time; System.out.println(time); } } Renderer public class TileEntityExtractorRender extends TileEntitySpecialRenderer { private final ModelExtractor model; public static final ResourceLocation Extractor = new ResourceLocation( Reference.MOD_ID.toLowerCase(), "/textures/models/ModelExtractor.png"); static boolean running = false; public TileEntityExtractorRender() { this.model = new ModelExtractor(); } private void adjustRotatePivotViaMeta(World world, int x, int y, int z) { int meta = world.getBlockMetadata(x, y, z); GL11.glPushMatrix(); GL11.glRotatef(meta * (-90), 0.0F, 0.0F, 1.0F); GL11.glPopMatrix(); } @Override public void renderTileEntityAt(TileEntity te, double x, double y, double z, float scale) { GL11.glPushMatrix(); GL11.glTranslatef((float) x + 0.5F, (float) y + 1.5F, (float) z + 0.5F); Minecraft.getMinecraft().renderEngine.func_110577_a(Extractor); GL11.glPushMatrix(); GL11.glRotatef(180F, 0.0F, 0.0F, 1.0F); TileEntityExtractor tile = (TileEntityExtractor) te; GL11.glRotatef(te.blockMetadata * 90, 0.0F, 1.0F, 0.0F); this.model.pump(tile.animationOffset); this.model.render((Entity) null, 0.0F, 0.0F, -0.1F, 0.0F, 0.0F, 0.0625F); GL11.glPopMatrix(); GL11.glPopMatrix(); } private void adjustLightFixture(World world, int i, int j, int k, Block block) { Tessellator tess = Tessellator.instance; float brightness = block.getBlockBrightness(world, i, j, k); int skyLight = world.getLightBrightnessForSkyBlocks(i, j, k, 0); int modulousModifier = skyLight % 65536; int divModifier = skyLight / 65536; tess.setColorOpaque_F(brightness, brightness, brightness); OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit,(float) modulousModifier, divModifier); } } Tile Entity public class TileEntityExtractor extends TileEntity{ public TileEntityExtractor(){ animationOffset = System.nanoTime() % 40000; } long animationOffset; } The println in the pump method gives me like -35000 (I inverted it because slider1.offsetY starts at 0 and goes down). With those kinds of numbers, my slider is thousands of blocks in the air, not where I want it. lol Did I do something wrong, or am I missing something? What's the deal? I suppose I could try to change the modulus values, but even then, it acted jerky and wild, and I couldn't tell if it was actually working as intended anyway. haha
  9. I had actually realized that I needed to be getting the variable from "tile" in this case, right after I had tried it out with this new way. -.- Now I have a long variable, and no clue what to do with it. Putting it directly into my motion code shoots the sliders to somewhere around 57,000, which is not ideal. If I'm not mistaken, model offset values are floats, so do I need some sort of cast or conversion, or am I missing something?
  10. I actually tried doing something very similar, and I can't get access to the method from the te instance called in renderTileEntityAt. At least not that I could see. It seems that "te" refers to the base tileEntity class, not TileEntityExtractor. the quest continues! lol EDIT: still giving it a shot. Couldn't hurt! lol
  11. Actually, I've since removed the "direction" variable, and opted for an alternate approach. I've got rotation down just fine, but the instanced animation is the thing killing me. lol public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entity, ItemStack stack) { if (entity == null) { return; } TileEntityExtractor tile = (TileEntityExtractor) world.getBlockTileEntity(x, y, z); if(!world.isRemote){ world.setBlockMetadataWithNotify(x, y, z, MathHelper.floor_double((double)(entity.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3, 3); } } There's the rotation detection method. Then in my model's renderer, I have TileEntityExtractor tile = (TileEntityExtractor) te; GL11.glRotatef(te.blockMetadata * 90, 0.0F, 1.0F, 0.0F); in my "renderTileEntityAt" method. That part all works fine and dandy. lol (I did need a glRotate on the item renderer to make it face the proper way, but oh well.) Any clues on the animation?
  12. How would I go about making changes to a block model (i.e. animations and block rotation) based on each instance of the block, and not change globally? I don't know of any other way to animate or rotate than changing values in the model class, which causes a global change. Am I initializing my model incorrectly, or what? lol block: public class BlockExtractor extends Block { public BlockExtractor(int par1, Material par2Material) { super(par1, par2Material); this.setHardness(10); this.setCreativeTab(BlockTab.blockTab); this.setUnlocalizedName("Extractor"); } public static boolean flag1; @Override public boolean canConnectRedstone(IBlockAccess world, int x, int y, int z, int side) { return true; } @Override public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entity, ItemStack stack) { if (entity == null) { return; } TileEntityExtractor tile = (TileEntityExtractor) world.getBlockTileEntity(x, y, z); tile.direction = MathHelper.floor_double((double)(entity.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3; } @Override @SideOnly(Side.CLIENT) public void registerIcons(IconRegister iconRegister) { blockIcon = iconRegister.registerIcon(Methods.textureName(this .getUnlocalizedName())); } @Override public boolean hasTileEntity(int metadata) { return true; } @Override public boolean renderAsNormalBlock() { return false; } @Override public boolean isOpaqueCube() { return false; } @Override public TileEntity createTileEntity(World world, int metadata) { return new TileEntityExtractor(); } @Override public int getRenderType() { return -1; } public void addCollisionBoxesToList(World par1World, int par2, int par3, int par4, AxisAlignedBB par5AxisAlignedBB, List par6List, Entity par7Entity) { this.setBlockBounds(-0.065F, 0.0F, -0.065F, 1.045F, 1.1F, 1.045F); super.addCollisionBoxesToList(par1World, par2, par3, par4, par5AxisAlignedBB, par6List, par7Entity); } @Override public void setBlockBoundsBasedOnState(IBlockAccess par1IBlockAccess, int par2, int par3, int par4) { this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F); } public boolean onBlockActivated(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9) { extract(par1World,par2,par3,par4); return false; } public static void extract(World world, int x, int y, int z){ ItemStack LightStack = new ItemStack(Items.ItemLightBall, 1); EntityItem LightItem = new EntityItem(world, x + 0.5, y + 0.5, z - 0.6, LightStack); LightItem.motionX = 0; LightItem.motionY = 0; LightItem.motionZ = -1; ItemStack DarkStack = new ItemStack(Items.ItemDarkBall, 1); EntityItem DarkItem = new EntityItem(world, x + 0.5, y + 0.5, z - 0.6, DarkStack); DarkItem.motionX = 0; DarkItem.motionY = 0; DarkItem.motionZ = -1; int ID = world.getBlockId(x, y + 1, z); if(!world.isRemote){ if(ID == IDRef.LIGHT_WOOD_ID){ world.setBlockToAir(x, y + 1, z); world.spawnEntityInWorld(LightItem); } if(ID == IDRef.DARK_LEAF_ID){ world.setBlockToAir(x, y + 1, z); world.spawnEntityInWorld(DarkItem); } } } } Renderer: public class TileEntityExtractorRender extends TileEntitySpecialRenderer { private final ModelExtractor model; public static final ResourceLocation Extractor = new ResourceLocation( Reference.MOD_ID.toLowerCase(), "/textures/models/ModelExtractor.png"); static boolean running = false; public TileEntityExtractorRender() { this.model = new ModelExtractor(); } private void adjustRotatePivotViaMeta(World world, int x, int y, int z) { int meta = world.getBlockMetadata(x, y, z); GL11.glPushMatrix(); GL11.glRotatef(meta * (-90), 0.0F, 0.0F, 1.0F); GL11.glPopMatrix(); } @Override public void renderTileEntityAt(TileEntity te, double x, double y, double z, float scale) { GL11.glPushMatrix(); GL11.glTranslatef((float) x + 0.5F, (float) y + 1.5F, (float) z + 0.5F); Minecraft.getMinecraft().renderEngine.func_110577_a(Extractor); GL11.glPushMatrix(); GL11.glRotatef(180F, 0.0F, 0.0F, 1.0F); TileEntityExtractor tile = (TileEntityExtractor) te; int direction = tile.direction; GL11.glRotatef(direction * 90, 0.0F, 1.0F, 0.0F); this.model.render((Entity) null, 0.0F, 0.0F, -0.1F, 0.0F, 0.0F, 0.0625F); GL11.glPopMatrix(); GL11.glPopMatrix(); } private void adjustLightFixture(World world, int i, int j, int k, Block block) { Tessellator tess = Tessellator.instance; float brightness = block.getBlockBrightness(world, i, j, k); int skyLight = world.getLightBrightnessForSkyBlocks(i, j, k, 0); int modulousModifier = skyLight % 65536; int divModifier = skyLight / 65536; tess.setColorOpaque_F(brightness, brightness, brightness); OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit,(float) modulousModifier, divModifier); } } Model: public class ModelExtractor extends ModelBase { ModelRenderer top; ModelRenderer bottom; ModelRenderer wall1; ModelRenderer wall2; ModelRenderer wall3; ModelRenderer wall4; ModelRenderer funnel; ModelRenderer beam; public static ModelRenderer slider1; public static ModelRenderer slider2; ModelRenderer output0; ModelRenderer output1; ModelRenderer output2; ModelRenderer output3; ModelRenderer output4; ModelRenderer base1; ModelRenderer base2; ModelRenderer base3; ModelRenderer base4; public ModelExtractor() { textureWidth = 64; textureHeight = 128; top = new ModelRenderer(this, 0, 0); top.addBox(-8F, 0F, -8F, 16, 1, 16); top.setRotationPoint(0F, 8F, 0F); top.setTextureSize(64, 128); top.mirror = true; setRotation(top, 0F, 0F, 0F); bottom = new ModelRenderer(this, 0, 0); bottom.addBox(-8F, 0F, -8F, 16, 1, 16); bottom.setRotationPoint(0F, 23F, 0F); bottom.setTextureSize(64, 128); bottom.mirror = true; setRotation(bottom, 0F, 0F, 0F); wall1 = new ModelRenderer(this, 0, 17); wall1.addBox(-8F, -1F, 0F, 18, 3, 1); wall1.setRotationPoint(-1F, 7F, -9F); wall1.setTextureSize(64, 128); wall1.mirror = true; setRotation(wall1, 0F, 0F, 0F); wall2 = new ModelRenderer(this, 0, 21); wall2.addBox(17F, -1F, -8F, 1, 3, 16); wall2.setRotationPoint(-9F, 7F, 0F); wall2.setTextureSize(64, 128); wall2.mirror = true; setRotation(wall2, 0F, 0F, 0F); wall3 = new ModelRenderer(this, 0, 17); wall3.addBox(-8F, -1F, 0F, 18, 3, 1); wall3.setRotationPoint(-1F, 7F, 8F); wall3.setTextureSize(64, 128); wall3.mirror = true; setRotation(wall3, 0F, 0F, 0F); wall4 = new ModelRenderer(this, 0, 21); wall4.addBox(0F, -1F, -8F, 1, 3, 16); wall4.setRotationPoint(-9F, 7F, 0F); wall4.setTextureSize(64, 128); wall4.mirror = true; setRotation(wall4, 0F, 0F, 0F); funnel = new ModelRenderer(this, 0, 59); funnel.addBox(-5F, -1F, -5F, 10, 2, 10); funnel.setRotationPoint(0F, 10F, 0F); funnel.setTextureSize(64, 128); funnel.mirror = true; setRotation(funnel, 0F, 0F, 0F); beam = new ModelRenderer(this, 0, 40); beam.addBox(-3F, -1F, -3F, 6, 13, 6); beam.setRotationPoint(0F, 11F, 0F); beam.setTextureSize(64, 128); beam.mirror = true; setRotation(beam, 0F, 0F, 0F); slider1 = new ModelRenderer(this, 0, 71); slider1.addBox(1F, -2F, -4F, 4, 4, ; slider1.setRotationPoint(0F, 21F, 0F); slider1.setTextureSize(64, 128); slider1.mirror = true; setRotation(slider1, 0F, 0F, 0F); slider2 = new ModelRenderer(this, 24, 71); slider2.addBox(-5F, -2F, -4F, 4, 4, ; slider2.setRotationPoint(0F, 21F, 0F); slider2.setTextureSize(64, 128); slider2.mirror = true; setRotation(slider2, 0F, 0F, 0F); output0 = new ModelRenderer(this, 0, 89); output0.addBox(-1F, -1F, 0F, 2, 2, 1); output0.setRotationPoint(0F, 16F, -4F); output0.setTextureSize(64, 128); output0.mirror = true; setRotation(output0, 0F, 0F, 0F); output1 = new ModelRenderer(this, 0, 83); output1.addBox(-3F, -3F, -1F, 6, 2, 4); output1.setRotationPoint(0F, 20F, -7F); output1.setTextureSize(64, 128); output1.mirror = true; setRotation(output1, 0F, 0F, 0F); output2 = new ModelRenderer(this, 0, 83); output2.addBox(-3F, -3F, -1F, 6, 2, 4); output2.setRotationPoint(0F, 16F, -7F); output2.setTextureSize(64, 128); output2.mirror = true; setRotation(output2, 0F, 0F, 0F); output3 = new ModelRenderer(this, 0, 92); output3.addBox(-3F, -3F, -1F, 2, 2, 4); output3.setRotationPoint(4F, 18F, -7F); output3.setTextureSize(64, 128); output3.mirror = true; setRotation(output3, 0F, 0F, 0F); output4 = new ModelRenderer(this, 0, 92); output4.addBox(-3F, -3F, -1F, 2, 2, 4); output4.setRotationPoint(0F, 18F, -7F); output4.setTextureSize(64, 128); output4.mirror = true; setRotation(output4, 0F, 0F, 0F); base1 = new ModelRenderer(this, 0, 102); base1.addBox(0F, 0F, -8F, 2, 1, 14); base1.setRotationPoint(5F, 22F, 1F); base1.setTextureSize(64, 128); base1.mirror = true; setRotation(base1, 0F, 0F, 0F); base2 = new ModelRenderer(this, 0, 102); base2.addBox(0F, 0F, -8F, 2, 1, 14); base2.setRotationPoint(-7F, 22F, 1F); base2.setTextureSize(64, 128); base2.mirror = true; setRotation(base2, 0F, 0F, 0F); base3 = new ModelRenderer(this, 0, 98); base3.addBox(0F, 0F, -8F, 10, 1, 3); base3.setRotationPoint(-5F, 22F, 12F); base3.setTextureSize(64, 128); base3.mirror = true; setRotation(base3, 0F, 0F, 0F); base4 = new ModelRenderer(this, 0, 98); base4.addBox(0F, 0F, -7F, 10, 1, 3); base4.setRotationPoint(-5F, 22F, 0F); base4.setTextureSize(64, 128); base4.mirror = true; setRotation(base4, 0F, 0F, 0F); } public void render(Entity entity, float f, float f1, float f2, float f3, float f4, float f5) { super.render(entity, f, f1, f2, f3, f4, f5); setRotationAngles(f, f1, f2, f3, f4, f5, entity); top.render(f5); bottom.render(f5); wall1.render(f5); wall2.render(f5); wall3.render(f5); wall4.render(f5); funnel.render(f5); beam.render(f5); slider1.render(f5); slider2.render(f5); output0.render(f5); output1.render(f5); output2.render(f5); output3.render(f5); output4.render(f5); base1.render(f5); base2.render(f5); base3.render(f5); base4.render(f5); } private void setRotation(ModelRenderer model, float x, float y, float z) { model.rotateAngleX = x; model.rotateAngleY = y; model.rotateAngleZ = z; } public void setRotationAngles(float f, float f1, float f2, float f3, float f4, float f5, Entity entity) { super.setRotationAngles(f, f1, f2, f3, f4, f5, entity); } static boolean down = false; public static void pump(){ if(slider1.offsetY > 0.0){ down = true; } if(slider1.offsetY < -0.5){ down = false; } long time = System.currentTimeMillis() % 40000L; if(down){ slider1.offsetY -= 0.01; } if(!down){ slider1.offsetY += 0.01; } slider2.offsetY = slider1.offsetY; } } Item Renderer: public class ItemExtractorRenderer implements IItemRenderer { private ModelExtractor ExtractorModel; public ItemExtractorRenderer() { ExtractorModel = new ModelExtractor(); } @Override public boolean handleRenderType(ItemStack item, ItemRenderType type) { return true; } @Override public boolean shouldUseRenderHelper(ItemRenderType type, ItemStack item, ItemRendererHelper helper) { return true; } @Override public void renderItem(ItemRenderType type, ItemStack item, Object... data) { TileEntityRenderer.instance.renderTileEntityAt(new TileEntityExtractor(), 0.0D, 0.0D, 0.0D, 0.0F); } } my tile entity just initializes the variable "direction," as I was hoping that storing it in the te would make it instanced. Right now, the block model will rotate to face the player on placement, but all instances rotate to match the last one placed (including ones in the inventory). Also, the pumping animation works, but it's all at the same rate and progress. I'd like the animation to be toggleable at some point, but that's not as important. The animation is called in my tick handler, to clarify that. tl;dr - How do I animate single instances of a custom modeled block?
  13. You'd need access to entityPlayer, and use EntityPlayer.getCurrentItemOrArmor(0) == <YOURIDHERE>
  14. I'm working on a mechanic that should do something pretty similar to iChun's portal gun when shot at the moon (it sucks blocks up and destroys them)... BUT, I'm having difficulty figuring out how to turn a block into a move-able entity. I have successfully made a block that jumps up and down when right clicked, but as soon as it touches the ground, it reverts back to the block, because it's using EntityFallingSand. Also, I'd prefer that gravity wasn't an issue in this case, as well. So will I need to create my own custom version of EntityFallingSand, or is there an easier way?
  15. Ok, so I got the animations working via the renderer class, but now it speeds up with each instance rendered, which is back to where I was before. am I doing this incorrectly somehow?? I'm using "this.model.[part].offsetY to modify a position in my RenderTileEntityAt method. I tried using glTranslatef, but I'm not seeing how to specify a specific piece of my model....
×
×
  • Create New...

Important Information

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