Search in sources :

Example 26 with TileEntityColonyBuilding

use of com.minecolonies.api.tileentities.TileEntityColonyBuilding in project minecolonies by ldtteam.

the class CreateColonyMessage method onExecute.

@Override
public void onExecute(final NetworkEvent.Context ctxIn, final boolean isLogicalServer) {
    final ServerPlayerEntity sender = ctxIn.getSender();
    final World world = ctxIn.getSender().level;
    if (sender == null) {
        return;
    }
    if (sender.getStats().getValue(Stats.ITEM_USED.get(ModItems.supplyChest)) <= 0 && !sender.isCreative()) {
        LanguageHandler.sendPlayerMessage(sender, "com.minecolonies.coremod.supplyneed");
        return;
    }
    final IColony colony = IColonyManager.getInstance().getClosestColony(world, townHall);
    String style = Constants.DEFAULT_STYLE;
    final TileEntity tileEntity = world.getBlockEntity(townHall);
    if (!(tileEntity instanceof TileEntityColonyBuilding)) {
        LanguageHandler.sendPlayerMessage(sender, "com.minecolonies.coremod.gui.colony.create.notileentity");
        return;
    }
    if (!((AbstractTileEntityColonyBuilding) tileEntity).getStyle().isEmpty()) {
        style = ((AbstractTileEntityColonyBuilding) tileEntity).getStyle();
    }
    if (MineColonies.getConfig().getServer().restrictColonyPlacement.get()) {
        final double spawnDistance = Math.sqrt(BlockPosUtil.getDistanceSquared2D(townHall, ((ServerWorld) world).getSharedSpawnPos()));
        if (spawnDistance < MineColonies.getConfig().getServer().minDistanceFromWorldSpawn.get()) {
            if (!world.isClientSide) {
                LanguageHandler.sendPlayerMessage(sender, CANT_PLACE_COLONY_TOO_CLOSE_TO_SPAWN, MineColonies.getConfig().getServer().minDistanceFromWorldSpawn.get());
            }
            return;
        } else if (spawnDistance > MineColonies.getConfig().getServer().maxDistanceFromWorldSpawn.get()) {
            if (!world.isClientSide) {
                LanguageHandler.sendPlayerMessage(sender, CANT_PLACE_COLONY_TOO_FAR_FROM_SPAWN, MineColonies.getConfig().getServer().maxDistanceFromWorldSpawn.get());
            }
            return;
        }
    }
    if (colony != null && !IColonyManager.getInstance().isFarEnoughFromColonies(world, townHall)) {
        LanguageHandler.sendPlayerMessage(sender, "com.minecolonies.coremod.gui.colony.denied.tooclose", colony.getName());
        return;
    }
    final IColony ownedColony = IColonyManager.getInstance().getIColonyByOwner(world, sender);
    if (ownedColony == null) {
        IColonyManager.getInstance().createColony(world, townHall, sender, style);
        IColonyManager.getInstance().getIColonyByOwner(world, sender).getBuildingManager().addNewBuilding((TileEntityColonyBuilding) tileEntity, world);
        LanguageHandler.sendPlayerMessage((PlayerEntity) sender, "com.minecolonies.coremod.progress.colony_founded");
        return;
    }
    LanguageHandler.sendPlayerMessage((PlayerEntity) sender, "com.minecolonies.coremod.gui.colony.create.failed");
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) ServerWorld(net.minecraft.world.server.ServerWorld) AbstractTileEntityColonyBuilding(com.minecolonies.api.tileentities.AbstractTileEntityColonyBuilding) AbstractTileEntityColonyBuilding(com.minecolonies.api.tileentities.AbstractTileEntityColonyBuilding) TileEntityColonyBuilding(com.minecolonies.api.tileentities.TileEntityColonyBuilding) IColony(com.minecolonies.api.colony.IColony) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) ServerWorld(net.minecraft.world.server.ServerWorld) World(net.minecraft.world.World)

Aggregations

TileEntityColonyBuilding (com.minecolonies.api.tileentities.TileEntityColonyBuilding)26 TileEntity (net.minecraft.tileentity.TileEntity)22 AbstractTileEntityColonyBuilding (com.minecolonies.api.tileentities.AbstractTileEntityColonyBuilding)18 NotNull (org.jetbrains.annotations.NotNull)14 ItemStack (net.minecraft.item.ItemStack)9 Nullable (org.jetbrains.annotations.Nullable)8 IBuilding (com.minecolonies.api.colony.buildings.IBuilding)6 CompoundNBT (net.minecraft.nbt.CompoundNBT)6 AbstractBlockHut (com.minecolonies.api.blocks.AbstractBlockHut)4 IColony (com.minecolonies.api.colony.IColony)4 TileEntityRack (com.minecolonies.api.tileentities.TileEntityRack)4 ICitizenData (com.minecolonies.api.colony.ICitizenData)2 IWareHouse (com.minecolonies.api.colony.buildings.workerbuildings.IWareHouse)2 ChatPriority (com.minecolonies.api.colony.interactionhandling.ChatPriority)2 ILocation (com.minecolonies.api.colony.requestsystem.location.ILocation)2 IRequest (com.minecolonies.api.colony.requestsystem.request.IRequest)2 IRequestable (com.minecolonies.api.colony.requestsystem.requestable.IRequestable)2 Delivery (com.minecolonies.api.colony.requestsystem.requestable.deliveryman.Delivery)2 IDeliverymanRequestable (com.minecolonies.api.colony.requestsystem.requestable.deliveryman.IDeliverymanRequestable)2 ItemStorage (com.minecolonies.api.crafting.ItemStorage)2