Jump to content

Making a custom rail placed on any side of a block


starwarsmace

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Ensure your system is running the latest version of Java. Sodium requires Java 17 or later for newer Minecraft versions (like 1.17+). 
    • Hi I wanted to my custom mob to hold any sword item, but didn’t rendered properly.   In entity class, make entity hold items as below: @Override public InteractionResult mobInteract(Player pPlayer, InteractionHand pHand) { //… ItemStack itemstack = pPlayer.getItemInHand(pHand); if (this.isTame()) { if ( (itemstack.is(Items.MELON_SLICE) || itemstack.is(Items.HONEY_BOTTLE)) && this.getHealth() < this.getMaxHealth() ) { //… } /* Handle holding sword */ else if (itemstack.getItem() instanceof SwordItem) { pPlayer.displayClientMessage(Component.literal("Clicked with item: " + itemstack.getDisplayName().getString()).withStyle(ChatFormatting.GOLD), true); //Return sword //pPlayer.getInventory().add(this.getItemInHand(InteractionHand.MAIN_HAND)); pPlayer.getInventory().add(this.getItemBySlot(EquipmentSlot.MAINHAND)); //The entity holds item //this.setItemInHand(InteractionHand.MAIN_HAND, itemstack); this.setItemSlot(EquipmentSlot.MAINHAND, itemstack.copy()); //Give copy of itemstack //If player is not in creative mode. From mobInteract() in wolf. if (!pPlayer.getAbilities().instabuild) { //Decrement sword count in hand pPlayer.getItemInHand(pHand).shrink(1); } return InteractionResult.SUCCESS; } else { //If player is sneaking pPlayer.displayClientMessage(getItemInHand(InteractionHand.MAIN_HAND).getDisplayName(), false); if (pPlayer.isShiftKeyDown()) { //Return sword //pPlayer.getInventory().add(this.getItemInHand(InteractionHand.MAIN_HAND)); pPlayer.getInventory().add(this.getItemBySlot(EquipmentSlot.MAINHAND)); //The entity holds nothing this.setItemInHand(InteractionHand.MAIN_HAND, ItemStack.EMPTY); return InteractionResult.SUCCESS; } else { //… } } else { return interactionresult; } }   And in render class, render the item as below: @Override public void render(RanaEntity pEntity, float pEntityYaw, float pPartialTicks, PoseStack pMatrixStack, MultiBufferSource pBuffer, int pPackedLight) { if(pEntity.isBaby()) { pMatrixStack.scale(0.5f, 0.5f, 0.5f); } model.setupAnim(pEntity, 0, 0, 0, pEntityYaw, 0); // //Get location and rotation of arm bone ModelPart rightArm = model.rightArm(); //Get right arm //Get location and rotation of item according to arm bone pMatrixStack.pushPose(); pMatrixStack.translate(rightArm.x, rightArm.y, rightArm.z); //Move to bone location pMatrixStack.mulPose(Axis.XP.rotationDegrees(rightArm.xRot)); //Rotate X pMatrixStack.mulPose(Axis.YP.rotationDegrees(rightArm.yRot)); //Rotate Y pMatrixStack.mulPose(Axis.ZP.rotationDegrees(rightArm.zRot)); //Rotate Z //Draw item //ItemStack itemStack = pEntity.getItemInHand(InteractionHand.MAIN_HAND); ItemStack itemStack = pEntity.getItemBySlot(EquipmentSlot.MAINHAND); if (!itemStack.isEmpty()) { //Offset pMatrixStack.translate(0.0, 0.0, 0.1); // Render the item //Minecraft.getInstance().getItemRenderer().renderStatic(itemStack, ItemDisplayContext.THIRD_PERSON_RIGHT_HAND, pPackedLight, OverlayTexture.NO_OVERLAY, pMatrixStack, pBuffer, pEntity.level(), pEntity.getId()); //itemRenderer.renderStatic(itemStack, ItemDisplayContext.THIRD_PERSON_RIGHT_HAND, pPackedLight, OverlayTexture.NO_OVERLAY, pMatrixStack, pBuffer, pEntity.level(), pEntity.getId()); itemInHandRenderer.renderItem(pEntity, itemStack, ItemDisplayContext.THIRD_PERSON_RIGHT_HAND, false, pMatrixStack, pBuffer, pEntity.getId()); } pMatrixStack.popPose(); super.render(pEntity, pEntityYaw, pPartialTicks, pMatrixStack, pBuffer, pPackedLight); }   I confirmed the entity can properly hold item(logically) but the item which the entity holds is not rendered at all.   Full code: https://github.com/sakiiiiika/ranamod   Thanks.
    • It is Immersive Melodies
    • MINECRAFT JAVA wht is ic_im it shows up yellow heres the modpack https://rocktheslayer.wixsite.com/my-site-7 also It wouldnt Let me submit a bug report only a suggestion for this post
  • Topics

×
×
  • Create New...

Important Information

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