Jump to content

[SOLVED] how to check the block ID's for all adjacent blocks


Recommended Posts

I'm not new to java, but i am to minecraft modding...

Is there a way to make all glass (or custom glass blocks) blocks check for adjacent glass block and load diffrent textures based on that info ?

i.e "if there is only a glass block left of this glass block, load xyz, else if..."


I realise there are already "connected textures mods" but I'm trying to make my own, I just have no clue where data of the minecraft world is stored or wich methods check for the JSON files in ored to decide wich texture to load for wich blocks.


Any help would be appreciated 

Edited by goingcrowd9
Link to comment
Share on other sites

Every block paramter is passed a World object and a BlockPos position argument (or three ints, x, y, and z). Get the neighbors and check their blockstate against the current one.


And if you're on a version that passes x,y, and z, update. Because BlockIDs are not a thing you should touch.

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.

Link to comment
Share on other sites

package com.goingcrowd9.blazemod.blocks;

import java.util.Random;

import com.goingcrowd9.blazemod.Main;
import com.goingcrowd9.blazemod.init.ModItems;

import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyBool;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraft.util.BlockRenderLayer;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.IStringSerializable;
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 CustomGlass extends BlockBase {
    /** Whether this glass block connects with the block left of it */
    public static final PropertyBool LEFT = PropertyBool.create("left");
    /** Whether this glass block connects with the block right of it */
    public static final PropertyBool RIGHT = PropertyBool.create("right");
    /** Whether this glass block connects with the block above it */
    public static final PropertyBool TOP = PropertyBool.create("top");
    /** Whether this glass block connects with the block below it */
    public static final PropertyBool BOTTOM = PropertyBool.create("bottom");
    public CustomGlass(String name, Material material) {
        super(name, material);
        this.setDefaultState(this.blockState.getBaseState().withProperty(LEFT, Boolean.valueOf(false)).withProperty(RIGHT, Boolean.valueOf(false)).withProperty(TOP, Boolean.valueOf(false)).withProperty(BOTTOM, Boolean.valueOf(false)));
    // without it the block directly 'behind' the glass doesn't get rendered
    public boolean isOpaqueCube(IBlockState state){ return false; }
    // glass drops nothing
    public int quantityDropped(Random random){ return 0; }

    // prevents glass from being a black cube with the glass texture on top
    public BlockRenderLayer getBlockLayer(){ return BlockRenderLayer.CUTOUT; }
    // Determines if an entity can path through this block
    public boolean isPassable(IBlockAccess worldIn, BlockPos pos){ return false; }

    // glass is not a full block
    public boolean isFullCube(IBlockState state){ return false; }

    // glass can (only) drop itself when mined with a 'Silk Touch' tool
    protected boolean canSilkHarvest(){ return true; }
    // Convert the BlockState into the correct metadata value ?? not sure ?
    public int getMetaFromState(IBlockState state){ return 0; }
    // determines if current side can be connected to
    public boolean canConnectSide(String sideToCheck, boolean otherArguments) {
        boolean connect = false;
        if(otherArguments) {    // just as placeholder !!
            connect = true;
        return connect;
    /* Get the actual Block state of this Block at the given position */
    public IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos)
        return state.withProperty(LEFT, canConnectSide("left", true) )
                    .withProperty(RIGHT, canConnectSide("left", false) )
                    .withProperty(TOP, canConnectSide("left", true) )
                    .withProperty(BOTTOM, canConnectSide("left", false) );

    /* generates every unique combination and tells minecraft we want to use the variables */
    public BlockStateContainer createBlockState() {
        return new BlockStateContainer(this, new IProperty[] {LEFT, RIGHT, TOP, BOTTOM} );

My customGlass Class ^


    "forge_marker": 1,
    "multipart": [
        {   "apply": { "model": "bm:glass_middle" } },
        {   "when": { "left": "true" },
            "apply": { "model": "bm:glass_left", "uvlock": true }
        {   "when": { "right": "true" },
            "apply": { "model": "bm:glass_right", "uvlock": true }
        {   "when": { "top": "true" },
            "apply": { "model": "bm:glass_top", "uvlock": true }
        {   "when": { "bottom": "true" },
            "apply": { "model": "bm:glass_bottom", "uvlock": true }

assets > blockstates > custom_glass.json ^


   "parent": "block/cube_all",
   "textures": {
       "all": "bm:blocks/glass_VARIANT"

assets > models > block / item > glass_VARIANT.json


I get a lot of errors in this form (basically for all possible variants) :

[15:15:01] [main/ERROR] [FML]: Exception loading model for variant bm:custom_glass#bottom=false,left=false,right=true,top=true for blockstate "bm:custom_glass[bottom=false,left=false,right=true,top=true]"


I first tried to give this block multiple blockstates and to load in into the game, but it doesn't display any texture at all...

My other custom block loads just fine but apparently it doesn't load or register all variants correctly ?

does anyone knows what I'm doing wrong ?


EDIT: by removing  "forge_marker": 1 the custom glass block now displays a texture

now I just try to get the blockstates of adjacent blockstates and make the method 'canConnectSide' working.

Edited by goingcrowd9
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.

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.

  • Create New...

Important Information

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