Jump to content

Recommended Posts

Posted

Until now, I've only modded for 1.7.10. I thought I should get myself up to date and make my next mod for 1.9; unfortunately, the new block handling system is getting the better of me.

 

I have a block class, and in the game, the block item renders just fine. However, when placed in the world, the block doesn't render at all, instead simply culling the adjacent blocks' faces leaving a "hole" in the world where the block should be.

 

Here's the block's model JSON file:

 

{
    "parent": "block/orientable",
    "textures": 
    {
        "top": "breedingseason:blocks/storage_chest_top",
        "front": "breedingseason:blocks/storage_chest_front",
        "side": "breedingseason:blocks/storage_chest_side"
    }
}

 

The textures are basic square PNGs like all Minecraft textures.

 

I have this "block instantiation helper" class:

 

package com.IceMetalPunk.breedingseason.blocks;

public class BreedingSeasonBlocks {
public static final BlockStorageChest StorageChest = new BlockStorageChest();
}

 

And here's the main class:

 

package com.IceMetalPunk.breedingseason;

import com.IceMetalPunk.breedingseason.blocks.BreedingSeasonBlocks;
import com.IceMetalPunk.breedingseason.handlers.BreedingEventHandler;
import com.IceMetalPunk.breedingseason.items.BreedingSeasonItems;

import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.RenderItem;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.registry.GameRegistry;

@Mod(modid = BreedingSeason.MODID, version = BreedingSeason.VERSION)
public class BreedingSeason {
public static final String MODID = "breedingseason";
public static final String VERSION = "1.0";

public static final BreedingSeason instance = new BreedingSeason();

public static final BreedingEventHandler eventListener = new BreedingEventHandler(MinecraftForge.EVENT_BUS);
public static final BreedingSeasonBlocks blocks = new BreedingSeasonBlocks();
public static final BreedingSeasonItems items = new BreedingSeasonItems();

public enum GUI_ENUM {
	STORAGE_CHEST
}

@EventHandler
public void init(FMLInitializationEvent event) {
	GameRegistry.register(blocks.StorageChest);
	GameRegistry.register(items.StorageChest);

	RenderItem renderItem = Minecraft.getMinecraft().getRenderItem();

	ModelResourceLocation modelLocation = new ModelResourceLocation(
			BreedingSeason.MODID + ":" + blocks.StorageChest.getUnlocalizedName().substring(5), "inventory");
	renderItem.getItemModelMesher().register(items.StorageChest, 0, modelLocation);
	// FIXME: Chest block is not rendering, while item is.
	ModelLoader.setCustomModelResourceLocation(items.StorageChest, 0, modelLocation);
}
}

 

And lastly, this is the block class itself; keep in mind I basically followed a tutorial for 1.8 and tried fixing the bits that were out of date. I get no errors, so I thought I did it right, but of course it also doesn't render, so...yeah.

 

package com.IceMetalPunk.breedingseason.blocks;

import java.util.Random;

import com.IceMetalPunk.breedingseason.BreedingSeason;
import com.IceMetalPunk.breedingseason.tileentities.TileEntityStorageChest;
import com.sun.istack.internal.Nullable;

import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyDirection;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.InventoryHelper;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

public class BlockStorageChest extends BlockContainer {

public static final PropertyDirection FACING = PropertyDirection.create("facing", EnumFacing.Plane.HORIZONTAL);

protected BlockStorageChest() {
	super(Material.IRON);
	this.setUnlocalizedName("storage_chest");
	this.setDefaultState(blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH));
	this.setCreativeTab(CreativeTabs.DECORATIONS); // TODO: Add creative tab
										// for the mod
	this.setRegistryName(new ResourceLocation(BreedingSeason.MODID, "storage_chest"));
}

@Override
public Item getItemDropped(IBlockState state, Random rand, int fortune) {
	return Item.getItemFromBlock(BreedingSeasonBlocks.StorageChest);
}

@Override
public void onBlockAdded(World world, BlockPos pos, IBlockState state) {
	if (!world.isRemote) {
		// Rotate block if the front side is blocked
		IBlockState blockToNorth = world.getBlockState(pos.offset(EnumFacing.NORTH));
		IBlockState blockToSouth = world.getBlockState(pos.offset(EnumFacing.SOUTH));
		IBlockState blockToEast = world.getBlockState(pos.offset(EnumFacing.EAST));
		IBlockState blockToWest = world.getBlockState(pos.offset(EnumFacing.WEST));
		EnumFacing enumfacing = (EnumFacing) state.getValue(FACING);

		if (enumfacing == EnumFacing.NORTH && blockToNorth.isFullBlock() && !blockToSouth.isFullBlock()) {
			enumfacing = EnumFacing.SOUTH;
		} else if (enumfacing == EnumFacing.SOUTH && blockToSouth.isFullBlock() && !blockToNorth.isFullBlock()) {
			enumfacing = EnumFacing.NORTH;
		} else if (enumfacing == EnumFacing.WEST && blockToWest.isFullBlock() && !blockToEast.isFullBlock()) {
			enumfacing = EnumFacing.EAST;
		} else if (enumfacing == EnumFacing.EAST && blockToEast.isFullBlock() && !blockToWest.isFullBlock()) {
			enumfacing = EnumFacing.WEST;
		}

		world.setBlockState(pos, state.withProperty(FACING, enumfacing), 2);
	}
}

