Polymer

Polymer

763k Downloads

How can I set my block to a block with custom faces, like the despenser.

masterblaster221 opened this issue ยท 3 comments

commented

How can I set a block to the likes of a Dispenser block with custom directions in the texture?
I have tried to use full_block but it comes out as note_block, most cases thats fine but i need to make it rotate based on player direction any help is appreciated

here is my error

java.lang.IllegalArgumentException: Cannot set property class_2753{name=facing, clazz=class net.minecraft.class_2350, values=[down, up, north, south, west, east]} as it does not exist in Block{minecraft:note_block}

code
package heartcore.blocks;

import eu.pb4.polymer.blocks.api.BlockModelType;
import eu.pb4.polymer.blocks.api.PolymerBlockModel;
import eu.pb4.polymer.blocks.api.PolymerBlockResourceUtils;
import eu.pb4.polymer.blocks.api.PolymerTexturedBlock;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.ItemPlacementContext;
import net.minecraft.item.Items;
import net.minecraft.state.StateManager;
import net.minecraft.state.property.DirectionProperty;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.Direction;

public class HeartCoreSimplePolymerBlock extends Block implements PolymerCapableBlock, PolymerTexturedBlock {

public final BlockState polymerBlockState;
public static final DirectionProperty FACING = DirectionProperty.of("facing", Direction.values());

public HeartCoreSimplePolymerBlock(String name, String MOD_ID) {
    super(Settings.copy(Blocks.DISPENSER));
    

    this.setDefaultState(this.stateManager.getDefaultState().with(FACING, Direction.NORTH));

    // Initialize polymer block state
    this.polymerBlockState = PolymerBlockResourceUtils.requestBlock(
        BlockModelType.FULL_BLOCK,
        PolymerBlockModel.of(Identifier.of(MOD_ID, name))
    );
}

// PolymerCapableBlock interface methods
@Override
public Block getPolymerBlock() {
    return this.polymerBlockState.getBlock();
}

@Override
public Item getPolymerItem() {
    return Items.BAMBOO_BLOCK; // Mimic the Bamboo Block item
}

@Override
public BlockState getPolymerBlockState(BlockState state) {
    // Return the polymer block state with the same facing direction
    return this.polymerBlockState.with(FACING, state.get(FACING));
}

@Override
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
    builder.add(FACING); // Register the "facing" property
}

@Override
public BlockState getPlacementState(ItemPlacementContext context) {
    // Determine the facing direction based on the player's placement
    Direction facing = context.getHorizontalPlayerFacing().getOpposite();
    return this.getDefaultState().with(FACING, facing);
}

}

commented

tbh i don't even understand this to much still learning

commented

I am on version 1.21

commented

You need to make sure you use correct instance for FACING, as by creating a new one it won't be equal to one used in your base block!