Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

I've made a turbine block that looks like a windmill. It's supposed to run off of steam blocks that I've added, but it doesn't rotate correctly.

 

 

My TESR class:

package com.example.gammacraft.blockRenderers;

import org.lwjgl.opengl.GL11;

import com.example.gammacraft.TileEntity.SteamTurbineTileEntity;

import assets.gammacraft.textures.models.SteamTurbineModel;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.entity.Entity;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ResourceLocation;

public class SteamTurbineRenderer extends TileEntitySpecialRenderer {

SteamTurbineModel model;

public SteamTurbineRenderer() {
	model = new SteamTurbineModel();
}

@Override
public void renderTileEntityAt(TileEntity tile, double x, double y,double z, float scale) {
	int dir = tile.getWorldObj().getBlockMetadata(tile.xCoord, tile.yCoord, tile.zCoord);
	SteamTurbineTileEntity te = (SteamTurbineTileEntity)tile.getWorldObj().getTileEntity(tile.xCoord, tile.yCoord, tile.zCoord);

	GL11.glPushMatrix();

	GL11.glTranslated(x+0.5F, y+0.5F, z);

	GL11.glRotated(te.getRotation(), 0, 0, 1);

	System.out.println(te.getRotation());

	GL11.glDisable(GL11.GL_LIGHTING);

	this.bindTexture(new ResourceLocation("gammacraft:textures/blocks/Candle.png"));

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

	GL11.glPopMatrix();


}

 

My TileEntity  (I will  add the packets later):

package com.example.gammacraft.TileEntity;

import net.minecraft.tileentity.TileEntity;

public class SteamTurbineTileEntity extends TileEntity {

public int Speed = 0;
public float rotation = 0;

public SteamTurbineTileEntity() {
	// TODO Auto-generated constructor stub
}

public void setRotation(float rot){
	this.rotation = rot;
}
public float getRotation(){
	return this.rotation;
}

public void setSpeed(int Speed){
	this.Speed = Speed;
}
public int getSpeed(){
	return this.Speed;
}

}

 

And my block class:

package com.example.gammacraft.blocks.energy;

import java.util.Random;

import com.example.gammacraft.gammacraft;
import com.example.gammacraft.TileEntity.SteamTurbineTileEntity;

import net.minecraft.block.Block;
import net.minecraft.block.BlockPistonBase;
import net.minecraft.block.ITileEntityProvider;
import net.minecraft.block.material.Material;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;

public class SteamTurbine extends Block implements ITileEntityProvider {

public SteamTurbine() {
	super(Material.iron);
	this.setCreativeTab(gammacraft.gammacraftcreativetab);
	this.setBlockName("SteamTurbine");
}

public void onNeighborBlockChange(World world, int x, int y, int z, Block block){
	SteamTurbineTileEntity te = (SteamTurbineTileEntity)world.getTileEntity(x, y, z);

	if(world.getBlock(x, y-1, z)==gammacraft.SteamBlock)te.Speed=5;


	world.scheduleBlockUpdate(x, y, z, (Block)this, 1);
}

public void updateTick(World world,int x,int y,int z,Random random){
	SteamTurbineTileEntity te = (SteamTurbineTileEntity)world.getTileEntity(x, y, z);

	te.setRotation(te.getRotation()+te.getSpeed());



	if(world.getBlock(x, y-1, z)!=gammacraft.SteamBlock){
	if(te.Speed>0){
		te.Speed--;
	}
	if(te.Speed<0){
		te.Speed++;
	}
	}else{
		if(te.Speed>0){
			te.Speed++;
		}
		if(te.Speed<0){
			te.Speed--;
		}
	}

	System.out.println(te.Speed);

	if(te.Speed!=0)
	world.scheduleBlockUpdate(x, y, z, (Block)this, 2);
}

@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float Hitx, float Hity, float Hitz) {
	if(player.getHeldItem()!=null){
		if(player.getHeldItem().getItem()==gammacraft.wrench){
			if(side!=0||side!=1){
				world.setBlockMetadataWithNotify(x, y, z, side-2, 0);
				System.out.println(side);
			}
			return true;
		}
	}
	return false;

}

@Override
public TileEntity createNewTileEntity(World var1, int var2) {
	return new SteamTurbineTileEntity();
}

@Override
public boolean isOpaqueCube(){
	return false;
}
@Override
    public int getRenderType() {
            return -1;
    }
 public boolean renderAsNormalBlock() {
         return false;
    }

}

The proud(ish) developer of Ancients

Not sure exactly what you mean without pictures but my guess is its because you are translating an extra 0.5 on the x and y values.

Try uning GL11.glTranslated(x, y, z); then rotate then GL11.glTranslated(0.5D, 0.5D, 0);

I am the author of Draconic Evolution

  • Author

I mean as in when you rotate a block, it rotates oddly

heres a video:

The proud(ish) developer of Ancients

It dosnt look like you are using the metadata to set the rotation on the renderer. Also the float at the end of renderTileAt isn't scale its the time since the last game tick

I am the author of Draconic Evolution

  • Author

I am using the metadata, I think the first post has a different trial than what I was doing (I'm using metadata*90 for the rotation).

Thanks, I wasn't sure what the last float was for, I've never seen any uses for it in any tutorials.

The proud(ish) developer of Ancients

Hi

 

It looks to me like your placement rotation is about right, but you are rotating around the wrong centrepoint.

In order to fix that, you need to do

GL11.glTranslatef(dX, dY, dZ);
glRotate
GL11.glTranslatef(-dX, -dY, -dZ);

where dX, dY and dZ are the translation you need to make your turbine rotate around its centrepoint.  You should be able to find that out from the program you used to make your model, alternatively trial and error will show you pretty quickly.

 

the final float that you've labelled 'scale' is actually partialTick.  Kind of like Brandon said, it's related to the time since the last tick.  It helps you make smoother animations.

 

For example, if you're drawing a spinning wheel using the code

rotationPositionInDegrees = degreesPerTick * numberOfTicks

and in your tileentity you have a field integerTickCount, which gets incremented every tick, for example in onUpdate(),

then if you just use

numberOfTicks = integerTickCount

you will get jerky animation with at most 20 frames per second.

Instead, if you use

numberOfTicks = integerTickCount + partialTickCount

your animation will be much smoother because you get 'partial' ticks between the integer values.  If your game is running at say 60 frames per second this looks much nicer.

 

-TGG

 

  • Author

So the centre point is in the middle of the main axle? And Is gl11.gltranslated relative or absolute?

The proud(ish) developer of Ancients

  • Author

I tried this:

GL11.glTranslated(0.5F, 0.5F, 0.5F);

GL11.glRotated(dir*90, 0, 1, 0);

GL11.glTranslated(-0.5F, -0.5F, -0.5F);

It works slightly better, but it's still offset a little bit.

The proud(ish) developer of Ancients

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

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.