├── README.md ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── .gitignore ├── src └── main │ ├── resources │ ├── pack.mcmeta │ ├── assets │ │ └── sit │ │ │ └── lang │ │ │ ├── de_de.json │ │ │ └── en_us.json │ └── META-INF │ │ └── neoforge.mods.toml │ └── java │ └── bl4ckscor3 │ └── mod │ └── sit │ ├── Configuration.java │ ├── Sit.java │ ├── SitClient.java │ ├── SitEntity.java │ ├── SitUtil.java │ └── SitHandler.java ├── gradle.properties ├── settings.gradle ├── LICENSE ├── gradlew.bat └── gradlew /README.md: -------------------------------------------------------------------------------- 1 | Download link: https://curseforge.com/minecraft/mc-mods/sit 2 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bl4ckscor3/Sit/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /bin 2 | /build 3 | /libs 4 | /.project 5 | /.classpath 6 | /.gradle 7 | /.settings 8 | *.launch 9 | /run 10 | /runs 11 | /logs 12 | .idea/ 13 | -------------------------------------------------------------------------------- /src/main/resources/pack.mcmeta: -------------------------------------------------------------------------------- 1 | { 2 | "pack": { 3 | "description": "Sit resources & data", 4 | "pack_format": 34, 5 | "supported_formats": [ 6 | 0, 7 | 2147483647 8 | ] 9 | } 10 | } -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | org.gradle.jvmargs=-Xmx3G 2 | org.gradle.daemon=false 3 | org.gradle.configuration-cache=true 4 | org.gradle.parallel=true 5 | neoForge.parchment.minecraftVersion=1.21.1 6 | neoForge.parchment.mappingsVersion=2024.11.17 -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | pluginManagement { 2 | repositories { 3 | mavenLocal() 4 | gradlePluginPortal() 5 | maven { url = 'https://maven.neoforged.net/releases' } 6 | } 7 | } 8 | 9 | plugins { 10 | id 'org.gradle.toolchains.foojay-resolver-convention' version '0.9.0' 11 | } 12 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.12.1-bin.zip 4 | networkTimeout=10000 5 | validateDistributionUrl=true 6 | zipStoreBase=GRADLE_USER_HOME 7 | zipStorePath=wrapper/dists 8 | -------------------------------------------------------------------------------- /src/main/resources/assets/sit/lang/de_de.json: -------------------------------------------------------------------------------- 1 | { 2 | "sit.configuration.block_reach_distance": "Maximaler Blockabstand", 3 | "sit.configuration.block_reach_distance.tooltip": "Der maximale Abstand in Blöcken, die der Spieler vom Block entfernt sein kann, um sich darauf hinzusetzen. Beachte, dass dieser Wert von der Vanilla-Distanz gedeckelt ist. Wenn der Wert 0 ist, muss der Spieler direkt auf dem Block stehen, um sich darauf hinsetzen zu können." 4 | } -------------------------------------------------------------------------------- /src/main/resources/assets/sit/lang/en_us.json: -------------------------------------------------------------------------------- 1 | { 2 | "sit.configuration.block_reach_distance": "Block Reach Distance", 3 | "sit.configuration.block_reach_distance.tooltip": "The maximum distance in blocks that the player can be away from a block to still be able to sit on it. Do note, that this is limited by how far a player can access a block in vanilla Minecraft. If this is set to 0, the player has to stand on top of the block to be able to sit on it." 4 | } -------------------------------------------------------------------------------- /src/main/resources/META-INF/neoforge.mods.toml: -------------------------------------------------------------------------------- 1 | modLoader="javafml" 2 | loaderVersion="[1,)" 3 | license="MIT https://github.com/bl4ckscor3/Sit/blob/neoforge/1.21/LICENSE" 4 | 5 | [[mods]] 6 | modId="sit" 7 | version="${file.jarVersion}" 8 | displayName="Sit" 9 | description='''Allows you to sit on slabs and stairs.''' 10 | issueTrackerURL="https://github.com/bl4ckscor3/Sit/issues" 11 | displayURL="https://curseforge.com/minecraft/mc-mods/sit" 12 | authors="bl4ckscor3" 13 | 14 | [[dependencies.sit]] 15 | modId="neoforge" 16 | type="required" 17 | versionRange="[21,)" 18 | ordering="NONE" 19 | side="BOTH" 20 | 21 | [[dependencies.sit]] 22 | modId="minecraft" 23 | type="required" 24 | versionRange="[1.21,1.22)" 25 | ordering="NONE" 26 | side="BOTH" -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 bl4ckscor3 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /src/main/java/bl4ckscor3/mod/sit/Configuration.java: -------------------------------------------------------------------------------- 1 | package bl4ckscor3.mod.sit; 2 | 3 | import org.apache.commons.lang3.tuple.Pair; 4 | 5 | import net.neoforged.neoforge.common.ModConfigSpec; 6 | import net.neoforged.neoforge.common.ModConfigSpec.IntValue; 7 | 8 | public class Configuration { 9 | public static final ModConfigSpec CONFIG_SPEC; 10 | public static final Configuration CONFIG; 11 | public final IntValue blockReachDistance; 12 | 13 | static { 14 | Pair specPair = new ModConfigSpec.Builder().configure(Configuration::new); 15 | 16 | CONFIG_SPEC = specPair.getRight(); 17 | CONFIG = specPair.getLeft(); 18 | } 19 | 20 | Configuration(ModConfigSpec.Builder builder) { 21 | //@formatter:off 22 | blockReachDistance = builder 23 | .comment("The maximum distance in blocks that the player can be away from a block to still be able to sit on it.", 24 | "Do note, that this is limited by how far a player can access a block in vanilla Minecraft.", 25 | "If this is set to 0, the player has to stand on top of the block to be able to sit on it.") 26 | .defineInRange("block_reach_distance", 4, 0, 1000); 27 | //@formatter:on 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/bl4ckscor3/mod/sit/Sit.java: -------------------------------------------------------------------------------- 1 | package bl4ckscor3.mod.sit; 2 | 3 | import net.minecraft.core.registries.Registries; 4 | import net.minecraft.world.entity.EntityType; 5 | import net.minecraft.world.entity.MobCategory; 6 | import net.neoforged.bus.api.IEventBus; 7 | import net.neoforged.fml.ModContainer; 8 | import net.neoforged.fml.common.Mod; 9 | import net.neoforged.fml.config.ModConfig; 10 | import net.neoforged.neoforge.registries.DeferredHolder; 11 | import net.neoforged.neoforge.registries.DeferredRegister; 12 | 13 | @Mod(Sit.MODID) 14 | public class Sit { 15 | public static final String MODID = "sit"; 16 | public static final DeferredRegister> ENTITY_TYPES = DeferredRegister.create(Registries.ENTITY_TYPE, MODID); 17 | public static final DeferredHolder, EntityType> SIT_ENTITY_TYPE = ENTITY_TYPES.register("entity_sit", () -> EntityType.Builder.of(SitEntity::new, MobCategory.MISC) 18 | //@formatter:off 19 | .setTrackingRange(256) 20 | .setUpdateInterval(20) 21 | .sized(0.0001F, 0.0001F) 22 | .build(MODID + ":entity_sit")); 23 | //@formatter:on 24 | 25 | public Sit(ModContainer modContainer, IEventBus modEventBus) { 26 | modContainer.registerConfig(ModConfig.Type.SERVER, Configuration.CONFIG_SPEC); 27 | ENTITY_TYPES.register(modEventBus); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/bl4ckscor3/mod/sit/SitClient.java: -------------------------------------------------------------------------------- 1 | package bl4ckscor3.mod.sit; 2 | 3 | import net.minecraft.client.renderer.culling.Frustum; 4 | import net.minecraft.client.renderer.entity.EntityRenderer; 5 | import net.minecraft.client.renderer.entity.EntityRendererProvider; 6 | import net.minecraft.client.renderer.entity.EntityRenderers; 7 | import net.minecraft.resources.ResourceLocation; 8 | import net.neoforged.api.distmarker.Dist; 9 | import net.neoforged.bus.api.SubscribeEvent; 10 | import net.neoforged.fml.ModContainer; 11 | import net.neoforged.fml.common.EventBusSubscriber; 12 | import net.neoforged.fml.common.Mod; 13 | import net.neoforged.fml.event.lifecycle.FMLClientSetupEvent; 14 | import net.neoforged.neoforge.client.gui.ConfigurationScreen; 15 | import net.neoforged.neoforge.client.gui.IConfigScreenFactory; 16 | 17 | @Mod(value = Sit.MODID, dist = Dist.CLIENT) 18 | @EventBusSubscriber(Dist.CLIENT) 19 | public class SitClient { 20 | public SitClient(ModContainer modContainer) { 21 | modContainer.registerExtensionPoint(IConfigScreenFactory.class, ConfigurationScreen::new); 22 | } 23 | 24 | @SubscribeEvent 25 | public static void onFMLCLientSetup(FMLClientSetupEvent event) { 26 | EntityRenderers.register(Sit.SIT_ENTITY_TYPE.get(), EmptyRenderer::new); 27 | } 28 | 29 | private static class EmptyRenderer extends EntityRenderer { 30 | protected EmptyRenderer(EntityRendererProvider.Context ctx) { 31 | super(ctx); 32 | } 33 | 34 | @Override 35 | public boolean shouldRender(SitEntity entity, Frustum camera, double camX, double camY, double camZ) { 36 | return false; 37 | } 38 | 39 | @Override 40 | public ResourceLocation getTextureLocation(SitEntity entity) { 41 | return null; 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/bl4ckscor3/mod/sit/SitEntity.java: -------------------------------------------------------------------------------- 1 | package bl4ckscor3.mod.sit; 2 | 3 | import net.minecraft.core.BlockPos; 4 | import net.minecraft.core.Direction; 5 | import net.minecraft.nbt.CompoundTag; 6 | import net.minecraft.network.protocol.Packet; 7 | import net.minecraft.network.protocol.game.ClientGamePacketListener; 8 | import net.minecraft.network.protocol.game.ClientboundAddEntityPacket; 9 | import net.minecraft.network.syncher.SynchedEntityData; 10 | import net.minecraft.server.level.ServerEntity; 11 | import net.minecraft.world.entity.Entity; 12 | import net.minecraft.world.entity.EntityType; 13 | import net.minecraft.world.entity.LivingEntity; 14 | import net.minecraft.world.entity.player.Player; 15 | import net.minecraft.world.level.Level; 16 | import net.minecraft.world.level.block.SupportType; 17 | import net.minecraft.world.phys.Vec3; 18 | 19 | public class SitEntity extends Entity { 20 | public SitEntity(EntityType type, Level level) { 21 | super(type, level); 22 | } 23 | 24 | public SitEntity(Level level, BlockPos pos) { 25 | super(Sit.SIT_ENTITY_TYPE.get(), level); 26 | setPos(pos.getX() + 0.5D, pos.getY() + 0.5D, pos.getZ() + 0.5D); 27 | noPhysics = true; 28 | } 29 | 30 | @Override 31 | public Vec3 getDismountLocationForPassenger(LivingEntity passenger) { 32 | if (passenger instanceof Player player) { 33 | Vec3 resetPosition = SitUtil.getPreviousPlayerPosition(player, this); 34 | 35 | if (resetPosition != null) { 36 | BlockPos belowResetPos = BlockPos.containing(resetPosition.x, resetPosition.y - 1, resetPosition.z); 37 | 38 | discard(); 39 | 40 | if (!player.level().getBlockState(belowResetPos).isFaceSturdy(level(), belowResetPos, Direction.UP, SupportType.FULL)) 41 | return new Vec3(resetPosition.x, resetPosition.y + 1, resetPosition.z); 42 | else 43 | return resetPosition; 44 | } 45 | } 46 | 47 | discard(); 48 | return super.getDismountLocationForPassenger(passenger); 49 | } 50 | 51 | @Override 52 | public void remove(RemovalReason reason) { 53 | super.remove(reason); 54 | 55 | SitUtil.removeSitEntity(level(), blockPosition()); 56 | } 57 | 58 | @Override 59 | protected void defineSynchedData(SynchedEntityData.Builder builder) {} 60 | 61 | @Override 62 | protected void readAdditionalSaveData(CompoundTag tag) {} 63 | 64 | @Override 65 | protected void addAdditionalSaveData(CompoundTag tag) {} 66 | 67 | @Override 68 | public Packet getAddEntityPacket(ServerEntity serverEntity) { 69 | return new ClientboundAddEntityPacket(this, serverEntity); 70 | } 71 | } -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | @rem SPDX-License-Identifier: Apache-2.0 17 | @rem 18 | 19 | @if "%DEBUG%"=="" @echo off 20 | @rem ########################################################################## 21 | @rem 22 | @rem Gradle startup script for Windows 23 | @rem 24 | @rem ########################################################################## 25 | 26 | @rem Set local scope for the variables with windows NT shell 27 | if "%OS%"=="Windows_NT" setlocal 28 | 29 | set DIRNAME=%~dp0 30 | if "%DIRNAME%"=="" set DIRNAME=. 31 | @rem This is normally unused 32 | set APP_BASE_NAME=%~n0 33 | set APP_HOME=%DIRNAME% 34 | 35 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 36 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 37 | 38 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 39 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 40 | 41 | @rem Find java.exe 42 | if defined JAVA_HOME goto findJavaFromJavaHome 43 | 44 | set JAVA_EXE=java.exe 45 | %JAVA_EXE% -version >NUL 2>&1 46 | if %ERRORLEVEL% equ 0 goto execute 47 | 48 | echo. 1>&2 49 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 50 | echo. 1>&2 51 | echo Please set the JAVA_HOME variable in your environment to match the 1>&2 52 | echo location of your Java installation. 1>&2 53 | 54 | goto fail 55 | 56 | :findJavaFromJavaHome 57 | set JAVA_HOME=%JAVA_HOME:"=% 58 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 59 | 60 | if exist "%JAVA_EXE%" goto execute 61 | 62 | echo. 1>&2 63 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 64 | echo. 1>&2 65 | echo Please set the JAVA_HOME variable in your environment to match the 1>&2 66 | echo location of your Java installation. 1>&2 67 | 68 | goto fail 69 | 70 | :execute 71 | @rem Setup the command line 72 | 73 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 74 | 75 | 76 | @rem Execute Gradle 77 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 78 | 79 | :end 80 | @rem End local scope for the variables with windows NT shell 81 | if %ERRORLEVEL% equ 0 goto mainEnd 82 | 83 | :fail 84 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 85 | rem the _cmd.exe /c_ return code! 86 | set EXIT_CODE=%ERRORLEVEL% 87 | if %EXIT_CODE% equ 0 set EXIT_CODE=1 88 | if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% 89 | exit /b %EXIT_CODE% 90 | 91 | :mainEnd 92 | if "%OS%"=="Windows_NT" endlocal 93 | 94 | :omega 95 | -------------------------------------------------------------------------------- /src/main/java/bl4ckscor3/mod/sit/SitUtil.java: -------------------------------------------------------------------------------- 1 | package bl4ckscor3.mod.sit; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | import org.apache.commons.lang3.tuple.Pair; 7 | 8 | import net.minecraft.core.BlockPos; 9 | import net.minecraft.resources.ResourceLocation; 10 | import net.minecraft.world.entity.player.Player; 11 | import net.minecraft.world.level.Level; 12 | import net.minecraft.world.phys.Vec3; 13 | 14 | /** 15 | * Use this class to manage sit entities correctly 16 | */ 17 | public class SitUtil { 18 | /** 19 | * >> This map only gets populated on server side. 20 | */ 21 | private static final Map>> OCCUPIED = new HashMap<>(); 22 | 23 | private SitUtil() {} 24 | 25 | /** 26 | * Adds a sit entity to the map that keeps track of them. This does not spawn the entity itself. 27 | * 28 | * @param level The level to add the entity in 29 | * @param blockPos The position at which to add the entity 30 | * @param entity The entity to add 31 | * @param playerPos The position of the player who is sitting down. Used for correctly positioning the player after 32 | * dismounting 33 | * @return true if the entity was added, false otherwhise. This is always false on the client. 34 | */ 35 | public static boolean addSitEntity(Level level, BlockPos blockPos, SitEntity entity, Vec3 playerPos) { 36 | if (!level.isClientSide) { 37 | ResourceLocation id = getDimensionTypeId(level); 38 | 39 | if (!OCCUPIED.containsKey(id)) 40 | OCCUPIED.put(id, new HashMap<>()); 41 | 42 | OCCUPIED.get(id).put(blockPos, Pair.of(entity, playerPos)); 43 | return true; 44 | } 45 | 46 | return false; 47 | } 48 | 49 | /** 50 | * Removes a sit entity from the map that keeps track of them. This does not remove the entity itself. 51 | * 52 | * @param level The level to remove the entity from 53 | * @param pos The position to remove the entity from 54 | * @return true if the entity was removed, false otherwhise. This is always false on the client. 55 | */ 56 | public static boolean removeSitEntity(Level level, BlockPos pos) { 57 | if (!level.isClientSide) { 58 | ResourceLocation id = getDimensionTypeId(level); 59 | 60 | if (OCCUPIED.containsKey(id)) { 61 | OCCUPIED.get(id).remove(pos); 62 | return true; 63 | } 64 | } 65 | 66 | return false; 67 | } 68 | 69 | /** 70 | * Gets the sit entity that is situated at the given position in the given level 71 | * 72 | * @param level The level to get the entity from 73 | * @param pos The position to get the entity from 74 | * @return The entity at the given position in the given level, null if there is none. This is always null on the client. 75 | */ 76 | public static SitEntity getSitEntity(Level level, BlockPos pos) { 77 | if (!level.isClientSide) { 78 | ResourceLocation id = getDimensionTypeId(level); 79 | 80 | if (OCCUPIED.containsKey(id) && OCCUPIED.get(id).containsKey(pos)) 81 | return OCCUPIED.get(id).get(pos).getLeft(); 82 | } 83 | 84 | return null; 85 | } 86 | 87 | /** 88 | * Gets the position the player was at before he sat down 89 | * 90 | * @param player The player 91 | * @param sitEntity The sit entity the player is sitting on 92 | * @return The position the player was at before he sat down, null if the player is not sitting. This is always null on the 93 | * client. 94 | */ 95 | public static Vec3 getPreviousPlayerPosition(Player player, SitEntity sitEntity) { 96 | if (!player.level().isClientSide) { 97 | ResourceLocation id = getDimensionTypeId(player.level()); 98 | 99 | if (OCCUPIED.containsKey(id)) { 100 | for (Pair pair : OCCUPIED.get(id).values()) { 101 | if (pair.getLeft() == sitEntity) 102 | return pair.getRight(); 103 | } 104 | } 105 | } 106 | 107 | return null; 108 | } 109 | 110 | /** 111 | * Checks whether there is a player sitting at the given block position in the given level 112 | * 113 | * @param level The level to check in 114 | * @param pos The position to check at 115 | * @return true if a player is sitting at the given position in the given level, false otherwhise. This is always false on 116 | * the client. 117 | */ 118 | public static boolean isOccupied(Level level, BlockPos pos) { 119 | ResourceLocation id = getDimensionTypeId(level); 120 | 121 | return SitUtil.OCCUPIED.containsKey(id) && SitUtil.OCCUPIED.get(id).containsKey(pos); 122 | } 123 | 124 | /** 125 | * Checks whether a player is sitting anywhere 126 | * 127 | * @param player The player to check 128 | * @return true if the given player is sitting anywhere, false otherwhise 129 | */ 130 | public static boolean isPlayerSitting(Player player) { 131 | for (ResourceLocation i : OCCUPIED.keySet()) { 132 | for (Pair pair : OCCUPIED.get(i).values()) { 133 | if (pair.getLeft().hasPassenger(player)) 134 | return true; 135 | } 136 | } 137 | 138 | return false; 139 | } 140 | 141 | private static ResourceLocation getDimensionTypeId(Level level) { 142 | return level.dimension().location(); 143 | } 144 | } 145 | -------------------------------------------------------------------------------- /src/main/java/bl4ckscor3/mod/sit/SitHandler.java: -------------------------------------------------------------------------------- 1 | package bl4ckscor3.mod.sit; 2 | 3 | import net.minecraft.core.BlockPos; 4 | import net.minecraft.core.Direction; 5 | import net.minecraft.world.entity.player.Player; 6 | import net.minecraft.world.level.Level; 7 | import net.minecraft.world.level.block.BedBlock; 8 | import net.minecraft.world.level.block.Block; 9 | import net.minecraft.world.level.block.HorizontalDirectionalBlock; 10 | import net.minecraft.world.level.block.SlabBlock; 11 | import net.minecraft.world.level.block.StairBlock; 12 | import net.minecraft.world.level.block.state.BlockState; 13 | import net.minecraft.world.level.block.state.properties.BedPart; 14 | import net.minecraft.world.level.block.state.properties.Half; 15 | import net.minecraft.world.level.block.state.properties.SlabType; 16 | import net.minecraft.world.phys.AABB; 17 | import net.neoforged.bus.api.SubscribeEvent; 18 | import net.neoforged.fml.common.EventBusSubscriber; 19 | import net.neoforged.neoforge.event.entity.player.PlayerInteractEvent.RightClickBlock; 20 | import net.neoforged.neoforge.event.level.BlockEvent.BreakEvent; 21 | 22 | @EventBusSubscriber(modid = Sit.MODID) 23 | public class SitHandler { 24 | private SitHandler() {} 25 | 26 | @SubscribeEvent 27 | public static void onRightClickBlock(RightClickBlock event) { 28 | Player player = event.getEntity(); 29 | 30 | if (!event.getLevel().isClientSide && event.getFace() == Direction.UP && !SitUtil.isPlayerSitting(player) && !player.isShiftKeyDown()) { 31 | Level level = event.getLevel(); 32 | BlockPos pos = event.getPos(); 33 | BlockState state = level.getBlockState(pos); 34 | Block block = level.getBlockState(pos).getBlock(); 35 | 36 | if (isValidBlock(level, pos, state, block) && isPlayerInRange(player, pos) && !SitUtil.isOccupied(level, pos) && player.getMainHandItem().isEmpty() && level.getBlockState(pos.above()).isAir()) { 37 | if (block instanceof SlabBlock && (!state.hasProperty(SlabBlock.TYPE) || state.getValue(SlabBlock.TYPE) != SlabType.BOTTOM)) 38 | return; 39 | else if (block instanceof StairBlock && (!state.hasProperty(StairBlock.HALF) || state.getValue(StairBlock.HALF) != Half.BOTTOM)) 40 | return; 41 | 42 | SitEntity sit = new SitEntity(level, pos); 43 | 44 | if (SitUtil.addSitEntity(level, pos, sit, player.position())) { 45 | level.addFreshEntity(sit); 46 | player.startRiding(sit); 47 | } 48 | } 49 | } 50 | } 51 | 52 | @SubscribeEvent 53 | public static void onBreak(BreakEvent event) { 54 | if (!event.getLevel().isClientSide()) { 55 | //BreakEvent gets a Level in its constructor, so the cast is safe 56 | SitEntity entity = SitUtil.getSitEntity((Level) event.getLevel(), event.getPos()); 57 | 58 | if (entity != null) { 59 | SitUtil.removeSitEntity((Level) event.getLevel(), event.getPos()); 60 | entity.ejectPassengers(); 61 | } 62 | } 63 | } 64 | 65 | /** 66 | * Returns whether or not the given block can be sat on 67 | * 68 | * @param level The level to check in 69 | * @param pos The position to check at 70 | * @param state The block state at the given position in the given level 71 | * @param block The block to check 72 | * @return true if the given block can be sat one, false otherwhise 73 | */ 74 | private static boolean isValidBlock(Level level, BlockPos pos, BlockState state, Block block) { 75 | boolean isValid = block instanceof SlabBlock || block instanceof StairBlock || isModBlock(block); 76 | 77 | if (!isValid && block instanceof BedBlock) { 78 | state = level.getBlockState(pos.relative(state.getValue(BedBlock.PART) == BedPart.HEAD ? state.getValue(HorizontalDirectionalBlock.FACING).getOpposite() : state.getValue(HorizontalDirectionalBlock.FACING))); 79 | 80 | if (!(state.getBlock() instanceof BedBlock)) //it's half a bed! 81 | isValid = true; 82 | } 83 | 84 | return isValid; 85 | } 86 | 87 | /** 88 | * Checks whether the given block is a specific block from a mod. Used to support stairs/slabs from other mods that don't 89 | * work with Sit by default. 90 | * 91 | * @param block The block to check 92 | * @return true if the block is a block to additionally support, false otherwise 93 | */ 94 | private static boolean isModBlock(Block block) { 95 | /* 96 | * if(ModList.get().isLoaded("immersiveengineering") && b instanceof 97 | * blusunrize.immersiveengineering.common.blocks.BlockIESlab) return true; else if(ModList.get().isLoaded("snowvariants") && 98 | * block instanceof trikzon.snowvariants.blocks.SnowSlab) return true; else 99 | */ return false; 100 | } 101 | 102 | /** 103 | * Returns whether or not the player is close enough to the block to be able to sit on it 104 | * 105 | * @param player The player 106 | * @param pos The position of the block to sit on 107 | * @return true if the player is close enough, false otherwhise 108 | */ 109 | private static boolean isPlayerInRange(Player player, BlockPos pos) { 110 | BlockPos playerPos = player.blockPosition(); 111 | int blockReachDistance = Configuration.CONFIG.blockReachDistance.get(); 112 | 113 | if (blockReachDistance == 0) //player has to stand on top of the block 114 | return playerPos.getY() - pos.getY() <= 1 && playerPos.getX() - pos.getX() == 0 && playerPos.getZ() - pos.getZ() == 0; 115 | 116 | pos = BlockPos.containing(pos.getX() + 0.5D, pos.getY() + 0.5D, pos.getZ() + 0.5D); 117 | 118 | AABB range = new AABB(pos.getX() + blockReachDistance, pos.getY() + blockReachDistance, pos.getZ() + blockReachDistance, pos.getX() - blockReachDistance, pos.getY() - blockReachDistance, pos.getZ() - blockReachDistance); 119 | 120 | playerPos = BlockPos.containing(playerPos.getX() + 0.5D, playerPos.getY() + 0.5D, playerPos.getZ() + 0.5D); 121 | return range.minX <= playerPos.getX() && range.minY <= playerPos.getY() && range.minZ <= playerPos.getZ() && range.maxX >= playerPos.getX() && range.maxY >= playerPos.getY() && range.maxZ >= playerPos.getZ(); 122 | } 123 | } 124 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # 4 | # Copyright © 2015-2021 the original authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | # SPDX-License-Identifier: Apache-2.0 19 | # 20 | 21 | ############################################################################## 22 | # 23 | # Gradle start up script for POSIX generated by Gradle. 24 | # 25 | # Important for running: 26 | # 27 | # (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is 28 | # noncompliant, but you have some other compliant shell such as ksh or 29 | # bash, then to run this script, type that shell name before the whole 30 | # command line, like: 31 | # 32 | # ksh Gradle 33 | # 34 | # Busybox and similar reduced shells will NOT work, because this script 35 | # requires all of these POSIX shell features: 36 | # * functions; 37 | # * expansions «$var», «${var}», «${var:-default}», «${var+SET}», 38 | # «${var#prefix}», «${var%suffix}», and «$( cmd )»; 39 | # * compound commands having a testable exit status, especially «case»; 40 | # * various built-in commands including «command», «set», and «ulimit». 41 | # 42 | # Important for patching: 43 | # 44 | # (2) This script targets any POSIX shell, so it avoids extensions provided 45 | # by Bash, Ksh, etc; in particular arrays are avoided. 46 | # 47 | # The "traditional" practice of packing multiple parameters into a 48 | # space-separated string is a well documented source of bugs and security 49 | # problems, so this is (mostly) avoided, by progressively accumulating 50 | # options in "$@", and eventually passing that to Java. 51 | # 52 | # Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, 53 | # and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; 54 | # see the in-line comments for details. 55 | # 56 | # There are tweaks for specific operating systems such as AIX, CygWin, 57 | # Darwin, MinGW, and NonStop. 58 | # 59 | # (3) This script is generated from the Groovy template 60 | # https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt 61 | # within the Gradle project. 62 | # 63 | # You can find Gradle at https://github.com/gradle/gradle/. 64 | # 65 | ############################################################################## 66 | 67 | # Attempt to set APP_HOME 68 | 69 | # Resolve links: $0 may be a link 70 | app_path=$0 71 | 72 | # Need this for daisy-chained symlinks. 73 | while 74 | APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path 75 | [ -h "$app_path" ] 76 | do 77 | ls=$( ls -ld "$app_path" ) 78 | link=${ls#*' -> '} 79 | case $link in #( 80 | /*) app_path=$link ;; #( 81 | *) app_path=$APP_HOME$link ;; 82 | esac 83 | done 84 | 85 | # This is normally unused 86 | # shellcheck disable=SC2034 87 | APP_BASE_NAME=${0##*/} 88 | # Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) 89 | APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit 90 | 91 | # Use the maximum available, or set MAX_FD != -1 to use that value. 92 | MAX_FD=maximum 93 | 94 | warn () { 95 | echo "$*" 96 | } >&2 97 | 98 | die () { 99 | echo 100 | echo "$*" 101 | echo 102 | exit 1 103 | } >&2 104 | 105 | # OS specific support (must be 'true' or 'false'). 106 | cygwin=false 107 | msys=false 108 | darwin=false 109 | nonstop=false 110 | case "$( uname )" in #( 111 | CYGWIN* ) cygwin=true ;; #( 112 | Darwin* ) darwin=true ;; #( 113 | MSYS* | MINGW* ) msys=true ;; #( 114 | NONSTOP* ) nonstop=true ;; 115 | esac 116 | 117 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 118 | 119 | 120 | # Determine the Java command to use to start the JVM. 121 | if [ -n "$JAVA_HOME" ] ; then 122 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 123 | # IBM's JDK on AIX uses strange locations for the executables 124 | JAVACMD=$JAVA_HOME/jre/sh/java 125 | else 126 | JAVACMD=$JAVA_HOME/bin/java 127 | fi 128 | if [ ! -x "$JAVACMD" ] ; then 129 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 130 | 131 | Please set the JAVA_HOME variable in your environment to match the 132 | location of your Java installation." 133 | fi 134 | else 135 | JAVACMD=java 136 | if ! command -v java >/dev/null 2>&1 137 | then 138 | die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 139 | 140 | Please set the JAVA_HOME variable in your environment to match the 141 | location of your Java installation." 142 | fi 143 | fi 144 | 145 | # Increase the maximum file descriptors if we can. 146 | if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then 147 | case $MAX_FD in #( 148 | max*) 149 | # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. 150 | # shellcheck disable=SC2039,SC3045 151 | MAX_FD=$( ulimit -H -n ) || 152 | warn "Could not query maximum file descriptor limit" 153 | esac 154 | case $MAX_FD in #( 155 | '' | soft) :;; #( 156 | *) 157 | # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. 158 | # shellcheck disable=SC2039,SC3045 159 | ulimit -n "$MAX_FD" || 160 | warn "Could not set maximum file descriptor limit to $MAX_FD" 161 | esac 162 | fi 163 | 164 | # Collect all arguments for the java command, stacking in reverse order: 165 | # * args from the command line 166 | # * the main class name 167 | # * -classpath 168 | # * -D...appname settings 169 | # * --module-path (only if needed) 170 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. 171 | 172 | # For Cygwin or MSYS, switch paths to Windows format before running java 173 | if "$cygwin" || "$msys" ; then 174 | APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) 175 | CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) 176 | 177 | JAVACMD=$( cygpath --unix "$JAVACMD" ) 178 | 179 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 180 | for arg do 181 | if 182 | case $arg in #( 183 | -*) false ;; # don't mess with options #( 184 | /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath 185 | [ -e "$t" ] ;; #( 186 | *) false ;; 187 | esac 188 | then 189 | arg=$( cygpath --path --ignore --mixed "$arg" ) 190 | fi 191 | # Roll the args list around exactly as many times as the number of 192 | # args, so each arg winds up back in the position where it started, but 193 | # possibly modified. 194 | # 195 | # NB: a `for` loop captures its iteration list before it begins, so 196 | # changing the positional parameters here affects neither the number of 197 | # iterations, nor the values presented in `arg`. 198 | shift # remove old arg 199 | set -- "$@" "$arg" # push replacement arg 200 | done 201 | fi 202 | 203 | 204 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 205 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 206 | 207 | # Collect all arguments for the java command: 208 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, 209 | # and any embedded shellness will be escaped. 210 | # * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be 211 | # treated as '${Hostname}' itself on the command line. 212 | 213 | set -- \ 214 | "-Dorg.gradle.appname=$APP_BASE_NAME" \ 215 | -classpath "$CLASSPATH" \ 216 | org.gradle.wrapper.GradleWrapperMain \ 217 | "$@" 218 | 219 | # Stop when "xargs" is not available. 220 | if ! command -v xargs >/dev/null 2>&1 221 | then 222 | die "xargs is not available" 223 | fi 224 | 225 | # Use "xargs" to parse quoted args. 226 | # 227 | # With -n1 it outputs one arg per line, with the quotes and backslashes removed. 228 | # 229 | # In Bash we could simply go: 230 | # 231 | # readarray ARGS < <( xargs -n1 <<<"$var" ) && 232 | # set -- "${ARGS[@]}" "$@" 233 | # 234 | # but POSIX shell has neither arrays nor command substitution, so instead we 235 | # post-process each arg (as a line of input to sed) to backslash-escape any 236 | # character that might be a shell metacharacter, then use eval to reverse 237 | # that process (while maintaining the separation between arguments), and wrap 238 | # the whole thing up as a single "set" statement. 239 | # 240 | # This will of course break if any of these variables contains a newline or 241 | # an unmatched quote. 242 | # 243 | 244 | eval "set -- $( 245 | printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | 246 | xargs -n1 | 247 | sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | 248 | tr '\n' ' ' 249 | )" '"$@"' 250 | 251 | exec "$JAVACMD" "$@" 252 | --------------------------------------------------------------------------------