Skip to content

Commit

Permalink
fix!: Remove restrictToCreative and generatedWaystonesUnbreakable opt…
Browse files Browse the repository at this point in the history
…ions, remove all breaking and placement restrictions #776
  • Loading branch information
BlayTheNinth committed Dec 20, 2023
1 parent e2bcf2f commit 7090572
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -149,15 +149,6 @@ protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockSt
builder.add(FACING, WATERLOGGED, ORIGIN);
}

@Override
public float getDestroyProgress(BlockState state, Player player, BlockGetter world, BlockPos pos) {
if (!WaystonePermissionManager.mayBreakWaystone(player, world, pos)) {
return -1f;
}

return super.getDestroyProgress(state, player, world, pos);
}

@Override
public boolean canSurvive(BlockState state, LevelReader world, BlockPos pos) {
if (!isDoubleBlock(state)) {
Expand All @@ -175,10 +166,6 @@ public boolean canSurvive(BlockState state, LevelReader world, BlockPos pos) {
@Nullable
@Override
public BlockState getStateForPlacement(BlockPlaceContext context) {
if (!WaystonePermissionManager.mayPlaceWaystone(context.getPlayer())) {
return null;
}

Level world = context.getLevel();
BlockPos pos = context.getClickedPos();
FluidState fluidState = world.getFluidState(pos);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,18 +84,10 @@ public static class XpCost {
}

public static class Restrictions {
@Synced
@Comment("If enabled, only creative players can place, edit or break waystones. This does NOT disable the crafting recipe.")
public boolean restrictToCreative = false;

@Synced
@Comment("If enabled, only the owner of a waystone (the one who placed it) can rename it.")
public boolean restrictRenameToOwner = false;

@Synced
@Comment("If enabled, waystones generated in worldgen are unbreakable.")
public boolean generatedWaystonesUnbreakable = false;

@Synced
@Comment("Set to ENABLED to have nearby pets teleport with you. Set to SAME_DIMENSION to have nearby pets teleport with you only if you're not changing dimensions. Set to DISABLED to disable.")
public TransportPets transportPets = TransportPets.SAME_DIMENSION;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,46 +3,12 @@
import net.blay09.mods.waystones.api.IWaystone;
import net.blay09.mods.waystones.api.WaystoneVisibility;
import net.blay09.mods.waystones.config.WaystonesConfig;
import net.minecraft.core.BlockPos;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
import org.jetbrains.annotations.Nullable;

public class WaystonePermissionManager {

public static boolean mayBreakWaystone(Player player, BlockGetter world, BlockPos pos) {
if (WaystonesConfig.getActive().restrictions.restrictToCreative && !player.getAbilities().instabuild) {
return false;
}

return WaystoneManager.get(player.getServer()).getWaystoneAt(world, pos).map(waystone -> {

if (!player.getAbilities().instabuild) {
if (waystone.wasGenerated() && WaystonesConfig.getActive().restrictions.generatedWaystonesUnbreakable) {
return false;
}

boolean isGlobal = waystone.getVisibility() == WaystoneVisibility.GLOBAL;
boolean mayBreakGlobalWaystones = !WaystonesConfig.getActive().restrictions.globalWaystoneSetupRequiresCreativeMode;
return !isGlobal || mayBreakGlobalWaystones;
}


return true;
}).orElse(true);

}

public static boolean mayPlaceWaystone(@Nullable Player player) {
return !WaystonesConfig.getActive().restrictions.restrictToCreative || (player != null && player.getAbilities().instabuild);
}

public static WaystoneEditPermissions mayEditWaystone(Player player, Level world, IWaystone waystone) {
if (WaystonesConfig.getActive().restrictions.restrictToCreative && !player.getAbilities().instabuild) {
return WaystoneEditPermissions.NOT_CREATIVE;
}

if (WaystonesConfig.getActive().restrictions.restrictRenameToOwner && !waystone.isOwner(player)) {
return WaystoneEditPermissions.NOT_THE_OWNER;
}
Expand Down

0 comments on commit 7090572

Please sign in to comment.