Jump to content

Fence Gate rendering problem 1.10.2 (Solved)


jjattack

Recommended Posts

Hi all, I am fairly new to forge and have been working things out slowly with stairs, fences and walls, but cannot get fence gates to work at all.

I was unable to find a work around to extend BlockFence, so I have a copy of it (almost) extending BlockHorizontal, which i'm pretty sure is wrong to begin with.. however, it is working in game as an item showing the correct texture , but when placing it it only appears as a pink and black box.

No matter how many times i go over the blockstate and model jsons i cant find any faults with them, so the error must be in the code which I just don't understand enough of to figure out. Any help would be greatly appreciated  :)

So here it is:

BasicFenceGate class

 

 

public class CoeBasicFenceGate extends BlockHorizontal implements ItemModelProvider{


	protected String thisname;
    public static final PropertyBool OPEN = PropertyBool.create("open");
    public static final PropertyBool POWERED = PropertyBool.create("powered");
    public static final PropertyBool IN_WALL = PropertyBool.create("in_wall");
    protected static final AxisAlignedBB AABB_COLLIDE_ZAXIS = new AxisAlignedBB(0.0D, 0.0D, 0.375D, 1.0D, 1.0D, 0.625D);
    protected static final AxisAlignedBB AABB_COLLIDE_XAXIS = new AxisAlignedBB(0.375D, 0.0D, 0.0D, 0.625D, 1.0D, 1.0D);
    protected static final AxisAlignedBB AABB_COLLIDE_ZAXIS_INWALL = new AxisAlignedBB(0.0D, 0.0D, 0.375D, 1.0D, 0.8125D, 0.625D);
    protected static final AxisAlignedBB AABB_COLLIDE_XAXIS_INWALL = new AxisAlignedBB(0.375D, 0.0D, 0.0D, 0.625D, 0.8125D, 1.0D);
    protected static final AxisAlignedBB AABB_CLOSED_SELECTED_ZAXIS = new AxisAlignedBB(0.0D, 0.0D, 0.375D, 1.0D, 1.5D, 0.625D);
    protected static final AxisAlignedBB AABB_CLOSED_SELECTED_XAXIS = new AxisAlignedBB(0.375D, 0.0D, 0.0D, 0.625D, 1.5D, 1.0D);

    public CoeBasicFenceGate(Material p_i46395_1_, MapColor p_i46395_2_, String name)
    {
        super(p_i46395_1_, p_i46395_2_);
        this.setDefaultState(this.blockState.getBaseState().withProperty(OPEN, Boolean.valueOf(false)).withProperty(POWERED, Boolean.valueOf(false)).withProperty(IN_WALL, Boolean.valueOf(false)));
        this.thisname = name;
		this.setUnlocalizedName(name);
		this.setRegistryName(name);
	}

	@Override
	public void registerItemModel(Item item) {
		CoeMod.proxy.registerItemRenderer(item, 0, thisname);
	}

	@Override
	public CoeBasicFenceGate setCreativeTab(CreativeTabs tab) {
		super.setCreativeTab(tab);
		return this;
	}

	@Override
	public CoeBasicFenceGate setLightLevel(float value)
    {
        this.lightValue = (int)(15.0F * value);
        return this;
    }

