This repository has been archived on 2023-11-26. You can view files and clone it, but cannot push or open issues or pull requests.
RelicCraft/src/main/java/com/thebrokenrail/reliccraft/block/TeleportationRestrictorBloc...

43 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.Material;
import net.minecraft.block.MaterialColor;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.inventory.Inventory;
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, Inventory inventory) {
int radius = !inventory.getInvStack(0).isEmpty() ? 128 : 0;
Box box = new Box(pos).expand(radius);
List<LivingEntity> list = world.getNonSpectatingEntities(LivingEntity.class, box);
for (LivingEntity entity : list) {
((TeleportingEntity) entity).resetTeleportCooldown();
}
}
@Override
public void grantAdvancement(PlayerEntity player) {
RelicCraft.ACTIVATE_TELEPORTATION_RESTRICTOR_CRITERION.trigger((ServerPlayerEntity) player);
}
}