Jump to content

Recommended Posts

Posted

I am making a block that needs to be able to spin around. Here is its code:

package com.leo.occultcraft.blocks;

import com.leo.occultcraft.CreativeTab;
import com.leo.occultcraft.Occultcraft;
import com.leo.occultcraft.gui.ModGuiHandler;
import com.leo.occultcraft.tiles.TileAthanor;

import net.minecraft.block.Block;
import net.minecraft.block.BlockHorizontal;
import net.minecraft.block.ITileEntityProvider;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.PropertyBool;
import net.minecraft.block.properties.PropertyDirection;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;

public class BlockAthanor extends Block implements ITileEntityProvider {
	public static final PropertyDirection facing = BlockHorizontal.FACING;
	public static final PropertyBool is_on = PropertyBool.create("is_on");
	
	public BlockAthanor() {
		super(Material.IRON);
		
		this.setHardness(2);
		this.setHarvestLevel("pickaxe", 1);
		this.setRegistryName("athanor");
		this.setUnlocalizedName("athanor");
		this.setCreativeTab(CreativeTab.occultcraftCreativeTab);
		
		this.setDefaultState(this.blockState.getBaseState().withProperty(is_on, false).withProperty(facing, EnumFacing.NORTH));
	}
	
	public BlockAthanor(Material materialIn) {
		super(materialIn);
	}

	@Override
	protected BlockStateContainer createBlockState() {
		return new BlockStateContainer(this, is_on, facing);
	}
	
	@Override
	public IBlockState getStateFromMeta(int meta) {
		return this.getDefaultState().withProperty(is_on, meta == 0);
	}
	
	@Override
	public int getMetaFromState(IBlockState state) {
		return state.getValue(is_on) ? 1: 0;
	}
	
	@Override
	public TileEntity createNewTileEntity(World worldIn, int meta) {
		return new TileAthanor();
	}
	
	@Override
	public void breakBlock(World world, BlockPos pos, IBlockState state) {
		super.breakBlock(world, pos, state);
		world.removeTileEntity(pos);
	}

	@Override
    public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
		if (!worldIn.isRemote) {
			playerIn.openGui(Occultcraft.instance, ModGuiHandler.athanorGUIID, worldIn, pos.getX(), pos.getY(), pos.getZ());
		}
		
		return true;
	}	
	
}

Here is the blockstate json:

  Reveal hidden contents

And the models:

  Reveal hidden contents
  Reveal hidden contents

I have tested the rotation with the TE Crescent Hammer and it works okay.

 

Before I added in the PropertyDirection the textures on the block appeared perfectly, but now that I have them there the textures will not appear.

 

I get this error log:

  Reveal hidden contents

 

Posted
  On 9/16/2017 at 1:54 PM, meee39 said:

[14:53:45] [main/ERROR] [FML]: Exception loading blockstate for the variant occultcraft:athanor#facing=west,is_on=false: 

java.lang.Exception: Could not load model definition for variant occultcraft:athanor

...

Caused by: java.lang.RuntimeException: Encountered an exception when loading model definition of 'occultcraft:athanor' from: 'occultcraft:blockstates/athanor.json' in resourcepack: 'FMLFileResourcePack:Occultcraft'

...

Caused by: java.lang.NullPointerException

at net.minecraftforge.common.model.TRSRTransformation.<init>(TRSRTransformation.java:102) ~[TRSRTransformation.class:?]

at net.minecraftforge.client.model.ForgeBlockStateV1$Variant$Deserializer.deserialize(ForgeBlockStateV1.java:500) ~[ForgeBlockStateV1$Variant$Deserializer.class:?]

at net.minecraftforge.client.model.ForgeBlockStateV1$Variant$Deserializer.deserialize(ForgeBlockStateV1.java:434) ~[ForgeBlockStateV1$Variant$Deserializer.class:?]

Expand  

 

The x and y properties in blockstates files can only rotate the model in increments of 90°, but your is_on=true,facing=east variant tries to rotate the model by 99°. This causes the NullPointerException in the TRSRTransformation constructor.

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
  On 9/17/2017 at 8:56 AM, meee39 said:

I changed it back to 90º but it still shows up as the purple and black texture (the textures are in the right place).

Expand  

 

Post the new blockstates file and FML log.

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
  Reveal hidden contents
  Reveal hidden contents

 

Posted
  On 9/17/2017 at 9:52 AM, meee39 said:

Exception loading model for variant occultcraft:athanor#facing=west,is_on=true for blockstate "occultcraft:athanor[facing=west,is_on=true]"

Expand  

The variant it's looking for:

[facing=west,is_on=true]

The variant in your blockstates file:

"is_on=true,facing=west": {

 

Can you spot the difference? Fully-defined variants are simply strings, they must be an exact match - forge doesn't know that you mean the same thing when you have the variants written in a different order. The correct order to write the variants is with the variant names in alphabetical order, so "facing" comes before "is_on".

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.