Jump to content

Recommended Posts

Posted

Warning: This is kind of complex to explain, so get ready for some lengthy paragraphs and lots of code to read.

 

I'm trying to add transparent stairs to my mod. They work flawlessly functionally, but rendering them properly has been a bit difficult. I've written the code properly to prevent x-raying and stuff like that, but the challenge I'm dealing with is determining when to render a side of a stairs. I'm basically taking the same approach as vanilla glass blocks, so that only the front textures render and you get a clear view through several stairs. Obviously, due to the many different shapes of stairs there are some combinations for which this is not possible and you are forced to render the sides, but I wanted to do as much as I could to make the transparent stairs as seamless as possible.

 

I've written out all the logic for rendering of sides based on the orientation, shape, and half (right-side-up or upside-down) of the stairs and the stairs or other blocks adjacent to that side and their rotations, shapes, and etc. and I've checked the logic multiple times and I believe it is fully robust and perfected. However, the actual implementation of that logic is where my problem is. Below you can see all the relevant classes, with StairsSideRenderLogic being the utility class I created to keep all the rendering logic outside of the custom stairs class (for readability's sake). This is where the flaw in my code (or Forge, but I'll get to that later) shows up. Through debugging I believe I have narrowed down the core of the problem being this: trying to get the value of the SHAPE property from the stairs is not giving the expected results. I'm basically taking an IBlockAccess, getting an IBlockState from it, and trying to get the value of the SHAPE property from it. But it keeps returning either the lowest possible value (STRAIGHT) or the highest possible value (OUTER_RIGHT), which of course makes the majority of my checks in the rendering logic fail.

 

When I try to get the values of the FACING or HALF properties of either the stairs being rendered or the adjacent block, it works without a problem. When I try to get the shape of the stairs being rendered, it works. But when I try to get the shape of the adjacent block, it never returns anything other than the aforementioned values. The only differences I can think of is that:

[*]I have an IBlockState for the block whose sides are being rendered, but only an IBlockAccess for the adjacent block, and...

[*]The SHAPE property is not saved to the metadata like the other 2 properties, as it is determined based on adjacent blocks. I don't have a complete understanding of what the difference between an IBlockAccess and an IBlockState is, but I have heard that the former is more limiting, which leads me to believe that an IBlockAccess doesn't know what its complete blockstate is, and only knows what is saved to metadata. If this is the case then I'm not sure what I should do in order to determine the info I need.

 

I should also mention and clarify that all the cases for rendering that don't involve trying to get the SHAPE of the adjacent block work entirely as expected, that everything else concerning rendering works fine and the problem only involves deciding when to render the side of one of the blocks, and this problem, as stated before, does not affect trying to get the SHAPE of the block to be rendered, but only the adjacent block, which is the one I only have an IBlockAccess for.

 

Any ideas? Here are all the classes you'd need to look at to fully understand how my stairs work. Again, StairsSideRenderLogic is the most important one as it is where the problem is, with the others included for context. As I've said before, I believe the logic for rendering is correct, but the ways in which I obtain the info used in the logic is flawed.

 

StairsSideRenderLogic.java (the logic for rendering the sides of stairs.)

package com.supergeniuszeb.colore.utility;

import com.supergeniuszeb.colore.common.blocks.BlockColore;
import com.supergeniuszeb.colore.common.blocks.BlockColoreStairs;
import com.supergeniuszeb.colore.common.blocks.BlockColoreTrans;
import com.supergeniuszeb.colore.common.blocks.BlockColoreTransSlabDouble;
import com.supergeniuszeb.colore.common.blocks.BlockColoreTransSlabHalf;
import com.supergeniuszeb.colore.common.blocks.BlockColoreTransStairs;
import com.supergeniuszeb.colore.common.blocks.EnumShade;
import com.supergeniuszeb.colore.common.blocks.IColorMatcher;

import net.minecraft.block.BlockSlab.EnumBlockHalf;
import net.minecraft.block.BlockStairs.EnumHalf;
import net.minecraft.block.BlockStairs.EnumShape;
import net.minecraft.block.state.IBlockState;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;