    public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos)
    {
        state = this.getActualState(state, source, pos);
        return ((Boolean)state.getValue(IN_WALL)).booleanValue() ? (((EnumFacing)state.getValue(FACING)).getAxis() == EnumFacing.Axis.X ? AABB_COLLIDE_XAXIS_INWALL : AABB_COLLIDE_ZAXIS_INWALL) : (((EnumFacing)state.getValue(FACING)).getAxis() == EnumFacing.Axis.X ? AABB_COLLIDE_XAXIS : AABB_COLLIDE_ZAXIS);
    }

    /**
     * Get the actual Block state of this Block at the given position. This applies properties not visible in the
     * metadata, such as fence connections.
     */
    public IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos)
    {
        EnumFacing.Axis enumfacing$axis = ((EnumFacing)state.getValue(FACING)).getAxis();

        if (enumfacing$axis == EnumFacing.Axis.Z && (worldIn.getBlockState(pos.west()).getBlock() == Blocks.COBBLESTONE_WALL || worldIn.getBlockState(pos.east()).getBlock() == Blocks.COBBLESTONE_WALL) || enumfacing$axis == EnumFacing.Axis.X && (worldIn.getBlockState(pos.north()).getBlock() == Blocks.COBBLESTONE_WALL || worldIn.getBlockState(pos.south()).getBlock() == Blocks.COBBLESTONE_WALL))
        {
            state = state.withProperty(IN_WALL, Boolean.valueOf(true));
        }

        return state;
    }

    /**
     * Returns the blockstate with the given rotation from the passed blockstate. If inapplicable, returns the passed
     * blockstate.
     */
    public IBlockState withRotation(IBlockState state, Rotation rot)
    {
        return state.withProperty(FACING, rot.rotate((EnumFacing)state.getValue(FACING)));
    }

    /**
     * Returns the blockstate with the given mirror of the passed blockstate. If inapplicable, returns the passed
     * blockstate.
     */
    public IBlockState withMirror(IBlockState state, Mirror mirrorIn)
    {
        return state.withRotation(mirrorIn.toRotation((EnumFacing)state.getValue(FACING)));
    }

    public boolean canPlaceBlockAt(World worldIn, BlockPos pos)
    {
        return worldIn.getBlockState(pos.down()).getMaterial().isSolid() ? super.canPlaceBlockAt(worldIn, pos) : false;
    }

    @Nullable
    public AxisAlignedBB getCollisionBoundingBox(IBlockState blockState, World worldIn, BlockPos pos)
    {
        return ((Boolean)blockState.getValue(OPEN)).booleanValue() ? NULL_AABB : (((EnumFacing)blockState.getValue(FACING)).getAxis() == EnumFacing.Axis.Z ? AABB_CLOSED_SELECTED_ZAXIS : AABB_CLOSED_SELECTED_XAXIS);
    }

    /**
     * Used to determine ambient occlusion and culling when rebuilding chunks for render
     */
    public boolean isOpaqueCube(IBlockState state)
    {
        return false;
    }

    public boolean isFullCube(IBlockState state)
    {
        return false;
    }

    public boolean isPassable(IBlockAccess worldIn, BlockPos pos)
    {
        return ((Boolean)worldIn.getBlockState(pos).getValue(OPEN)).booleanValue();
    }

    /**
     * Called by ItemBlocks just before a block is actually set in the world, to allow for adjustments to the
     * IBlockstate
     */
    public IBlockState onBlockPlaced(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer)
    {
        return this.getDefaultState().withProperty(FACING, placer.getHorizontalFacing()).withProperty(OPEN, Boolean.valueOf(false)).withProperty(POWERED, Boolean.valueOf(false)).withProperty(IN_WALL, Boolean.valueOf(false));
    }

    public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, @Nullable ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ)
    {
        if (((Boolean)state.getValue(OPEN)).booleanValue())
        {
            state = state.withProperty(OPEN, Boolean.valueOf(false));
            worldIn.setBlockState(pos, state, 10);
        }
        else
        {
            EnumFacing enumfacing = EnumFacing.fromAngle((double)playerIn.rotationYaw);

            if (state.getValue(FACING) == enumfacing.getOpposite())
            {
                state = state.withProperty(FACING, enumfacing);
            }

            state = state.withProperty(OPEN, Boolean.valueOf(true));
            worldIn.setBlockState(pos, state, 10);
        }

        worldIn.playEvent(playerIn, ((Boolean)state.getValue(OPEN)).booleanValue() ? 1008 : 1014, pos, 0);
        return true;
    }

    /**
     * Called when a neighboring block was changed and marks that this state should perform any checks during a neighbor
     * change. Cases may include when redstone power is updated, cactus blocks popping off due to a neighboring solid
     * block, etc.
     */
    public void neighborChanged(IBlockState state, World worldIn, BlockPos pos, Block blockIn)
    {
        if (!worldIn.isRemote)
        {
            boolean flag = worldIn.isBlockPowered(pos);

            if (flag || blockIn.getDefaultState().canProvidePower())
            {
                if (flag && !((Boolean)state.getValue(OPEN)).booleanValue() && !((Boolean)state.getValue(POWERED)).booleanValue())
                {
                    worldIn.setBlockState(pos, state.withProperty(OPEN, Boolean.valueOf(true)).withProperty(POWERED, Boolean.valueOf(true)), 2);
                    worldIn.playEvent((EntityPlayer)null, 1008, pos, 0);
                }
                else if (!flag && ((Boolean)state.getValue(OPEN)).booleanValue() && ((Boolean)state.getValue(POWERED)).booleanValue())
                {
                    worldIn.setBlockState(pos, state.withProperty(OPEN, Boolean.valueOf(false)).withProperty(POWERED, Boolean.valueOf(false)), 2);
                    worldIn.playEvent((EntityPlayer)null, 1014, pos, 0);
                }
                else if (flag != ((Boolean)state.getValue(POWERED)).booleanValue())
                {
                    worldIn.setBlockState(pos, state.withProperty(POWERED, Boolean.valueOf(flag)), 2);
                }
            }
        }
    }

    @SideOnly(Side.CLIENT)
    public boolean shouldSideBeRendered(IBlockState blockState, IBlockAccess blockAccess, BlockPos pos, EnumFacing side)
    {
        return true;
    }

    /**
     * Convert the given metadata into a BlockState for this Block
     */
    public IBlockState getStateFromMeta(int meta)
    {
        return this.getDefaultState().withProperty(FACING, EnumFacing.getHorizontal(meta)).withProperty(OPEN, Boolean.valueOf((meta & 4) != 0)).withProperty(POWERED, Boolean.valueOf((meta &  != 0));
    }

    /**
     * Convert the BlockState into the correct metadata value
     */
    public int getMetaFromState(IBlockState state)
    {
        int i = 0;
        i = i | ((EnumFacing)state.getValue(FACING)).getHorizontalIndex();

        if (((Boolean)state.getValue(POWERED)).booleanValue())
        {
            i |= 8;
        }

        if (((Boolean)state.getValue(OPEN)).booleanValue())
        {
            i |= 4;
        }

        return i;
    }

    protected BlockStateContainer createBlockState()
    {
        return new BlockStateContainer(this, new IProperty[] {FACING, OPEN, POWERED, IN_WALL});
    }
}

 

 

 

