Jump to content

1.15 | I want to apply BedBlock


Zemelua

Recommended Posts

I'm making a chair that I can sit on right now, and I wrote the following code with reference to the startSleeping of the bed, but I get an error. I don't know the cause. Probably a DataParameter. After this, I want to use EXPANSIONMOD_POSE and CHAIR_POTISION, so I want to use this. If it can't be used, is there any alternative?
Note that the idea of using a mountable entity in the first place is not appropriate because you want to pose when sitting or make more complicated movements.

public class ExpansionModEntity extends Entity{
	public ExpansionModEntity(EntityType<?> entityTypeIn, World worldIn) {
		super(entityTypeIn, worldIn);
	}

	protected static final DataParameter<ExpansionModPose> EXPANSIONMOD_POSE = EntityDataManager.createKey(ExpansionModEntity.class, ExpansionModDataSerializers.EXPANSIONMOD_POSE);
	private static final DataParameter<Optional<BlockPos>> CHAIR_POSITION = EntityDataManager.createKey(ExpansionModEntity.class, DataSerializers.OPTIONAL_BLOCK_POS);

	public void setPose(ExpansionModPose poseIn) {
		this.dataManager.set(EXPANSIONMOD_POSE, poseIn);
	}

	private void setSittingPosition(BlockPos pos) {
		this.setPosition(pos.getX() + 0.5, pos.getY(), pos.getZ() + 0.5);
	}

	public Optional<BlockPos> getChairPosition() {
		return this.dataManager.get(CHAIR_POSITION);
	}

	public void setChairPosition(BlockPos pos) {
		this.dataManager.set(CHAIR_POSITION, Optional.of(pos));
	}

	public void clearChairPosition() {
		this.dataManager.set(CHAIR_POSITION, Optional.empty());
	}

	public void startSitting(BlockPos pos) {
		if (this.isPassenger()) {
			this.stopRiding();
		}

		this.setPose(ExpansionModPose.SITTING);
		this.setSittingPosition(pos);
		this.setChairPosition(pos);
	}

	@Override
	protected void registerData() {
	}

	@Override
	protected void readAdditional(CompoundNBT compound) {
	}

	@Override
	protected void writeAdditional(CompoundNBT compound) {
	}

	@Override
	public IPacket<?> createSpawnPacket() {
		return null;
	}
}
public class ChairBlock extends Block implements IWaterLoggable{
	public static final DirectionProperty FACING = HorizontalBlock.HORIZONTAL_FACING;
	public static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED;

	public static final VoxelShape BASE = VoxelShapes.or(
			Block.makeCuboidShape(2, 8, 2, 14, 10, 14),
			Block.makeCuboidShape(2, 0, 2, 4, 8, 4),
			Block.makeCuboidShape(2, 0, 12, 4, 8, 14),
			Block.makeCuboidShape(12, 0, 12, 14, 8, 14),
			Block.makeCuboidShape(12, 0, 2, 14, 8, 4)
		);
	public static final VoxelShape SHAPE_NORTH = VoxelShapes.or(
			BASE,
			Block.makeCuboidShape(2, 10, 12, 14, 18, 14)
	);
	public static final VoxelShape SHAPE_EAST = VoxelShapes.or(
			BASE,
			Block.makeCuboidShape(2, 10, 2, 4, 18, 14)
	);
	public static final VoxelShape SHAPE_SOUTH = VoxelShapes.or(
			BASE,
			Block.makeCuboidShape(2, 10, 2, 14, 18, 4)
	);
	public static final VoxelShape SHAPE_WEST = VoxelShapes.or(
			BASE,
			Block.makeCuboidShape(12, 10, 2, 14, 18, 14)
	);

	public ChairBlock(Properties properties) {
		super(properties);
		this.setDefaultState(this.stateContainer.getBaseState()
				.with(FACING, Direction.NORTH)
				.with(WATERLOGGED, false)
		);
	}

	@Override
	public BlockState getStateForPlacement(BlockItemUseContext context) {
		return this.getDefaultState()
				.with(FACING, context.getPlacementHorizontalFacing().getOpposite());
	}

	@SuppressWarnings("deprecation")
	public FluidState getFluidState(BlockState state) {
		return state.get(WATERLOGGED) ? Fluids.WATER.getStillFluidState(false) : super.getFluidState(state);
	}

	@Override
	protected void fillStateContainer(StateContainer.Builder<Block, BlockState> builder) {
		builder.add(
				FACING,
				WATERLOGGED
		);
	}

	@Override
	public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) {
		switch (state.get(FACING)) {
			case NORTH:
				return SHAPE_NORTH;
			case SOUTH:
				return SHAPE_SOUTH;
			case EAST:
				return SHAPE_EAST;
			case WEST:
				return SHAPE_WEST;
			default:
				return SHAPE_NORTH;
		}
	}

	@Override
	public ActionResultType onBlockActivated(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand handIn, BlockRayTraceResult hit) {
		ExpansionModEntity expansionModEntity = new ExpansionModEntity(EntityType.PLAYER, worldIn);
		expansionModEntity.startSitting(pos);
		return null;

		//return SeatEntity.create(worldIn, pos, 0.4, player);
	}
}

 

Link to comment
Share on other sites

  • Zemelua changed the title to 1.15 | I want to apply BedBlock

So, after that, read the vanilla code a little and protect protected static final DataParameter <ExpansionModPose> EXPANSIONMOD_POSE = EntityDataManager.createKey (ExpansionModEntity.class, ExpansionModDataSerializers.EXPANSIONMOD_POSE); protected static final DataParameter <ExpansionModPose> EXPANSIONMOD_POSE = EntityDataManager.create I rewrote it to .EXPANSIONMOD_POSE) ;, but found that I needed to add it with register in order to apply the dataManager to the player. Does this need to replace the vanilla player?

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



×
×
  • Create New...

Important Information

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