public class StairsSideRenderLogic implements IColorMatcher {
//Used to get the side of a stairs relative to its FACING property.
public static EnumFacing getRelativeSide(EnumFacing facing1, EnumFacing facing2) {
	if (facing1 == EnumFacing.EAST) {
		switch (facing2) {
			case NORTH:
				return EnumFacing.WEST;
			case EAST:
				return EnumFacing.NORTH;
			case SOUTH:
				return EnumFacing.EAST;
			case WEST:
				return EnumFacing.SOUTH;
			default:
				break; //Assuming this method is used right, this should never happen.
		}
	}
	if (facing1 == EnumFacing.SOUTH) {
		switch (facing2) {
			case NORTH:
				return EnumFacing.SOUTH;
			case EAST:
				return EnumFacing.WEST;
			case SOUTH:
				return EnumFacing.NORTH;
			case WEST:
				return EnumFacing.EAST;
			default:
				break;
		}
	}
	if (facing1 == EnumFacing.WEST) {
		switch (facing2) {
			case NORTH:
				return EnumFacing.EAST;
			case EAST:
				return EnumFacing.SOUTH;
			case SOUTH:
				return EnumFacing.WEST;
			case WEST:
				return EnumFacing.NORTH;
			default:
				break;
		}
	}
	return facing2;
}
//Used to get which way the adjacent stairs is facing, relative to the block it is adjacent to.
public static EnumFacing getRelativeFacing(EnumFacing facing1, EnumFacing facing2) {
	if (facing1 == EnumFacing.EAST) {
		switch (facing2) {
			case NORTH:
				return EnumFacing.WEST;
			case EAST:
				return EnumFacing.NORTH;
			case SOUTH:
				return EnumFacing.EAST;
			case WEST:
				return EnumFacing.SOUTH;
			default:
				break; //Assuming this method is used right, this should never happen.
		}
	}
	if (facing1 == EnumFacing.SOUTH) {
		switch (facing2) {
			case NORTH:
				return EnumFacing.SOUTH;
			case EAST:
				return EnumFacing.EAST;
			case SOUTH:
				return EnumFacing.NORTH;
			case WEST:
				return EnumFacing.WEST;
			default:
				break;
		}
	}
	if (facing1 == EnumFacing.WEST) {
		switch (facing2) {
			case NORTH:
				return EnumFacing.EAST;
			case EAST:
				return EnumFacing.SOUTH;
			case SOUTH:
				return EnumFacing.WEST;
			case WEST:
				return EnumFacing.NORTH;
			default:
				break;
		}
	}
	return facing2;
}

//Logic method that decides whether or not to render a side of a stairs block depending on
//what block is adjacent to it and what their blockstates are.
public static boolean shouldSideBeRendered(IBlockState blockState, IBlockAccess blockAccess, BlockPos pos, EnumFacing side) {
	IBlockState adjBlockState = blockAccess.getBlockState(pos.offset(side));
	if (adjBlockState.getBlock() instanceof BlockColoreTransStairs) {

		EnumFacing blockFacing = blockState.getValue(BlockColoreTransStairs.FACING);
		EnumFacing adjBlockRelativeFacing = getRelativeFacing(blockFacing, adjBlockState.getValue(BlockColoreTransStairs.FACING));

		EnumFacing blockRelativeSide = getRelativeSide(blockFacing, side);

		EnumHalf blockHalf = blockState.getValue(BlockColoreTransStairs.HALF);
		EnumHalf adjBlockHalf = adjBlockState.getValue(BlockColoreTransStairs.HALF);

		EnumShape blockShape = blockState.getValue(BlockColoreTransStairs.SHAPE);
		EnumShape adjBlockShape = adjBlockState.getValue(BlockColoreTransStairs.SHAPE);
		System.out.println(adjBlockShape);
		if (side == EnumFacing.UP) {
			if (blockHalf == EnumHalf.TOP && adjBlockHalf == EnumHalf.BOTTOM) {
				return false;
			}
			if (blockHalf == EnumHalf.BOTTOM && adjBlockHalf == EnumHalf.TOP) {
				if (blockShape == adjBlockShape && adjBlockRelativeFacing == EnumFacing.NORTH) {
					return false;
				}
			}
		}
		if (side == EnumFacing.DOWN) {
			if (blockHalf == EnumHalf.BOTTOM && adjBlockHalf == EnumHalf.TOP) {
				return false;
			}
			if (blockHalf == EnumHalf.TOP && adjBlockHalf == EnumHalf.BOTTOM) {
				if (blockShape == adjBlockShape && adjBlockRelativeFacing == EnumFacing.NORTH) {
					return false;
				}
			}
		}

		if (blockRelativeSide == EnumFacing.NORTH && adjBlockRelativeFacing == EnumFacing.SOUTH) {
			if (adjBlockShape == EnumShape.STRAIGHT || adjBlockShape == EnumShape.INNER_LEFT || adjBlockShape == EnumShape.INNER_RIGHT) {
				return false;
			}
		}
		if (blockHalf == adjBlockHalf) {
			if (blockRelativeSide == EnumFacing.SOUTH && adjBlockRelativeFacing == EnumFacing.SOUTH) {
				return false;
			}
			if (blockShape == EnumShape.STRAIGHT) { //Tested with debugging and this works.
				if (blockRelativeSide == EnumFacing.NORTH) { //This also works.
					if (adjBlockRelativeFacing == EnumFacing.EAST) { //This does too.
						if (adjBlockShape == EnumShape.INNER_RIGHT) { //This doesn't.
							return false;
						}
					}
					if (adjBlockRelativeFacing == EnumFacing.WEST) {
						if (adjBlockShape == EnumShape.INNER_LEFT) {
							return false;
						}
					}
				}
				if (blockRelativeSide == EnumFacing.EAST) {
					if (adjBlockRelativeFacing == EnumFacing.NORTH) {
						return false;
					}
					if (adjBlockRelativeFacing == EnumFacing.EAST) {
						//When called, this always prints out "straight" or "outer_right", which makes no sense.
						System.out.println(blockAccess.getBlockState(pos.offset(side)).getValue(BlockColoreTransStairs.SHAPE).toString());
						if (adjBlockShape == EnumShape.INNER_LEFT) {
							System.out.println("2Test successful! BLAH BLAH BLAH!");
							return false;
						}
					}
					if (adjBlockRelativeFacing == EnumFacing.SOUTH) {
						if (adjBlockShape == EnumShape.INNER_RIGHT) {
							return false;
						}
					}
				}
				if (blockRelativeSide == EnumFacing.SOUTH) {
					return false;
				}
				if (blockRelativeSide == EnumFacing.WEST) {
					if (adjBlockRelativeFacing == EnumFacing.NORTH) {
						return false;
					}
					if (adjBlockRelativeFacing == EnumFacing.SOUTH) {
						if (adjBlockShape == EnumShape.INNER_LEFT) {
							return false;
						}
					}
					if (adjBlockRelativeFacing == EnumFacing.WEST) {
						if (adjBlockShape == EnumShape.INNER_RIGHT) {
							return false;
						}
					}
				}
				if (blockShape == EnumShape.INNER_LEFT) {
					if (blockRelativeSide == EnumFacing.NORTH) {
						if (adjBlockRelativeFacing == EnumFacing.EAST) {
							if (adjBlockShape == EnumShape.INNER_RIGHT) {
								return false;
							}
						}
						if (adjBlockRelativeFacing == EnumFacing.WEST) {
							if (adjBlockShape == EnumShape.INNER_LEFT) {
								return false;
							}
						}
					}
					if (blockRelativeSide == EnumFacing.EAST) {
						if (adjBlockRelativeFacing == EnumFacing.NORTH) {
							return false;
						}
						if (adjBlockRelativeFacing == EnumFacing.EAST) {
							if (adjBlockShape == EnumShape.INNER_LEFT) {
								return false;
							}
						}
						if (adjBlockRelativeFacing == EnumFacing.SOUTH) {
							if (adjBlockShape == EnumShape.INNER_RIGHT) {
								return false;
							}
						}
					}
					if (blockRelativeSide == EnumFacing.SOUTH) {
						if (adjBlockShape != EnumShape.OUTER_LEFT) {
							return false;
						}
					}
					if (blockRelativeSide == EnumFacing.WEST) {
						if (adjBlockRelativeFacing == EnumFacing.SOUTH) {
							if (adjBlockShape == EnumShape.INNER_LEFT) {
								return false;
							}
						}
					}
				}
				if (blockShape == EnumShape.INNER_RIGHT) {
					if (blockRelativeSide == EnumFacing.NORTH) {
						if (adjBlockRelativeFacing == EnumFacing.EAST) {
							if (adjBlockShape == EnumShape.INNER_RIGHT) {
								return false;
							}
						}
						if (adjBlockRelativeFacing == EnumFacing.WEST) {
							if (adjBlockShape == EnumShape.INNER_LEFT) {
								return false;
							}
						}
					}
					if (blockRelativeSide == EnumFacing.EAST) {
						if (adjBlockRelativeFacing == EnumFacing.SOUTH) {
							if (adjBlockShape == EnumShape.INNER_RIGHT) {
								return false;
							}
						}
						if (adjBlockRelativeFacing == EnumFacing.WEST) {
							if (adjBlockShape != EnumShape.OUTER_RIGHT) {
								return false;
							}
						}
					}
					if (blockRelativeSide == EnumFacing.SOUTH) {
						if (adjBlockShape != EnumShape.OUTER_RIGHT) {
							return false;
						}
					}
					if (blockRelativeSide == EnumFacing.WEST) {
						if (adjBlockRelativeFacing == EnumFacing.SOUTH) {
							if (adjBlockShape == EnumShape.INNER_LEFT) {
								return false;
							}
						}
						if (adjBlockRelativeFacing == EnumFacing.WEST) {
							if (adjBlockShape == EnumShape.INNER_RIGHT) {
								return false;
							}
						}
					}
				}
				if (blockShape == EnumShape.OUTER_LEFT) {
					if (blockRelativeSide == EnumFacing.NORTH) {
						if (adjBlockShape != EnumShape.OUTER_RIGHT) {
							return false;
						}
					}
					if (blockRelativeSide == EnumFacing.EAST || blockRelativeSide == EnumFacing.SOUTH) {
						return false;
					}
					if (blockRelativeSide == EnumFacing.WEST) {
						if (adjBlockRelativeFacing == EnumFacing.NORTH) {
							return false;
						}
						if (adjBlockRelativeFacing == EnumFacing.SOUTH) {
							if (adjBlockShape == EnumShape.INNER_LEFT) {
								return false;
							}
						}
						if (adjBlockRelativeFacing == EnumFacing.WEST) {
							if (adjBlockShape == EnumShape.INNER_RIGHT) {
								return false;
							}
						}
					}
				}
				if (blockShape == EnumShape.OUTER_RIGHT) {
					if (blockRelativeSide == EnumFacing.NORTH) {
						if (adjBlockShape != EnumShape.OUTER_LEFT) {
							return false;
						}
					}
					if (blockRelativeSide == EnumFacing.EAST) {
						if (adjBlockRelativeFacing == EnumFacing.NORTH) {
							return false;
						}
						if (adjBlockRelativeFacing == EnumFacing.EAST) {
							if (adjBlockShape == EnumShape.INNER_LEFT) {
								return false;
							}
						}
						if (adjBlockRelativeFacing == EnumFacing.SOUTH) {
							if (adjBlockShape == EnumShape.INNER_RIGHT) {
								return false;
							}
						}
					}
					if (blockRelativeSide == EnumFacing.SOUTH || blockRelativeSide == EnumFacing.WEST) {
						return false;
					}
				}
			}
		}
	}

	if (adjBlockState.getBlock() instanceof BlockColoreTrans || adjBlockState.getBlock() instanceof BlockColoreTransSlabDouble) {
		if (doShadeAndColorMatch(blockState, adjBlockState)) {
			return false;
		}
	}
	if (adjBlockState.getBlock() instanceof BlockColoreTransSlabHalf) {
		if ((side == EnumFacing.UP && adjBlockState.getValue(BlockColoreTransSlabHalf.HALF) == EnumBlockHalf.BOTTOM) ||
				(side == EnumFacing.DOWN && adjBlockState.getValue(BlockColoreTransSlabHalf.HALF) == EnumBlockHalf.TOP)) {
			if (doShadeAndColorMatch(blockState, adjBlockState)) {
				return false;
			}
		}
	}
        return true;
    }

//Used to check if the shade & color of the stairs matches that of the adjacent normal block, half-slab, or double-slab.
public static boolean doShadeAndColorMatch(IBlockState blockState, IBlockState adjBlockState) {
	for (String shade : UtilityLists.shadeList) {
		if (blockState.getBlock().getRegistryName().toString().contains(shade) && adjBlockState.getValue(BlockColore.SHADE) == EnumShade.valueOf(shade.toUpperCase())) {
			if (IColorMatcher.isSameColor(blockState, adjBlockState)) {
				return true;
			}
		}
	}
	return false;
}
}

 