Blocks class

 

public CoeBlocks{

public static CoeBasicFenceGate coe_gate_stone;




public static void init() {

	coe_gate_stone = register(new CoeBasicFenceGate(Material.ROCK,MapColor.STONE, "coe_gate_stone").setCreativeTab(CoeBlocks.CoE_Vanilla_Extras));

}

private static <T extends Block> T register(T block, ItemBlock itemBlock) {
	GameRegistry.register(block);
	GameRegistry.register(itemBlock);

	if (block instanceof ItemModelProvider) {
		((ItemModelProvider)block).registerItemModel(itemBlock);
	}

	return block;
}

private static <T extends Block> T register(T block) {
	ItemBlock itemBlock = new ItemBlock(block);
	itemBlock.setRegistryName(block.getRegistryName());
	return register(block, itemBlock);
}

}

 

 

blockstate "coe_gate_stone.json"

 

{
    "variants": {
        "facing=south,in_wall=false,open=false": { "model": "coe:coe_gatefence_stone_closed", "uvlock": true },
        "facing=west,in_wall=false,open=false":  { "model": "coe:coe_gatefence_stone_closed", "uvlock": true, "y": 90 },
        "facing=north,in_wall=false,open=false": { "model": "coe:coe_gatefence_stone_closed", "uvlock": true, "y": 180 },
        "facing=east,in_wall=false,open=false":  { "model": "coe:coe_gatefence_stone_closed", "uvlock": true, "y": 270 },
        "facing=south,in_wall=false,open=true": { "model": "coe:coe_gatefence_stone_open", "uvlock": true },
        "facing=west,in_wall=false,open=true":  { "model": "coe:coe_gatefence_stone_open", "uvlock": true, "y": 90 },
        "facing=north,in_wall=false,open=true": { "model": "coe:coe_gatefence_stone_open", "uvlock": true, "y": 180 },
        "facing=east,in_wall=false,open=true":  { "model": "coe:coe_gatefence_stone_open", "uvlock": true, "y": 270 },
        "facing=south,in_wall=true,open=false": { "model": "coe:coe_gatewall_stone_closed", "uvlock": true },
        "facing=west,in_wall=true,open=false":  { "model": "coe:coe_gatewall_stone_closed", "uvlock": true, "y": 90 },
        "facing=north,in_wall=true,open=false": { "model": "coe:coe_gatewall_stone_closed", "uvlock": true, "y": 180 },
        "facing=east,in_wall=true,open=false":  { "model": "coe:coe_gatewall_stone_closed", "uvlock": true, "y": 270 },
        "facing=south,in_wall=true,open=true": { "model": "coe:coe_gatewall_stone_open", "uvlock": true },
        "facing=west,in_wall=true,open=true":  { "model": "coe:coe_gatewall_stone_open", "uvlock": true, "y": 90 },
        "facing=north,in_wall=true,open=true": { "model": "coe:coe_gatewall_stone_open", "uvlock": true, "y": 180 },
        "facing=east,in_wall=true,open=true":  { "model": "coe:coe_gatewall_stone_open", "uvlock": true, "y": 270 }
    }
}

 

 

