Jump to content

[1.19.2] Issues creating variants


SmokyEli

Recommended Posts

I managed to add a few diffrent blockstates to a custom flowerpot, but Im having issues with the flowered variant, I used an if statement but it doesnt seem to run properly and for some reason now the registry on the block class doesnt run either when it did before

Log:

Spoiler

java.lang.IllegalArgumentException: Cannot set property IntegerProperty{name=variation, clazz=class java.lang.Integer, values=[0, 1]} as it does not exist in Block{minecraft:air}

java.lang.NullPointerException: Registry Object not present: bloomyflora_mod:roped_flowerpot

java.lang.IllegalArgumentException: Cannot set property IntegerProperty{name=variation, clazz=class java.lang.Integer, values=[0, 1]} as it does not exist in Block{minecraft:air}

java.lang.NullPointerException: Registry Object not present: bloomyflora_mod:roped_flowerpot

Process 'command 'D:\JKD Modding MC\bin\java.exe'' finished with non-zero exit value -1

Yet the code doesnt seem to have any errors in their class or .json files, I would appriciate if someone could tell me what did I do wrong

 

ModBlocks Class:

Spoiler

package com.Smoky.BloomyFlora.blocks;

import com.Smoky.BloomyFlora.BloomyFlora_Mod;

import com.Smoky.BloomyFlora.items.ModItems;

import net.minecraft.world.item.BlockItem;

import net.minecraft.world.item.CreativeModeTab;

import net.minecraft.world.item.Item; import net.minecraft.world.level.block.Block;

import net.minecraft.world.level.block.state.BlockBehaviour;

import net.minecraft.world.level.material.Material;

import net.minecraftforge.eventbus.api.IEventBus;

import net.minecraftforge.registries.DeferredRegister;

import net.minecraftforge.registries.ForgeRegistries;

import net.minecraftforge.registries.RegistryObject;

import java.util.function.Supplier;

public class ModBlocks

{ public static final DeferredRegister<Block> BLOCKS = DeferredRegister.create(ForgeRegistries.BLOCKS, BloomyFlora_Mod.MOD_ID);

//Test bloque

public static final RegistryObject<Block> CAJA = registerBlock("caja", () -> new Block(BlockBehaviour.Properties.of(Material.WOOD)),CreativeModeTab.TAB_BUILDING_BLOCKS);

//Test CustomBlock - bugged

public static final RegistryObject<Block> ROPED_FLOWERPOT = registerBlock("roped_flowerpot", () -> new FlowerPots_Blocks(BlockBehaviour.Properties.of(Material.DECORATION).noOcclusion()),CreativeModeTab.TAB_BUILDING_BLOCKS);

private static <T extends Block> RegistryObject<T> registerBlock(String name, Supplier<T> block,CreativeModeTab tab){ RegistryObject<T> toReturn = BLOCKS.register(name, block); registerBlockItem( name, toReturn, tab); return toReturn; }

private static <T extends Block> RegistryObject<Item> registerBlockItem ( String name, RegistryObject<T> block, CreativeModeTab tab){ return ModItems.ITEMS.register(name, () -> new BlockItem(block.get(), new Item.Properties().tab(tab))); } public static void register(IEventBus eventBus) { BLOCKS.register(eventBus); } }

FlowerPots_Blocks Class:

Spoiler

package com.Smoky.BloomyFlora.blocks;

import net.minecraft.core.BlockPos;

import net.minecraft.core.Direction;

import net.minecraft.world.InteractionHand;

import net.minecraft.world.InteractionResult;

import net.minecraft.world.item.Item;

import net.minecraft.world.item.ItemStack;

import net.minecraft.world.item.Items;

import net.minecraft.world.item.context.BlockPlaceContext;

import net.minecraft.world.level.BlockGetter;

import net.minecraft.world.level.Level;

import net.minecraft.world.level.block.*;

import net.minecraft.world.level.block.state.BlockState;

import net.minecraft.world.level.block.state.StateDefinition;

import net.minecraft.world.level.block.state.properties.BlockStateProperties;

import net.minecraft.world.level.block.state.properties.DirectionProperty;

import net.minecraft.world.level.block.state.properties.IntegerProperty;

import net.minecraft.world.phys.BlockHitResult;

import net.minecraft.world.phys.shapes.CollisionContext;

import net.minecraft.world.phys.shapes.Shapes;

import net.minecraft.world.phys.shapes.VoxelShape;

import org.jetbrains.annotations.Nullable;

 

