Jump to content

Villagers don't recognize special type of door as a door.


ken2020

Recommended Posts

Hello, I have tried to update the code to my door. The door is a special type of door where instead of hanging on the edge of a block, it goes through the center. For some reason however, the villagers do not recognize it as a door, and therefore never use it. How can I add to my code to make them use it?

 

package com.kenmod.objects.blocks.doors;

import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.DoorBlock;
import net.minecraft.block.HorizontalBlock;
import net.minecraft.state.BooleanProperty;
import net.minecraft.state.DirectionProperty;
import net.minecraft.state.EnumProperty;
import net.minecraft.state.Property;
import net.minecraft.state.StateContainer.Builder;
import net.minecraft.state.properties.BlockStateProperties;
import net.minecraft.state.properties.DoorHingeSide;
import net.minecraft.state.properties.DoubleBlockHalf;
import net.minecraft.util.Direction;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.shapes.ISelectionContext;
import net.minecraft.util.math.shapes.VoxelShape;
import net.minecraft.world.IBlockReader;

public class CenteredDoor extends DoorBlock {
	
	public static final DirectionProperty FACING = HorizontalBlock.HORIZONTAL_FACING;
	public static final BooleanProperty OPEN = BlockStateProperties.OPEN;
	public static final EnumProperty<DoorHingeSide> HINGE = BlockStateProperties.DOOR_HINGE;
	public static final BooleanProperty POWERED = BlockStateProperties.POWERED;
	public static final EnumProperty<DoubleBlockHalf> HALF = BlockStateProperties.DOUBLE_BLOCK_HALF;
	
	protected static final VoxelShape default_shape = Block.makeCuboidShape(0.0D, 0.0D, 7.0D, 16.0D, 16.0D, 9.0D);
	protected static final VoxelShape north_south = Block.makeCuboidShape(0.0D, 0.0D, 7.0D, 16.0D, 16.0D, 9.0D);
	protected static final VoxelShape east_west = Block.makeCuboidShape(7.0D, 0.0D, 0.0D, 9.0D, 16.0D, 16.0D);
	protected static final VoxelShape south_l = Block.makeCuboidShape(13.0D, 0.0D, 7.0D, 16.0D, 16.0D, 21.0D);
	protected static final VoxelShape south_r = Block.makeCuboidShape(0.0D, 0.0D, 7.0D, 3.0D, 16.0D, 21.0D);
	protected static final VoxelShape north_l = Block.makeCuboidShape(0.0D, 0.0D, 9.0D, 3.0D, 16.0D, -5.0D);
	protected static final VoxelShape north_r = Block.makeCuboidShape(13.0D, 0.0D, 9.0D, 16.0D, 16.0D, -5.0D);
	protected static final VoxelShape east_l = Block.makeCuboidShape(7.0D, 0.0D, 0.0D, 21.0D, 16.0D, 3.0D);
	protected static final VoxelShape east_r = Block.makeCuboidShape(7.0D, 0.0D, 13.0D, 21.0D, 16.0D, 16.0D);
	protected static final VoxelShape west_l = Block.makeCuboidShape(9.0D, 0.0D, 13.0D, -5.0D, 16.0D, 16.0D);
	protected static final VoxelShape west_r = Block.makeCuboidShape(9.0D, 0.0D, 0.0D, -5.0D, 16.0D, 3.0D);
	
	public CenteredDoor (Properties properties) {
		super(properties);
	}
	@Override
	public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) {
		Direction dir = (Direction)state.get((Property<?>)FACING);
	    DoorHingeSide side = (DoorHingeSide)state.get((Property<DoorHingeSide>)HINGE);
	    Boolean open = (Boolean)state.get((Property<?>)OPEN);
	    if ((dir == Direction.NORTH || dir == Direction.SOUTH) && !open.booleanValue()) {
	    	return north_south; 
	    }
	    if ((dir == Direction.EAST || dir == Direction.WEST) && !open.booleanValue()) {
	    	return east_west; 
	    }
	    if (dir == Direction.NORTH && side == DoorHingeSide.LEFT) {
	    	return north_l; 
	    }
	    if (dir == Direction.NORTH && side == DoorHingeSide.RIGHT) {
	    	return north_r; 
	    }
	    if (dir == Direction.SOUTH && side == DoorHingeSide.LEFT) {
	    	return south_l; 
	    }
	    if (dir == Direction.SOUTH && side == DoorHingeSide.RIGHT) {
	    	return south_r; 
	    }
	    if (dir == Direction.EAST && side == DoorHingeSide.LEFT) {
	    	return east_l; 
	    }
	    if (dir == Direction.EAST && side == DoorHingeSide.RIGHT) {
	    	return east_r; 
	    }
	    if (dir == Direction.WEST && side == DoorHingeSide.LEFT) {
	    	return west_l; 
	    }
	    if (dir == Direction.WEST && side == DoorHingeSide.RIGHT) {
	    	return west_r; 
	    }
	    return default_shape;
	}
	
	@Override
	protected void fillStateContainer(Builder<Block, BlockState> builder) {
		builder.add(new Property[] {
			HALF,
			FACING,
			OPEN,
			HINGE,
			POWERED
		});
	}
}

 

Link to comment
Share on other sites

Ok I did this:

