Skip to content
This repository has been archived by the owner on Feb 10, 2025. It is now read-only.

Commit

Permalink
Update to 1.0.2 - now it is possible to teleport when torch, sign etc…
Browse files Browse the repository at this point in the history
…. is on the wall above elevator
  • Loading branch information
krystejj committed Jul 8, 2024
1 parent 0c4fd61 commit c62b2a1
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 38 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ org.gradle.jvmargs=-Xmx1G
org.gradle.parallel=true

# Mod Properties
mod_version=1.0.1+1.21
mod_version=1.0.2+1.21
maven_group=me.krystejj
archives_base_name=ase

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import me.krystejj.ase.ASESounds;
import me.krystejj.ase.config.ConfigManager;
import me.krystejj.ase.util.BlockStateUtils;
import me.krystejj.ase.util.PlayerUtils;
import me.krystejj.ase.util.TagUtils;
import net.minecraft.block.BlockState;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Text;
Expand Down Expand Up @@ -55,7 +55,7 @@ private static boolean checkPosForElevator(int y, World world, BlockPos playerBl
BlockState nextElevState = world.getBlockState(nextElevPos);

// Iterate further if the current block isn't an elevator
if (!TagUtils.isBlockElevator(nextElevState)) return false;
if (!BlockStateUtils.isBlockElevator(nextElevState)) return false;

// Check if there is a space for player to teleport
if (!PlayerUtils.canTpToElevator(world, nextElevPos)) {
Expand All @@ -69,7 +69,8 @@ private static boolean checkPosForElevator(int y, World world, BlockPos playerBl
private static void tpToElevator(ServerPlayerEntity player, BlockPos elevPos, BlockState elevState) {
// Calculate y coordinate for teleportation
double y = elevPos.getY() + 1;
if (TagUtils.isBlockCarpet(player.getWorld().getBlockState(elevPos.up()))) y += 0.06250d; // Carpet height
if (BlockStateUtils.isBlockCarpet(player.getWorld().getBlockState(elevPos.up())))
y += 0.06250d; // Carpet height

// Teleport a player
player.inTeleportationState = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import net.minecraft.registry.tag.TagKey;
import net.minecraft.util.Identifier;

public class TagUtils {
public class BlockStateUtils {
public static boolean isBlockElevator(BlockState blockState) {
return blockHasTag(blockState, Identifier.of(ASE.MOD_ID, "elevators"));
}
Expand All @@ -15,6 +15,10 @@ public static boolean isBlockCarpet(BlockState blockState) {
return blockHasTag(blockState, Identifier.of(ASE.MOD_ID, "carpets"));
}

public static boolean isAirOrWallBlock(BlockState blockState) {
return blockState.isAir() || blockHasTag(blockState, Identifier.of(ASE.MOD_ID, "wall_blocks"));
}

public static boolean blockHasTag(BlockState blockState, Identifier tagId) {
return blockState.streamTags().toList().contains(TagKey.of(RegistryKeys.BLOCK, tagId));
}
Expand Down
13 changes: 6 additions & 7 deletions src/main/java/me/krystejj/ase/util/PlayerUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,24 @@

import me.krystejj.ase.config.ConfigManager;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;

public class PlayerUtils {
public static boolean isStandingOnElevator(PlayerEntity player) {
BlockState standingBlockState = getStandingBlockState(player);
if (TagUtils.isBlockElevator(standingBlockState)) return true;
else return ConfigManager.config.allowCarpetsOnElevator && TagUtils.isBlockCarpet(standingBlockState)
&& TagUtils.isBlockElevator(getStandingBlockState(player, -1));
if (BlockStateUtils.isBlockElevator(standingBlockState)) return true;
else return ConfigManager.config.allowCarpetsOnElevator && BlockStateUtils.isBlockCarpet(standingBlockState)
&& BlockStateUtils.isBlockElevator(getStandingBlockState(player, -1));
}

public static boolean canTpToElevator(World world, BlockPos elevPos) {
BlockState firstState = world.getBlockState(elevPos.up());
BlockState secondState = world.getBlockState(elevPos.up(2));
if (firstState.isOf(Blocks.AIR) && secondState.isOf(Blocks.AIR)) return true;
else return ConfigManager.config.allowCarpetsOnElevator && TagUtils.isBlockCarpet(firstState)
&& secondState.isOf(Blocks.AIR);
if (BlockStateUtils.isAirOrWallBlock(firstState) && BlockStateUtils.isAirOrWallBlock(secondState)) return true;
else return ConfigManager.config.allowCarpetsOnElevator && BlockStateUtils.isBlockCarpet(firstState)
&& BlockStateUtils.isAirOrWallBlock(secondState);
}

public static BlockState getStandingBlockState(PlayerEntity player) {
Expand Down
10 changes: 10 additions & 0 deletions src/main/resources/data/ase/tags/block/torches.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"values": [
"minecraft:torch",
"minecraft:wall_torch",
"minecraft:soul_torch",
"minecraft:soul_wall_torch",
"minecraft:redstone_torch",
"minecraft:redstone_wall_torch"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"values": [
"minecraft:tripwire_hook",
"minecraft:tripwire"
]
}
11 changes: 11 additions & 0 deletions src/main/resources/data/ase/tags/block/wall_blocks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"values": [
"#ase:torches",
"#ase:tripwire_components",
"#minecraft:pressure_plates",
"#minecraft:rails",
"#minecraft:banners",
"#minecraft:signs",
"minecraft:redstone_wire"
]
}
6 changes: 0 additions & 6 deletions src/main/resources/data/ase/tags/item/carpets.json

This file was deleted.

20 changes: 0 additions & 20 deletions src/main/resources/data/ase/tags/item/elevators.json

This file was deleted.

0 comments on commit c62b2a1

Please # to comment.