Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Making a custom rail placed on any side of a block


starwarsmace
 Share

Recommended Posts

I have been trying to make rails that you put on any side of the block and it will still work. So like upside down riding.cheesy.gif

Anyway, for the time being I'm just trying to be able to put the rail on any side of the block. Here is my code for it.

 

package com.starwarsmace.sticky_rails.blocks;

import static net.minecraftforge.common.util.ForgeDirection.EAST;
import static net.minecraftforge.common.util.ForgeDirection.NORTH;
import static net.minecraftforge.common.util.ForgeDirection.SOUTH;
import static net.minecraftforge.common.util.ForgeDirection.WEST;
import static net.minecraftforge.common.util.ForgeDirection.UP;
import static net.minecraftforge.common.util.ForgeDirection.DOWN;
import net.minecraft.block.BlockRail;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;

public class StickyRail extends BlockRail{
public StickyRail(){
	super();
}



	public boolean canPlaceBlockOnSide(World world, int x, int y, int z, int orientation){
	ForgeDirection dir = ForgeDirection.getOrientation(orientation);
	return 	(dir == DOWN  && world.isSideSolid(x, y + 1, z, DOWN )) ||
			(dir == UP    && world.isSideSolid(x, y - 1, z, UP   )) ||
			(dir == NORTH && world.isSideSolid(x, y, z + 1, NORTH)) ||
			(dir == SOUTH && world.isSideSolid(x, y, z - 1, SOUTH)) ||
			(dir == WEST  && world.isSideSolid(x + 1, y, z, WEST )) ||
			(dir == EAST  && world.isSideSolid(x - 1, y, z, EAST ));
}

   
public boolean canPlaceBlockAt(World world, int x, int y, int z){
    return 	world.isSideSolid(x - 1, y, z, EAST ) ||
    		world.isSideSolid(x + 1, y, z, WEST ) ||
    		world.isSideSolid(x, y, z - 1, SOUTH) ||
    		world.isSideSolid(x, y, z + 1, NORTH) ||
    		world.isSideSolid(x, y - 1, z, UP   ) ||
    		world.isSideSolid(x, y + 1, z, DOWN );
}

}

 

It behaves almost exactly like a regular rail. I can't place it anywhere special like underneath or on the sides. What else special do you have to do? In the lever class this is all that was needed to be put on any side of a block. I must be missing something...

I'm back from being gone for... I think its been about a year. I'm pretty sure nobody remembers me, but hello anybody who does!

Link to comment
Share on other sites

Well, first you will also need to actually place the rail in the rotated form and, speaking of the rotated form, you will actually need a way to render that rotated model.

Oh...

Is the button and lever some type of special render in the render type? That would explain it....

What handles rotated forms?

 

Found this though...

/**
     * The type of render function that is called for this block
     */
    public int getRenderType()
    {
        return 12;
    }

Wait in the render types, they have numbers, maybe I could copy/ modify one of the lever renderers or something. I'll see what I can come up with.

I'm back from being gone for... I think its been about a year. I'm pretty sure nobody remembers me, but hello anybody who does!

Link to comment
Share on other sites

 

Wait in the render types, they have numbers, maybe I could copy/ modify one of the lever renderers or something. I'll see what I can come up with.

Ok... im stumped...

I really don't know what the heck the code for rendering the lever in RenderBlocks means... I think I should start from scratch...

How exactly do I make the renderer...?

I'm back from being gone for... I think its been about a year. I'm pretty sure nobody remembers me, but hello anybody who does!

Link to comment
Share on other sites

Hmmmm.... I just realized something that I should have realized a long time ago...

 

I could just flip the block render wise on a 180 degree angle if its upside down.

Isn't it something like...

GL11.glPushMatrix();
GL11.glRotatef(0, 180, 0, 0);
GL11.glPopMatrix();

 

 

I'm back from being gone for... I think its been about a year. I'm pretty sure nobody remembers me, but hello anybody who does!

Link to comment
Share on other sites

Hmmmm.... I just realized something that I should have realized a long time ago...

 

I could just flip the block render wise on a 180 degree angle if its upside down.

Isn't it something like...

GL11.glPushMatrix();
GL11.glRotatef(0, 180, 0, 0);
GL11.glPopMatrix();

No, this will not work. But you are close. This will rotate empty matrix. To rotate renderer - create new matrix, rotate it, render block, pop this matrix.

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

 Share



×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.