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

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.