@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand,
		@Nullable ItemStack item, EnumFacing side, float x, float y, float z) {
	if (!world.isRemote) {
		player.openGui(BreedingSeason.instance, BreedingSeason.GUI_ENUM.STORAGE_CHEST.ordinal(), world, pos.getX(),
				pos.getY(), pos.getZ());
	}

	return true;
}

@Override
public TileEntity createNewTileEntity(World worldIn, int meta) {
	return new TileEntityStorageChest();
}

@Override
public IBlockState onBlockPlaced(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ,
		int meta, EntityLivingBase placer) {
	return getDefaultState().withProperty(FACING, placer.getAdjustedHorizontalFacing().getOpposite());
}

@Override
public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer,
		ItemStack stack) {
	worldIn.setBlockState(pos, state.withProperty(FACING, placer.getAdjustedHorizontalFacing().getOpposite()), 2);
}

@Override
public void breakBlock(World worldIn, BlockPos pos, IBlockState state) {

	TileEntity tileentity = worldIn.getTileEntity(pos);

	if (tileentity instanceof TileEntityStorageChest) {
		InventoryHelper.dropInventoryItems(worldIn, pos, (TileEntityStorageChest) tileentity);
		worldIn.updateComparatorOutputLevel(pos, this);
	}
	super.breakBlock(worldIn, pos, state);
}

@Override
@SideOnly(Side.CLIENT)
public ItemStack getItem(World worldIn, BlockPos pos, IBlockState state) {
	return new ItemStack(Item.getItemFromBlock(BreedingSeasonBlocks.StorageChest));
}

@Override
public IBlockState getStateFromMeta(int meta) {
	EnumFacing enumfacing = EnumFacing.getFront(meta);

	if (enumfacing.getAxis() == EnumFacing.Axis.Y) {
		enumfacing = EnumFacing.NORTH;
	}

	return getDefaultState().withProperty(FACING, enumfacing);
}

@Override
public int getMetaFromState(IBlockState state) {
	return ((EnumFacing) state.getValue(FACING)).getIndex();
}

@Override
protected BlockStateContainer createBlockState() {
	return new BlockStateContainer(this, new IProperty[] { FACING });
}

@SideOnly(Side.CLIENT)
static final class SwitchEnumFacing {
	static final int[] enumFacingArray = new int[EnumFacing.values().length];

	static {
		try {
			enumFacingArray[EnumFacing.WEST.ordinal()] = 1;
		} catch (NoSuchFieldError var4) {
			;
		}

		try {
			enumFacingArray[EnumFacing.EAST.ordinal()] = 2;
		} catch (NoSuchFieldError var3) {
			;
		}

		try {
			enumFacingArray[EnumFacing.NORTH.ordinal()] = 3;
		} catch (NoSuchFieldError var2) {
			;
		}

		try {
			enumFacingArray[EnumFacing.SOUTH.ordinal()] = 4;
		} catch (NoSuchFieldError var1) {
			;
		}
	}
}
}

 

What I don't understand is this: if the item model is just parented to the block model, then how come the item model renders fine but the block model doesn't?

Whatever Minecraft needs, it is most likely not yet another tool tier.

Posted

Egietje is dumb. "Blockstate" and "model" aren't related. You need a blockstate file AND a model file.

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

Sorry for missing it in the OP, but yes, I do have the following blockstate file in the blockstates folder (storage_chest.json):

 

{
    "variants": {
        "facing=north": { "model": "breedingseason:storage_chest" },
        "facing=south": { "model": "breedingseason:storage_chest", "y": 180 },
        "facing=west":  { "model": "breedingseason:storage_chest", "y": 270 },
        "facing=east":  { "model": "breedingseason:storage_chest", "y": 90 }
    }
}

Whatever Minecraft needs, it is most likely not yet another tool tier.

Posted

Don't use BlockContainer, simply override createTileEntity and hasTileEntity from the Block class.

 

If you look into the BlockContainer class, you'll see it does a lot with the rendering, and is simply a pain in the proverbial behind.

Also previously known as eAndPi.

"Pi, is there a station coming up where we can board your train of thought?" -Kronnn

Published Mods: Underworld

Handy links: Vic_'s Forge events Own WIP Tutorials.

Posted

Don't use BlockContainer, simply override createTileEntity and hasTileEntity from the Block class.

 

If you look into the BlockContainer class, you'll see it does a lot with the rendering, and is simply a pain in the proverbial behind.

 

Thank you! This worked and fixed the problem! :D I was in the habit of using BlockContainer for any block with an inventory...I will not be doing that anymore xD Thanks again!

Whatever Minecraft needs, it is most likely not yet another tool tier.

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.