model files (4 of them - names the same as in the blockstate)

 

{
    "parent": "block/fence_gate_open",
    "textures": {
        "texture": "minecraft:blocks/stone"
    }
}

{
    "parent": "block/wall_gate_open",
    "textures": {
        "texture": "minecraft:blocks/stone"
    }
}
{
    "parent": "block/fence_gate_closed",
    "textures": {
        "texture": "minecraft:blocks/stone"
    }
}

{
    "parent": "block/wall_gate_closed",
    "textures": {
        "texture": "minecraft:blocks/stone"
    }
}

 

Link to comment
Share on other sites

I forgot the interface which it uses. I'm probably missing something obvious, although the models work on the fences walls and stars which are registered the same way.

 

 

import net.minecraft.item.Item;

 

public interface ItemModelProvider {

void registerItemModel(Item item);

 

}

Link to comment
Share on other sites

Also

// This
"parent": "block/fence_gate_open",
// and
"parent": "block/fence_gate_closed",
// Don't exist in vanilla 1.10

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

// This

"parent": "block/fence_gate_open",

// and

"parent": "block/fence_gate_closed",

// Don't exist in vanilla 1.10

 

That could be problematic... although the files do exist in the minecraft models folder, I made a copy of what was in them, renamed and linked the model files to the new ones, but that didn't work either.

I don't quite understand how the json links to the code, other than the name. Is there any information on this anywhere?

Link to comment
Share on other sites

registry name is used as a lookup for the blockstate file.

 

If the registry name is set as "asdfqwer123" then it will look in assets/yourmodid/blockstates/ for a file named "asdfqwer1234.json"

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

Copy the fence gates files from vanilla into your mod. Then extends your mod fence gate files instead of the vanilla fence gate files

 

I copied BlockFenceGate to create the BasicFenceGate class, although i changed it's constructor from accepting BlockPlanks.EnumType to Material and MapColor. I tried to create a direct copy of fence, and then extend that, although that produces no different results. I guess the real question should be asking is how to extend BlockFenceGate correctly, although the fact the item model shows up in game correctly suggests the blockstate may be wrong after all. I really have no clue lol.

 

Edit:

Also, I register the models in the proxies:

 

import net.minecraft.item.Item;

public class CommonProxy {

public void registerItemRenderer(Item item, int meta, String id) {
}
}

import jjattack.coe.main.CoeMod;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.item.Item;
import net.minecraftforge.client.model.ModelLoader;

public class ClientProxy extends CommonProxy {

@Override
public void registerItemRenderer(Item item, int meta, String id) {
	ModelLoader.setCustomModelResourceLocation(item, meta, new ModelResourceLocation(CoeMod.modId + ":" + id, "inventory"));
}

}

 

 

 

 

Further Edit - having looked back through the forums the same problem was already discussed.

I changed the blockstate to:

 

