Jump to content

Struggling with Blockstate


Branone

Recommended Posts

I have read the forge documentation: http://mcforge.readthedocs.io/en/latest/blockstates/states/

 

It does give a step-by-step walkthrough, but a lot of the time when it explains what to do I don't actually understand what I'm suppose to type and I just find it difficult learning what to do and how to do it.

 

Here is my code so far. I've followed all of the instructions but the thing is I think the block is still relying on the normal tag which I set in the blockstate. I took out the normal tag because it shouldn't need that anymore and sure enough I get the error: "Model definition for location odm:hot_tub_empty#normal not found". Also when I look at the block in-game using the F3 function, it doesn't show any of the metadata properties below the name of the block.

 

Blockstate JSON

{
    "variants": {
        "back=false,forward=false,left=false,right=false": {"model": "odm:hot_tub_empty"},
        "back=true,forward=true,left=true,right=true": {"model": "odm:hot_tub_center_empty"},
        "back=true,forward=false,left=false,right=false": {"model": "odm:hot_tub_side_empty"},
        "back=false,forward=true,left=false,right=false": {"model": "odm:hot_tub_side_empty", "y": 180},
        "back=false,forward=false,left=true,right=false": {"model": "odm:hot_tub_side_empty", "y": 270},
        "back=false,forward=false,left=false,right=true": {"model": "odm:hot_tub_side_empty", "y": 90},
        "back=true,forward=true,left=false,right=false": {"model": "odm:hot_tub_sides_two_empty", "y": 90},
        "back=false,forward=false,left=true,right=true": {"model": "odm:hot_tub_sides_two_empty"},
        "back=true,forward=false,left=true,right=false": {"model": "odm:hot_tub_corner_empty", "y": 270},
        "back=true,forward=false,left=false,right=true": {"model": "odm:hot_tub_corner_empty"},
        "back=false,forward=true,left=true,right=false": {"model": "odm:hot_tub_corner_empty", "y": 180},
        "back=true,forward=false,left=true,right=false": {"model": "odm:hot_tub_corner_empty", "y": 270},
        "back=true,forward=true,left=false,right=true": {"model": "odm:hot_tub_sides_three_empty"},
        "back=false,forward=true,left=true,right=true": {"model": "odm:hot_tub_sides_three_empty", "y": 90},
        "back=true,forward=true,left=true,right=false": {"model": "odm:hot_tub_sides_three_empty", "y": 180},
        "back=true,forward=false,left=true,right=true": {"model": "odm:hot_tub_sides_three_empty", "y": 270}
    }
}

 

Block Class

package branone.oddments.blocks;

import branone.oddments.OddmentsMod;
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.BlockState;
import net.minecraft.block.state.IBlockState;
import net.minecraft.util.BlockPos;
import net.minecraft.world.IBlockAccess;

public class BlockHotTub extends Block {

public static final PropertyBool BACK = PropertyBool.create("back");
public static final PropertyBool FORWARD = PropertyBool.create("forward");
public static final PropertyBool LEFT = PropertyBool.create("left");
public static final PropertyBool RIGHT = PropertyBool.create("right");

public BlockHotTub(Material materialIn) {
	super(materialIn);
	this.setCreativeTab(OddmentsMod.tabOddments);
	this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
	this.setDefaultState(this.blockState.getBaseState().withProperty(BACK, false).withProperty(FORWARD, false).withProperty(LEFT, false).withProperty(RIGHT, false));
}

@Override
public boolean isOpaqueCube()
{
	return false;
}

@Override
public boolean isFullCube()
{
	return false;
}

@Override
public IBlockState getActualState(IBlockState state, IBlockAccess world, BlockPos pos)
{
	boolean forward = world.getBlockState(pos.north()).getBlock() == this;
	boolean back = world.getBlockState(pos.south()).getBlock() == this;
	boolean left = world.getBlockState(pos.west()).getBlock() == this;
	boolean right = world.getBlockState(pos.east()).getBlock() == this;
	return state.withProperty(BACK, back).withProperty(FORWARD, forward).withProperty(LEFT, left).withProperty(RIGHT, right);
}

@Override
protected BlockState createBlockState() {
	return new BlockState(this, new IProperty[] {BACK, FORWARD, LEFT, RIGHT});
}

@Override
public int getMetaFromState(IBlockState state) {
	return  0;
}

@Override
public IBlockState getStateFromMeta(int meta) {
	return this.getDefaultState();
}	
}

 

Block Initialization

package branone.oddments.init;

import branone.oddments.Reference;
import branone.oddments.blocks.BlockFan;
import branone.oddments.blocks.BlockFlatscreenTV;
import branone.oddments.blocks.BlockFloorLamp;
import branone.oddments.blocks.BlockKettle;
import branone.oddments.blocks.BlockHotTub;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.client.Minecraft;
import net.minecraft.client.resources.model.ModelResourceLocation;
import net.minecraft.item.Item;
import net.minecraftforge.fml.common.registry.GameRegistry;

public class OddmentsBlocks {

public static Block kettle;
public static Block fan;
public static Block flatscreen_tv;
public static Block floor_lamp;
public static Block hot_tub_empty;

public static void init() {
	kettle = new BlockKettle(Material.iron).setUnlocalizedName("kettle");
	fan = new BlockFan(Material.rock).setUnlocalizedName("fan");
	flatscreen_tv = new BlockFlatscreenTV(Material.iron).setUnlocalizedName("flatscreen_tv");
	floor_lamp = new BlockFloorLamp(Material.cloth).setUnlocalizedName("floor_lamp");
	hot_tub_empty = new BlockFloorLamp(Material.cloth).setUnlocalizedName("hot_tub_empty");
}

public static void registerBlocks() {
	GameRegistry.registerBlock(kettle, kettle.getUnlocalizedName().substring(5));
	GameRegistry.registerBlock(fan, fan.getUnlocalizedName().substring(5));
	GameRegistry.registerBlock(flatscreen_tv, flatscreen_tv.getUnlocalizedName().substring(5));
	GameRegistry.registerBlock(floor_lamp, floor_lamp.getUnlocalizedName().substring(5));
	GameRegistry.registerBlock(hot_tub_empty, hot_tub_empty.getUnlocalizedName().substring(5));
}

public static void registerRenders() {
	registerRender(kettle);
	registerRender(fan);
	registerRender(flatscreen_tv);
	registerRender(floor_lamp);
	registerRender(hot_tub_empty);
}

public static void registerRender(Block block) {
	Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(Item.getItemFromBlock(block), 0, new ModelResourceLocation(Reference.MOD_ID + ":" + block.getUnlocalizedName().substring(5), "inventory"));
}
}

 

Link to comment
Share on other sites

Show how you register your models.

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Link to comment
Share on other sites

Show how you register your models.

Added.

Don't use Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register

Instead use ModelLoader.setCustomModelResourceLocation

Don't use item.getUnlocalizedName

Instead use item.getRegistryName and don't append your modid to this.

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

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



×
×
  • Create New...

Important Information

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