Jump to content

Recommended Posts

Posted (edited)

For about 2 weeks now I can't figure out what my mistake is.
In general, at first I just made a block on which I pulled an oriented texture, and it worked perfectly, but then when I started trying to add functionality to the block (ripping it off the furnace functionality) Minecraft started complaining that it couldn't find the required parameter in the block, I checked everything, it looks correct (and before that it worked), it seems to be registered during installation.
The only thing I can blame is that it was necessary to somehow register abstract classes or somehow think about blockentity.

I forgot to mention, this happens when placing a block in the world, the texture on the item itself is normal.

Error:

java.lang.IllegalArgumentException: Cannot set property DirectionProperty{name=facing, clazz=class net.minecraft.core.Direction, values=[north, east, south, west, up, down]} as it does not exist in Block{infernaltech:geothermal_generator}
    at net.minecraft.world.level.block.state.StateHolder.setValue(StateHolder.java:122) ~[forge-1.20.4-49.1.13_mapped_official_1.20.4.jar:?] {re:classloading}
    at ru.artem.alaverdyan.infernaltech.common.block.Mechanism.getStateForPlacement(Mechanism.java:69) ~[main/:?] {re:classloading}
    at net.minecraft.world.item.BlockItem.getPlacementState(BlockItem.java:119) ~[forge-1.20.4-49.1.13_mapped_official_1.20.4.jar:?] {re:classloading}
    at net.minecraft.world.item.BlockItem.place(BlockItem.java:65) ~[forge-1.20.4-49.1.13_mapped_official_1.20.4.jar:?] {re:classloading}
    at net.minecraft.world.item.BlockItem.useOn(BlockItem.java:46) ~[forge-1.20.4-49.1.13_mapped_official_1.20.4.jar:?] {re:classloading}
    at net.minecraft.world.item.ItemStack.lambda$useOn$10(ItemStack.java:274) ~[forge-1.20.4-49.1.13_mapped_official_1.20.4.jar:?] {re:classloading,xf:fml:forge:itemstack}
    at net.minecraft.world.item.ItemStack.onItemUse(ItemStack.java:289) ~[forge-1.20.4-49.1.13_mapped_official_1.20.4.jar:?] {re:classloading,xf:fml:forge:itemstack}
    at net.minecraft.world.item.ItemStack.useOn(ItemStack.java:274) ~[forge-1.20.4-49.1.13_mapped_official_1.20.4.jar:?] {re:classloading,xf:fml:forge:itemstack}
    at net.minecraft.client.multiplayer.MultiPlayerGameMode.performUseItemOn(MultiPlayerGameMode.java:337) ~[forge-1.20.4-49.1.13_mapped_official_1.20.4.jar:?] {re:classloading,pl:runtimedistcleaner:A}
    at net.minecraft.client.multiplayer.MultiPlayerGameMode.lambda$useItemOn$4(MultiPlayerGameMode.java:292) ~[forge-1.20.4-49.1.13_mapped_official_1.20.4.jar:?] {re:classloading,pl:runtimedistcleaner:A}


Mechanism.java

Spoiler

 

public abstract class Mechanism extends BaseEntityBlock {
    public static final DirectionProperty FACING;

    public Mechanism(Properties properties) {
        super(properties);
        this.registerDefaultState(this.stateDefinition.any().setValue(FACING, Direction.NORTH));
    }

    protected abstract MapCodec<? extends Mechanism> codec();

    public InteractionResult use(BlockState p_48706_, Level p_48707_, BlockPos p_48708_, Player p_48709_, InteractionHand p_48710_, BlockHitResult p_48711_) {
        if (p_48707_.isClientSide) {
            return InteractionResult.SUCCESS;
        } else {
            this.openContainer(p_48707_, p_48708_, p_48709_);
            return InteractionResult.CONSUME;
        }
    }

    protected abstract void openContainer(Level var1, BlockPos var2, Player var3);

    @javax.annotation.Nullable
    protected static <T extends BlockEntity> BlockEntityTicker<T> createMechanismTicker(Level p_151988_, BlockEntityType<T> p_151989_, BlockEntityType<? extends MechanismEntity> p_151990_) {
        return p_151988_.isClientSide ? null : createTickerHelper(p_151989_, p_151990_, MechanismEntity::serverTick);
    }

    @Override
    public void setPlacedBy(Level p_48694_, BlockPos p_48695_, BlockState p_48696_, LivingEntity p_48697_, ItemStack p_48698_) {
        if (p_48698_.hasCustomHoverName()) {
            BlockEntity entity = p_48694_.getBlockEntity(p_48695_);
            if (entity instanceof MechanismEntity) {
                ((MechanismEntity) entity).setCustomName(p_48698_.getHoverName());
            }
        }
    }

    @Override
    protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> p_49915_) {
        p_49915_.add(new Property[]{FACING});
        super.createBlockStateDefinition(p_49915_);
    }

    @Override
    public BlockState getStateForPlacement(BlockPlaceContext context) {
        return defaultBlockState().setValue(BlockStateProperties.FACING, context.getHorizontalDirection().getOpposite());
    }

    static {
        FACING = HorizontalDirectionalBlock.FACING;
    }
}

GeothermalGenerator.java

Spoiler

 

public class GeothermalGenerator extends Mechanism {

    public static final MapCodec<GeothermalGenerator> CODEC = simpleCodec(GeothermalGenerator::new);

    public MapCodec<GeothermalGenerator> codec() {
        return CODEC;
    }

    public GeothermalGenerator(BlockBehaviour.Properties properties) {
        super(properties);
    }

    @Override
    public @Nullable <T extends BlockEntity> BlockEntityTicker<T> getTicker(Level p_153212_, BlockState p_153213_, BlockEntityType<T> p_153214_) {
        return createMechanismTicker(p_153212_, p_153214_, ITBlockEntities.GEOTHERMAL_GENERATOR.get());
    }

    @Override
    protected void openContainer(Level var1, BlockPos var2, Player var3) {
    }

    @Override
    public @Nullable BlockEntity newBlockEntity(BlockPos blockPos, BlockState blockState) {
        return new GeothermalGeneratorEntity(blockPos, blockState);
    }
}

blockstates\geothermal_generator.json

Spoiler

 

{
  "variants": {
    "facing=east": {
      "model": "infernaltech:block/geothermal_generator",
      "y": 90
    },
    "facing=north": {
      "model": "infernaltech:block/geothermal_generator"
    },
    "facing=south": {
      "model": "infernaltech:block/geothermal_generator",
      "y": 180
    },
    "facing=west": {
      "model": "infernaltech:block/geothermal_generator",
      "y": 270
    }
  }
}

 

Edited by Mega4oSS
translation error
Posted

You're using the wrong FACING property in Mechanism#getStateForPlacementBlockStateProperties.FACING instead of Mechanism.FACINGHorizontalDirectionalBlock.FACING or BlockStateProperties.HORIZONTAL_FACING (which all refer to the same value). The former includes all six Direction values, the latter only includes the four horizontal values.

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
8 hours ago, Choonster said:

You're using the wrong FACING property in Mechanism#getStateForPlacementBlockStateProperties.FACING instead of Mechanism.FACINGHorizontalDirectionalBlock.FACING or BlockStateProperties.HORIZONTAL_FACING (which all refer to the same value). The former includes all six Direction values, the latter only includes the four horizontal values.

 

Thank you very much, it works.

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.