Jump to content

Instanced block model changes


Meoco

Recommended Posts

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?

Link to comment
Share on other sites

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?

 

 

Link to comment
Share on other sites

Hi

 

I'd suggest something like - change your

public static void pump(){

to be

public void pump(long animationOffset)

with

long time = (System.currentTimeMillis() + animationOffset) % 40000L; 

 

add a field to your TileEntityExtractor

long animationOffset;

 

in the default constructor for your TileEntityExtractor add

animationOffset = System.nanoTime % 40000;

 

in your renderTileEntityAt add

 

this.model.pump(te.animationOffset);
this.model.render((Entity) null, 0.0F, 0.0F, -0.1F, 0.0F, 0.0F, 0.0625F);

 

Disclaimer - I haven't tried to compile this code so bits of the syntax might not be 100% right

 

-TGG

 

 

 

 

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Read this, especially the last paragraph that should solve the above..

http://docs.oracle.com/javase/tutorial/java/IandI/subclasses.html

If you guys dont get it.. then well ya.. try harder...

Link to comment
Share on other sites

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. :P  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? :P

Link to comment
Share on other sites

The long variable came from TheGreyGhost's suggestion. :P

 

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? xD 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

Link to comment
Share on other sites

Hi

 

The long value in the code I suggested is based on your pump animation code, which appeared to be designed to go through a full animation cycle once every 40 seconds using a value from 0 to 39999.  Now that I look at it more closely I see that time isn't actually used at all.  Guess I should have read it more thoroughly.  As you've got it currently, the slider will move by a fixed amount every time pump is called, so if the framerate is uneven or you have multiple sliders it will be choppy

 

 

 

 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;
  }
}

 

If you want your slider position to animate like this:

(1) start at slider position 0

(2) over 2 seconds, decrease evenly to -0.5

(3) over the next 2 seconds, increase evenly to 0

(4) repeat from 2

 

then something like this should work:

 

 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.0;
  final float MID_CYCLE_SLIDER_POS = -0.5;
  long time = (System.currentTimeMillis() + animationOffset) % CYCLE_TIME_IN_MS;
  if (time < HALF_CYCLE_TIME_IN_MS) {
    slider1.offsetY = START_SLIDER_POS + (time / 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 / HALF_CYCLE_TIME_IN_MS) * (START_SLIDER_POS - MID_CYCLE_SLIDER_POS); 
  }
}

 

-TGG

Link to comment
Share on other sites

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. :P )!!

 

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! :D

 

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();
}

Link to comment
Share on other sites

Hi

 

no worries, glad I could help.

 

So if you want to start the animation when you right-click the block, you need to set the animationOffset so that the slider position is zero when you right click the block.

 

in other words, time is zero

long time = (System.currentTimeMillis() + animationOffset) % CYCLE_TIME_IN_MS;

 

so in the right click you need to set your animationOffset equal to -System.currentTimeMillis(), so that

System.currentTimeMillis() + animationOffset == 0.

 

the initialisation in the constructor was just to provide a random starting point so the blocks are not all synchronised, there's nothing special about it.

animationOffset = System.nanoTime() % 40000;

 

Your onBlockActivated should have something like this in it:

	public boolean onBlockActivated(World par1World, int x, int y,
		int z, EntityPlayer par5EntityPlayer, int par6, float par7,
		float par8, float par9) {
if (par1World.isRemote) {
  TileEntity tileEntity =  par1World.getBlockTileEntity(x, y, z);
  if (tileEntity != null && tileEntity instanceof TileEntityExtractor) {
    ((TileEntityExtractor)tileEntity).animationOffset = - System.currentTimeMillis();
  }

}

// etc
}

 

-TGG

Link to comment
Share on other sites

Well, TGG, I tried your idea, and it did not work. :P 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. :P 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. :P

Link to comment
Share on other sites

Keen, glad you got it to work!

 

Re graceful sliding back to zero - I suggest you could add a "shutdown animation" flag in addition to your existing"start animation flag", to make it complete the cycle that it's currently on then stop at zero.

 

You could do this by: In your pump method, add the line

 

  long numberOfCyclesSinceStart = (System.currentTimeMillis() + animationOffset) / CYCLE_TIME_IN_MS;

 

When your "stop animation flag" is triggered, calculate which cycle it's currently on, save it to the tileentity, and keep animating until you see numberOfCyclesSinceStart increase above the saved value (i.e. it is about to start the next pump cycle), then force "time" to zero and hold it there until the pump starts again.

 

Alternatively you could use your "shutdown animation" flag to choose a completely separate pump method for updating the animation.

 

-TGG

 

 

Link to comment
Share on other sites

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).

Link to comment
Share on other sites

Hi

 

Stopping the animation while the game is paused is a bit trickier.  You would need to run your own "clock" to replace the System.currentTimeMillis(), by subscribing to onPreClientTick, checking Minecraft.isGamePaused, and updating your clock (20 times per second), then reading the value of this clock in your renderer.

 

To be honest that's moderately advanced stuff and probably not worth the effort?  Does it really matter if the animation keeps going while the game is paused?

 

Re the smooth animation- if you post what you tried we can give you some more guidance.

 

-TGG

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

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