{
    "replace": false,
    "values": [
        "minecraft:oak_door",
        "minecraft:spruce_door",
        "minecraft:birch_door",
        "minecraft:jungle_door",
        "minecraft:acacia_door",
        "minecraft:dark_oak_door",
        "minecraft:crimson_door",
        "minecraft:warped_door",
        "kenmod:oak_cabin_door"
    ]
}

{
	"replace": false,
	"values": [
		"minecraft:oak_door",
		"minecraft:spruce_door",
		"minecraft:birch_door",
		"minecraft:jungle_door",
		"minecraft:acacia_door",
		"minecraft:dark_oak_door",
		"minecraft:crimson_door",
		"minecraft:warped_door",
		"kenmod:oak_cabin_door"
	]
}

But they still don't open the door.

Link to comment
Share on other sites

19 hours ago, ken2020 said:

Ok I did this:

{
    "replace": false,
    "values": [
        "minecraft:oak_door",
        "minecraft:spruce_door",
        "minecraft:birch_door",
        "minecraft:jungle_door",
        "minecraft:acacia_door",
        "minecraft:dark_oak_door",
        "minecraft:crimson_door",
        "minecraft:warped_door",
        "kenmod:oak_cabin_door"
    ]
}


{
	"replace": false,
	"values": [
		"minecraft:oak_door",
		"minecraft:spruce_door",
		"minecraft:birch_door",
		"minecraft:jungle_door",
		"minecraft:acacia_door",
		"minecraft:dark_oak_door",
		"minecraft:crimson_door",
		"minecraft:warped_door",
		"kenmod:oak_cabin_door"
	]
}

But they still don't open the door.

Where did you put this?

How to ask a good coding question: https://stackoverflow.com/help/how-to-ask

Give logs, code, desired effects, and actual effects. Be thorough or we can't help you. Don't post code without putting it in a code block (the <> button on the post - select "C-type Language"): syntax highlighting makes everything easier, and it keeps the post tidy.

 

My own mod, Magiks Most Evile: GitHub (https://github.com/GenElectrovise/MagiksMostEvile) Wiki (https://magiksmostevile.fandom.com/wiki/Magiks_Most_Evile_Wiki)

Edit your own signature at https://www.minecraftforge.net/forum/settings/signature/

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.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • As the title says i keep on crashing on forge 1.20.1 even without any mods downloaded, i have the latest drivers (nvidia) and vanilla minecraft works perfectly fine for me logs: https://pastebin.com/5UR01yG9
    • Hello everyone, I'm making this post to seek help for my modded block, It's a special block called FrozenBlock supposed to take the place of an old block, then after a set amount of ticks, it's supposed to revert its Block State, Entity, data... to the old block like this :  The problem I have is that the system breaks when handling multi blocks (I tried some fix but none of them worked) :  The bug I have identified is that the function "setOldBlockFields" in the item's "setFrozenBlock" function gets called once for the 1st block of multiblock getting frozen (as it should), but gets called a second time BEFORE creating the first FrozenBlock with the data of the 1st block, hence giving the same data to the two FrozenBlock :   Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=head] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@73681674 BlockEntityData : id:"minecraft:bed",x:3,y:-60,z:-6} Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=3, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=2, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} here is the code inside my custom "freeze" item :    @Override     public @NotNull InteractionResult useOn(@NotNull UseOnContext pContext) {         if (!pContext.getLevel().isClientSide() && pContext.getHand() == InteractionHand.MAIN_HAND) {             BlockPos blockPos = pContext.getClickedPos();             BlockPos secondBlockPos = getMultiblockPos(blockPos, pContext.getLevel().getBlockState(blockPos));             if (secondBlockPos != null) {                 createFrozenBlock(pContext, secondBlockPos);             }             createFrozenBlock(pContext, blockPos);             return InteractionResult.SUCCESS;         }         return super.useOn(pContext);     }     public static void createFrozenBlock(UseOnContext pContext, BlockPos blockPos) {         BlockState oldState = pContext.getLevel().getBlockState(blockPos);         BlockEntity oldBlockEntity = oldState.hasBlockEntity() ? pContext.getLevel().getBlockEntity(blockPos) : null;         CompoundTag oldBlockEntityData = oldState.hasBlockEntity() ? oldBlockEntity.serializeNBT() : null;         if (oldBlockEntity != null) {             pContext.getLevel().removeBlockEntity(blockPos);         }         BlockState FrozenBlock = setFrozenBlock(oldState, oldBlockEntity, oldBlockEntityData);         pContext.getLevel().setBlockAndUpdate(blockPos, FrozenBlock);     }     public static BlockState setFrozenBlock(BlockState blockState, @Nullable BlockEntity blockEntity, @Nullable CompoundTag blockEntityData) {         BlockState FrozenBlock = BlockRegister.FROZEN_BLOCK.get().defaultBlockState();         ((FrozenBlock) FrozenBlock.getBlock()).setOldBlockFields(blockState, blockEntity, blockEntityData);         return FrozenBlock;     }  
    • It is an issue with quark - update it to this build: https://www.curseforge.com/minecraft/mc-mods/quark/files/3642325
    • Remove Instant Massive Structures Mod from your server     Add new crash-reports with sites like https://paste.ee/  
  • Topics

×
×
  • Create New...

Important Information

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