Jump to content

Recommended Posts

Posted

I am trying to make a spinning block with an obj model.

So far it went quite well:

jjfLKDe.png

 

But if I try to start the block to spin around via. TRSRTransformation the block stops the model rendering and displays a normal block with missing texture.

Block:

public class BlockPylon extends Block implements ITileEntityProvider {

public static final BlockPylon INSTANCE = new BlockPylon();
public static final String name = "pylon";
public ExtendedBlockState state = new ExtendedBlockState(this, new IProperty[0], new IUnlistedProperty[] {OBJModel.OBJProperty.INSTANCE});

public BlockPylon()
{
	super(Material.rock);
	setUnlocalizedName(Ragnarok.MODID + ":" + name);
	setCreativeTab(CreativeTabs.tabBlock);
}

@Override
public TileEntity createNewTileEntity(World world, int meta)
{
	return new TilePylon();
}

@Override
public boolean isOpaqueCube(IBlockState state)
{
	return false;
}

@Override
public boolean isFullCube(IBlockState state)
{
	return false;
}

@Override
public boolean hasTileEntity(IBlockState state)
{
	return true;
}

@Override
public IBlockState getExtendedState(IBlockState state, IBlockAccess world, BlockPos pos)
{
	if (world.getTileEntity(pos) != null && world.getTileEntity(pos) instanceof TilePylon)
        {
		TilePylon te = (TilePylon) world.getTileEntity(pos);
            if (te.state != null)
            {
                return ((IExtendedBlockState) this.state.getBaseState()).withProperty(OBJModel.OBJProperty.INSTANCE, te.state);
            }
        }
        return state;
}

@Override
protected BlockStateContainer createBlockState()
{
	return new ExtendedBlockState(this, new IProperty[0], new IUnlistedProperty[] {OBJModel.OBJProperty.INSTANCE});
}
}

 

Tile:

public class TilePylon extends TileEntity implements ITickable {

public OBJModel.OBJState state;
private double anglePitch = 0D;
private double step = 0;

public TilePylon()
    {
        this.state = new OBJModel.OBJState(Lists.newArrayList(OBJModel.Group.ALL), true);
    }

@Override
public void update()
{
	step += Math.PI / 80;
	if(step >= Math.PI / 2)
		step = step - Math.PI;
	anglePitch = step;
	if (this.worldObj.isRemote)
	{
		Quat4f rot = new Quat4f(0, 0, 0, 1);
		AxisAngle4d pitch = new AxisAngle4d(1, 0, 0, -anglePitch);
		Quat4f pitchQuat = new Quat4f();
		pitchQuat.set(pitch);
		rot.mul(pitchQuat);
		Matrix4f matrix = new Matrix4f();
            matrix.setIdentity();
            matrix.setRotation(rot);
            TRSRTransformation transform = new TRSRTransformation(matrix);
            transform = TRSRTransformation.blockCenterToCorner(transform);
            this.state = new OBJModel.OBJState(Lists.newArrayList(OBJModel.Group.ALL), true, transform);
            //this.worldObj.setBlockState(pos, BlockPylon.INSTANCE.getExtendedState(worldObj.getBlockState(pos), worldObj, pos));
            this.worldObj.markBlockRangeForRenderUpdate(pos, pos);
        }
}

}

 

Loader:

@EventHandler
public void preInit(FMLPreInitializationEvent event)
{
	BlockPylon.INSTANCE.setRegistryName(BlockPylon.name);
	GameRegistry.register(BlockPylon.INSTANCE);
	ItemBlock item = new ItemBlock(BlockPylon.INSTANCE);
	item.setRegistryName(BlockPylon.name);
	GameRegistry.register(item);
	GameRegistry.registerTileEntity(TilePylon.class, "pylon");
	if (event.getSide() == Side.CLIENT)
            clientPreInit();
}

private void clientPreInit()
    {
	OBJLoader.INSTANCE.addDomain(MODID.toLowerCase());
        Item item = Item.getItemFromBlock(BlockPylon.INSTANCE);
        ModelLoader.setCustomModelResourceLocation(item, 0, new ModelResourceLocation(MODID.toLowerCase() + ":" + BlockPylon.name, "inventory"));
    }

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.