BlockColoreTransStairs.java

package com.supergeniuszeb.colore.common.blocks;

import com.supergeniuszeb.colore.utility.StairsSideRenderLogic;

import net.minecraft.block.state.IBlockState;
import net.minecraft.util.BlockRenderLayer;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

public class BlockColoreTransStairs extends BlockColoreStairs {

public BlockColoreTransStairs(String name, EnumColor color) {
	super(name, color);
	this.setLightOpacity(0);
}

@SideOnly(Side.CLIENT)
    public BlockRenderLayer getBlockLayer()
    {
        return BlockRenderLayer.TRANSLUCENT;
    }

/**
     * Used to determine ambient occlusion and culling when rebuilding chunks for render
     */
@Override
    public boolean isOpaqueCube(IBlockState state)
    {
        return false;
    }
    
//Determines whether or not a side of the stairs should be rendered.
@Override
@SideOnly(Side.CLIENT)
    public boolean shouldSideBeRendered(IBlockState blockState, IBlockAccess blockAccess, BlockPos pos, EnumFacing side) {
        return StairsSideRenderLogic.shouldSideBeRendered(blockState, blockAccess, pos, side);
    }

@Override
    public boolean doesSideBlockRendering(IBlockState state, IBlockAccess world, BlockPos pos, EnumFacing face) {
        return false;
    }

}

 

BlockColoreStairs.java (regular opaque custom stairs class that is extended by BlockColoreTransStairs)

package com.supergeniuszeb.colore.common.blocks;

import com.supergeniuszeb.colore.common.init.ModCreativeTabs;

import net.minecraft.block.BlockStairs;
import net.minecraft.init.Blocks;

public class BlockColoreStairs extends BlockStairs implements IBlockName, IColoreColor {

private EnumColor color;

public BlockColoreStairs(String name, EnumColor color) {
	super(Blocks.COBBLESTONE.getDefaultState()); //Just getting the most generic state I can think of. 
	this.setHardness(1.5f);
	this.setHarvestLevel("pickaxe", 0);
	this.setResistance(10.0f);
	this.useNeighborBrightness = true;
	IBlockName.setBlockName(this, name);
	this.color = color;
	this.setCreativeTab(ModCreativeTabs.stairsTab);
}

@Override
public EnumColor getColor() {
	return color;
}

}

 

Thanks in advance for your help, and once this is sorted out, hopefully this rendering code will help others who want to make transparent stairs in their mods! (Transparency + non-full-cubes + different shapes depending on blockstates = really difficult! :P)

Colore - The mod that adds monochrome blocks in every color of the rainbow!

http://www.minecraftforge.net/forum/index.php?topic=35149

 

If you're looking to learn how to make mods for 1.9.4, I wrote a helpful article with links to a lot of useful resources for learning Minecraft 1.9.4 modding!

 

http://supergeniuszeb.com/mods/a-helpful-list-of-minecraft-1-9-4-modding-resources/

Posted

To clarify:

  • IBlockAccess

    is an interface implemented by

    World

    that provides access to blocks,

    TileEntities

    , biomes, etc.

  • IBlockState

    is a collection of properties and values representing the current state of a

    Block


Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Posted

1. You can use Block#getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos) or Block#getExtendedState(IBlockState state, IBlockAccess worldIn, BlockPos pos).

I can't see any better way in performance, since the block state is not saved into the world itself.

2. I think the code could be easily cleaned further by using for loops and maps.

 

EDIT: Gotten from BlockStairs code, the stairs also use this way.

public void addCollisionBoxToList(IBlockState state, World worldIn, BlockPos pos, AxisAlignedBB entityBox, List<AxisAlignedBB> collidingBoxes, @Nullable Entity entityIn)
    {
        state = this.getActualState(state, worldIn, pos);

        for (AxisAlignedBB axisalignedbb : getCollisionBoxList(state))
        {
            addCollisionBoxToList(pos, entityBox, collidingBoxes, axisalignedbb);
        }
    }

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

Posted

To clarify:

  • IBlockAccess

    is an interface implemented by

    World

    that provides access to blocks,

    TileEntities

    , biomes, etc.

  • IBlockState

    is a collection of properties and values representing the current state of a

    Block


1. You can use Block#getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos) or Block#getExtendedState(IBlockState state, IBlockAccess worldIn, BlockPos pos).

I can't see any better way in performance, since the block state is not saved into the world itself.

2. I think the code could be easily cleaned further by using for loops and maps.

 

