Jump to content
  • Home
  • Files
  • Docs
Topics
  • All Content

  • This Topic
  • This Forum

  • Advanced Search
  • Existing user? Sign In  

    Sign In



    • Not recommended on shared computers


    • Forgot your password?

  • Sign Up
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • 1.15 | I want to apply BedBlock
Currently Supported: 1.16.X (Latest) and 1.15.X (LTS)
Sign in to follow this  
Followers 0
Zemelua

1.15 | I want to apply BedBlock

By Zemelua, November 21, 2020 in Modder Support

  • Reply to this topic
  • Start new topic

Recommended Posts

Zemelua    0

Zemelua

Zemelua    0

  • Stone Miner
  • Zemelua
  • Members
  • 0
  • 55 posts
Posted November 21, 2020

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);
	}
}

 

  • Quote

Share this post


Link to post
Share on other sites

Zemelua    0

Zemelua

Zemelua    0

  • Stone Miner
  • Zemelua
  • Members
  • 0
  • 55 posts
Posted November 21, 2020

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?

  • Quote

Share this post


Link to post
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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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.

    • Insert image from URL
×
  • Desktop
  • Tablet
  • Phone
Sign in to follow this  
Followers 0
Go To Topic Listing



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • avbavey
      Can’t download forge on Mac?

      By avbavey · Posted 12 minutes ago

      I tried downloading the launcher from the website, then I go to Finder and locate it and double click it. Then it shows a pop up that says “the java JAR file (name of the file) could bot be launched.” How do I open it?? Also, this sounds weird but the Mac keyboard stopped working so I have to use a Windows keyboard with the Mac computer. Please help ASAP!
    • Shrayzz
      Forge 1.4.7 : Problèmes d'installation

      By Shrayzz · Posted 21 minutes ago

      Bonjour, j'aimerais me faire une partie en 1.4.7 moddé car certains mods ne sont disponibles que sur cette version. Récemment, j'ai acheté un nouveau pc l'ancien ne marchait plus. Le problème, c'est qu'étant donné que le fichier "minecraft.jar" du dossier "bin" de ".minecraft" n'existe plus. Le type d'installation de forge n'est plus le même qu'avant, je suis donc allé voir sur des forums pour savoir comment je pourrais faire mais tous sont obsolètes. Pourriez-vous m'aider à installer cette version, je voulais savoir si on pouvait toujours en faire des serveurs avec cette version? Merci de votre réponse.
    • PedreHenrry
      my minecraft crashed by "rendering overlay"

      By PedreHenrry · Posted 25 minutes ago

      tomorrow i do this  
    • ChampionAsh5357
      How to register WallOrFloorItem / Torch

      By ChampionAsh5357 · Posted 1 hour ago

      Nope, you're just registering the item twice. Your block calls this method which creates an item to which you then create another item under the same name.
    • StealthyNoodle
      How to register WallOrFloorItem / Torch

      By StealthyNoodle · Posted 1 hour ago

      Certainly! https://github.com/Fnkee/solidrocks I see that I'm running a copy method on the torch, under the ItemTagsProvider (ModItemTagsProvider). That should be transfering data from the block tag into an item tag. Maybe that's what's causing the duplicate registration.
  • Topics

    • avbavey
      0
      Can’t download forge on Mac?

      By avbavey
      Started 12 minutes ago

    • Shrayzz
      0
      Forge 1.4.7 : Problèmes d'installation

      By Shrayzz
      Started 21 minutes ago

    • PedreHenrry
      4
      my minecraft crashed by "rendering overlay"

      By PedreHenrry
      Started 4 hours ago

    • StealthyNoodle
      5
      How to register WallOrFloorItem / Torch

      By StealthyNoodle
      Started 13 hours ago

    • Sr_endi
      0
      [1.16.4]How to set the light value of an block

      By Sr_endi
      Started 1 hour ago

  • Who's Online (See full list)

    • GabrielIsDa1
    • Shrayzz
    • Reflector_10
    • avbavey
    • MadSkillMaster
    • larsgerrits
    • ChampionAsh5357
    • Draco18s
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • 1.15 | I want to apply BedBlock
  • Theme

Copyright © 2019 ForgeDevelopment LLC · Ads by Longitude Ads LLC Powered by Invision Community