Posted January 6, 20232 yr Good nights the thing is a wanna made soome chairs where the player can sit on well idont know where to start it must be a block detecthing player and forcing the sitting pose or the chair must be an orce entity ? Edited January 7, 20232 yr by perromercenary00
January 7, 20232 yr Author im doing some advances here but still missing something soo i made an custom entity coping things from AbstractHorse and pig class i set a fire particle to know where the entity is and the entity spawns but player dont mount it Spoiler package mercblk.entity; import com.google.common.collect.ImmutableList; import net.minecraft.core.BlockPos; import net.minecraft.nbt.CompoundTag; import net.minecraft.network.protocol.Packet; import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResult; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.PlayerRideableJumping; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; import net.minecraft.world.level.Level; import net.minecraft.world.phys.Vec3; import net.minecraft.world.scores.Team; import net.minecraftforge.network.NetworkHooks; import net.minecraft.core.Direction; import net.minecraft.core.particles.ParticleTypes; //#################### #################### #################### #################### #################### //esta entidad existe solo para servir de guia public class toilet_entity extends Entity implements PlayerRideableJumping { private int tick; // private ItemEntity target_entity = null; private BlockPos target_block = null; private Direction direccion = Direction.UP; private Level warudo = null; private ImmutableList<Entity> passengers = ImmutableList.of(); // #################### #################### #################### public toilet_entity(EntityType<?> w_entity, Level warudo) { super(w_entity, warudo); this.warudo = warudo; } // #################### #################### #################### public toilet_entity(EntityType<?> a_entity, Level warudo, BlockPos pos) { super(a_entity, warudo); this.warudo = warudo; this.target_block = pos; Vec3 ve = new Vec3(pos.getX() + 0.5D, pos.getY() + 0.5D, pos.getZ() + 0.5D); this.setPos(ve); } // #################### #################### #################### public toilet_entity(EntityType<?> a_entity, Level warudo, BlockPos pos, Direction direccion) { super(a_entity, warudo); this.warudo = warudo; this.target_block = pos; this.direccion = direccion; Vec3 ve = new Vec3(pos.getX() + 0.5D, pos.getY() + 0.5D, pos.getZ() + 0.5D); this.setPos(ve); } // #################### #################### #################### public BlockPos get_target_block() { return this.target_block; } // #################### #################### #################### public Direction get_direccion() { return direccion; } // #################### #################### #################### public InteractionResult mobInteract(Player p_29489_, InteractionHand p_29490_) { InteractionResult interactionresult = super.interact(p_29489_, p_29490_); System.out.println("mobInteract(whith Player pe )"); return interactionresult; } @Override public InteractionResult interact(Player pe, InteractionHand mano) { InteractionResult interactionresult = super.interact(pe, mano); System.out.println("interact(whith Player pe )"); //public void positionRider(Entity p_20312_) //public boolean startRiding(Entity p_20330_) //addPassenger(Entity p_20349_) /* @deprecated Forge: Use {@link #canBeRiddenUnderFluidType(net.minecraftforge.fluids.FluidType, Entity) rider sensitive version} @Deprecated public boolean rideableUnderWater() { return true; } public boolean isAlliedTo(Entity p_20355_) { return this.isAlliedTo(p_20355_.getTeam()); } public boolean isAlliedTo(Team p_20032_) { return this.getTeam() != null ? this.getTeam().isAlliedTo(p_20032_) : false; } */ // public InteractionResult mobInteract(Player p_29489_, InteractionHand // p_29490_) { if (!this.level.isClientSide) { pe.startRiding(this); } return InteractionResult.PASS; } // #################### #################### #################### @Override public boolean isVehicle() { return !this.passengers.isEmpty(); } // #################### #################### #################### private boolean mustdie() { // life limit if (this.tick > 200) { // System.out.println( "aligner_entity.mustdie( time limit // ("+this.level.isClientSide+") )" ); this.discard(); this.kill(); return true; } return false; } // #################### #################### #################### @Override public void tick() { this.mustdie(); this.warudo.addParticle(ParticleTypes.FLAME, this.getX(), this.getY(), this.getZ(), 0.0D, 0.0D, 0.0D); this.tick++; } @Override protected void defineSynchedData() { // TODO Auto-generated method stub } @Override protected void readAdditionalSaveData(CompoundTag p_70037_1_) { // TODO Auto-generated method stub } @Override protected void addAdditionalSaveData(CompoundTag p_213281_1_) { // TODO Auto-generated method stub } // comunications // in ExplosiveArrowEntity.java @Override public Packet<?> getAddEntityPacket() { return NetworkHooks.getEntitySpawningPacket(this); } // #################### #################### #################### // #################### #################### #################### @Override public void onPlayerJump(int p_21696_) { // TODO Auto-generated method stub } @Override public boolean canJump() { // TODO Auto-generated method stub return false; } @Override public void handleStartJump(int p_21695_) { // TODO Auto-generated method stub } @Override public void handleStopJump() { // TODO Auto-generated method stub } } the toilet_block Spoiler package mercblk.blocks.toilet; import java.util.ArrayList; import java.util.function.Predicate; import javax.annotation.Nullable; import mercblk.blocks.BlockInit; import mercblk.entity.EntityInit; import mercblk.entity.aligner_entity; import mercblk.entity.manhole_watcher_entity; import mercblk.entity.toilet_entity; import mercblk.util.Postate; import mercblk.util.Target; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.nbt.CompoundTag; import net.minecraft.server.level.ServerLevel; import net.minecraft.sounds.SoundEvent; import net.minecraft.sounds.SoundSource; import net.minecraft.tags.FluidTags; import net.minecraft.util.RandomSource; import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResult; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.Pose; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; import net.minecraft.world.item.context.BlockPlaceContext; import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.Level; import net.minecraft.world.level.LevelAccessor; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.SimpleWaterloggedBlock; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.StateDefinition; import net.minecraft.world.level.block.state.properties.BlockStateProperties; import net.minecraft.world.level.block.state.properties.BooleanProperty; import net.minecraft.world.level.block.state.properties.DirectionProperty; import net.minecraft.world.level.gameevent.GameEvent; import net.minecraft.world.level.material.Fluid; import net.minecraft.world.level.material.FluidState; import net.minecraft.world.level.material.Fluids; import net.minecraft.world.level.pathfinder.PathComputationType; import net.minecraft.world.phys.AABB; import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.Vec2; import net.minecraft.world.phys.Vec3; import net.minecraft.world.phys.shapes.BooleanOp; import net.minecraft.world.phys.shapes.CollisionContext; import net.minecraft.world.phys.shapes.Shapes; import net.minecraft.world.phys.shapes.VoxelShape; //import net.minecraft.item.Item; //########## ########## ########## ########## public class toilet extends Block implements SimpleWaterloggedBlock { // ########## ########## ########## ########## public static final DirectionProperty FACING = BlockStateProperties.HORIZONTAL_FACING;// .FACING; public static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED; public static final BooleanProperty ENABLED = BlockStateProperties.ENABLED; public static final BooleanProperty POWERED = BlockStateProperties.POWERED; public static final String tipo = "panel"; // six ways waterloggable panel // ########## ########## ########## ########## // a una unidad protected static final VoxelShape HOLE = Block.box(6.0D, 0.0D, 6.0D, 10.0D, 8.0D, 10.0D); protected static final VoxelShape NB_0 = Block.box(3.0D, 0.0D, 0.0D, 13.0D, 8.0D, 12.0D); protected static final VoxelShape NT_0 = Block.box(1.0D, 7.0D, 12.0D, 15.0D, 16.0D, 16.0D); protected static final VoxelShape SB_0 = Block.box(3.0D, 0.0D, 4.0D, 13.0D, 8.0D, 16.0D); protected static final VoxelShape ST_0 = Block.box(1.0D, 7.0D, 0.0D, 15.0D, 16.0D, 4.0D); protected static final VoxelShape EB_0 = Block.box(4.0D, 0.0D, 3.0D, 16.0D, 8.0D, 13.0D); protected static final VoxelShape ET_0 = Block.box(0.0D, 7.0D, 1.0D, 4.0D, 16.0D, 15.0D); protected static final VoxelShape WB_0 = Block.box(0.0D, 0.0D, 3.0D, 12.0D, 8.0D, 13.0D); protected static final VoxelShape WT_0 = Block.box(12.0D, 7.0D, 1.0D, 16.0D, 16.0D, 15.0D); protected static final VoxelShape caja_e = Shapes.join(Shapes.join(EB_0, HOLE, BooleanOp.ONLY_FIRST), ET_0, BooleanOp.OR); protected static final VoxelShape caja_w = Shapes.join(Shapes.join(WB_0, HOLE, BooleanOp.ONLY_FIRST), WT_0, BooleanOp.OR); protected static final VoxelShape caja_s = Shapes.join(Shapes.join(SB_0, HOLE, BooleanOp.ONLY_FIRST), ST_0, BooleanOp.OR); protected static final VoxelShape caja_n = Shapes.join(Shapes.join(NB_0, HOLE, BooleanOp.ONLY_FIRST), NT_0, BooleanOp.OR); protected static final VoxelShape NO_AABB = Block.box(0.0D, 0.0D, 0.0D, 0.0D, 0.0D, 0.0D); // ########## ########## ########## ########## public toilet(Block.Properties properties) { super(properties); this.registerDefaultState(this.stateDefinition.any().setValue(FACING, Direction.NORTH) .setValue(WATERLOGGED, Boolean.valueOf(false)).setValue(ENABLED, Boolean.valueOf(false)) .setValue(POWERED, Boolean.valueOf(false))); } // ########## ########## ########## ########## @Override protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) { builder.add(FACING, WATERLOGGED, ENABLED, POWERED); } // ########## ########## ########## ########## // @Override public String get_tipo() { return tipo; } // ########## ########## ########## ########## @Override public boolean useShapeForLightOcclusion(BlockState p_220074_1_) { return false; } // ########## ########## ########## ########## // aqui es donde se selecciona que bordes va a tener el pblocke basado en el // block state @Override public VoxelShape getShape(BlockState blkstate, BlockGetter blockgetter, BlockPos blockpos, CollisionContext collision) { // BlockState blkstate = blockgetter.getBlockState(blockpos); Direction direction = blkstate.getValue(FACING); switch (direction) { case EAST: return caja_e; case WEST: return caja_w; case SOUTH: return caja_s; case NORTH: return caja_n; } return NO_AABB; } // ########## ########## ########## ########## // On right click @Override public InteractionResult use(BlockState blkstate, Level warudo, BlockPos pos, Player pe, InteractionHand hand, BlockHitResult hit) { ItemStack itemstack = pe.getItemInHand(hand); if (!warudo.isClientSide) { Postate postate = new Postate(warudo, pos); Target target = new Target(warudo, pe, 10); Vec3 ivh = target.getVh_inner(); Vec2 vh = target.getVh_fcoor(); //guest if player click the toilet lever if (ivh.y > 0.5) { if (vh.x > 0.1 && vh.x < 0.25) { if (vh.y > 0.75 && vh.y < 0.86) { System.out.println("#Halar la palanca"); //reset the lever in x ticks warudo.scheduleTick(pos, this, this.getPressDuration()); if( !postate.get_POWERED() ) { toilet_entity r_entity = setOpen( warudo, blkstate, pos); if( r_entity != null ) { //p_entity.addPassenger(pe); r_entity.startRiding(pe); } } postate.set_POWERED(!postate.get_POWERED()); Postate waterblock = postate.below(2); waterblock.update_WATERLOGGED(); postate.set_ENABLED(waterblock.is_WATERLOGGED()); } } } System.out.println("vh=>" + vh.x + ", " + vh.y); if (vh.y > 0.5D) { System.out.println("#tanque"); } else { System.out.println("#tasa"); } if (itemstack.getItem() == BlockInit.MANHOLE_PANEL.get().asItem()) { int age = postate.get_AGE_5(); if (age > 4) { itemstack.shrink(1); postate.set_AGE_5(0); postate.setBlock(10); return InteractionResult.sidedSuccess(warudo.isClientSide); // } } postate.setBlock(2); // this.setOpen(warudo, blkstate, pos); } return InteractionResult.sidedSuccess(warudo.isClientSide); // // return InteractionResult.PASS; } // ########## ########## ########## ########## // @Override public static toilet_entity setOpen(Level warudo, BlockState blkstate, BlockPos pos) { //System.out.println("setOpen"); toilet_entity r_entity = null; if (!warudo.isClientSide) { toilet_entity m_entity = there_is_toilet_entity_around(warudo, pos); // if (m_entity == null) { // if sucefull return the toilet entitiy try { r_entity = new toilet_entity( EntityInit.TOILET_ENTITY.get(), warudo, pos); warudo.addFreshEntity(r_entity); } catch (Exception e) { System.out.println("Something went wrong." + e.toString()); } } } return r_entity; } // ########## ########## ########## ########## //this is just to avoid spawning multiple entities inside same block // @Override public static toilet_entity there_is_toilet_entity_around(Level warudo, BlockPos pos) { AABB bb = new AABB(pos);// .inflate(1.0F); ArrayList<toilet_entity> list = new ArrayList<toilet_entity>(); Predicate<? super Entity> cosa = target -> (target instanceof toilet_entity);// for (toilet_entity entity1 : warudo.getEntitiesOfClass(toilet_entity.class, bb)) { return entity1; } return null; } // ########## ########## ########## ########## @Override public void entityInside(BlockState blkstate, Level warudo, BlockPos pos, Entity entity) { //if (!warudo.isClientSide) { Postate postate = new Postate(warudo, pos); if (postate.get_POWERED()) { entity.setPose(Pose.LONG_JUMPING); //Pose.CROUCHING } } } // ########## ########## ########## ########## @Override public boolean canBeReplaced(BlockState p_56373_, BlockPlaceContext p_56374_) { return false; } // ########## ########## ########## ########## @Override @Nullable public BlockState getStateForPlacement(BlockPlaceContext context) { BlockPos pos = context.getClickedPos(); Postate postate = new Postate(context.getLevel(), context.getClickedPos()); postate.setBlockState(this.defaultBlockState()); Level warudo = context.getLevel(); Direction facing = context.getHorizontalDirection().getOpposite(); if (facing == null) { return this.defaultBlockState(); } postate.set_FACING(facing);// (context.getHorizontalDirection()); // context.getHorizontalDirection() postate.update_WATERLOGGED(); Postate waterblock = postate.below(2); waterblock.update_WATERLOGGED(); postate.set_ENABLED(waterblock.is_WATERLOGGED()); // .setValue(ENABLED, Boolean.valueOf(false)) // .setValue(POWERED, Boolean.valueOf(false)) // postate.set_WATERLOGGED(fluidstate.getType() == Fluids.WATER); return postate.getBlockState(); } // ########## ########## ########## ########## @Override public FluidState getFluidState(BlockState blkstate) { return blkstate.getValue(WATERLOGGED) ? Fluids.WATER.getSource(false) : super.getFluidState(blkstate); } // ########## ########## ########## ########## @Override public boolean canPlaceLiquid(BlockGetter p_56301_, BlockPos p_56302_, BlockState p_56303_, Fluid p_56304_) { return !p_56303_.getValue(BlockStateProperties.WATERLOGGED) && p_56304_ == Fluids.WATER; } // ########## ########## ########## ########## @Override public boolean placeLiquid(LevelAccessor p_56306_, BlockPos p_56307_, BlockState p_56308_, FluidState p_56309_) { if (!p_56308_.getValue(BlockStateProperties.WATERLOGGED) && p_56309_.getType() == Fluids.WATER) { if (!p_56306_.isClientSide()) { p_56306_.setBlock(p_56307_, p_56308_.setValue(BlockStateProperties.WATERLOGGED, Boolean.valueOf(true)), 3); p_56306_.scheduleTick(p_56307_, p_56309_.getType(), p_56309_.getType().getTickDelay(p_56306_)); } return true; } else { return false; } } // ########## ########## ########## ########## @Override public ItemStack pickupBlock(LevelAccessor p_154560_, BlockPos p_154561_, BlockState p_154562_) { if (p_154562_.getValue(BlockStateProperties.WATERLOGGED)) { p_154560_.setBlock(p_154561_, p_154562_.setValue(BlockStateProperties.WATERLOGGED, Boolean.valueOf(false)), 3); if (!p_154562_.canSurvive(p_154560_, p_154561_)) { p_154560_.destroyBlock(p_154561_, true); } return new ItemStack(Items.WATER_BUCKET); } else { return ItemStack.EMPTY; } } // ########## ########## ########## ########## @Override public boolean isPathfindable(BlockState p_56376_, BlockGetter p_56377_, BlockPos p_56378_, PathComputationType p_56379_) { switch (p_56379_) { case LAND: return false; case WATER: return p_56377_.getFluidState(p_56378_).is(FluidTags.WATER); case AIR: return false; default: return false; } } private int getPressDuration() { return 40; } // ########## ########## ########## ########## public void tick(BlockState blkstate, ServerLevel slevel, BlockPos pos, RandomSource randomsource) { Level warudo = (Level) slevel; Postate postate = new Postate(warudo, pos); postate.update_WATERLOGGED(); Postate waterblock = postate.below(2); waterblock.update_WATERLOGGED(); postate.set_ENABLED(waterblock.is_WATERLOGGED()); postate.set_POWERED(false); postate.setBlock(2); } // ########## ########## ########## ########## // ########## ########## ########## ########## // ########## ########## ########## ########## // ########## ########## ########## ########## } if( !postate.get_POWERED() ) { toilet_entity r_entity = setOpen( warudo, blkstate, pos); if( r_entity != null ) { //p_entity.addPassenger(pe); r_entity.startRiding(pe); } } set some SystemOut's and it seems i cannot right click the entity but entity has bounding box // #################### #################### #################### public InteractionResult mobInteract(Player p_29489_, InteractionHand p_29490_) { InteractionResult interactionresult = super.interact(p_29489_, p_29490_); System.out.println("mobInteract(whith Player pe )"); return interactionresult; } @Override public InteractionResult interact(Player pe, InteractionHand mano) { InteractionResult interactionresult = super.interact(pe, mano); System.out.println("interact(whith Player pe )"); } i missing something or you cannot make an rideable entity just extending from entity class ? thanks for your time
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.