44 lines
1.5 KiB
Java
44 lines
1.5 KiB
Java
package com.thebrokenrail.reliccraft.block;
|
|
|
|
import com.thebrokenrail.reliccraft.RelicCraft;
|
|
import net.fabricmc.fabric.api.block.FabricBlockSettings;
|
|
import net.minecraft.block.BlockState;
|
|
import net.minecraft.block.Material;
|
|
import net.minecraft.block.MaterialColor;
|
|
import net.minecraft.entity.Entity;
|
|
import net.minecraft.entity.player.PlayerEntity;
|
|
import net.minecraft.server.network.ServerPlayerEntity;
|
|
import net.minecraft.util.math.BlockPos;
|
|
import net.minecraft.util.math.Box;
|
|
import net.minecraft.world.World;
|
|
|
|
import java.util.List;
|
|
|
|
public class TeleportationRestrictorBlock extends AbstractDragonEggHolderBlock {
|
|
public interface TeleportingEntity {
|
|
boolean cannotTeleport();
|
|
|
|
void resetTeleportCooldown();
|
|
}
|
|
|
|
public TeleportationRestrictorBlock() {
|
|
super(FabricBlockSettings.of(Material.STONE, MaterialColor.BLACK).strength(50.0F, 1200.0F).build());
|
|
}
|
|
|
|
@Override
|
|
public void tick(World world, BlockPos pos) {
|
|
BlockState state = world.getBlockState(pos);
|
|
int radius = state.get(ACTIVE) ? 128 : 0;
|
|
Box box = new Box(pos).expand(radius);
|
|
List<Entity> list = world.getEntities(Entity.class, box, null);
|
|
for (Entity entity : list) {
|
|
((TeleportingEntity) entity).resetTeleportCooldown();
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void grantAdvancement(PlayerEntity player) {
|
|
RelicCraft.ACTIVATE_TELEPORTATION_RESTRICTOR_CRITERION.trigger((ServerPlayerEntity) player);
|
|
}
|
|
}
|