public class FlowerPots_Blocks extends HorizontalDirectionalBlock{

public static final DirectionProperty FACING = BlockStateProperties.FACING;

public static final IntegerProperty VARIATION = IntegerProperty.create("variation", 0, 1);

 

public FlowerPots_Blocks(Properties properties) { super(properties);

this.registerDefaultState(this.stateDefinition.any()

.setValue(FACING, Direction.NORTH)

.setValue(VARIATION, 0)); }

 

//Voxel Shape

private static final VoxelShape SHAPE_NORTH = Shapes.or( Block.box(4D, 0D, 6.5D, 12D, 10D, 16D) );

private static final VoxelShape SHAPE_EAST = Shapes.or( Block.box(0D, 0D, 0D, 16D, 10D, 16D) );

private static final VoxelShape SHAPE_SOUTH = Shapes.or( Block.box(4D, 0D, 0D, 12D, 10D, 9.5D) );

private static final VoxelShape SHAPE_WEST = Shapes.or( Block.box(0D, 0D, 0D, 16D, 10D, 16D) );

private static final VoxelShape SHAPE_UP = Shapes.or( Block.box(5D, 0D, 5D, 11D, 6D, 11D), Block.box(4D, 6D, 4D, 12D, 8D, 12D) );

private static final VoxelShape SHAPE_DOWN = Shapes.or( Block.box(4D, 0D, 4D, 12D, 16D, 12D) );

 

@Override public VoxelShape getShape(BlockState state, BlockGetter worldIn, BlockPos pos, CollisionContext context)

{ switch (state.getValue(FACING)) {

case EAST: return SHAPE_EAST;

case SOUTH: return SHAPE_SOUTH;

case WEST: return SHAPE_WEST;

case NORTH: return SHAPE_NORTH;

case UP: return SHAPE_UP;

default: return SHAPE_DOWN; } }

 

//Overrides

@Nullable

@Override public BlockState getStateForPlacement(BlockPlaceContext context) { Direction direction = context.getClickedFace(); return this.defaultBlockState().setValue(FACING, direction); }

@Override public BlockState rotate(BlockState state, Rotation rot) { return state.setValue(FACING, rot.rotate(state.getValue(FACING))); }

@Override public BlockState mirror(BlockState state, Mirror mirrorIn) { return state.rotate(mirrorIn.getRotation(state.getValue(FACING))); }

@Override protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) { builder.add(FACING); }

 

//Use Flower in Flowerpot

@Override

public InteractionResult use(BlockState state, Level world, BlockPos pos, net.minecraft.world.entity.player.Player player, InteractionHand hand, BlockHitResult hit)

{ ItemStack itemstack = player.getItemInHand(hand);

Item item = itemstack.getItem();

Item item1 = null ;

Item item2 = Items.DANDELION;

Item item3 = Items.PINK_TULIP;

int currentVariation = state.getValue(VARIATION);

if (item == item1) { if (!world.isClientSide) { world.setBlock(pos, state.setValue(VARIATION, 0), 2);

if (!player.isCreative()) { itemstack.shrink(1); } } return InteractionResult.SUCCESS; }

else if (item == item2) { if (!world.isClientSide) { world.setBlock(pos, state.setValue(VARIATION, 1), 2);

if (!player.isCreative()) { itemstack.shrink(1); } } return InteractionResult.SUCCESS; }

else if (item == item3) { if (!world.isClientSide) { world.setBlock(pos, state.setValue(VARIATION, 2), 2);

if (!player.isCreative()) { itemstack.shrink(1); } } return InteractionResult.SUCCESS; }

else if (itemstack.isEmpty()) { if (!world.isClientSide) { ItemStack returnItemStack;

if (currentVariation == 1) { returnItemStack = new ItemStack(item2); }

else { returnItemStack = new ItemStack(item3); } player.addItem(returnItemStack); world.setBlock(pos, state.setValue(VARIATION, 0), 2); // 0 represents the empty state }

return InteractionResult.SUCCESS; } return InteractionResult.PASS; } }

roped_flowerpot.json:

Spoiler

{ "variants":

{ "facing=north,variation=0": {"model": "bloomyflora_mod:block/wall_flowerpot"},

"facing=east,variation=0": {"model": "bloomyflora_mod:block/wall_flowerpot", "y": 90},

"facing=south,variation=0": {"model": "bloomyflora_mod:block/wall_flowerpot", "y": 180},

"facing=west,variation=0": {"model": "bloomyflora_mod:block/wall_flowerpot", "y": 270},

"facing=up,variation=0": {"model": "bloomyflora_mod:block/roped_flowerpot"},

"facing=down,variation=0": {"model": "bloomyflora_mod:block/hanging_flowerpot"},

"facing=north,variation=1": {"model": "bloomyflora_mod:block/wall_flowerpot"},

"facing=east,variation=1": {"model": "bloomyflora_mod:block/wall_flowerpot", "y": 90},

"facing=south,variation=1": {"model": "bloomyflora_mod:block/wall_flowerpot", "y": 180},

"facing=west,variation=1": {"model": "bloomyflora_mod:block/wall_flowerpot", "y": 270},

"facing=up,variation=1": {"model": "bloomyflora_mod:block/roped_flowerpot"},

"facing=down,variation=1": {"model": "bloomyflora_mod:block/hanging_flowerpot"} } }

If you wonder if the name of the json in the model block or blockstates is wrong i checked that already, as well as the registry in the main, I didnt changed anything besides de if statements and the roped_flowerpot json to add a variant

I would really appriciate any type of help, I cant find much around this

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.



×
×
  • Create New...

Important Information

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