Thanks! Changing my code to get the actual-state fixed the problem! The stairs now render entirely as intended. It actually makes a lot of sense that since IBlockAccess is implemented and used by World, you wouldn't be able to directly get the full blockstate of a block from it, since the actual/extended state isn't saved to the world. (While fixing it I also discovered another minor unrelated problem where I accidentally mis-nested some of the if statements, which I've fixed now.)

 

Abastro, could you explain how I could use for loops and maps to make the code cleaner? I'm not sure what you mean. As for optimizing the logic, I've already made it relative to the orientation of the stairs being rendered, which has reduced the size of the logic to be 4x smaller than what it would be otherwise. (A north-facing stairs with an east-facing stairs on its east side = an east-facing stairs with a south-facing stairs on its south side.) If you take a look at the code you'll see I check for the most general cases (like bottom-half-stairs on top of top-half stairs) which should always return false before I check for more specific cases that are more difficult to determine, and I don't think there are any redundant checks left in the logic that could be abstracted, but correct me if I'm wrong.

 

The updated StairsSideRenderLogic.java

package com.supergeniuszeb.colore.utility;

import com.supergeniuszeb.colore.common.blocks.BlockColore;
import com.supergeniuszeb.colore.common.blocks.BlockColoreStairs;
import com.supergeniuszeb.colore.common.blocks.BlockColoreTrans;
import com.supergeniuszeb.colore.common.blocks.BlockColoreTransSlabDouble;
import com.supergeniuszeb.colore.common.blocks.BlockColoreTransSlabHalf;
import com.supergeniuszeb.colore.common.blocks.BlockColoreTransStairs;
import com.supergeniuszeb.colore.common.blocks.EnumShade;
import com.supergeniuszeb.colore.common.blocks.IColorMatcher;

import net.minecraft.block.BlockSlab.EnumBlockHalf;
import net.minecraft.block.BlockStairs.EnumHalf;
import net.minecraft.block.BlockStairs.EnumShape;
import net.minecraft.block.state.IBlockState;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraftforge.common.property.IExtendedBlockState;

public class StairsSideRenderLogic implements IColorMatcher {
//Used to get the side of a stairs relative to its FACING property.
public static EnumFacing getRelativeSide(EnumFacing facing1, EnumFacing facing2) {
	if (facing1 == EnumFacing.EAST) {
		switch (facing2) {
			case NORTH:
				return EnumFacing.WEST;
			case EAST:
				return EnumFacing.NORTH;
			case SOUTH:
				return EnumFacing.EAST;
			case WEST:
				return EnumFacing.SOUTH;
			default:
				break; //Assuming this method is used right, this should never happen.
		}
	}
	if (facing1 == EnumFacing.SOUTH) {
		switch (facing2) {
			case NORTH:
				return EnumFacing.SOUTH;
			case EAST:
				return EnumFacing.WEST;
			case SOUTH:
				return EnumFacing.NORTH;
			case WEST:
				return EnumFacing.EAST;
			default:
				break;
		}
	}
	if (facing1 == EnumFacing.WEST) {
		switch (facing2) {
			case NORTH:
				return EnumFacing.EAST;
			case EAST:
				return EnumFacing.SOUTH;
			case SOUTH:
				return EnumFacing.WEST;
			case WEST:
				return EnumFacing.NORTH;
			default:
				break;
		}
	}
	return facing2;
}
//Used to get which way the adjacent stairs is facing, relative to the block it is adjacent to.
public static EnumFacing getRelativeFacing(EnumFacing facing1, EnumFacing facing2) {
	if (facing1 == EnumFacing.EAST) {
		switch (facing2) {
			case NORTH:
				return EnumFacing.WEST;
			case EAST:
				return EnumFacing.NORTH;
			case SOUTH:
				return EnumFacing.EAST;
			case WEST:
				return EnumFacing.SOUTH;
			default:
				break; //Assuming this method is used right, this should never happen.
		}
	}
	if (facing1 == EnumFacing.SOUTH) {
		switch (facing2) {
			case NORTH:
				return EnumFacing.SOUTH;
			case EAST:
				return EnumFacing.WEST;
			case SOUTH:
				return EnumFacing.NORTH;
			case WEST:
				return EnumFacing.EAST;
			default:
				break;
		}
	}
	if (facing1 == EnumFacing.WEST) {
		switch (facing2) {
			case NORTH:
				return EnumFacing.EAST;
			case EAST:
				return EnumFacing.SOUTH;
			case SOUTH:
				return EnumFacing.WEST;
			case WEST:
				return EnumFacing.NORTH;
			default:
				break;
		}
	}
	return facing2;
}

//Logic method that decides whether or not to render a side of a stairs block depending on
//what block is adjacent to it and what their blockstates are.
public static boolean shouldSideBeRendered(IBlockState blockState, IBlockAccess blockAccess, BlockPos pos, EnumFacing side) {

	IBlockState adjBlockState = blockAccess.getBlockState(pos.offset(side)).getActualState(blockAccess, pos.offset(side));

	if (adjBlockState.getBlock() instanceof BlockColoreTransStairs) {

		EnumFacing blockFacing = blockState.getValue(BlockColoreTransStairs.FACING);
		EnumFacing adjBlockRelativeFacing = getRelativeFacing(blockFacing, adjBlockState.getValue(BlockColoreTransStairs.FACING));

		EnumFacing blockRelativeSide = getRelativeSide(blockFacing, side);

		EnumHalf blockHalf = blockState.getValue(BlockColoreTransStairs.HALF);
		EnumHalf adjBlockHalf = adjBlockState.getValue(BlockColoreTransStairs.HALF);

		EnumShape blockShape = blockState.getValue(BlockColoreTransStairs.SHAPE);
		EnumShape adjBlockShape = adjBlockState.getValue(BlockColoreTransStairs.SHAPE);

		if (side == EnumFacing.UP) {
			if (blockHalf == EnumHalf.TOP && adjBlockHalf == EnumHalf.BOTTOM) {
				return false;
			}
			if (blockHalf == EnumHalf.BOTTOM && adjBlockHalf == EnumHalf.TOP) {
				if (blockShape == adjBlockShape && adjBlockRelativeFacing == EnumFacing.NORTH) {
					return false;
				}
			}
		}
		if (side == EnumFacing.DOWN) {
			if (blockHalf == EnumHalf.BOTTOM && adjBlockHalf == EnumHalf.TOP) {
				return false;
			}
			if (blockHalf == EnumHalf.TOP && adjBlockHalf == EnumHalf.BOTTOM) {
				if (blockShape == adjBlockShape && adjBlockRelativeFacing == EnumFacing.NORTH) {
					return false;
				}
			}
		}
		for (EnumFacing facing : EnumFacing.HORIZONTALS) {
			if (blockRelativeSide == facing && adjBlockRelativeFacing == facing.getOpposite()) {
				if (adjBlockShape == EnumShape.STRAIGHT || adjBlockShape == EnumShape.INNER_LEFT || adjBlockShape == EnumShape.INNER_RIGHT) {
					return false;
				}
			}
		}

		if (blockHalf == adjBlockHalf) {
			if (blockRelativeSide == EnumFacing.SOUTH && adjBlockRelativeFacing == EnumFacing.SOUTH) {
				return false;
			}
			if (blockShape == EnumShape.STRAIGHT) {
				if (blockRelativeSide == EnumFacing.NORTH) {
					if (adjBlockRelativeFacing == EnumFacing.EAST) {
						if (adjBlockShape == EnumShape.INNER_RIGHT) {
							return false;
						}
					}
					if (adjBlockRelativeFacing == EnumFacing.WEST) {
						if (adjBlockShape == EnumShape.INNER_LEFT) {
							return false;
						}
					}
				}
				if (blockRelativeSide == EnumFacing.EAST) {
					if (adjBlockRelativeFacing == EnumFacing.NORTH) {
						return false;
					}
					if (adjBlockRelativeFacing == EnumFacing.EAST) {
						if (adjBlockShape == EnumShape.INNER_LEFT) {
							return false;
						}
					}
					if (adjBlockRelativeFacing == EnumFacing.SOUTH) {
						if (adjBlockShape == EnumShape.INNER_RIGHT) {
							return false;
						}
					}
					if (adjBlockRelativeFacing == EnumFacing.WEST) {
						if (adjBlockShape == EnumShape.OUTER_RIGHT) {
							return false;
						}
					}
				}
				if (blockRelativeSide == EnumFacing.SOUTH) {
					return false;
				}
				if (blockRelativeSide == EnumFacing.WEST) {
					if (adjBlockRelativeFacing == EnumFacing.NORTH) {
						return false;
					}
					if (adjBlockRelativeFacing == EnumFacing.EAST) {
						if (adjBlockShape == EnumShape.OUTER_LEFT) {
							return false;
						}
					}
					if (adjBlockRelativeFacing == EnumFacing.SOUTH) {
						if (adjBlockShape == EnumShape.INNER_LEFT) {
							return false;
						}
					}
					if (adjBlockRelativeFacing == EnumFacing.WEST) {
						if (adjBlockShape == EnumShape.INNER_RIGHT) {
							return false;
						}
					}
				}
			}
			if (blockShape == EnumShape.INNER_LEFT) {
				if (blockRelativeSide == EnumFacing.NORTH) {
					if (adjBlockRelativeFacing == EnumFacing.EAST) {
						if (adjBlockShape == EnumShape.INNER_RIGHT) {
							return false;
						}
					}
					if (adjBlockRelativeFacing == EnumFacing.WEST) {
						if (adjBlockShape == EnumShape.INNER_LEFT) {
							return false;
						}
					}
				}
				if (blockRelativeSide == EnumFacing.EAST) {
					if (adjBlockRelativeFacing == EnumFacing.NORTH) {
						return false;
					}
					if (adjBlockRelativeFacing == EnumFacing.EAST) {
						if (adjBlockShape == EnumShape.INNER_LEFT) {
							return false;
						}
					}
					if (adjBlockRelativeFacing == EnumFacing.SOUTH) {
						if (adjBlockShape == EnumShape.INNER_RIGHT) {
							return false;
						}
					}
				}
				if (blockRelativeSide == EnumFacing.SOUTH) {
					if (adjBlockShape != EnumShape.OUTER_LEFT) {
						return false;
					}
				}
				if (blockRelativeSide == EnumFacing.WEST) {
					if (adjBlockRelativeFacing == EnumFacing.SOUTH) {
						if (adjBlockShape == EnumShape.INNER_LEFT) {
							return false;
						}
					}
				}
			}
			if (blockShape == EnumShape.INNER_RIGHT) {
				if (blockRelativeSide == EnumFacing.NORTH) {
					if (adjBlockRelativeFacing == EnumFacing.EAST) {
						if (adjBlockShape == EnumShape.INNER_RIGHT) {
							return false;
						}
					}
					if (adjBlockRelativeFacing == EnumFacing.WEST) {
						if (adjBlockShape == EnumShape.INNER_LEFT) {
							return false;
						}
					}
				}
				if (blockRelativeSide == EnumFacing.EAST) {
					if (adjBlockRelativeFacing == EnumFacing.SOUTH) {
						if (adjBlockShape == EnumShape.INNER_RIGHT) {
							return false;
						}
					}
					if (adjBlockRelativeFacing == EnumFacing.WEST) {
						if (adjBlockShape != EnumShape.OUTER_RIGHT) {
							return false;
						}
					}
				}
				if (blockRelativeSide == EnumFacing.SOUTH) {
					if (adjBlockShape != EnumShape.OUTER_RIGHT) {
						return false;
					}
				}
				if (blockRelativeSide == EnumFacing.WEST) {
					if (adjBlockRelativeFacing == EnumFacing.NORTH) {
						return false;
					}
					if (adjBlockRelativeFacing == EnumFacing.SOUTH) {
						if (adjBlockShape == EnumShape.INNER_LEFT) {
							return false;
						}
					}
					if (adjBlockRelativeFacing == EnumFacing.WEST) {
						if (adjBlockShape == EnumShape.INNER_RIGHT) {
							return false;
						}
					}
				}
			}
			if (blockShape == EnumShape.OUTER_LEFT) {
				if (blockRelativeSide == EnumFacing.NORTH) {
					if (adjBlockShape != EnumShape.OUTER_RIGHT) {
						return false;
					}
				}
				if (blockRelativeSide == EnumFacing.EAST || blockRelativeSide == EnumFacing.SOUTH) {
					return false;
				}
				if (blockRelativeSide == EnumFacing.WEST) {
					if (adjBlockRelativeFacing == EnumFacing.NORTH) {
						return false;
					}
					if (adjBlockRelativeFacing == EnumFacing.EAST) {
						if (adjBlockShape == EnumShape.OUTER_LEFT) {
							return false;
						}
					}
					if (adjBlockRelativeFacing == EnumFacing.SOUTH) {
						if (adjBlockShape == EnumShape.INNER_LEFT) {
							return false;
						}
					}
					if (adjBlockRelativeFacing == EnumFacing.WEST) {
						if (adjBlockShape == EnumShape.INNER_RIGHT) {
							return false;
						}
					}
				}
			}
			if (blockShape == EnumShape.OUTER_RIGHT) {
				if (blockRelativeSide == EnumFacing.NORTH) {
					if (adjBlockShape != EnumShape.OUTER_LEFT) {
						return false;
					}
				}
				if (blockRelativeSide == EnumFacing.EAST) {
					if (adjBlockRelativeFacing == EnumFacing.NORTH) {
						return false;
					}
					if (adjBlockRelativeFacing == EnumFacing.EAST) {
						if (adjBlockShape == EnumShape.INNER_LEFT) {
							return false;
						}
					}
					if (adjBlockRelativeFacing == EnumFacing.SOUTH) {
						if (adjBlockShape == EnumShape.INNER_RIGHT) {
							return false;
						}
					}
				}
				if (blockRelativeSide == EnumFacing.SOUTH || blockRelativeSide == EnumFacing.WEST) {
					return false;
				}
			}
		}
	}
	if (adjBlockState.getBlock() instanceof BlockColoreTrans || adjBlockState.getBlock() instanceof BlockColoreTransSlabDouble) {
		if (doShadeAndColorMatch(blockState, adjBlockState)) {
			return false;
		}
	}
	if (adjBlockState.getBlock() instanceof BlockColoreTransSlabHalf) {
		if ((side == EnumFacing.UP && adjBlockState.getValue(BlockColoreTransSlabHalf.HALF) == EnumBlockHalf.BOTTOM) ||
				(side == EnumFacing.DOWN && adjBlockState.getValue(BlockColoreTransSlabHalf.HALF) == EnumBlockHalf.TOP)) {
			if (doShadeAndColorMatch(blockState, adjBlockState)) {
				return false;
			}
		}
	}
        return true;
    }

//Used to check if the shade & color of the stairs matches that of the adjacent normal block, half-slab, or double-slab.
public static boolean doShadeAndColorMatch(IBlockState blockState, IBlockState adjBlockState) {
	for (String shade : UtilityLists.shadeList) {
		if (blockState.getBlock().getRegistryName().toString().contains(shade) && adjBlockState.getValue(BlockColore.SHADE) == EnumShade.valueOf(shade.toUpperCase())) {
			if (IColorMatcher.isSameColor(blockState, adjBlockState)) {
				return true;
			}
		}
	}
	return false;
}
}

Colore - The mod that adds monochrome blocks in every color of the rainbow!

http://www.minecraftforge.net/forum/index.php?topic=35149

 

If you're looking to learn how to make mods for 1.9.4, I wrote a helpful article with links to a lot of useful resources for learning Minecraft 1.9.4 modding!

 

http://supergeniuszeb.com/mods/a-helpful-list-of-minecraft-1-9-4-modding-resources/

Posted

I call IBlockAccess "world lite."  The interface is everything that a World object is, except that you can't change anything.  It's effectively read-only.  But because it's a read-only world object you can get any information you want or need from the world.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

I call IBlockAccess "world lite."  The interface is everything that a World object is, except that you can't change anything.  It's effectively read-only.  But because it's a read-only world object you can get any information you want or need from the world.

Thanks, that's a very useful description. Given that context, it makes sense why a lot of methods that take an IBlockAccess as a parameter call the parameter "world".

Colore - The mod that adds monochrome blocks in every color of the rainbow!

http://www.minecraftforge.net/forum/index.php?topic=35149

 

If you're looking to learn how to make mods for 1.9.4, I wrote a helpful article with links to a lot of useful resources for learning Minecraft 1.9.4 modding!

 

http://supergeniuszeb.com/mods/a-helpful-list-of-minecraft-1-9-4-modding-resources/

Posted

I did another run-through of my stair-rendering logic and optimized it some more, combining several if-statements with &&, abstracting others that applied to multiple shapes, and removing unnecessary if-statements. I also made the stair-side-rendering work properly with the other stairs so that sides will render if the color & shade of the stairs don't match. Hopefully this code will benefit other people trying to make translucent stairs.

 

package com.supergeniuszeb.colore.utility;

import com.supergeniuszeb.colore.common.blocks.BlockColore;
import com.supergeniuszeb.colore.common.blocks.BlockColoreSlab;
import com.supergeniuszeb.colore.common.blocks.BlockColoreStairs;
import com.supergeniuszeb.colore.common.blocks.BlockColoreTrans;
import com.supergeniuszeb.colore.common.blocks.BlockColoreTransSlabDouble;
import com.supergeniuszeb.colore.common.blocks.BlockColoreTransSlabHalf;
import com.supergeniuszeb.colore.common.blocks.BlockColoreTransStairs;
import com.supergeniuszeb.colore.common.blocks.EnumShade;
import com.supergeniuszeb.colore.common.blocks.IColorMatcher;

import net.minecraft.block.BlockSlab.EnumBlockHalf;
import net.minecraft.block.BlockStairs.EnumHalf;
import net.minecraft.block.BlockStairs.EnumShape;
import net.minecraft.block.state.IBlockState;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumFacing.Axis;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;

public class StairsSideRenderLogic implements IColorMatcher {
//Used to get the side of a stairs relative to its FACING property.
//Also used to get the FACING of an adjacent stairs relative to the block it is adjacent to.
public static EnumFacing getRelativeFacing(EnumFacing facing1, EnumFacing facing2) {
	if (facing2.getAxis() == Axis.X || facing2.getAxis() == Axis.Z) {
		if (facing1 == EnumFacing.EAST) {
			return facing2.rotateYCCW();
		}
		if (facing1 == EnumFacing.SOUTH) {
			return facing2.getOpposite();
		}
		if (facing1 == EnumFacing.WEST) {
			return facing2.rotateY();
		}
	}
	return facing2;
}

//Logic method that decides whether or not to render a side of a stairs block depending on
//what block is adjacent to it and what their blockstates are.
public static boolean shouldSideBeRendered(IBlockState blockState, IBlockAccess blockAccess, BlockPos pos, EnumFacing side) {

	IBlockState adjBlockState = blockAccess.getBlockState(pos.offset(side)).getActualState(blockAccess, pos.offset(side));

	EnumFacing blockFacing = blockState.getValue(BlockColoreStairs.FACING);
	EnumFacing blockRelativeSide = getRelativeFacing(blockFacing, side);
	EnumHalf blockHalf = blockState.getValue(BlockColoreTransStairs.HALF);
	EnumShape blockShape = blockState.getValue(BlockColoreTransStairs.SHAPE);

	if (doShadeAndColorMatch(blockState, adjBlockState)) {
		if (adjBlockState.getBlock() instanceof BlockColoreTransStairs) {
			EnumFacing adjBlockRelativeFacing = getRelativeFacing(blockFacing, adjBlockState.getValue(BlockColoreTransStairs.FACING));
			EnumHalf adjBlockHalf = adjBlockState.getValue(BlockColoreTransStairs.HALF);
			EnumShape adjBlockShape = adjBlockState.getValue(BlockColoreTransStairs.SHAPE);

			if (side == EnumFacing.UP) {
				if (blockHalf == EnumHalf.TOP && adjBlockHalf == EnumHalf.BOTTOM) {
					return false;
				}
				if (blockHalf == EnumHalf.BOTTOM && adjBlockHalf == EnumHalf.TOP
						&& blockShape == adjBlockShape && adjBlockRelativeFacing == EnumFacing.NORTH) {
					return false;
				}
			}
			if (side == EnumFacing.DOWN) {
				if (blockHalf == EnumHalf.BOTTOM && adjBlockHalf == EnumHalf.TOP) {
					return false;
				}
				if (blockHalf == EnumHalf.TOP && adjBlockHalf == EnumHalf.BOTTOM
						&& blockShape == adjBlockShape && adjBlockRelativeFacing == EnumFacing.NORTH) {
					return false;
				}
			}
			for (EnumFacing facing : EnumFacing.HORIZONTALS) {
				if (blockRelativeSide == facing) {
					if (adjBlockRelativeFacing == facing.rotateY() && adjBlockShape == EnumShape.INNER_RIGHT) {
						return false;
					}
					if (adjBlockRelativeFacing == facing.getOpposite()
							&& (adjBlockShape == EnumShape.STRAIGHT || adjBlockShape == EnumShape.INNER_LEFT || adjBlockShape == EnumShape.INNER_RIGHT)) {
						return false;
					}
					if (adjBlockRelativeFacing == facing.rotateYCCW() && adjBlockShape == EnumShape.INNER_LEFT) {
						return false;
					}
				}
			}

			if (blockHalf == adjBlockHalf) {
				if (blockRelativeSide == EnumFacing.SOUTH && adjBlockRelativeFacing == EnumFacing.SOUTH) {
					return false;
				}
				if (blockShape == EnumShape.STRAIGHT) {
					if (blockRelativeSide == EnumFacing.EAST) {
						if (adjBlockRelativeFacing == EnumFacing.NORTH) {
							return false;
						}
						if (adjBlockRelativeFacing == EnumFacing.EAST && adjBlockShape == EnumShape.INNER_LEFT) {
							return false;
						}
						if (adjBlockRelativeFacing == EnumFacing.WEST && adjBlockShape == EnumShape.OUTER_RIGHT) {
							return false;
						}
					}
					if (blockRelativeSide == EnumFacing.SOUTH) {
						return false;
					}
					if (blockRelativeSide == EnumFacing.WEST) {
						if (adjBlockRelativeFacing == EnumFacing.NORTH) {
							return false;
						}
						if (adjBlockRelativeFacing == EnumFacing.EAST && adjBlockShape == EnumShape.OUTER_LEFT) {
							return false;
						}
						if (adjBlockRelativeFacing == EnumFacing.WEST && adjBlockShape == EnumShape.INNER_RIGHT) {
							return false;
						}
					}
				}
				if (blockShape == EnumShape.INNER_LEFT) {
					if (blockRelativeSide == EnumFacing.EAST) {
						if (adjBlockRelativeFacing == EnumFacing.NORTH) {
							return false;
						}
						if (adjBlockRelativeFacing == EnumFacing.EAST && adjBlockShape == EnumShape.INNER_LEFT) {
							return false;
						}
					}
					if (blockRelativeSide == EnumFacing.SOUTH && adjBlockShape != EnumShape.OUTER_LEFT) {
						return false;
					}
				}
				if (blockShape == EnumShape.INNER_RIGHT) {
					if (blockRelativeSide == EnumFacing.SOUTH && adjBlockShape != EnumShape.OUTER_RIGHT) {
						return false;
					}
					if (blockRelativeSide == EnumFacing.WEST) {
						if (adjBlockRelativeFacing == EnumFacing.NORTH) {
							return false;
						}
						if (adjBlockRelativeFacing == EnumFacing.WEST && adjBlockShape == EnumShape.INNER_RIGHT) {
							return false;
						}
					}
				}
				if (blockShape == EnumShape.OUTER_LEFT) {
					if (blockRelativeSide == EnumFacing.NORTH && adjBlockShape != EnumShape.OUTER_RIGHT) {
						return false;
					}
					if (blockRelativeSide == EnumFacing.EAST || blockRelativeSide == EnumFacing.SOUTH) {
						return false;
					}
					if (blockRelativeSide == EnumFacing.WEST) {
						if (adjBlockRelativeFacing == EnumFacing.NORTH) {
							return false;
						}
						if (adjBlockRelativeFacing == EnumFacing.EAST && adjBlockShape == EnumShape.OUTER_LEFT) {
							return false;
						}
						if (adjBlockRelativeFacing == EnumFacing.WEST && adjBlockShape == EnumShape.INNER_RIGHT) {
							return false;
						}
					}
				}
				if (blockShape == EnumShape.OUTER_RIGHT) {
					if (blockRelativeSide == EnumFacing.NORTH && adjBlockShape != EnumShape.OUTER_LEFT) {
						return false;
					}
					if (blockRelativeSide == EnumFacing.EAST) {
						if (adjBlockRelativeFacing == EnumFacing.NORTH) {
							return false;
						}
						if (adjBlockRelativeFacing == EnumFacing.EAST && adjBlockShape == EnumShape.INNER_LEFT) {
							return false;
						}
						if (adjBlockRelativeFacing == EnumFacing.WEST && adjBlockShape == EnumShape.OUTER_RIGHT) {
							return false;
						}
					}
					if (blockRelativeSide == EnumFacing.SOUTH || blockRelativeSide == EnumFacing.WEST) {
						return false;
					}
				}
			}
		}
		if (adjBlockState.getBlock() instanceof BlockColoreTrans || adjBlockState.getBlock() instanceof BlockColoreTransSlabDouble) {
			return false;
		}
		if (adjBlockState.getBlock() instanceof BlockColoreTransSlabHalf) {
			if ((side == EnumFacing.UP && adjBlockState.getValue(BlockColoreSlab.HALF) == EnumBlockHalf.BOTTOM)
					|| (side == EnumFacing.DOWN && adjBlockState.getValue(BlockColoreSlab.HALF) == EnumBlockHalf.TOP)) {
				return false;
			}
			if ((blockHalf == EnumHalf.BOTTOM && adjBlockState.getValue(BlockColoreSlab.HALF) == EnumBlockHalf.BOTTOM)
					|| (blockHalf == EnumHalf.TOP && adjBlockState.getValue(BlockColoreSlab.HALF) == EnumBlockHalf.TOP)) {
				if (blockShape != EnumShape.INNER_LEFT && blockShape != EnumShape.INNER_RIGHT && blockRelativeSide == EnumFacing.SOUTH) {
					return false;
				}
				if (blockShape == EnumShape.OUTER_LEFT && blockRelativeSide == EnumFacing.EAST) {
					return false;
				}
				if (blockShape == EnumShape.OUTER_RIGHT && blockRelativeSide == EnumFacing.WEST) {
					return false;
				}
			}
		}
	}
        return true;
    }

//Used to check if the shade & color of the stairs matches that of the adjacent normal block, half-slab, or double-slab.
public static boolean doShadeAndColorMatch(IBlockState blockState, IBlockState adjBlockState) {
	if (IColorMatcher.isSameColor(blockState, adjBlockState)) {
		for (String shade : UtilityLists.shadeList) {
			if (adjBlockState.getBlock() instanceof BlockColoreStairs) {
				if (blockState.getBlock().getRegistryName().toString().contains(shade) && adjBlockState.getBlock().getRegistryName().toString().contains(shade)) {
					return true;
				}
			} else if (blockState.getBlock().getRegistryName().toString().contains(shade) && adjBlockState.getValue(BlockColore.SHADE) == EnumShade.valueOf(shade.toUpperCase())) {
				return true;
			}
		}
	}
	return false;
}
}

 

Still curious if there's anything I can do to improve it even more, though. Also, there's this other problem(?) I'm having with my mod. Whenever I start up the game, I get a bunch of identical errors saying:

[Client thread/ERROR] [FML]: MultiModel minecraft:builtin/missing is empty (no base model or parts were provided/resolved)

But I can't find any problems with any of my item or block models, and they all work and look as intended. Is this a Forge bug or am I doing something wrong?

 

EDIT: Updated the code above again - simplified the functions used to convert an EnumFacing to one relative to the stairs being rendered.

Colore - The mod that adds monochrome blocks in every color of the rainbow!

http://www.minecraftforge.net/forum/index.php?topic=35149

 

If you're looking to learn how to make mods for 1.9.4, I wrote a helpful article with links to a lot of useful resources for learning Minecraft 1.9.4 modding!

 

http://supergeniuszeb.com/mods/a-helpful-list-of-minecraft-1-9-4-modding-resources/

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

    • Version 1.19 - Forge 41.0.63 I want to create a wolf entity that I can ride, so far it seems to be working, but the problem is that when I get on the wolf, I can’t control it. I then discovered that the issue is that the server doesn’t detect that I’m riding the wolf, so I’m struggling with synchronization. However, it seems to not be working properly. As I understand it, the server receives the packet but doesn’t register it correctly. I’m a bit new to Java, and I’ll try to provide all the relevant code and prints *The comments and prints are translated by chatgpt since they were originally in Spanish* Thank you very much in advance No player is mounted, or the passenger is not a player. No player is mounted, or the passenger is not a player. No player is mounted, or the passenger is not a player. No player is mounted, or the passenger is not a player. No player is mounted, or the passenger is not a player. MountableWolfEntity package com.vals.valscraft.entity; import com.vals.valscraft.network.MountSyncPacket; import com.vals.valscraft.network.NetworkHandler; import net.minecraft.client.Minecraft; import net.minecraft.network.syncher.EntityDataAccessor; import net.minecraft.network.syncher.EntityDataSerializers; import net.minecraft.network.syncher.SynchedEntityData; import net.minecraft.server.MinecraftServer; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.Mob; import net.minecraft.world.entity.ai.attributes.AttributeSupplier; import net.minecraft.world.entity.ai.attributes.Attributes; import net.minecraft.world.entity.animal.Wolf; import net.minecraft.world.entity.player.Player; import net.minecraft.world.entity.Entity; import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResult; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; import net.minecraft.world.level.Level; import net.minecraft.world.phys.Vec3; import net.minecraftforge.event.TickEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.network.PacketDistributor; public class MountableWolfEntity extends Wolf { private boolean hasSaddle; private static final EntityDataAccessor<Byte> DATA_ID_FLAGS = SynchedEntityData.defineId(MountableWolfEntity.class, EntityDataSerializers.BYTE); public MountableWolfEntity(EntityType<? extends Wolf> type, Level level) { super(type, level); this.hasSaddle = false; } @Override protected void defineSynchedData() { super.defineSynchedData(); this.entityData.define(DATA_ID_FLAGS, (byte)0); } public static AttributeSupplier.Builder createAttributes() { return Wolf.createAttributes() .add(Attributes.MAX_HEALTH, 20.0) .add(Attributes.MOVEMENT_SPEED, 0.3); } @Override public InteractionResult mobInteract(Player player, InteractionHand hand) { ItemStack itemstack = player.getItemInHand(hand); if (itemstack.getItem() == Items.SADDLE && !this.hasSaddle()) { if (!player.isCreative()) { itemstack.shrink(1); } this.setSaddle(true); return InteractionResult.SUCCESS; } else if (!level.isClientSide && this.hasSaddle()) { player.startRiding(this); MountSyncPacket packet = new MountSyncPacket(true); // 'true' means the player is mounted NetworkHandler.CHANNEL.sendToServer(packet); // Ensure the server handles the packet return InteractionResult.SUCCESS; } return InteractionResult.PASS; } @Override public void travel(Vec3 travelVector) { if (this.isVehicle() && this.getControllingPassenger() instanceof Player) { System.out.println("The wolf has a passenger."); System.out.println("The passenger is a player."); Player player = (Player) this.getControllingPassenger(); // Ensure the player is the controller this.setYRot(player.getYRot()); this.yRotO = this.getYRot(); this.setXRot(player.getXRot() * 0.5F); this.setRot(this.getYRot(), this.getXRot()); this.yBodyRot = this.getYRot(); this.yHeadRot = this.yBodyRot; float forward = player.zza; float strafe = player.xxa; if (forward <= 0.0F) { forward *= 0.25F; } this.flyingSpeed = this.getSpeed() * 0.1F; this.setSpeed((float) this.getAttributeValue(Attributes.MOVEMENT_SPEED) * 1.5F); this.setDeltaMovement(new Vec3(strafe, travelVector.y, forward).scale(this.getSpeed())); this.calculateEntityAnimation(this, false); } else { // The wolf does not have a passenger or the passenger is not a player System.out.println("No player is mounted, or the passenger is not a player."); super.travel(travelVector); } } public boolean hasSaddle() { return this.hasSaddle; } public void setSaddle(boolean hasSaddle) { this.hasSaddle = hasSaddle; } @Override protected void dropEquipment() { super.dropEquipment(); if (this.hasSaddle()) { this.spawnAtLocation(Items.SADDLE); this.setSaddle(false); } } @SubscribeEvent public static void onServerTick(TickEvent.ServerTickEvent event) { if (event.phase == TickEvent.Phase.START) { MinecraftServer server = net.minecraftforge.server.ServerLifecycleHooks.getCurrentServer(); if (server != null) { for (ServerPlayer player : server.getPlayerList().getPlayers()) { if (player.isPassenger() && player.getVehicle() instanceof MountableWolfEntity) { MountableWolfEntity wolf = (MountableWolfEntity) player.getVehicle(); System.out.println("Tick: " + player.getName().getString() + " is correctly mounted on " + wolf); } } } } } private boolean lastMountedState = false; @Override public void tick() { super.tick(); if (!this.level.isClientSide) { // Only on the server boolean isMounted = this.isVehicle() && this.getControllingPassenger() instanceof Player; // Only print if the state changed if (isMounted != lastMountedState) { if (isMounted) { Player player = (Player) this.getControllingPassenger(); // Verify the passenger is a player System.out.println("Server: Player " + player.getName().getString() + " is now mounted."); } else { System.out.println("Server: The wolf no longer has a passenger."); } lastMountedState = isMounted; } } } @Override public void addPassenger(Entity passenger) { super.addPassenger(passenger); if (passenger instanceof Player) { Player player = (Player) passenger; if (!this.level.isClientSide && player instanceof ServerPlayer) { // Send the packet to the server to indicate the player is mounted NetworkHandler.CHANNEL.send(PacketDistributor.PLAYER.with(() -> (ServerPlayer) player), new MountSyncPacket(true)); } } } @Override public void removePassenger(Entity passenger) { super.removePassenger(passenger); if (passenger instanceof Player) { Player player = (Player) passenger; if (!this.level.isClientSide && player instanceof ServerPlayer) { // Send the packet to the server to indicate the player is no longer mounted NetworkHandler.CHANNEL.send(PacketDistributor.PLAYER.with(() -> (ServerPlayer) player), new MountSyncPacket(false)); } } } @Override public boolean isControlledByLocalInstance() { Entity entity = this.getControllingPassenger(); return entity instanceof Player; } @Override public void positionRider(Entity passenger) { if (this.hasPassenger(passenger)) { double xOffset = Math.cos(Math.toRadians(this.getYRot() + 90)) * 0.4; double zOffset = Math.sin(Math.toRadians(this.getYRot() + 90)) * 0.4; passenger.setPos(this.getX() + xOffset, this.getY() + this.getPassengersRidingOffset() + passenger.getMyRidingOffset(), this.getZ() + zOffset); } } } MountSyncPacket package com.vals.valscraft.network; import com.vals.valscraft.entity.MountableWolfEntity; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.player.Player; import net.minecraftforge.network.NetworkEvent; import java.util.function.Supplier; public class MountSyncPacket { private final boolean isMounted; public MountSyncPacket(boolean isMounted) { this.isMounted = isMounted; } public void encode(FriendlyByteBuf buffer) { buffer.writeBoolean(isMounted); } public static MountSyncPacket decode(FriendlyByteBuf buffer) { return new MountSyncPacket(buffer.readBoolean()); } public void handle(NetworkEvent.Context context) { context.enqueueWork(() -> { ServerPlayer player = context.getSender(); // Get the player from the context if (player != null) { // Verifies if the player has dismounted if (!isMounted) { Entity vehicle = player.getVehicle(); if (vehicle instanceof MountableWolfEntity wolf) { // Logic to remove the player as a passenger wolf.removePassenger(player); System.out.println("Server: Player " + player.getName().getString() + " is no longer mounted."); } } } }); context.setPacketHandled(true); // Marks the packet as handled } } networkHandler package com.vals.valscraft.network; import com.vals.valscraft.valscraft; import net.minecraft.resources.ResourceLocation; import net.minecraftforge.network.NetworkRegistry; import net.minecraftforge.network.simple.SimpleChannel; import net.minecraftforge.network.NetworkEvent; import java.util.function.Supplier; public class NetworkHandler { private static final String PROTOCOL_VERSION = "1"; public static final SimpleChannel CHANNEL = NetworkRegistry.newSimpleChannel( new ResourceLocation(valscraft.MODID, "main"), () -> PROTOCOL_VERSION, PROTOCOL_VERSION::equals, PROTOCOL_VERSION::equals ); public static void init() { int packetId = 0; // Register the mount synchronization packet CHANNEL.registerMessage( packetId++, MountSyncPacket.class, MountSyncPacket::encode, MountSyncPacket::decode, (msg, context) -> msg.handle(context.get()) // Get the context with context.get() ); } }  
    • Do you use features of inventory profiles next (ipnext) or is there a change without it?
    • Remove rubidium - you are already using embeddium, which is a fork of rubidium
  • Topics

×
×
  • Create New...

Important Information

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