{
  "forge_marker": 1,
  "defaults": {
    "textures": {
      "texture": "minecraft:blocks/stone"
    }
  },
  "variants": {
     "normal": { "model": "fence_gate_closed" },
     "inventory": { "model": "fence_gate_closed" },
        "facing=south,in_wall=false,open=false,powered=true": { "model": "fence_gate_closed", "uvlock": true },
        "facing=west,in_wall=false,open=false,powered=true":  { "model": "fence_gate_closed", "uvlock": true, "y": 90 },
        "facing=north,in_wall=false,open=false,powered=true": { "model": "fence_gate_closed", "uvlock": true, "y": 180 },
        "facing=east,in_wall=false,open=false,powered=true":  { "model": "fence_gate_closed", "uvlock": true, "y": 270 },
        "facing=south,in_wall=false,open=true,powered=true": { "model": "fence_gate_open", "uvlock": true },
        "facing=west,in_wall=false,open=true,powered=true":  { "model": "fence_gate_open", "uvlock": true, "y": 90 },
        "facing=north,in_wall=false,open=true,powered=true": { "model": "fence_gate_open", "uvlock": true, "y": 180 },
        "facing=east,in_wall=false,open=true,powered=true":  { "model": "fence_gate_open", "uvlock": true, "y": 270 },
        "facing=south,in_wall=true,open=false,powered=true": { "model": "wall_gate_closed", "uvlock": true },
        "facing=west,in_wall=true,open=false,powered=true":  { "model": "wall_gate_closed", "uvlock": true, "y": 90 },
        "facing=north,in_wall=true,open=false,powered=true": { "model": "wall_gate_closed", "uvlock": true, "y": 180 },
        "facing=east,in_wall=true,open=false,powered=true":  { "model": "wall_gate_closed", "uvlock": true, "y": 270 },
        "facing=south,in_wall=true,open=true,powered=true": { "model": "wall_gate_open", "uvlock": true },
        "facing=west,in_wall=true,open=true,powered=true":  { "model": "wall_gate_open", "uvlock": true, "y": 90 },
        "facing=north,in_wall=true,open=true,powered=true": { "model": "wall_gate_open", "uvlock": true, "y": 180 },
        "facing=east,in_wall=true,open=true,powered=true":  { "model": "wall_gate_open", "uvlock": true, "y": 270 },
        "facing=south,in_wall=false,open=false,powered=false": { "model": "fence_gate_closed", "uvlock": true },
        "facing=west,in_wall=false,open=false,powered=false":  { "model": "fence_gate_closed", "uvlock": true, "y": 90 },
        "facing=north,in_wall=false,open=false,powered=false": { "model": "fence_gate_closed", "uvlock": true, "y": 180 },
        "facing=east,in_wall=false,open=false,powered=false":  { "model": "fence_gate_closed", "uvlock": true, "y": 270 },
        "facing=south,in_wall=false,open=true,powered=false": { "model": "fence_gate_open", "uvlock": true },
        "facing=west,in_wall=false,open=true,powered=false":  { "model": "fence_gate_open", "uvlock": true, "y": 90 },
        "facing=north,in_wall=false,open=true,powered=false": { "model": "fence_gate_open", "uvlock": true, "y": 180 },
        "facing=east,in_wall=false,open=true,powered=false":  { "model": "fence_gate_open", "uvlock": true, "y": 270 },
        "facing=south,in_wall=true,open=false,powered=false": { "model": "wall_gate_closed", "uvlock": true },
        "facing=west,in_wall=true,open=false,powered=false":  { "model": "wall_gate_closed", "uvlock": true, "y": 90 },
        "facing=north,in_wall=true,open=false,powered=false": { "model": "wall_gate_closed", "uvlock": true, "y": 180 },
        "facing=east,in_wall=true,open=false,powered=false":  { "model": "wall_gate_closed", "uvlock": true, "y": 270 },
        "facing=south,in_wall=true,open=true,powered=false": { "model": "wall_gate_open", "uvlock": true },
        "facing=west,in_wall=true,open=true,powered=false":  { "model": "wall_gate_open", "uvlock": true, "y": 90 },
        "facing=north,in_wall=true,open=true,powered=false": { "model": "wall_gate_open", "uvlock": true, "y": 180 },
        "facing=east,in_wall=true,open=true,powered=false":  { "model": "wall_gate_open", "uvlock": true, "y": 270 }
    }
}

 

 

and it all works. Thanks MCrafterzz for your old post!  :)

 

Further further edit: Getting it to work with my walls and fences however is a different story, and it looks as though I will need to do the same with the wall class as with the fence gate.

 

Is this the preferable method of adding new variants of existing blocks then, rather than extending the base files?

 

I have this code in my wall class, is it possible to have something which would make neighboring blocks have the same effect? allowing you to have vanilla fences/walls work with new ones? Or is there another way?

 

    private boolean canConnectTo(IBlockAccess worldIn, BlockPos pos)
    {
        IBlockState iblockstate = worldIn.getBlockState(pos);
        Block block = iblockstate.getBlock();
        return block == Blocks.BARRIER ? false : ((!(block instanceof CoeBlockWall)) && !(block instanceof BlockFenceGate) && !(block instanceof BlockWall) && !(block instanceof CoeBasicFenceGate) ? (CoeBlockWall.blockMaterial.isOpaque() && iblockstate.isFullCube() ? CoeBlockWall.blockMaterial != Material.GOURD : false) : true);
    }

 

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.


×
×
  • Create New...

Important Information

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