Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var chairs = [
- "minecraft:oak_stairs",
- "minecraft:stone_stairs",
- "minecraft:brick_stairs",
- "minecraft:stone_brick_stairs",
- "minecraft:nether_brick_stairs",
- "minecraft:sandstone_stairs",
- "minecraft:spruce_stairs",
- "minecraft:birch_stairs",
- "minecraft:jjungle_stairs",
- "minecraft:quartz_stairs",
- "minecraft:acacia_stairs",
- "minecraft:dark_oak_stairs",
- "minecraft:red_sandstone_stairs",
- "minecraft:purpur_stairs"
- ];
- var chairs_msg = {
- blocked: "You can't sit on it when it was getting blocked.",
- sitting: "Maybe someone is sitting on it before than you.",
- higher: "You can't sit on it because your leg is too short."
- }
- function interact(e){
- if(e.type == 2 &&
- chairs.indexOf(e.target.name) != -1 &&
- e.target.metadata < 4 &&
- e.player.mainhandItem.name == "minecraft:air" &&
- e.player.offhandItem.name == "minecraft:air" &&
- ! e.player.isSneaking()
- ){
- e.setCanceled(true);
- if(!e.target.world.getBlock(e.target.x, e.target.y+1, e.target.z).isAir()) {
- e.API.executeCommand(e.target.world, "/title " + e.player.name + " actionbar {\"text\":\"" + chairs_msg.blocked + "\"}");
- return;
- }
- if(e.player.world.getNearbyEntities(e.target.pos, 0, -1).length != 0) {
- e.API.executeCommand(e.target.world, "/title " + e.player.name + " actionbar {\"text\":\"" + chairs_msg.sitting + "\"}");
- return;
- }
- if(e.player.y < e.target.y-1) {
- e.API.executeCommand(e.target.world, "/title " + e.player.name + " actionbar {\"text\":\"" + chairs_msg.higher + "\"}");
- return;
- }
- var chair = e.player.world.createEntity("armor_stand");
- chair.setPosition(e.target.x+0.5, e.target.y+0.35, e.target.z+0.5);
- chair.spawn();
- var nbt = chair.getEntityNbt();
- nbt.setByte("Small", 1);
- nbt.setByte("NoBasePlate", 1);
- nbt.setByte("Invulnerable", 1);
- nbt.setByte("FallFlying", 1);
- nbt.setByte("Marker", 1);
- nbt.setByte("NoGravity", 1);
- nbt.setByte("Invisible", 1);
- chair.setEntityNbt(nbt);
- chair.addRider(e.player);
- if(e.player.tempdata.has("chair")) e.player.tempdata.get("chair").despawn();
- e.player.tempdata.put("chair", chair);
- }
- }
- function tick(e){
- if(e.player.tempdata.has("chair")){
- var temp = e.player.tempdata.get("chair");
- if(temp.getRiders().length == 0 ||
- chairs.indexOf(e.player.world.getBlock(temp.blockX, temp.blockY, temp.blockZ).name)==-1
- ){
- temp.despawn();
- e.player.tempdata.remove("chair");
- }
- }
- }
- function logout(e){
- if(e.player.tempdata.has("chair")){
- e.player.tempdata.get("chair").despawn();
- e.player.tempdata.remove("chair");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement